diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php
index 9231ed3..c0966e6 100644
--- a/scripts/weekly_report.php
+++ b/scripts/weekly_report.php
@@ -1,7 +1,4 @@
fetchArray(SQLITE3_ASSOC))
{
- array_push($detections, $detection);
+ $detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
}
echo "# Week ".date('W', $enddate)." Report (".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate).")\n";
- echo "= Top 10 Species =\n";
+ echo "= Top 10 Species =
";
$i = 0;
- foreach($detections as $detection)
+ foreach($detections as $com_name=>$scount)
{
$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)).'"');
+ $statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$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;");
@@ -49,18 +46,41 @@ if(isset($_GET['ascii'])) {
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
$priorweekcount = $totalcount['COUNT(*)'];
- $percentagediff = round((1 - $priorweekcount / $detection["COUNT(*)"]) * 100);
+ $percentagediff = round((1 - $priorweekcount / $scount) * 100);
if($percentagediff > 0) {
- $percentagediff = "+".$percentagediff."%";
+ $percentagediff = "+".$percentagediff."%";
} else {
- $percentagediff = "-".abs($percentagediff)."%";
+ $percentagediff = "-".abs($percentagediff)."%";
}
- echo $detection["Com_Name"]." - ".$detection["COUNT(*)"]." (".$percentagediff.")\n";
+ echo $com_name." - ".$scount." (".$percentagediff.")
";
}
}
+ echo "
= Species Detected for the First Time: =
";
+
+ $newspeciescount=0;
+ foreach($detections as $com_name=>$scount)
+ {
+ $statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$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(*)'];
+
+ if($nonthisweekcount == 0) {
+ $newspeciescount++;
+ echo $com_name." - ".$scount."
";
+ }
+ }
+ if($newspeciescount == 0) {
+ echo "No new species were seen this week.";
+ }
+
die();
}
@@ -96,7 +116,7 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
}
}
$i++;
- array_push($detections, $detection);
+ $detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
}
?>
@@ -113,12 +133,11 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
$scount)
{
$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)).'"');
+ $statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$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;");
@@ -127,7 +146,7 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
$priorweekcount = $totalcount['COUNT(*)'];
- $percentagediff = round((1 - $priorweekcount / $detection["COUNT(*)"]) * 100);
+ $percentagediff = round((1 - $priorweekcount / $scount) * 100);
if($percentagediff > 0) {
$percentagediff = "+".$percentagediff."%";
@@ -135,7 +154,7 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
$percentagediff = "-".abs($percentagediff)."%";
}
- echo "
| "; ?> | +"; ?> |
|---|---|
| ".$detection["Com_Name"]." ".$detections[$key]["COUNT(*)"]." | |
| ".$com_name." ".$scount." | |
| No new species were seen this week. |