mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
statistics2.cgi: improve nodesToday handling, add submissions per day
git-svn-id: https://svn.fhem.de/fhem/trunk@14880 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
9c2f29c54f
commit
29e14195f2
@ -87,17 +87,7 @@ sub insertDB() {
|
|||||||
my $geo = getLocation();
|
my $geo = getLocation();
|
||||||
|
|
||||||
my $decoded = decode_json($json);
|
my $decoded = decode_json($json);
|
||||||
if (defined($decoded->{'system'}{'revision'})) {
|
$json = revInfo($decoded) if (defined($decoded->{'system'}{'revision'}));
|
||||||
# replace revision number with revision date
|
|
||||||
my $rev = $decoded->{'system'}{'revision'} + 1;
|
|
||||||
if($rev =~ /^\d+$/) {
|
|
||||||
my $d = (split(/ /,qx(sudo -u rko /usr/bin/svn info -r $rev $fhemPathSvn|grep Date:)))[3];
|
|
||||||
return undef unless (defined($d));
|
|
||||||
my ($year,$mon,$mday) = split(/-/,$d);
|
|
||||||
$decoded->{'system'}{'revdate'} = mktime(0,0,7,$mday,($mon-1),($year-1900),0,0,0);
|
|
||||||
$json = encode_json $decoded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$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";
|
||||||
@ -133,13 +123,34 @@ sub getLocation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub revInfo($) {
|
||||||
|
# replace revision number with revision date
|
||||||
|
my ($decoded) = @_;
|
||||||
|
my $rev = $decoded->{'system'}{'revision'} + 1;
|
||||||
|
if($rev =~ /^\d+$/) {
|
||||||
|
my $d = (split(/ /,qx(sudo -u rko /usr/bin/svn info -r $rev $fhemPathSvn|grep Date:)))[3];
|
||||||
|
# my $d = (split(/ /,qx(/usr/bin/svn info -r $rev $fhemPathSvn|grep Date:)))[3];
|
||||||
|
return undef unless (defined($d));
|
||||||
|
my ($year,$mon,$mday) = split(/-/,$d);
|
||||||
|
$decoded->{'system'}{'revdate'} = mktime(0,0,7,$mday,($mon-1),($year-1900),0,0,0);
|
||||||
|
return encode_json $decoded;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sub add2total() {
|
sub add2total() {
|
||||||
|
|
||||||
|
my $today = strftime("%Y-%m-%d", localtime);
|
||||||
|
my $tnYear = strftime("%Y", localtime);
|
||||||
|
my $nodesToday = $dbh->selectrow_array("SELECT count(*) FROM jsonNodes where lastSeen like '$today%'");
|
||||||
|
$nodesToday //= 1;
|
||||||
|
|
||||||
my $sql = q(SELECT * from jsonNodes where uniqueID = 'databaseInfo');
|
my $sql = q(SELECT * from jsonNodes where uniqueID = 'databaseInfo');
|
||||||
my $sth = $dbh->prepare( $sql );
|
my $sth = $dbh->prepare( $sql );
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
my @dbInfo = $sth->fetchrow_array();
|
my @dbInfo = $sth->fetchrow_array();
|
||||||
my $dbInfo = decode_json $dbInfo[3];
|
my $dbInfo = decode_json $dbInfo[3];
|
||||||
$dbInfo->{'submissionsTotal'}++;
|
$dbInfo->{'submissionsTotal'}++;
|
||||||
|
$dbInfo->{'submissionsPerDay'}{$tnYear}{$today} = ($nodesToday-1); # do not count dbInfo
|
||||||
my $new = encode_json $dbInfo;
|
my $new = encode_json $dbInfo;
|
||||||
|
|
||||||
$sth = $dbh->prepare(q{INSERT OR REPLACE INTO jsonNodes(uniqueID,json) VALUES(?,?)});
|
$sth = $dbh->prepare(q{INSERT OR REPLACE INTO jsonNodes(uniqueID,json) VALUES(?,?)});
|
||||||
@ -155,8 +166,7 @@ sub doAggregate() {
|
|||||||
die "Cannot connect: $DBI::errstr";
|
die "Cannot connect: $DBI::errstr";
|
||||||
|
|
||||||
my $today = strftime("%Y-%m-%d", localtime);
|
my $today = strftime("%Y-%m-%d", localtime);
|
||||||
my $nodesToday = $dbh->selectrow_array("SELECT count(*) FROM jsonNodes where lastSeen like '$today%'");
|
my $tnYear = strftime("%Y", localtime);
|
||||||
$nodesToday //= 0;
|
|
||||||
|
|
||||||
my ($sql,@dbInfo,%countAll,$decoded,$res);
|
my ($sql,@dbInfo,%countAll,$decoded,$res);
|
||||||
|
|
||||||
@ -170,6 +180,9 @@ sub doAggregate() {
|
|||||||
my $started = substr($dbInfo->{'submissionsSince'},0,10);
|
my $started = substr($dbInfo->{'submissionsSince'},0,10);
|
||||||
my $nodesTotal = $dbInfo->{'submissionsTotal'};
|
my $nodesTotal = $dbInfo->{'submissionsTotal'};
|
||||||
my $nodes12 = 0;
|
my $nodes12 = 0;
|
||||||
|
my $nodesToday = $dbInfo->{'submissionsPerDay'}{$tnYear}{$today}
|
||||||
|
if defined($dbInfo->{$tnYear}{$today});
|
||||||
|
$nodesToday //= 0;
|
||||||
|
|
||||||
map { $countAll{system}{age}{$_} = 0; } (0,7,30,180,365,999);
|
map { $countAll{system}{age}{$_} = 0; } (0,7,30,180,365,999);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user