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

statistics2.cgi: add nodesToday

git-svn-id: https://svn.fhem.de/fhem/trunk@14766 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2017-07-22 19:00:23 +00:00
parent 0b1de8a8c0
commit 0f4c235ee2

View File

@ -31,7 +31,7 @@ use DBI;
use CGI qw(:standard Vars); use CGI qw(:standard Vars);
#use Data::Dumper; #use Data::Dumper;
use JSON; use JSON;
use POSIX qw(mktime); use POSIX qw(mktime strftime);
use Time::HiRes qw(time); use Time::HiRes qw(time);
use lib "./lib"; use lib "./lib";
@ -154,6 +154,10 @@ sub doAggregate() {
$dbh = DBI->connect($dsn,"","", { RaiseError => 1, ShowErrorStatement => 1 }) || $dbh = DBI->connect($dsn,"","", { RaiseError => 1, ShowErrorStatement => 1 }) ||
die "Cannot connect: $DBI::errstr"; die "Cannot connect: $DBI::errstr";
my $today = strftime("%Y-%m-%d", localtime);
my $nodesToday = $dbh->selectrow_array("SELECT count(*) FROM jsonNodes where lastSeen like '$today%'");
$nodesToday //= 0;
my ($sql,@dbInfo,%countAll,$decoded,$res); my ($sql,@dbInfo,%countAll,$decoded,$res);
$sql = q(SELECT * from jsonNodes where uniqueID = 'databaseInfo'); $sql = q(SELECT * from jsonNodes where uniqueID = 'databaseInfo');
@ -202,7 +206,6 @@ sub doAggregate() {
if (defined($decoded->{'system'}{'revdate'})){ if (defined($decoded->{'system'}{'revdate'})){
$res = $decoded->{'system'}{'revdate'}; $res = $decoded->{'system'}{'revdate'};
# my $age = sprintf("%.1f",(time - $res)/86400);
my $age = int((time - $res)/86400); my $age = int((time - $res)/86400);
$countAll{'system'}{'age'}{'0'}++ if ($age <= 1); $countAll{'system'}{'age'}{'0'}++ if ($age <= 1);
$countAll{'system'}{'age'}{'7'}++ if ($age > 1 && $age <= 7); $countAll{'system'}{'age'}{'7'}++ if ($age > 1 && $age <= 7);
@ -233,7 +236,7 @@ sub doAggregate() {
$dbh->disconnect(); $dbh->disconnect();
return ($updated,$started,$nodesTotal,$nodes12,%countAll); return ($updated,$started,$nodesTotal,$nodes12,$nodesToday,%countAll);
} }
# ---------- do the presentation ---------- # ---------- do the presentation ----------
@ -243,13 +246,14 @@ sub viewStatistics() {
my $q = new CGI; my $q = new CGI;
$q->charset('utf-8'); $q->charset('utf-8');
if($data{type} && $data{type} eq "json") { # return result als JSON object if($data{type} && $data{type} eq "json") { # return result als JSON object
my ($updated,$started,$nodesTotal,$nodes12,%countAll) = doAggregate(); my ($updated,$started,$nodesTotal,$nodes12,$nodesToday,%countAll) = doAggregate();
my $json = encode_json({updated => $updated, my $json = encode_json({updated => $updated,
generated => time()-$start, generated => time()-$start,
started => $started, started => $started,
nodesTotal => $nodesTotal, nodesTotal => $nodesTotal,
nodes12 => $nodes12, nodes12 => $nodes12,
nodesToday => $nodesToday,
data => \%countAll data => \%countAll
}); });
print $q->header( -type => "application/json", print $q->header( -type => "application/json",