From 828d9d8757a1f48849d9308f708ebc0dd8ee0431 Mon Sep 17 00:00:00 2001 From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com> Date: Tue, 28 Jun 2022 11:11:11 -0400 Subject: [PATCH] Initial notification support --- scripts/weekly_report.php | 57 +++++++++++++++++++++++++++ scripts/weekly_report_notification.sh | 6 +++ 2 files changed, 63 insertions(+) create mode 100644 scripts/weekly_report_notification.sh diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php index 59a7c61..9231ed3 100644 --- a/scripts/weekly_report.php +++ b/scripts/weekly_report.php @@ -7,6 +7,63 @@ $startdate = strtotime('last sunday') - (7*86400); $enddate = strtotime('last sunday') - (1*86400); $debug = false; + +if(isset($_GET['ascii'])) { + + $db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE); + if($db == False){ + echo "Database is busy"; + header("refresh: 0;"); + } + + $statement1 = $db->prepare('SELECT DISTINCT(Com_Name), COUNT(*) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'" GROUP By Com_Name ORDER BY COUNT(*) DESC'); + if($statement1 == False){ + echo "Database is busy"; + header("refresh: 0;"); + } + $result1 = $statement1->execute(); + + $detections = []; + $i = 0; + while($detection=$result1->fetchArray(SQLITE3_ASSOC)) + { + array_push($detections, $detection); + } + + echo "# Week ".date('W', $enddate)." Report (".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate).")\n"; + + echo "= Top 10 Species =\n"; + + $i = 0; + foreach($detections as $detection) + { + $i++; + + if($i <= 10) { + $statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$detection["Com_Name"].'" AND Date BETWEEN "'.date("Y-m-d",$startdate - (7*86400)).'" AND "'.date("Y-m-d",$enddate - (7*86400)).'"'); + if($statement2 == False){ + echo "Database is busy"; + header("refresh: 0;"); + } + $result2 = $statement2->execute(); + $totalcount = $result2->fetchArray(SQLITE3_ASSOC); + $priorweekcount = $totalcount['COUNT(*)']; + + $percentagediff = round((1 - $priorweekcount / $detection["COUNT(*)"]) * 100); + + if($percentagediff > 0) { + $percentagediff = "+".$percentagediff."%"; + } else { + $percentagediff = "-".abs($percentagediff)."%"; + } + + echo $detection["Com_Name"]." - ".$detection["COUNT(*)"]." (".$percentagediff.")\n"; + } + } + + die(); +} + ?>