More stats, formatting

This commit is contained in:
ehpersonal38
2022-06-29 17:09:38 -04:00
parent 1c28e6d0cf
commit b6bf1bedca
2 changed files with 58 additions and 5 deletions
-3
View File
@@ -46,9 +46,6 @@ body::-webkit-scrollbar {
<form action="" method="GET" id="views"> <form action="" method="GET" id="views">
<button type="submit" name="view" value="Recordings" form="views">Recordings</button> <button type="submit" name="view" value="Recordings" form="views">Recordings</button>
</form> </form>
<form action="" method="GET" id="views">
<button type="submit" name="view" value="Weekly Report" form="views">Weekly Report</button>
</form>
<form action="" method="GET" id="views"> <form action="" method="GET" id="views">
<button type="submit" name="view" value="View Log" form="views">View Log</button> <button type="submit" name="view" value="View Log" form="views">View Log</button>
</form> </form>
+58 -2
View File
@@ -1,4 +1,7 @@
<?php <?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$startdate = strtotime('last sunday') - (7*86400); $startdate = strtotime('last sunday') - (7*86400);
$enddate = strtotime('last sunday') - (1*86400); $enddate = strtotime('last sunday') - (1*86400);
@@ -20,6 +23,53 @@ if(isset($_GET['ascii'])) {
} }
$result1 = $statement1->execute(); $result1 = $statement1->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 = "<span style='color:green;font-size:small'>+".$percentagedifftotal."%</span>";
} else {
$percentagedifftotal = "<span style='color:red;font-size:small'>-".abs($percentagedifftotal)."%</span>";
}
$percentagedifftotaldistinctspecies = round((1 - $priortotalspeciestally / $totalspeciestally) * 100);
if($percentagedifftotaldistinctspecies > 0) {
$percentagedifftotaldistinctspecies = "<span style='color:green;font-size:small'>+".$percentagedifftotaldistinctspecies."%</span>";
} else {
$percentagedifftotaldistinctspecies = "<span style='color:red;font-size:small'>-".abs($percentagedifftotaldistinctspecies)."%</span>";
}
$detections = []; $detections = [];
$i = 0; $i = 0;
while($detection=$result1->fetchArray(SQLITE3_ASSOC)) while($detection=$result1->fetchArray(SQLITE3_ASSOC))
@@ -27,7 +77,10 @@ if(isset($_GET['ascii'])) {
$detections[$detection["Com_Name"]] = $detection["COUNT(*)"]; $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: <b>".$totalcount."</b> (".$percentagedifftotal.")<br>";
echo "Unique Species Detected: <b>".$totalspeciestally."</b> (".$percentagedifftotaldistinctspecies.")<br><br>";
echo "= <b>Top 10 Species</b> =<br>"; echo "= <b>Top 10 Species</b> =<br>";
@@ -81,6 +134,9 @@ if(isset($_GET['ascii'])) {
echo "No new species were seen this week."; echo "No new species were seen this week.";
} }
echo "<hr><small>* data from ".date('F jS, Y',$startdate)."".date('F jS, Y',$enddate).".</small><br>";
echo '<small>* percentages are calculated relative to week '.(date('W', $enddate) - 1).'.</small>';
die(); die();
} }
@@ -199,5 +255,5 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
<br> <br>
<div style="text-align:center"> <div style="text-align:center">
<small style="font-size:small">* percentages are calculated relative to week <?php echo date('W', $enddate) - 1; ?></small> <hr><small style="font-size:small">* percentages are calculated relative to week <?php echo date('W', $enddate) - 1; ?></small>
</div> </div>