diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php
index 0d8b262..59a7c61 100644
--- a/scripts/weekly_report.php
+++ b/scripts/weekly_report.php
@@ -5,6 +5,8 @@ error_reporting(E_ALL);
$startdate = strtotime('last sunday') - (7*86400);
$enddate = strtotime('last sunday') - (1*86400);
+
+$debug = false;
?>
Week ".date('W', $enddate)." Report".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate)."
";
@@ -16,50 +18,114 @@ if($db == False){
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 LIMIT 10');
+if($debug == false){
+$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');
+} else {
+ $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(*) ASC');
+}
if($statement1 == False){
echo "Database is busy";
header("refresh: 0;");
}
$result1 = $statement1->execute();
-?>
-
-
-
-
- | "; ?> |
-
-
-
-fetchArray(SQLITE3_ASSOC))
{
-
-$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.")
|
";
+ if($debug == true){
+ if($i > 10) {
+ break;
+ }
+ }
+ $i++;
+ array_push($detections, $detection);
+
}
?>
-
-
+
+
+
+
+
+
+ | "; ?> |
+
+
+
+ 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.")
| ";
+ }
+ }
+ ?>
+
+
+ |
+
+
+
+
+ | "; ?> |
+
+
+
+ $val) {
+ if ($val['Com_Name'] === $id) {
+ return $key;
+ }
+ }
+ return null;
+ }
+
+ foreach($detections as $detection)
+ {
+ $statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$detection["Com_Name"].'" AND Date NOT BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'"');
+ if($statement3 == False){
+ echo "Database is busy";
+ header("refresh: 0;");
+ }
+ $result3 = $statement3->execute();
+ $totalcount = $result3->fetchArray(SQLITE3_ASSOC);
+ $nonthisweekcount = $totalcount['COUNT(*)'];
+
+ // TODO: add a "no species were seen for the first time this week", if applicable
+
+ if($nonthisweekcount == 0) {
+ $key = array_search($detection["Com_Name"], array_column($detections, 'Com_Name'));
+ echo "".$detection["Com_Name"]." ".$detections[$key]["COUNT(*)"]."
| ";
+ }
+ }
+ ?>
+
+
+ |
+