2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 16:56:54 +00:00

Current working version.

git-svn-id: https://svn.fhem.de/fhem/trunk@3297 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-06-17 17:45:34 +00:00
parent 384f72f334
commit d02c13592c

View File

@ -65,6 +65,10 @@ sub drawColumnChartTop10ModDef(@);
sub drawBarChartModules(@); sub drawBarChartModules(@);
sub viewStatistics(); sub viewStatistics();
my %tblColName;
my %tblSum;
my %tblCnt;
# cascading style sheet # cascading style sheet
my $css = "http://fhem.de/../css/style.css"; my $css = "http://fhem.de/../css/style.css";
@ -328,20 +332,30 @@ sub drawColumnChartTop10ModDef(@) {
my ($table,$postfix,$rowtitle,$width,$height,$divID) = @_; my ($table,$postfix,$rowtitle,$width,$height,$divID) = @_;
$sth = $dbh->prepare("SELECT * FROM $table where 1=0"); $sth = $dbh->prepare("SELECT * FROM $table where 1=0");
$sth->execute(); $sth->execute();
my $res = $sth->{NAME}; my @res = @{$sth->{NAME}};
$tblColName{$table} = \@res;
$sth->finish; $sth->finish;
my %hash = ();
foreach my $column (@$res) { my @cols = map { "sum($_),count($_)" }
my ($sum) = $dbh->selectrow_array("SELECT sum($column) FROM $table"); grep { $_ ne "uniqueID" } @res;
$hash{$column} = $sum; $sth = $dbh->prepare("SELECT ".join(",",@cols)." FROM $table");
$sth->execute();
my @row = $sth->fetchrow_array;
my %sum = ();
my %cnt = ();
for(my $idx = 0; $idx < @res; $idx++) {
$sum{$res[$idx]} = $row[2*$idx];
$cnt{$res[$idx]} = $row[2*$idx+1];
} }
$sth->finish;
$tblSum{$table} = \%sum;
$tblCnt{$table} = \%cnt;
my $data; my $data;
my $i=0; my $i=0;
foreach my $column (sort {$hash{$b} <=> $hash{$a}} keys %hash) { foreach my $column (sort {$sum{$b} <=> $sum{$a}} keys %sum) {
next if($column eq "uniqueID");
next if($excludeFromTop10definitions =~ /$column/); next if($excludeFromTop10definitions =~ /$column/);
$data .= "\t['$column',$hash{$column}],\n"; $data .= "\t['$column',$sum{$column}],\n";
$i++; $i++;
last if($i == 10); last if($i == 10);
} }
@ -577,6 +591,7 @@ sub drawTable3cols(@) {
my %hash; my %hash;
while(my $h = $sth->fetchrow_hashref) { while(my $h = $sth->fetchrow_hashref) {
foreach my $k (keys %{$h}) { foreach my $k (keys %{$h}) {
next if($k eq "uniqueID");
$hash{$k}{count}++ if($h->{$k}); $hash{$k}{count}++ if($h->{$k});
$hash{$k}{sum} += $h->{$k} if($h->{$k}); $hash{$k}{sum} += $h->{$k} if($h->{$k});
} }