From b6bf1bedcaeb06c0e50a0cbe4de01c3e8972b36e Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Wed, 29 Jun 2022 17:09:38 -0400 Subject: [PATCH] More stats, formatting --- homepage/views.php | 3 -- scripts/weekly_report.php | 60 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/homepage/views.php b/homepage/views.php index 5618dad..56ae606 100644 --- a/homepage/views.php +++ b/homepage/views.php @@ -46,9 +46,6 @@ body::-webkit-scrollbar {
- diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php index 0fbf2e1..4968c3f 100644 --- a/scripts/weekly_report.php +++ b/scripts/weekly_report.php @@ -1,4 +1,7 @@ execute(); + $statement4 = $db->prepare('SELECT DISTINCT(Com_Name), COUNT(*) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'"'); + if($statement4 == False){ + echo "Database is busy"; + header("refresh: 0;"); + } + $result4 = $statement4->execute(); + $totalcount = $result4->fetchArray(SQLITE3_ASSOC)['COUNT(*)']; + + $statement5 = $db->prepare('SELECT DISTINCT(Com_Name), COUNT(*) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate- (7*86400)).'" AND "'.date("Y-m-d",$enddate- (7*86400)).'"'); + if($statement5 == False){ + echo "Database is busy"; + header("refresh: 0;"); + } + $result5 = $statement5->execute(); + $priortotalcount = $result5->fetchArray(SQLITE3_ASSOC)['COUNT(*)']; + + $statement6 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'"'); + if($statement6 == False){ + echo "Database is busy"; + header("refresh: 0;"); + } + $result6 = $statement6->execute(); + $totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC)['COUNT(DISTINCT(Com_Name))']; + + $statement7 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate- (7*86400)).'" AND "'.date("Y-m-d",$enddate- (7*86400)).'"'); + if($statement7 == False){ + echo "Database is busy"; + header("refresh: 0;"); + } + $result7= $statement7->execute(); + $priortotalspeciestally = $result7->fetchArray(SQLITE3_ASSOC)['COUNT(DISTINCT(Com_Name))']; + + $percentagedifftotal = round((1 - $priortotalcount / $totalcount) * 100); + + if($percentagedifftotal > 0) { + $percentagedifftotal = "+".$percentagedifftotal."%"; + } else { + $percentagedifftotal = "-".abs($percentagedifftotal)."%"; + } + + $percentagedifftotaldistinctspecies = round((1 - $priortotalspeciestally / $totalspeciestally) * 100); + if($percentagedifftotaldistinctspecies > 0) { + $percentagedifftotaldistinctspecies = "+".$percentagedifftotaldistinctspecies."%"; + } else { + $percentagedifftotaldistinctspecies = "-".abs($percentagedifftotaldistinctspecies)."%"; + } + $detections = []; $i = 0; while($detection=$result1->fetchArray(SQLITE3_ASSOC)) @@ -27,7 +77,10 @@ if(isset($_GET['ascii'])) { $detections[$detection["Com_Name"]] = $detection["COUNT(*)"]; } - echo "# Week ".date('W', $enddate)." Report (".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate).")\n"; + echo "# BirdNET-Pi: Week ".date('W', $enddate)." Report\n"; + + echo "Total Detections: ".$totalcount." (".$percentagedifftotal.")