From 9d171bf850a91e6cdce2d950b9cc5592e82fb74b Mon Sep 17 00:00:00 2001 From: betateilchen <> Date: Fri, 26 May 2017 16:48:23 +0000 Subject: [PATCH] statistics2.cgi: code cleanup, prepare for release git-svn-id: https://svn.fhem.de/fhem/trunk@14383 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/contrib/statistics/statistics2.cgi | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/fhem/contrib/statistics/statistics2.cgi b/fhem/contrib/statistics/statistics2.cgi index 635a1d1e2..eb903f6ce 100644 --- a/fhem/contrib/statistics/statistics2.cgi +++ b/fhem/contrib/statistics/statistics2.cgi @@ -1,9 +1,13 @@ #!/usr/bin/perl -w -# $Id$ -# ---------------------------------------- -# database insert provided by betateilchen -# ---------------------------------------- -# + +=for comment + +$Id$ +---------------------------------------- +database stuff provided by betateilchen +---------------------------------------- + +=cut use strict; use warnings; @@ -19,7 +23,6 @@ use Data::Dumper; sub insertDB(); sub getLocation(); sub add2total(); - sub doAggregate(); sub viewStatistics(); @@ -38,13 +41,12 @@ my $dbh; my $sth; my $limit = "datetime('now', '-12 months')"; - -# css stuff (to be changed for production use) +# css stuff (to be changed for real use) my $css = "style.css"; -# ---------- decide task ---------- +# ---------- decide target ---------- -if(index($ua,"FHEM") > -1) { +if ($ua =~ m/FHEM/) { insertDB(); print header("application/x-www-form-urlencoded"); print "==> ok"; @@ -94,7 +96,7 @@ sub getLocation() { } sub add2total() { - my $sql = "SELECT * from jsonNodes where uniqueID = 'databaseInfo'"; + my $sql = q(SELECT * from jsonNodes where uniqueID = 'databaseInfo'); my $sth = $dbh->prepare( $sql ); $sth->execute(); my @dbInfo = $sth->fetchrow_array(); @@ -108,6 +110,7 @@ sub add2total() { } # ---------- count everything for statistics ---------- +# ---------- called by viewStatistics() ---------- sub doAggregate() { $dbh = DBI->connect($dsn,"","", { RaiseError => 1, ShowErrorStatement => 1 }) || @@ -115,8 +118,7 @@ sub doAggregate() { my ($sql,@dbInfo,%countAll,$decoded,$res); -# ($updated,$started,$nodesTotal,$nodes12,%countAll) - $sql = "SELECT * from jsonNodes where uniqueID = 'databaseInfo'"; + $sql = q(SELECT * from jsonNodes where uniqueID = 'databaseInfo'); $sth = $dbh->prepare( $sql ); $sth->execute(); @dbInfo = $sth->fetchrow_array(); @@ -127,8 +129,7 @@ sub doAggregate() { my $nodesTotal = $dbInfo->{'submissionsTotal'}; my $nodes12 = 0; - $sql = "SELECT geo,json FROM jsonNodes WHERE lastSeen > $limit AND uniqueID <> 'databaseInfo'"; -# $sql = "SELECT geo,json FROM jsonNodes WHERE uniqueID <> 'databaseInfo'"; + $sql = qq(SELECT geo,json FROM jsonNodes WHERE lastSeen > $limit AND uniqueID <> 'databaseInfo'); $sth = $dbh->prepare( $sql ); $sth->execute();