Revert "Code Consolidation for API preparations & hard coded path replacements"

This commit is contained in:
ehpersonal38
2023-05-19 20:03:02 -04:00
committed by GitHub
parent 09b4c56c96
commit 9c1f4175e2
21 changed files with 1632 additions and 3309 deletions
+85 -66
View File
@@ -1,9 +1,7 @@
<?php
if(file_exists('./scripts/common.php')){
include_once "./scripts/common.php";
}else{
include_once "./common.php";
}
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
$startdate = strtotime('last sunday') - (7*86400);
$enddate = strtotime('last sunday') - (1*86400);
@@ -11,38 +9,51 @@ $enddate = strtotime('last sunday') - (1*86400);
$debug = false;
if(isset($_GET['ascii'])) {
$weekly_species_counts = getWeeklyReportSpeciesDetectionCounts();
if($weekly_species_counts['detections']['success'] == False){
echo $weekly_species_counts['detections']['message'];
header("refresh: 0;");
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
if($db == False){
echo "Database is busy";
header("refresh: 0;");
}
$result1 = $weekly_species_counts['detections']['data'];
if($weekly_species_counts['totalcount']['success'] == False){
echo $weekly_species_counts['totalcount']['message'];
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;");
}
$totalcount = $weekly_species_counts['totalcount']['data']['COUNT(*)'];
$result1 = $statement1->execute();
if($weekly_species_counts['priortotalcount']['success'] == False){
echo $weekly_species_counts['priortotalcount']['message'];
header("refresh: 0;");
$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;");
}
$priortotalcount = $weekly_species_counts['priortotalcount']['data']['COUNT(*)'];
$result4 = $statement4->execute();
$totalcount = $result4->fetchArray(SQLITE3_ASSOC)['COUNT(*)'];
$weekly_species_talley = getWeeklyReportSpeciesTalley();
if($weekly_species_talley['totalspeciestally']['success'] == False){
echo $weekly_species_talley['totalspeciestally']['message'];
header("refresh: 0;");
$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;");
}
$totalspeciestally = $weekly_species_talley['totalspeciestally']['data']['COUNT(DISTINCT(Com_Name))'];
$result5 = $statement5->execute();
$priortotalcount = $result5->fetchArray(SQLITE3_ASSOC)['COUNT(*)'];
if($weekly_species_talley['priortotalspeciestally']['success'] == False){
echo $weekly_species_talley['priortotalspeciestally']['message'];
header("refresh: 0;");
$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;");
}
$priortotalspeciestally = $weekly_species_talley['priortotalspeciestally']['data']['COUNT(DISTINCT(Com_Name))'];
$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( (($totalcount - $priortotalcount) / $priortotalcount) * 100 );
@@ -61,10 +72,11 @@ if(isset($_GET['ascii'])) {
$detections = [];
$i = 0;
foreach ($result1 as $detection)
while($detection=$result1->fetchArray(SQLITE3_ASSOC))
{
$detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
}
echo "# BirdNET-Pi: Week ".date('W', $enddate)." Report\n";
echo "Total Detections: <b>".$totalcount."</b> (".$percentagedifftotal.")<br>";
@@ -78,12 +90,14 @@ if(isset($_GET['ascii'])) {
$i++;
if($i <= 10) {
$statement2 = getWeeklyReportSpeciesDetection($com_name);
if($statement2['success'] == False){
echo $statement2['message'];
header("refresh: 0;");
$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;");
}
$priorweekcount = $statement2['data']['COUNT(*)'];
$result2 = $statement2->execute();
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
$priorweekcount = $totalcount['COUNT(*)'];
// really percent changed
if($priorweekcount > 0){
@@ -107,12 +121,14 @@ if(isset($_GET['ascii'])) {
$newspeciescount=0;
foreach($detections as $com_name=>$scount)
{
$statement3 = getWeeklyReportSpeciesDetection($com_name,false);
if($statement3['success'] == False){
echo $statement3['message'];
header("refresh: 0;");
$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;");
}
$nonthisweekcount = $statement3['data']['COUNT(*)'];
$result3 = $statement3->execute();
$totalcount = $result3->fetchArray(SQLITE3_ASSOC);
$nonthisweekcount = $totalcount['COUNT(*)'];
if($nonthisweekcount == 0) {
$newspeciescount++;
@@ -137,27 +153,26 @@ if(isset($_GET['ascii'])) {
echo "<h1>Week ".date('W', $enddate)." Report</h1>".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate)."<br>";
?></div><?php
if($debug == false){
$weekly_species_counts = getWeeklyReportSpeciesDetectionCounts();
if($weekly_species_counts['detections']['success'] == False){
echo $weekly_species_counts['detections']['message'];
header("refresh: 0;");
}
$result1 = $weekly_species_counts['detections']['data'];
} else {
$weekly_species_counts = getWeeklyReportSpeciesDetectionCounts(false);
if($weekly_species_counts['detections']['success'] == False){
echo $weekly_species_counts['detections']['message'];
header("refresh: 0;");
}
$result1 = $weekly_species_counts['detections']['data'];
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
if($db == False){
echo "Database is busy";
header("refresh: 0;");
}
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();
$detections = [];
$i = 0;
foreach ($result1 as $detection)
while($detection=$result1->fetchArray(SQLITE3_ASSOC))
{
if($debug == true){
if($i > 10) {
@@ -186,12 +201,14 @@ foreach ($result1 as $detection)
{
$i++;
if($i <= 10) {
$statement2 = getWeeklyReportSpeciesDetection($com_name);
if($statement2['success'] == False){
echo $statement2['message'];
header("refresh: 0;");
$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;");
}
$priorweekcount = $statement2['data']['COUNT(*)'];
$result2 = $statement2->execute();
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
$priorweekcount = $totalcount['COUNT(*)'];
if ($priorweekcount > 0) {
$percentagediff = round( (($scount - $priorweekcount) / $priorweekcount) * 100 );
@@ -225,12 +242,14 @@ foreach ($result1 as $detection)
$newspeciescount=0;
foreach($detections as $com_name=>$scount)
{
$statement3 = getWeeklyReportSpeciesDetection($com_name,false);
if($statement3['success'] == False){
echo $statement3['message'];
header("refresh: 0;");
$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;");
}
$nonthisweekcount = $statement3['data']['COUNT(*)'];
$result3 = $statement3->execute();
$totalcount = $result3->fetchArray(SQLITE3_ASSOC);
$nonthisweekcount = $totalcount['COUNT(*)'];
if($nonthisweekcount == 0) {
$newspeciescount++;