2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 06:48:43 +00:00

statistics2.cgi: only count official modules

git-svn-id: https://svn.fhem.de/fhem/trunk@27395 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2023-04-05 10:27:53 +00:00
parent aae6c990cf
commit d75000cf9d

View File

@ -23,13 +23,18 @@ GNU General Public License for more details.
database stuff provided by betateilchen database stuff provided by betateilchen
visualisation provided by markusbloch visualisation provided by markusbloch
--------------------------------------------------------------------------------
2023-04-05 - add support for makeOffical() (count official modules only)
=cut =cut
use strict; use strict;
use warnings; use warnings;
use DBI; use DBI;
use CGI qw(:standard Vars); use CGI qw(:standard Vars);
#use Data::Dumper; #use Data::Dumper; # for debug only
use JSON; use JSON;
use POSIX qw(mktime strftime); use POSIX qw(mktime strftime);
use Time::HiRes qw(time); use Time::HiRes qw(time);
@ -40,7 +45,7 @@ use Geo::IP;
sub insertDB(); sub insertDB();
sub getLocation(); sub getLocation();
sub revInfo($); sub revInfo($);
sub makeOfficial(); sub makeOfficial($);
sub add2total(); sub add2total();
sub doAggregate(); sub doAggregate();
sub viewStatistics(); sub viewStatistics();
@ -64,7 +69,12 @@ my $sth;
my $limit = "datetime('now', '-12 months')"; my $limit = "datetime('now', '-12 months')";
# path to working copy # path to working copy
my $fhemPathSvn = '/opt/fhem';
# used for development (betateilchen)
# my $fhemPathSvn = '/opt/fhem';
# used for production on FHEM server
my $fhemPathSvn = '/home/rko/fhemupdate/fhem';
# ---------- decide target ---------- # ---------- decide target ----------
@ -89,8 +99,9 @@ sub insertDB() {
my $geo = getLocation(); my $geo = getLocation();
my $decoded = decode_json($json); my $decoded = decode_json($json);
$json = revInfo($decoded) if (defined($decoded->{'system'}{'revision'})); $decoded = revInfo($decoded) if (defined($decoded->{'system'}{'revision'}));
makeOfficial(); # delete inofficial modules from statistics data $decoded = makeOfficial($decoded);
$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";
@ -131,22 +142,29 @@ sub revInfo($) {
my ($decoded) = @_; my ($decoded) = @_;
my $rev = $decoded->{'system'}{'revision'} + 1; my $rev = $decoded->{'system'}{'revision'} + 1;
if($rev =~ /^\d+$/) { if($rev =~ /^\d+$/) {
my $d = (split(/ /,qx(sudo -u rko /usr/bin/svn info -r $rev $fhemPathSvn|grep Date:)))[3];
# used for development (betateilchen)
# my $d = (split(/ /,qx(/usr/bin/svn info -r $rev $fhemPathSvn|grep Date:)))[3]; # my $d = (split(/ /,qx(/usr/bin/svn info -r $rev $fhemPathSvn|grep Date:)))[3];
# used for production on FHEM server
my $d = (split(/ /,qx(sudo -u rko /usr/bin/svn info -r $rev $fhemPathSvn|grep Date:)))[3];
return undef unless (defined($d)); return undef unless (defined($d));
my ($year,$mon,$mday) = split(/-/,$d); my ($year,$mon,$mday) = split(/-/,$d);
$decoded->{'system'}{'revdate'} = mktime(0,0,7,$mday,($mon-1),($year-1900),0,0,0); $decoded->{'system'}{'revdate'} = mktime(0,0,7,$mday,($mon-1),($year-1900),0,0,0);
return encode_json $decoded; return $decoded;
} }
} }
sub makeOfficial() { sub makeOfficial($) {
my %official = (); # delete inofficial modules from statistics data
my ($decoded) = @_;
my %official = ('system'=>1);
open (FH, "$fhemPathSvn/controls_fhem.txt") || die "Sorry!!"; open (FH, "$fhemPathSvn/controls_fhem.txt") || die "Sorry!!";
while (<FH>) { $official{$1} = 1 if ($_ =~ /FHEM\/\d\d_(.*)\.pm/) } while (<FH>) { $official{$1} = 1 if ($_ =~ /FHEM\/\d\d_(.*)\.pm/) }
close FH; close FH;
foreach my $key (keys %$decoded) { delete $decoded->{$key} unless $official{$key} } foreach my $key (keys %$decoded) { delete $decoded->{$key} unless $official{$key} }
return; return $decoded;
} }
sub add2total() { sub add2total() {