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

statistics2.cgi: code cleanup, prepare for release

git-svn-id: https://svn.fhem.de/fhem/trunk@14383 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2017-05-26 16:48:23 +00:00
parent f88384da35
commit 9d171bf850

View File

@ -1,9 +1,13 @@
#!/usr/bin/perl -w #!/usr/bin/perl -w
# $Id$
# ---------------------------------------- =for comment
# database insert provided by betateilchen
# ---------------------------------------- $Id$
# ----------------------------------------
database stuff provided by betateilchen
----------------------------------------
=cut
use strict; use strict;
use warnings; use warnings;
@ -19,7 +23,6 @@ use Data::Dumper;
sub insertDB(); sub insertDB();
sub getLocation(); sub getLocation();
sub add2total(); sub add2total();
sub doAggregate(); sub doAggregate();
sub viewStatistics(); sub viewStatistics();
@ -38,13 +41,12 @@ my $dbh;
my $sth; my $sth;
my $limit = "datetime('now', '-12 months')"; my $limit = "datetime('now', '-12 months')";
# css stuff (to be changed for real use)
# css stuff (to be changed for production use)
my $css = "style.css"; my $css = "style.css";
# ---------- decide task ---------- # ---------- decide target ----------
if(index($ua,"FHEM") > -1) { if ($ua =~ m/FHEM/) {
insertDB(); insertDB();
print header("application/x-www-form-urlencoded"); print header("application/x-www-form-urlencoded");
print "==> ok"; print "==> ok";
@ -94,7 +96,7 @@ sub getLocation() {
} }
sub add2total() { sub add2total() {
my $sql = "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();
@ -108,6 +110,7 @@ sub add2total() {
} }
# ---------- count everything for statistics ---------- # ---------- count everything for statistics ----------
# ---------- called by viewStatistics() ----------
sub doAggregate() { sub doAggregate() {
$dbh = DBI->connect($dsn,"","", { RaiseError => 1, ShowErrorStatement => 1 }) || $dbh = DBI->connect($dsn,"","", { RaiseError => 1, ShowErrorStatement => 1 }) ||
@ -115,8 +118,7 @@ sub doAggregate() {
my ($sql,@dbInfo,%countAll,$decoded,$res); my ($sql,@dbInfo,%countAll,$decoded,$res);
# ($updated,$started,$nodesTotal,$nodes12,%countAll) $sql = q(SELECT * from jsonNodes where uniqueID = 'databaseInfo');
$sql = "SELECT * from jsonNodes where uniqueID = 'databaseInfo'";
$sth = $dbh->prepare( $sql ); $sth = $dbh->prepare( $sql );
$sth->execute(); $sth->execute();
@dbInfo = $sth->fetchrow_array(); @dbInfo = $sth->fetchrow_array();
@ -127,8 +129,7 @@ sub doAggregate() {
my $nodesTotal = $dbInfo->{'submissionsTotal'}; my $nodesTotal = $dbInfo->{'submissionsTotal'};
my $nodes12 = 0; my $nodes12 = 0;
$sql = "SELECT geo,json FROM jsonNodes WHERE lastSeen > $limit AND uniqueID <> 'databaseInfo'"; $sql = qq(SELECT geo,json FROM jsonNodes WHERE lastSeen > $limit AND uniqueID <> 'databaseInfo');
# $sql = "SELECT geo,json FROM jsonNodes WHERE uniqueID <> 'databaseInfo'";
$sth = $dbh->prepare( $sql ); $sth = $dbh->prepare( $sql );
$sth->execute(); $sth->execute();