2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-13 17:26:34 +00:00

statistics: rework started

- bring back colored bars in legend
- remove dummy and eventTypes from Top10

git-svn-id: https://svn.fhem.de/fhem/trunk@8248 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2015-03-20 15:15:58 +00:00
parent 3cdd32543b
commit 5a163788a9
2 changed files with 110 additions and 30 deletions

View File

@ -0,0 +1,75 @@
body { border:0; background-color: #FFFFE7;
font-family:Arial, sans-serif; font-size:16px;}
input { font-family:Arial, sans-serif; font-size:16px; }
select { font-family:Arial, sans-serif; font-size:16px; }
#logo { margin-top:10px; margin-left:20px; width:120px; height:132px;
background-image:url(fhemicon.png); }
#menu { margin-top:10px; margin-left:20px; width:140px; }
#menuScrollArea { width: 175px; left:0px; top:0px; height:100%;
position:fixed; overflow-x:hidden; overflow-y:auto; }
#hdr { position:absolute; top:10px; left:180px; }
#content { position:absolute; top:50px; left:180px; bottom:20px; right:10px; }
/*#rightcontent { position:absolute; top:0px; left:0px; bottom:20px; right:10px; }*/
#connect_err { background-color: #000000; color: #FFFFFF;
position:absolute; top:0px; left:40px; z-index: 10; }
.devType { padding-top:20px; }
a { color: #278727; }
img { border-style: none; }
.wide { width:100%; }
table.block { border:1px solid gray; background: #F8F8E0; }
table.block tr.odd { background: #F0F0D8; }
table.block tr.sel { background: #F0F0D8; }
table { border-radius:8px; }
table.room { border:1px solid gray; width: 100%; background: #D7FFFF; }
table.room tr.sel { background: #A0FFFF; }
#right { position:absolute; top:0px; left:180px; width:80%; height:100%; }
h2,h3,h4 { color:#52865D; line-height:1.3;
margin-top:1.5em; font-family:Arial,Sans-serif; }
div.dist { padding-top:0.3em; }
button.dist { margin:10px; background:transparent; border:0px; cursor:pointer; }
a img { border-style:none; }
.col2 { text-align:center; }
/* detail-selector & slider */
.makeTable { display:inline; float:left; clear:left;
margin-top:10px; margin-bottom:20px;}
.makeSelect { display:inline; float:left; clear:left; }
select { margin-left:5px; margin-right:5px; }
.get,.set,.attr { margin-bottom:5px; float:left; }
.slider { float:left; width:250px; height:26px; }
/* detail only */
.makeSelect .slider {background:#F0F0D8; border-radius:8px;}
/* timepicker */
.set .set { margin-bottom:2px; margin-top:3px; }
.handle { position:relative; cursor:pointer; width:50px;
height:20px; line-height:20px;
-webkit-user-select:none; -moz-user-select:none; -user-select:none;
border:3px solid; color:#278727; text-align:center; }
.downText { margin-top:2px; }
pre { white-space: pre-wrap; }
#svg { height:32px; width:32px; fill:#278727; }
#svg.on,svg.FS20_on { fill:orange; }
/* next lines are for remotecontrol */
.rc_body { border-style: solid; border-color: gray; border-width: 2px; padding: 5px;
background: #C8C8B0; font-size:6px;}
.rc_button { padding: 5px 7px;}
.rc_button img { border-style: solid; border-width: 1px; border-color: transparent; }
.rc_button img:active { border-color: gray; }
.changed { color:red; }

View File

@ -1,11 +1,12 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
################################################################ ################################################################
# $Id$ # $Id$
# vim: ts=2:et
# #
# (c) 2012 Copyright: Martin Fischer (m_fischer at gmx dot de) # (c) 2012 Copyright: Martin Fischer (m_fischer at gmx dot de)
# All rights reserved # All rights reserved
# #
# Rework started: 2015 by betateilchen
#
# This script free software; you can redistribute it and/or modify # This script free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
@ -69,20 +70,20 @@ my %tblColName;
my %tblSum; my %tblSum;
my %tblCnt; my %tblCnt;
# cascading style sheet
my $css = "http://fhem.de/../css/style.css";
# exclude modules from top 10 graph
my $excludeFromTop10modules = "at autocreate notify telnet weblink FileLog FHEMWEB Global SUNRISE_EL";
my $excludeFromTop10definitions = "at autocreate notify telnet weblink FileLog FHEMWEB Global SUNRISE_EL";
# directory cointains databases # directory cointains databases
my $datadir = "./data"; my $datadir = "./data";
# cascading style sheet
#my $css = "http://fhem.de/../css/style.css";
my $css = "$datadir/style.css";
# geo ip database file from http://www.maxmind.com/download/geoip/database/ # geo ip database file from http://www.maxmind.com/download/geoip/database/
# should be updated once per month # should be updated once per month
my $geoIPDat = "$datadir/GeoLiteCity.dat"; my $geoIPDat = "$datadir/GeoLiteCity.dat";
# exclude modules from top 10
my $excludeModules = "at autocreate dummy eventTypes notify telnet weblink FileLog FHEMWEB Global SUNRISE_EL";
# database # database
my $dbf = "$datadir/fhem_statistics_db.sqlite"; my $dbf = "$datadir/fhem_statistics_db.sqlite";
my $dsn = "dbi:SQLite:dbname=$dbf"; my $dsn = "dbi:SQLite:dbname=$dbf";
@ -114,23 +115,22 @@ sub viewStatistics() {
my $cArch = drawPieChart("nodes","arch","Architecture",390,300,"chart_arch"); my $cArch = drawPieChart("nodes","arch","Architecture",390,300,"chart_arch");
my $cRelease = drawPieChart("nodes","release","FHEM Release",390,300,"chart_release"); my $cRelease = drawPieChart("nodes","release","FHEM Release",390,300,"chart_release");
my $cPerl = drawPieChart("nodes","perl","Perl Version",390,300,"chart_perl"); my $cPerl = drawPieChart("nodes","perl","Perl Version",390,300,"chart_perl");
my $cModulesTop10 = drawColumnChartTop10Modules("modules","modulestop10",,"Used",800,300,"chart_modulestop10"); my $cModulesTop10 = drawColumnChartTop10Modules("modules","modulestop10",,"Used",800,300,"chart_modulestop10");
my $cModDefTop10 = drawColumnChartTop10ModDef("modules","definitions","Definitions",800,300,"chart_moddeftop10"); my $cModDefTop10 = drawColumnChartTop10ModDef("modules","definitions","Definitions",800,300,"chart_moddeftop10");
#my $cModules = drawBarChartModules("modules","modules","Used","Definitions",800,600,"chart_modules"); #my $cModules = drawBarChartModules("modules","modules","Used","Definitions",800,600,"chart_modules");
my $mWorld = drawRegionsMap("locations","countryname","world","map_world"); my $mWorld = drawRegionsMap("locations","countryname","world","map_world");
my $mEU = drawRegionsMap("locations","countryname","150","map_europe"); my $mEU = drawRegionsMap("locations","countryname","150","map_europe");
my $mWesternEU = drawMarkersMap("locations","city","155","map_germany"); my $mWesternEU = drawMarkersMap("locations","city","155","map_germany");
my $tModules = drawTable3cols("modules","total_modules","string","Module","number","Used","number","Definitions","table_modules"); my $tModules = drawTable3cols("modules","total_modules","string","Module","number","Used","number","Definitions","table_modules");
#my $tModDef = drawTable("modules","total_moddef","string","Module","number","Definitions","table_moddef"); #my $tModDef = drawTable("modules","total_moddef","string","Module","number","Definitions","table_moddef");
my $tModels = drawTable2cols("models","total_models","string","Model","boolean","defined","table_models"); my $tModels = drawTable2cols("models","total_models","string","Model","boolean","defined","table_models");
my @res = $dbh->selectrow_array("SELECT created FROM db"); my @res = $dbh->selectrow_array("SELECT created FROM db");
my $since = "@res"; my $since = "@res";
print header; # print header;
print start_html( print start_html(
-title => 'fhem.de - Statistics', -title => 'fhem.de - Statistics',
-author => 'm_fischer@gmx.de', -author => 'm_fischer@gmx.de',
-base => 'true',
-style => {-src => $css}, -style => {-src => $css},
-meta => {'keywords' => 'fhem houseautomation statistics'}, -meta => {'keywords' => 'fhem houseautomation statistics'},
-script => [ -script => [
@ -149,17 +149,19 @@ sub viewStatistics() {
my ($nodes) = $dbh->selectrow_array("SELECT COUNT(uniqueID) FROM nodes"); my ($nodes) = $dbh->selectrow_array("SELECT COUNT(uniqueID) FROM nodes");
print <<END; print <<END;
<div id="menuScrollArea">
<div id="logo"></div> <div id="logo"></div>
<div id="menu"> <div id="menu">
<table><tbody><tr><td> <table><tr><td>
<table id="room"> <table class="room">
<tr><td></td></tr> <tr><td></td></tr>
<tr><td><b>back to</b></td></tr> <tr><td><b>back to</b></td></tr>
<tr><td></td></tr> <tr><td></td></tr>
<tr><td><a href="http://fhem.de">Homepage</a></td></tr> <tr><td><a href="http://fhem.de">Homepage</a></td></tr>
<tr><td></td></tr> <tr><td></td></tr>
</tbody></table> </table>
</td></tr></tbody></table> </td></tr></table>
</div>
</div> </div>
<div id="right"> <div id="right">
@ -184,11 +186,11 @@ sub viewStatistics() {
<h4>Top 10 of most commonly used modules<small><sup>1</sup></small>...</h4> <h4>Top 10 of most commonly used modules<small><sup>1</sup></small>...</h4>
<div id="chart_modulestop10" style="width: 800px; height: 300px; border: 1px solid black;"></div> <div id="chart_modulestop10" style="width: 800px; height: 300px; border: 1px solid black;"></div>
<small><sup>1</sup> excluded from graph: $excludeFromTop10modules</small> <small><sup>1</sup> excluded from graph: $excludeModules</small>
<h4>Top 10 of total definitions by module<small><sup>1</sup></small>...</h4> <h4>Top 10 of total definitions by module<small><sup>1</sup></small>...</h4>
<div id="chart_moddeftop10" style="width: 800px; height: 300px; border: 1px solid black;"></div> <div id="chart_moddeftop10" style="width: 800px; height: 300px; border: 1px solid black;"></div>
<small><sup>1</sup> excluded from graph: $excludeFromTop10definitions</small> <small><sup>1</sup> excluded from graph: $excludeModules</small>
<!-- <!--
// <h4>Top 20 of most commonly used modules (with total definitions by module)...</h4> // <h4>Top 20 of most commonly used modules (with total definitions by module)...</h4>
@ -218,7 +220,8 @@ sub viewStatistics() {
<div style="clear:both;"></div> <div style="clear:both;"></div>
<div id="footer" style="position:relative; left: -100px; text-align: center;"> <div id="footer" style="position:relative; left: -100px; text-align: center;">
<p><small>Layout by M. Fischer - Click <a href="http://www.fischer-net.de/kontakt.html">here</a> to leave your comments.</small></p> <p><small>Layout by M. Fischer<br/>
Rework 2015 started by betateilchen</small></p>
</div> </div>
</div> </div>
END END
@ -282,13 +285,14 @@ END
sub drawColumnChartTop10Modules(@) { sub drawColumnChartTop10Modules(@) {
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 LIMIT 0");
$sth->execute(); $sth->execute();
my $res = $sth->{NAME}; my $res = $sth->{NAME};
$sth->finish; $sth->finish;
my %hash = (); my %hash = ();
foreach my $column (@$res) { foreach my $column (@$res) {
next unless $column;
#my ($sum) = $dbh->selectrow_array("SELECT sum($column) FROM $table"); #my ($sum) = $dbh->selectrow_array("SELECT sum($column) FROM $table");
my ($sum) = $dbh->selectrow_array("SELECT count($column) FROM $table WHERE $column != 0"); my ($sum) = $dbh->selectrow_array("SELECT count($column) FROM $table WHERE $column != 0");
$hash{$column} = $sum; $hash{$column} = $sum;
@ -298,7 +302,7 @@ sub drawColumnChartTop10Modules(@) {
my $i=0; my $i=0;
foreach my $column (sort {$hash{$b} <=> $hash{$a}} keys %hash) { foreach my $column (sort {$hash{$b} <=> $hash{$a}} keys %hash) {
next if($column eq "uniqueID"); next if($column eq "uniqueID");
next if($excludeFromTop10modules =~ /$column/); next if($excludeModules =~ /$column/);
$data .= "\t['$column',$hash{$column}],\n"; $data .= "\t['$column',$hash{$column}],\n";
$i++; $i++;
last if($i == 10); last if($i == 10);
@ -330,14 +334,14 @@ END
sub drawColumnChartTop10ModDef(@) { 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 LIMIT 0");
$sth->execute(); $sth->execute();
my @res = @{$sth->{NAME}}; my @res = @{$sth->{NAME}};
$tblColName{$table} = \@res; $tblColName{$table} = \@res;
$sth->finish; $sth->finish;
my @cols = map { "sum($_),count($_)" } my @cols = map { "sum($_),count($_)" }
grep { $_ ne "uniqueID" } @res; grep { $_ ne "uniqueID" && $_ } @res;
$sth = $dbh->prepare("SELECT ".join(",",@cols)." FROM $table"); $sth = $dbh->prepare("SELECT ".join(",",@cols)." FROM $table");
$sth->execute(); $sth->execute();
my @row = $sth->fetchrow_array; my @row = $sth->fetchrow_array;
@ -354,7 +358,7 @@ sub drawColumnChartTop10ModDef(@) {
my $data; my $data;
my $i=0; my $i=0;
foreach my $column (sort {$sum{$b} <=> $sum{$a}} keys %sum) { foreach my $column (sort {$sum{$b} <=> $sum{$a}} keys %sum) {
next if($excludeFromTop10definitions =~ /$column/); next if($excludeModules =~ /$column/);
$data .= "\t['$column',$sum{$column}],\n"; $data .= "\t['$column',$sum{$column}],\n";
$i++; $i++;
last if($i == 10); last if($i == 10);
@ -438,6 +442,7 @@ sub drawMarkersMap(@) {
my %hash = (); my %hash = ();
foreach my $row (@$res) { foreach my $row (@$res) {
my ($value) = @$row; my ($value) = @$row;
$value =~ s/\'/_/g;
my ($count) = $dbh->selectrow_array("SELECT COUNT(*) FROM $table WHERE $column = '$value'"); my ($count) = $dbh->selectrow_array("SELECT COUNT(*) FROM $table WHERE $column = '$value'");
#$value = "Germany" if($value eq ""); #$value = "Germany" if($value eq "");
next if($value eq ""); next if($value eq "");
@ -692,7 +697,7 @@ sub insertDB() {
$sth = $dbh->prepare(q{DELETE FROM models WHERE uniqueID=?}); $sth = $dbh->prepare(q{DELETE FROM models WHERE uniqueID=?});
$sth->execute($uniqueID); $sth->execute($uniqueID);
# insert new modules of fhem node # insert new models of fhem node
$sth = $dbh->prepare("INSERT INTO models (uniqueID) VALUES (?)"); $sth = $dbh->prepare("INSERT INTO models (uniqueID) VALUES (?)");
$sth->execute($uniqueID); $sth->execute($uniqueID);