busyTimeout(1000);
$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');
ensure_db_ok($statement1);
$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).'"');
ensure_db_ok($statement4);
$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)).'"');
ensure_db_ok($statement5);
$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).'"');
ensure_db_ok($statement6);
$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)).'"');
ensure_db_ok($statement7);
$result7= $statement7->execute();
$priortotalspeciestally = $result7->fetchArray(SQLITE3_ASSOC)['COUNT(DISTINCT(Com_Name))'];
$percentagedifftotal = round( (($totalcount - $priortotalcount) / $priortotalcount) * 100 );
if($percentagedifftotal > 0) {
$percentagedifftotal = "+".$percentagedifftotal."%";
} else {
$percentagedifftotal = "-".abs($percentagedifftotal)."%";
}
$percentagedifftotaldistinctspecies = round( (($totalspeciestally - $priortotalspeciestally) / $priortotalspeciestally) * 100 );
if($percentagedifftotaldistinctspecies > 0) {
$percentagedifftotaldistinctspecies = "+".$percentagedifftotaldistinctspecies."%";
} else {
$percentagedifftotaldistinctspecies = "-".abs($percentagedifftotaldistinctspecies)."%";
}
$detections = [];
$i = 0;
while($detection=$result1->fetchArray(SQLITE3_ASSOC))
{
$detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
}
echo "# BirdNET-Pi: Week ".date('W', $enddate)." Report\n";
echo "Total Detections: ".$totalcount." (".$percentagedifftotal.")
";
echo "Unique Species Detected: ".$totalspeciestally." (".$percentagedifftotaldistinctspecies.")
";
echo "= Top 10 Species =
";
$i = 0;
foreach($detections as $com_name=>$scount)
{
$i++;
if($i <= 10) {
$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)).'"');
ensure_db_ok($statement2);
$result2 = $statement2->execute();
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
$priorweekcount = $totalcount['COUNT(*)'];
// really percent changed
if($priorweekcount > 0){
$percentagediff = round( (($scount - $priorweekcount) / $priorweekcount) * 100 );
if($percentagediff > 0) {
$percentagediff = "+".$percentagediff."%";
} else {
$percentagediff = "-".abs($percentagediff)."%";
}
echo $com_name." - ".$scount." (".$percentagediff.")
";
} else {
echo $com_name." - ".$scount ."
";
}
}
}
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).'"');
ensure_db_ok($statement3);
$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.";
}
$prevweek = date('W', $enddate) - 1;
if($prevweek < 1) { $prevweek = 52; }
echo "
* data from ".date('Y-m-d', $startdate)." — ".date('Y-m-d',$enddate).".
";
echo '* percentages are calculated relative to week '.($prevweek).'.';
die();
}
?>
Week ".date('W', $enddate)." Report".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate)."
";
?>
busyTimeout(1000);
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');
}
ensure_db_ok($statement1);
$result1 = $statement1->execute();
$detections = [];
$i = 0;
while($detection=$result1->fetchArray(SQLITE3_ASSOC))
{
if($debug == true){
if($i > 10) {
break;
}
}
$i++;
$detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
}
?>
| "; ?> |
$scount)
{
$i++;
if($i <= 10) {
$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)).'"');
ensure_db_ok($statement2);
$result2 = $statement2->execute();
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
$priorweekcount = $totalcount['COUNT(*)'];
if ($priorweekcount > 0) {
$percentagediff = round( (($scount - $priorweekcount) / $priorweekcount) * 100 );
} else {
$percentagediff = 0;
}
if($percentagediff > 0) {
$percentagediff = "+".$percentagediff."%";
} else {
$percentagediff = "-".abs($percentagediff)."%";
}
echo "".$com_name." ".$scount." (".$percentagediff.")
| ";
}
}
?>
|
| "; ?> |
$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).'"');
ensure_db_ok($statement3);
$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. | ";
}
?>
|
* percentages are calculated relative to week