Query Consolidate Code for API Preparations
All SQL Queries were moved into their respective functions and parameterized, there were some slight logic changes in the front end pages to accommodate data being returned differently but existing functionality is maintained A common function is used to execute the queries and looks after binding any parameterized values that have been supplied. Other code for deleting / protecting detection's, frequency shift, Flickr API call etc have also been moved into common.php to be used later by the API Two new functions getDirectory and getFilePath were introduced in aims and make it easier to relocate files. This will be worked into all existing php files to replace hardcoded paths
This commit is contained in:
+1053
File diff suppressed because it is too large
Load Diff
+12
-20
@@ -1,13 +1,5 @@
|
||||
<?php
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors',1);
|
||||
ini_set('display_startup_errors',1);
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
} elseif (file_exists('./scripts/firstrun.ini')) {
|
||||
$config = parse_ini_file('./scripts/firstrun.ini');
|
||||
}
|
||||
include_once "./scripts/common.php";
|
||||
|
||||
if(isset($_GET['date'])){
|
||||
$theDate = $_GET['date'];
|
||||
@@ -17,12 +9,11 @@ $theDate = date('Y-m-d');
|
||||
$chart = "Combo-$theDate.png";
|
||||
$chart2 = "Combo2-$theDate.png";
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
|
||||
$statement1 = $db->prepare("SELECT COUNT(*) FROM detections
|
||||
WHERE Date == \"$theDate\"");
|
||||
$result1 = $statement1->execute();
|
||||
$totalcount = $result1->fetchArray(SQLITE3_ASSOC);
|
||||
$statement1 = getDetectionCountByDate($theDate);
|
||||
if($statement1['success'] == False){
|
||||
echo $statement1['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
|
||||
if(isset($_GET['blocation']) ) {
|
||||
|
||||
@@ -45,16 +36,17 @@ if(isset($_GET['blocation']) ) {
|
||||
$hrsinday = 24;
|
||||
for($i=0;$i<$hrsinday;$i++) {
|
||||
$starttime = strtotime("12 AM") + (3600*$i);
|
||||
$endtime = date("H:i",$starttime + 3600);
|
||||
|
||||
$statement1 = $db->prepare("SELECT DISTINCT(Com_Name), COUNT(*) FROM detections WHERE Date == \"$theDate\" AND Time > '".date("H:i", $starttime)."' AND Time < '".date("H:i",$starttime + 3600)."' AND Confidence > 0.75 GROUP By Com_Name ORDER BY COUNT(*) DESC");
|
||||
if($statement1 == False){
|
||||
echo "Database is busy";
|
||||
$statement1 = getDetectionBreakdownByTime($theDate,$starttime,$endtime);
|
||||
if($statement1['success'] == False){
|
||||
echo $statement1['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result1 = $statement1->execute();
|
||||
$result1 = $statement1['data'];
|
||||
|
||||
$detections = [];
|
||||
while($detection=$result1->fetchArray(SQLITE3_ASSOC))
|
||||
foreach ($result1 as $detection)
|
||||
{
|
||||
$detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
|
||||
}
|
||||
|
||||
+86
-143
@@ -1,36 +1,39 @@
|
||||
<?php
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
ini_set('session.gc_maxlifetime', 7200);
|
||||
ini_set('user_agent', 'PHP_Flickr/1.0');
|
||||
session_set_cookie_params(7200);
|
||||
session_start();
|
||||
include_once "./scripts/common.php";
|
||||
|
||||
//error_reporting(E_ERROR);
|
||||
//ini_set('display_errors',1);
|
||||
//ini_set('session.gc_maxlifetime', 7200);
|
||||
//ini_set('user_agent', 'PHP_Flickr/1.0');
|
||||
//session_set_cookie_params(7200);
|
||||
//session_start();
|
||||
|
||||
$myDate = date('Y-m-d');
|
||||
$chart = "Combo-$myDate.png";
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
if($db == False) {
|
||||
echo "Database is busy";
|
||||
//$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
//if($db == False) {
|
||||
// echo "Database is busy";
|
||||
// header("refresh: 0;");
|
||||
//}
|
||||
//
|
||||
//if (file_exists('./scripts/thisrun.txt')) {
|
||||
// $config = parse_ini_file('./scripts/thisrun.txt');
|
||||
//} elseif (file_exists('./scripts/firstrun.ini')) {
|
||||
// $config = parse_ini_file('./scripts/firstrun.ini');
|
||||
//}
|
||||
//
|
||||
//$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
|
||||
//$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
|
||||
//$home = trim($home);
|
||||
|
||||
$todaycount_data = getDetectionCountToday();
|
||||
|
||||
if($todaycount_data['success'] == False){
|
||||
echo $todaycount_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
} elseif (file_exists('./scripts/firstrun.ini')) {
|
||||
$config = parse_ini_file('./scripts/firstrun.ini');
|
||||
}
|
||||
|
||||
$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
|
||||
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
|
||||
$home = trim($home);
|
||||
|
||||
$statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == DATE(\'now\', \'localtime\')');
|
||||
if($statement2 == False) {
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result2 = $statement2->execute();
|
||||
$todaycount = $result2->fetchArray(SQLITE3_ASSOC);
|
||||
$todaycount = $todaycount_data['data'];
|
||||
|
||||
if(isset($_GET['custom_image'])){
|
||||
if(isset($config["CUSTOM_IMAGE"])) {
|
||||
@@ -53,11 +56,9 @@ if(isset($_GET['blacklistimage'])) {
|
||||
if($submittedpwd == $config['CADDY_PWD'] && $submitteduser == 'birdnet'){
|
||||
|
||||
$imageid = $_GET['blacklistimage'];
|
||||
$file_handle = fopen($home."/BirdNET-Pi/scripts/blacklisted_images.txt", 'a+');
|
||||
fwrite($file_handle, $imageid . "\n");
|
||||
fclose($file_handle);
|
||||
$result = blacklistFlickrImage($imageid);
|
||||
unset($_SESSION['images']);
|
||||
die("OK");
|
||||
die($result['message']);
|
||||
} else {
|
||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
@@ -74,115 +75,58 @@ if(isset($_GET['blacklistimage'])) {
|
||||
}
|
||||
|
||||
if(isset($_GET['fetch_chart_string']) && $_GET['fetch_chart_string'] == "true") {
|
||||
$myDate = date('Y-m-d');
|
||||
$chart = "Combo-$myDate.png";
|
||||
$chart = getChartString();
|
||||
echo $chart;
|
||||
die();
|
||||
}
|
||||
|
||||
if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isset($_GET['previous_detection_identifier'])) {
|
||||
|
||||
$statement4 = $db->prepare('SELECT Com_Name, Sci_Name, Date, Time, Confidence, File_Name FROM detections ORDER BY Date DESC, Time DESC LIMIT 15');
|
||||
if($statement4 == False) {
|
||||
echo "Database is busy";
|
||||
$result4 = getMostRecentDetection(15);
|
||||
|
||||
if ($result4['success'] == False) {
|
||||
echo $result4['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result4 = $statement4->execute();
|
||||
if(!isset($_SESSION['images'])) {
|
||||
$_SESSION['images'] = [];
|
||||
}
|
||||
$result4 = $result4['data'];
|
||||
|
||||
$iterations = 0;
|
||||
$lines;
|
||||
$licenses_urls = array();
|
||||
$processed_detections = 0;
|
||||
|
||||
// hopefully one of the 5 most recent detections has an image that is valid, we'll use that one as the most recent detection until the newer ones get their images created
|
||||
while($mostrecent = $result4->fetchArray(SQLITE3_ASSOC)) {
|
||||
foreach ($result4 as $mostrecent){
|
||||
$iterations++;
|
||||
$comname = preg_replace('/ /', '_', $mostrecent['Com_Name']);
|
||||
$sciname = preg_replace('/ /', '_', $mostrecent['Sci_Name']);
|
||||
$comname = preg_replace('/\'/', '', $comname);
|
||||
$filename = "/By_Date/".$mostrecent['Date']."/".$comname."/".$mostrecent['File_Name'];
|
||||
$args = "&license=2%2C3%2C4%2C5%2C6%2C9&orientation=square,portrait";
|
||||
$comnameprefix = "%20bird";
|
||||
|
||||
// check to make sure the image actually exists, sometimes it takes a minute to be created\
|
||||
if(file_exists($home."/BirdSongs/Extracted".$filename.".png")){
|
||||
if($_GET['previous_detection_identifier'] == $filename) { die(); }
|
||||
if($_GET['only_name'] == "true") { echo $comname.",".$filename;die(); }
|
||||
|
||||
$iterations++;
|
||||
|
||||
if (!empty($config["FLICKR_API_KEY"])) {
|
||||
|
||||
if(!empty($config["FLICKR_FILTER_EMAIL"])) {
|
||||
if(!isset($_SESSION["FLICKR_FILTER_EMAIL"])) {
|
||||
unset($_SESSION['images']);
|
||||
$_SESSION['FLICKR_FILTER_EMAIL'] = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.people.findByEmail&api_key=".$config["FLICKR_API_KEY"]."&find_email=".$config["FLICKR_FILTER_EMAIL"]."&format=json&nojsoncallback=1"), true)["user"]["nsid"];
|
||||
}
|
||||
$args = "&user_id=".$_SESSION['FLICKR_FILTER_EMAIL'];
|
||||
$comnameprefix = "";
|
||||
} else {
|
||||
if(isset($_SESSION["FLICKR_FILTER_EMAIL"])) {
|
||||
unset($_SESSION["FLICKR_FILTER_EMAIL"]);
|
||||
unset($_SESSION['images']);
|
||||
if (file_exists(getDirectory('extracted') . "/" . $filename . ".png")) {
|
||||
if ($_GET['previous_detection_identifier'] == $filename) {
|
||||
die();
|
||||
}
|
||||
if ($_GET['only_name'] == "true") {
|
||||
echo $comname . "," . $filename;
|
||||
die();
|
||||
}
|
||||
|
||||
$processed_detections++;
|
||||
|
||||
// if we already searched flickr for this species before, use the previous image rather than doing an unneccesary api call
|
||||
$key = array_search($comname, array_column($_SESSION['images'], 0));
|
||||
if($key !== false) {
|
||||
$image = $_SESSION['images'][$key];
|
||||
} else {
|
||||
// Get license information if we haven't already
|
||||
if (empty($licenses_urls)) {
|
||||
$licenses_url = "https://api.flickr.com/services/rest/?method=flickr.photos.licenses.getInfo&api_key=".$config["FLICKR_API_KEY"]."&format=json&nojsoncallback=1";
|
||||
$licenses_response = file_get_contents($licenses_url);
|
||||
$licenses_data = json_decode($licenses_response, true)["licenses"]["license"];
|
||||
foreach ($licenses_data as $license) {
|
||||
$license_id = $license["id"];
|
||||
$license_name = $license["name"];
|
||||
$license_url = $license["url"];
|
||||
$licenses_urls[$license_id] = $license_url;
|
||||
}
|
||||
}
|
||||
//Get the flickr image for this detection
|
||||
$flickr_Image = getFlickrImage($mostrecent);
|
||||
|
||||
// only open the file once per script execution
|
||||
if(!isset($lines)) {
|
||||
$lines = file($home."/BirdNET-Pi/model/labels_flickr.txt");
|
||||
}
|
||||
// convert sci name to English name
|
||||
foreach($lines as $line){
|
||||
if(strpos($line, $mostrecent['Sci_Name']) !== false){
|
||||
$engname = trim(explode("_", $line)[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Read the blacklisted image ids from the file into an array
|
||||
$blacklisted_ids = array_map('trim', file($home."/BirdNET-Pi/scripts/blacklisted_images.txt"));
|
||||
|
||||
// Make the API call
|
||||
$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=".str_replace(" ", "%20", $engname).$comnameprefix."&sort=relevance".$args."&per_page=5&media=photos&format=json&nojsoncallback=1"), true)["photos"]["photo"];
|
||||
|
||||
// Find the first photo that is not blacklisted or is not the specific blacklisted id
|
||||
$photo = null;
|
||||
foreach ($flickrjson as $flickrphoto) {
|
||||
if ($flickrphoto["id"] !== "4892923285" && !in_array($flickrphoto["id"], $blacklisted_ids)) {
|
||||
$photo = $flickrphoto;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$license_url = "https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=".$config["FLICKR_API_KEY"]."&photo_id=".$photo["id"]."&format=json&nojsoncallback=1";
|
||||
$license_response = file_get_contents($license_url);
|
||||
$license_info = json_decode($license_response, true)["photo"]["license"];
|
||||
$license_url = $licenses_urls[$license_info];
|
||||
|
||||
$modaltext = "https://flickr.com/photos/".$photo["owner"]."/".$photo["id"];
|
||||
$authorlink = "https://flickr.com/people/".$photo["owner"];
|
||||
$imageurl = 'https://farm' .$photo["farm"]. '.static.flickr.com/' .$photo["server"]. '/' .$photo["id"]. '_' .$photo["secret"]. '.jpg';
|
||||
array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink, $license_url));
|
||||
$image = $_SESSION['images'][count($_SESSION['images'])-1];
|
||||
}
|
||||
if ($flickr_Image['image_found']) {
|
||||
//Remap the data from returned data into an array that is referenced in our HTML
|
||||
//to save have to rewrite or adjust it
|
||||
$flickr_Image_data = $flickr_Image['data'];
|
||||
$image = [
|
||||
0 => $flickr_Image_data['Com_Name_clean'],
|
||||
1 => $flickr_Image_data['photos'][0]['image_url'],
|
||||
2 => $flickr_Image_data['photos'][0]['photo_title'],
|
||||
3 => $flickr_Image_data['photos'][0]['modal_text'],
|
||||
4 => $flickr_Image_data['photos'][0]['author_link'],
|
||||
5 => $flickr_Image_data['photos'][0]['license_url']
|
||||
];
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -223,7 +167,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
|
||||
</table> <?php break;
|
||||
}
|
||||
}
|
||||
if($iterations == 0) {
|
||||
if($processed_detections == 0) {
|
||||
if($todaycount['COUNT(*)'] > 0) {
|
||||
echo "<h3>Your system is currently processing a backlog of audio. This can take several hours before normal functionality of your BirdNET-Pi resumes.</h3>";
|
||||
} else {
|
||||
@@ -235,37 +179,36 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
|
||||
|
||||
if(isset($_GET['ajax_left_chart']) && $_GET['ajax_left_chart'] == "true") {
|
||||
|
||||
$statement = $db->prepare('SELECT COUNT(*) FROM detections');
|
||||
if($statement == False) {
|
||||
echo "Database is busy";
|
||||
$totalcount_data = getDetectionCountAll();
|
||||
if($totalcount_data['success'] == False){
|
||||
echo $totalcount_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result = $statement->execute();
|
||||
$totalcount = $result->fetchArray(SQLITE3_ASSOC);
|
||||
$totalcount = $totalcount_data['data'];
|
||||
|
||||
$statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == Date(\'now\', \'localtime\') AND TIME >= TIME(\'now\', \'localtime\', \'-1 hour\')');
|
||||
if($statement3 == False) {
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result3 = $statement3->execute();
|
||||
$hourcount = $result3->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$statement5 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections WHERE Date == Date(\'now\',\'localtime\')');
|
||||
if($statement5 == False) {
|
||||
echo "Database is busy";
|
||||
$hourcount_data = getDetectionCountLastHour();
|
||||
if($hourcount_data['success'] == False){
|
||||
echo $hourcount_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result5 = $statement5->execute();
|
||||
$speciestally = $result5->fetchArray(SQLITE3_ASSOC);
|
||||
$hourcount = $hourcount_data['data'];
|
||||
|
||||
$statement6 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections');
|
||||
if($statement6 == False) {
|
||||
echo "Database is busy";
|
||||
|
||||
$speciestally_data = getSpeciesTalley();
|
||||
if($speciestally_data['success'] == False){
|
||||
echo $speciestally_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result6 = $statement6->execute();
|
||||
$totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC);
|
||||
$speciestally = $speciestally_data['data'];
|
||||
|
||||
|
||||
$totalspeciestally_data = getAllSpeciesTalley();
|
||||
if($totalspeciestally_data['success'] == False){
|
||||
echo $totalspeciestally_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$totalspeciestally = $totalspeciestally_data['data'];
|
||||
|
||||
?>
|
||||
<table>
|
||||
|
||||
+75
-127
@@ -1,44 +1,17 @@
|
||||
<?php
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
if($db == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
} elseif (file_exists('firstrun.ini')) {
|
||||
$config = parse_ini_file('firstrun.ini');
|
||||
}
|
||||
|
||||
$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
|
||||
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
|
||||
$home = trim($home);
|
||||
|
||||
include_once "./scripts/common.php";
|
||||
|
||||
if(isset($_GET['deletefile'])) {
|
||||
if(isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
$submittedpwd = $_SERVER['PHP_AUTH_PW'];
|
||||
$submitteduser = $_SERVER['PHP_AUTH_USER'];
|
||||
if($submittedpwd == $config['CADDY_PWD'] && $submitteduser == 'birdnet'){
|
||||
$statement1 = $db->prepare('DELETE FROM detections WHERE File_Name = "'.explode("/",$_GET['deletefile'])[2].'" LIMIT 1');
|
||||
if($statement1 == False){
|
||||
echo "Error";
|
||||
header("refresh: 0;");
|
||||
} else {
|
||||
$file_pointer = $home."/BirdSongs/Extracted/By_Date/".$_GET['deletefile'];
|
||||
if (!exec("sudo rm $file_pointer && sudo rm $file_pointer.png")) {
|
||||
echo "OK";
|
||||
} else {
|
||||
echo "Error";
|
||||
}
|
||||
|
||||
}
|
||||
$result1 = $statement1->execute();
|
||||
$filename_to_delete = $_GET['deletefile'];
|
||||
$message = deleteDetection($filename_to_delete)['message'];
|
||||
echo $message;
|
||||
die();
|
||||
|
||||
} else {
|
||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
@@ -58,31 +31,17 @@ if(isset($_GET['excludefile'])) {
|
||||
$submittedpwd = $_SERVER['PHP_AUTH_PW'];
|
||||
$submitteduser = $_SERVER['PHP_AUTH_USER'];
|
||||
if($submittedpwd == $config['CADDY_PWD'] && $submitteduser == 'birdnet'){
|
||||
if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt")) {
|
||||
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start\n##end\n");
|
||||
}
|
||||
|
||||
if(isset($_GET['exclude_add'])) {
|
||||
$myfile = fopen($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "a") or die("Unable to open file!");
|
||||
$txt = $_GET['excludefile'];
|
||||
fwrite($myfile, $txt."\n");
|
||||
fwrite($myfile, $txt.".png\n");
|
||||
fclose($myfile);
|
||||
echo "OK";
|
||||
$response_data = protectDetectionFromDeletion('protect', $_GET['excludefile']);
|
||||
echo $response_data['message'];
|
||||
die();
|
||||
} else {
|
||||
$lines = file($home."/BirdNET-Pi/scripts/disk_check_exclude.txt");
|
||||
$search = $_GET['excludefile'];
|
||||
|
||||
$result = '';
|
||||
foreach($lines as $line) {
|
||||
if(stripos($line, $search) === false && stripos($line, $search.".png") === false) {
|
||||
$result .= $line;
|
||||
}
|
||||
}
|
||||
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", $result);
|
||||
echo "OK";
|
||||
$response_data = protectDetectionFromDeletion('unprotect', $_GET['excludefile']);
|
||||
echo $response_data['message'];
|
||||
die();
|
||||
}
|
||||
|
||||
} else {
|
||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
@@ -102,42 +61,23 @@ $shifted_path = $home."/BirdSongs/Extracted/By_Date/shifted/";
|
||||
if(isset($_GET['shiftfile'])) {
|
||||
|
||||
$filename = $_GET['shiftfile'];
|
||||
$pp = pathinfo($filename);
|
||||
$dir = $pp['dirname'];
|
||||
$fn = $pp['filename'];
|
||||
$ext = $pp['extension'];
|
||||
$pi = $home."/BirdSongs/Extracted/By_Date/";
|
||||
|
||||
$doShift = null;
|
||||
if (isset($_GET['doshift'])) {
|
||||
$freqshift_tool = $config['FREQSHIFT_TOOL'];
|
||||
|
||||
if ($freqshift_tool == "ffmpeg") {
|
||||
$cmd = "sudo /usr/bin/nohup /usr/bin/ffmpeg -y -i \"".$pi.$filename."\" -af \"rubberband=pitch=".$config['FREQSHIFT_LO']."/".$config['FREQSHIFT_HI']."\" \"".$shifted_path.$filename."\"";
|
||||
shell_exec("sudo mkdir -p ".$shifted_path.$dir." && ".$cmd);
|
||||
|
||||
} else if ($freqshift_tool == "sox") {
|
||||
//linux.die.net/man/1/sox
|
||||
$soxopt = "-q";
|
||||
$soxpitch = $config['FREQSHIFT_PITCH'];
|
||||
$cmd = "sudo /usr/bin/nohup /usr/bin/sox \"".$pi.$filename."\" \"".$shifted_path.$filename."\" pitch ".$soxopt." ".$soxpitch;
|
||||
shell_exec("sudo mkdir -p ".$shifted_path.$dir." && ".$cmd);
|
||||
}
|
||||
} else {
|
||||
$cmd = "sudo rm -f " . $shifted_path.$filename;
|
||||
shell_exec($cmd);
|
||||
$doShift = true;
|
||||
}
|
||||
|
||||
echo "OK";
|
||||
$response_data = frequencyShiftDetectionAudio($filename, $doShift);
|
||||
echo $response_data['message'];
|
||||
die();
|
||||
}
|
||||
|
||||
if(isset($_GET['bydate'])){
|
||||
$statement = $db->prepare('SELECT DISTINCT(Date) FROM detections GROUP BY Date ORDER BY Date DESC');
|
||||
if($statement == False){
|
||||
echo "Database is busy";
|
||||
$result_data = getDetectionsByDate();
|
||||
if($result_data['success'] == False){
|
||||
echo $result_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result = $statement->execute();
|
||||
$result = $result_data['data'];
|
||||
$view = "bydate";
|
||||
|
||||
#Specific Date
|
||||
@@ -146,30 +86,36 @@ if(isset($_GET['bydate'])){
|
||||
session_start();
|
||||
$_SESSION['date'] = $date;
|
||||
if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
|
||||
$statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" GROUP BY Com_Name ORDER BY COUNT(*) DESC");
|
||||
$sort = $_GET['sort'];
|
||||
} else {
|
||||
$statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" ORDER BY Com_Name");
|
||||
$sort = null;
|
||||
}
|
||||
if($statement == False){
|
||||
echo "Database is busy";
|
||||
$result_data = getDetectionsByDate($date, $sort);
|
||||
if($result_data['success'] == False){
|
||||
echo $result_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result = $statement->execute();
|
||||
$result = $result_data['data'];
|
||||
|
||||
$view = "date";
|
||||
|
||||
#By Species
|
||||
} elseif(isset($_GET['byspecies'])) {
|
||||
if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
|
||||
$statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');
|
||||
$sort = $_GET['sort'];
|
||||
} else {
|
||||
$statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name ASC');
|
||||
$sort = null;
|
||||
}
|
||||
|
||||
session_start();
|
||||
if($statement == False){
|
||||
echo "Database is busy";
|
||||
|
||||
$resultArr_data = getDetectionsBySpecies(null, $sort);
|
||||
if($resultArr_data['success'] == False){
|
||||
echo $resultArr_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result = $statement->execute();
|
||||
$result = $resultArr_data['data']['species'];
|
||||
|
||||
$view = "byspecies";
|
||||
|
||||
#Specific Species
|
||||
@@ -177,15 +123,16 @@ if(isset($_GET['bydate'])){
|
||||
$species = $_GET['species'];
|
||||
session_start();
|
||||
$_SESSION['species'] = $species;
|
||||
$statement = $db->prepare("SELECT * FROM detections WHERE Com_Name == \"$species\" ORDER BY Com_Name");
|
||||
$statement3 = $db->prepare("SELECT Date, Time, Sci_Name, MAX(Confidence), File_Name FROM detections WHERE Com_Name == \"$species\" ORDER BY Com_Name");
|
||||
if($statement == False || $statement3 == False){
|
||||
echo "Database is busy";
|
||||
|
||||
$resultArr_data = getDetectionsBySpecies($species, null);
|
||||
if($resultArr_data['success'] == False){
|
||||
echo $resultArr_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result = $statement->execute();
|
||||
$result3 = $statement3->execute();
|
||||
$result = $resultArr_data['data']['species'];
|
||||
$resul3 = $resultArr_data['data']['species_MaxConf'];
|
||||
$view = "species";
|
||||
|
||||
} else {
|
||||
session_start();
|
||||
session_unset();
|
||||
@@ -312,18 +259,18 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
|
||||
<?php
|
||||
#By Date
|
||||
if($view == "bydate") {
|
||||
while($results=$result->fetchArray(SQLITE3_ASSOC)){
|
||||
$date = $results['Date'];
|
||||
foreach ($result as $bd_result){
|
||||
$date = $bd_result['Date'];
|
||||
if(realpath($home."/BirdSongs/Extracted/By_Date/".$date) !== false){
|
||||
echo "<td>
|
||||
<button action=\"submit\" name=\"date\" value=\"$date\">".($date == date('Y-m-d') ? "Today" : $date)."</button></td></tr>";}}
|
||||
<button action=\"submit\" name=\"date\" value=\"$date\">".($date == date('Y-m-d') ? "Today" : $date)."</button></td></tr>";}
|
||||
}
|
||||
|
||||
#By Species
|
||||
} elseif($view == "byspecies") {
|
||||
$birds = array();
|
||||
while($results=$result->fetchArray(SQLITE3_ASSOC))
|
||||
{
|
||||
$name = $results['Com_Name'];
|
||||
foreach ($result as $species_bird_name) {
|
||||
$name = $species_bird_name['Com_Name'];
|
||||
$birds[] = $name;
|
||||
}
|
||||
|
||||
@@ -355,9 +302,8 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
|
||||
}
|
||||
} elseif($view == "date") {
|
||||
$birds = array();
|
||||
while($results=$result->fetchArray(SQLITE3_ASSOC))
|
||||
{
|
||||
$name = $results['Com_Name'];
|
||||
foreach ($result as $species_bird_name) {
|
||||
$name = $species_bird_name['Com_Name'];
|
||||
if (realpath($home . "/BirdSongs/Extracted/By_Date/" . $date . "/" . str_replace(" ", "_", $name)) !== false) {
|
||||
$birds[] = $name;
|
||||
}
|
||||
@@ -428,37 +374,37 @@ if ($fp) {
|
||||
}
|
||||
|
||||
$name = $_GET['species'];
|
||||
$confidence = null;
|
||||
if(isset($_SESSION['date'])) {
|
||||
$date = $_SESSION['date'];
|
||||
if(isset($_GET['sort']) && $_GET['sort'] == "confidence") {
|
||||
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" AND Date == \"$date\" ORDER BY Confidence DESC");
|
||||
} else {
|
||||
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" AND Date == \"$date\" ORDER BY Time DESC");
|
||||
$confidence = $_GET['sort'];
|
||||
}
|
||||
$result2_data = getSpeciesDetectionInfo($name, $date, $confidence);
|
||||
} else {
|
||||
if(isset($_GET['sort']) && $_GET['sort'] == "confidence") {
|
||||
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" ORDER BY Confidence DESC");
|
||||
} else {
|
||||
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" ORDER BY Date DESC, Time DESC");
|
||||
$confidence = $_GET['sort'];
|
||||
}
|
||||
$result2_data = getSpeciesDetectionInfo($name, null, $confidence);
|
||||
}
|
||||
if($statement2 == False){
|
||||
echo "Database is busy";
|
||||
|
||||
if ($result2_data['success'] == False) {
|
||||
echo $result2_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result2 = $statement2->execute();
|
||||
$num_rows = 0;
|
||||
while ($result2->fetchArray(SQLITE3_ASSOC)) {
|
||||
$num_rows++;
|
||||
}
|
||||
$result2->reset(); // reset the pointer to the beginning of the result set
|
||||
$result2 = $result2_data['data'];
|
||||
|
||||
//Count number of records we have
|
||||
$num_rows = count($result2);
|
||||
|
||||
echo "<table>
|
||||
<tr>
|
||||
<th>$name</th>
|
||||
</tr>";
|
||||
$iter=0;
|
||||
while($results=$result2->fetchArray(SQLITE3_ASSOC))
|
||||
while($iter < count($result2))
|
||||
{
|
||||
$results = $result2[$iter];
|
||||
$comname = preg_replace('/ /', '_', $results['Com_Name']);
|
||||
$comname = preg_replace('/\'/', '', $comname);
|
||||
$date = $results['Date'];
|
||||
@@ -471,6 +417,7 @@ echo "<table>
|
||||
$confidence = round((float)round($results['Confidence'],2) * 100 ) . '%';
|
||||
$filename_formatted = $date."/".$comname."/".$results['File_Name'];
|
||||
|
||||
$iter++;
|
||||
// file was deleted by disk check, no need to show the detection in recordings
|
||||
if(!file_exists($home."/BirdSongs/Extracted/".$filename)) {
|
||||
continue;
|
||||
@@ -478,12 +425,11 @@ echo "<table>
|
||||
if(!in_array($filename_formatted, $disk_check_exclude_arr) && isset($_GET['only_excluded'])) {
|
||||
continue;
|
||||
}
|
||||
$iter++;
|
||||
|
||||
if($num_rows < 100){
|
||||
$imageelem = "<video onplay='setLiveStreamVolume(0)' onended='setLiveStreamVolume(1)' onpause='setLiveStreamVolume(1)' controls poster=\"$filename_png\" preload=\"none\" title=\"$filename\"><source src=\"$filename\"></video>";
|
||||
} else {
|
||||
$imageelem = "<a href=\"$filename\"><img src=\"$filename_png\"></a>";
|
||||
$imageelem = "<a target='_blank' href=\"$filename\"><img src=\"$filename_png\"></a>";
|
||||
}
|
||||
|
||||
if($config["FULL_DISK"] == "purge") {
|
||||
@@ -531,17 +477,17 @@ echo "<table>
|
||||
|
||||
if(isset($_GET['filename'])){
|
||||
$name = $_GET['filename'];
|
||||
$statement2 = $db->prepare("SELECT * FROM detections where File_name == \"$name\" ORDER BY Date DESC, Time DESC");
|
||||
if($statement2 == False){
|
||||
echo "Database is busy";
|
||||
$result2_data = getDetectionsByFilename($name);
|
||||
if($result2_data['success'] == False){
|
||||
echo $result2_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result2 = $statement2->execute();
|
||||
$result2 = $result2_data['data'];
|
||||
echo "<table>
|
||||
<tr>
|
||||
<th>$name</th>
|
||||
</tr>";
|
||||
while($results=$result2->fetchArray(SQLITE3_ASSOC))
|
||||
foreach ($result2 as $results)
|
||||
{
|
||||
$comname = preg_replace('/ /', '_', $results['Com_Name']);
|
||||
$comname = preg_replace('/\'/', '', $comname);
|
||||
@@ -600,7 +546,9 @@ echo "<table>
|
||||
</tr>";
|
||||
}
|
||||
|
||||
}echo "</table>";}?>
|
||||
}
|
||||
echo "</table>";
|
||||
}?>
|
||||
</div>
|
||||
<style>
|
||||
td.spec {
|
||||
|
||||
+74
-64
@@ -1,61 +1,84 @@
|
||||
<?php
|
||||
ini_set('user_agent', 'PHP_Flickr/1.0');
|
||||
error_reporting(0);
|
||||
ini_set('display_errors', 0);
|
||||
include_once "./scripts/common.php";
|
||||
|
||||
//$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
//if($db == False) {
|
||||
// echo "Database busy";
|
||||
// header("refresh: 0;");
|
||||
//}
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
if($db == False) {
|
||||
echo "Database busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
|
||||
if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
|
||||
|
||||
$statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');
|
||||
if($statement == False) {
|
||||
echo "Database busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result = $statement->execute();
|
||||
// $statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');
|
||||
// if($statement == False) {
|
||||
// echo "Database busy";
|
||||
// header("refresh: 0;");
|
||||
// }
|
||||
// $result = $statement->execute();
|
||||
//
|
||||
// $statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');
|
||||
// if($statement == False) {
|
||||
// echo "Database busy";
|
||||
// header("refresh: 0;");
|
||||
// }
|
||||
//
|
||||
// $result2 = $statement2->execute();
|
||||
|
||||
$statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');
|
||||
if($statement == False) {
|
||||
echo "Database busy";
|
||||
$sort = "occurrences";
|
||||
$result2_data = getSpeciesBestRecordingList($sort);
|
||||
|
||||
if ($result2_data['success'] == False) {
|
||||
echo $result2_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result2 = $statement2->execute();
|
||||
$result2 = $result2_data['data'];
|
||||
} else {
|
||||
|
||||
$statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC');
|
||||
if($statement == False) {
|
||||
echo "Database busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result = $statement->execute();
|
||||
// $statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC');
|
||||
// if($statement == False) {
|
||||
// echo "Database busy";
|
||||
// header("refresh: 0;");
|
||||
// }
|
||||
// $result = $statement->execute();
|
||||
//
|
||||
// $statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC');
|
||||
// if($statement == False) {
|
||||
// echo "Database busy";
|
||||
// header("refresh: 0;");
|
||||
// }
|
||||
// $result2 = $statement2->execute();
|
||||
|
||||
$statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC');
|
||||
if($statement == False) {
|
||||
echo "Database busy";
|
||||
$result2_data = getSpeciesBestRecordingList();
|
||||
|
||||
if ($result2_data['success'] == False) {
|
||||
echo $result2_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result2 = $statement2->execute();
|
||||
$result2 = $result2_data['data'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(isset($_GET['species'])){
|
||||
$selection = $_GET['species'];
|
||||
$statement3 = $db->prepare("SELECT Com_Name, Sci_Name, COUNT(*), MAX(Confidence), File_Name, Date, Time from detections WHERE Com_Name = \"$selection\"");
|
||||
if($statement3 == False) {
|
||||
echo "Database busy";
|
||||
// $statement3 = $db->prepare("SELECT Com_Name, Sci_Name, COUNT(*), MAX(Confidence), File_Name, Date, Time from detections WHERE Com_Name = \"$selection\"");
|
||||
// if($statement3 == False) {
|
||||
// echo "Database busy";
|
||||
// header("refresh: 0;");
|
||||
// }
|
||||
// $result3 = $statement3->execute();
|
||||
$result3_data = getBestRecordingsForSpecies($selection);
|
||||
if($result3_data['success'] == False){
|
||||
echo $result3_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result3 = $statement3->execute();
|
||||
$result3 = $result3_data['data'];
|
||||
}
|
||||
|
||||
$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
|
||||
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
|
||||
$home = trim($home);
|
||||
//$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
|
||||
//$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
|
||||
//$home = trim($home);
|
||||
if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt") || strpos(file_get_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt"),"##start") === false) {
|
||||
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "");
|
||||
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start\n##end\n");
|
||||
@@ -91,7 +114,7 @@ if(!file_exists($home."/BirdNET-Pi/scripts/disk_check_exclude.txt") || strpos(fi
|
||||
<table style="padding-top:10px">
|
||||
<?php
|
||||
$birds = array();
|
||||
while($results=$result2->fetchArray(SQLITE3_ASSOC))
|
||||
foreach($result2 as $results)
|
||||
{
|
||||
$comname = preg_replace('/ /', '_', $results['Com_Name']);
|
||||
$comname = preg_replace('/\'/', '', $comname);
|
||||
@@ -176,7 +199,7 @@ function setModalText(iter, title, text, authorlink) {
|
||||
$species = $_GET['species'];
|
||||
$iter=0;
|
||||
$lines;
|
||||
while($results=$result3->fetchArray(SQLITE3_ASSOC)){
|
||||
foreach ($result3 as $results){
|
||||
$count = $results['COUNT(*)'];
|
||||
$maxconf = round((float)round($results['MAX(Confidence)'],2) * 100 ) . '%';
|
||||
$date = $results['Date'];
|
||||
@@ -204,33 +227,20 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){
|
||||
|
||||
ob_flush();
|
||||
flush();
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
} elseif (file_exists('./scripts/firstrun.ini')) {
|
||||
$config = parse_ini_file('./scripts/firstrun.ini');
|
||||
}
|
||||
if (! empty($config["FLICKR_API_KEY"])) {
|
||||
// only open the file once per script execution
|
||||
if(!isset($lines)) {
|
||||
$lines = file($home."/BirdNET-Pi/model/labels_flickr.txt");
|
||||
}
|
||||
// convert sci name to English name
|
||||
foreach($lines as $line){
|
||||
if(strpos($line, $results['Sci_Name']) !== false){
|
||||
$engname = trim(explode("_", $line)[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$flickr_data = getFlickrImage($results, true);
|
||||
|
||||
$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=\"".str_replace(' ', '%20', $engname)."\"&license=2%2C3%2C4%2C5%2C6%2C9&sort=relevance&per_page=15&format=json&nojsoncallback=1"), true)["photos"]["photo"];
|
||||
|
||||
foreach ($flickrjson as $val) {
|
||||
//Loop over the photos data
|
||||
if ($flickr_data['image_found']) {
|
||||
$flickr_image_data = $flickr_data['data']['photos'];
|
||||
$iter = 0;
|
||||
foreach ($flickr_image_data as $key => $img_data) {
|
||||
$imageurl = $img_data['image_url'];
|
||||
$title = $img_data['photo_title'];
|
||||
$modaltext = $img_data['modal_text'];
|
||||
$authorlink = $img_data['author_link'];
|
||||
|
||||
echo "<span style='cursor:pointer;' onclick='setModalText(" . $iter . ",\"" . $title . "\",\"" . $modaltext . "\", \"" . $authorlink . "\")'><img style='vertical-align:top' src=\"$imageurl\"></span>";
|
||||
$iter++;
|
||||
$modaltext = "https://flickr.com/photos/".$val["owner"]."/".$val["id"];
|
||||
$authorlink = "https://flickr.com/people/".$val["owner"];
|
||||
$imageurl = 'https://farm' .$val["farm"]. '.static.flickr.com/' .$val["server"]. '/' .$val["id"]. '_' .$val["secret"]. '.jpg';
|
||||
echo "<span style='cursor:pointer;' onclick='setModalText(".$iter.",\"".$val["title"]."\",\"".$modaltext."\", \"".$authorlink."\")'><img style='vertical-align:top' src=\"$imageurl\"></span>";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -246,7 +256,7 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){
|
||||
<table>
|
||||
<?php
|
||||
$excludelines = [];
|
||||
while($results=$result->fetchArray(SQLITE3_ASSOC))
|
||||
foreach($result2 as $results)
|
||||
{
|
||||
$comname = preg_replace('/ /', '_', $results['Com_Name']);
|
||||
$comname = preg_replace('/\'/', '', $comname);
|
||||
@@ -266,8 +276,8 @@ array_push($excludelines, $results['Date']."/".$comname."/".$results['File_Name'
|
||||
<?php
|
||||
}
|
||||
|
||||
$file = file_get_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt");
|
||||
file_put_contents($home."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start"."\n".implode("\n",$excludelines)."\n".substr($file, strpos($file, "##end")));
|
||||
$file = file_get_contents(getDirectory('home')."/BirdNET-Pi/scripts/disk_check_exclude.txt");
|
||||
file_put_contents(getDirectory('home')."/BirdNET-Pi/scripts/disk_check_exclude.txt", "##start"."\n".implode("\n",$excludelines)."\n".substr($file, strpos($file, "##end")));
|
||||
?>
|
||||
</table>
|
||||
</form>
|
||||
|
||||
+56
-208
@@ -1,128 +1,65 @@
|
||||
<?php
|
||||
ini_set('session.gc_maxlifetime', 7200);
|
||||
ini_set('user_agent', 'PHP_Flickr/1.0');
|
||||
session_set_cookie_params(7200);
|
||||
session_start();
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
} elseif (file_exists('./scripts/firstrun.ini')) {
|
||||
$config = parse_ini_file('./scripts/firstrun.ini');
|
||||
}
|
||||
|
||||
if($config["SITE_NAME"] == "") {
|
||||
$site_name = "BirdNET-Pi";
|
||||
} else {
|
||||
$site_name = $config['SITE_NAME'];
|
||||
}
|
||||
include_once "./scripts/common.php";
|
||||
|
||||
if($kiosk == true) {
|
||||
echo "<div style='margin-top:20px' class=\"centered\"><h1><a><img class=\"topimage\" src=\"images/bnp.png\"></a></h1></div>
|
||||
</div><div class=\"centered\"><h3>$site_name</h3></div><hr>";
|
||||
}
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
if($db == False){
|
||||
echo "Database is busy";
|
||||
$totalcount_data = getDetectionCountAll();
|
||||
if($totalcount_data['success'] == False){
|
||||
echo $totalcount_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$totalcount = $totalcount_data['data'];
|
||||
|
||||
$statement1 = $db->prepare('SELECT COUNT(*) FROM detections');
|
||||
if($statement1 == False){
|
||||
echo "Database is busy";
|
||||
|
||||
$todaycount_data = getDetectionCountToday();
|
||||
if($todaycount_data['success'] == False){
|
||||
echo $todaycount_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result1 = $statement1->execute();
|
||||
$totalcount = $result1->fetchArray(SQLITE3_ASSOC);
|
||||
$todaycount = $todaycount_data['data'];
|
||||
|
||||
$statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == DATE(\'now\', \'localtime\')');
|
||||
if($statement2 == False){
|
||||
echo "Database is busy";
|
||||
|
||||
$hourcount_data = getDetectionCountLastHour();
|
||||
if($hourcount_data['success'] == False){
|
||||
echo $hourcount_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result2 = $statement2->execute();
|
||||
$todaycount = $result2->fetchArray(SQLITE3_ASSOC);
|
||||
$hourcount = $hourcount_data['data'];
|
||||
|
||||
$statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == Date(\'now\', \'localtime\') AND TIME >= TIME(\'now\', \'localtime\', \'-1 hour\')');
|
||||
if($statement3 == False){
|
||||
echo "Database is busy";
|
||||
|
||||
$mostrecent_data = getMostRecentDetection();
|
||||
if($mostrecent_data['success'] == False){
|
||||
echo $mostrecent_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result3 = $statement3->execute();
|
||||
$hourcount = $result3->fetchArray(SQLITE3_ASSOC);
|
||||
$mostrecent = $mostrecent_data['data'];
|
||||
|
||||
$statement4 = $db->prepare('SELECT Com_Name, Sci_Name, Time, Confidence FROM detections LIMIT 1');
|
||||
if($statement4 == False){
|
||||
echo "Database is busy";
|
||||
|
||||
$todayspeciestally_data = getSpeciesTalley();
|
||||
if($todayspeciestally_data['success'] == False){
|
||||
echo $todayspeciestally_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result4 = $statement4->execute();
|
||||
$mostrecent = $result4->fetchArray(SQLITE3_ASSOC);
|
||||
$todayspeciestally = $todayspeciestally_data['data'];
|
||||
|
||||
$statement5 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections WHERE Date == Date(\'now\', \'localtime\')');
|
||||
if($statement5 == False){
|
||||
echo "Database is busy";
|
||||
|
||||
$totalspeciestally_data = getAllSpeciesTalley();
|
||||
if($totalspeciestally_data['success'] == False){
|
||||
echo $totalspeciestally_data['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result5 = $statement5->execute();
|
||||
$todayspeciestally = $result5->fetchArray(SQLITE3_ASSOC);
|
||||
$totalspeciestally = $totalspeciestally_data['data'];
|
||||
|
||||
$statement6 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections');
|
||||
if($statement6 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result6 = $statement6->execute();
|
||||
$totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
|
||||
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
|
||||
$home = trim($home);
|
||||
|
||||
if(isset($_GET['comname'])) {
|
||||
$birdName = $_GET['comname'];
|
||||
$birdName = str_replace("_", " ", $birdName);
|
||||
|
||||
echo getBirdDetectionStats($birdName)['data'];
|
||||
|
||||
// Prepare a SQL statement to retrieve the detection data for the specified bird
|
||||
$stmt = $db->prepare('SELECT Date, COUNT(*) AS Detections FROM detections WHERE Com_Name = :com_name AND Date BETWEEN DATE("now", "-30 days") AND DATE("now") GROUP BY Date');
|
||||
|
||||
// Bind the bird name parameter to the SQL statement
|
||||
$stmt->bindValue(':com_name', $birdName);
|
||||
|
||||
// Execute the SQL statement and get the result set
|
||||
$result = $stmt->execute();
|
||||
|
||||
// Fetch the result set as an associative array
|
||||
$data = array();
|
||||
while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
|
||||
$data[$row['Date']] = $row['Detections'];
|
||||
}
|
||||
|
||||
// Create an array of all dates in the last 14 days
|
||||
$last14Days = array();
|
||||
for ($i = 0; $i < 31; $i++) {
|
||||
$last14Days[] = date('Y-m-d', strtotime("-$i days"));
|
||||
}
|
||||
|
||||
// Merge the data array with the last14Days array
|
||||
$data = array_merge(array_fill_keys($last14Days, 0), $data);
|
||||
|
||||
// Sort the data by date in ascending order
|
||||
ksort($data);
|
||||
|
||||
// Convert the data to an array of objects
|
||||
$data = array_map(function($date, $count) {
|
||||
return array('date' => $date, 'count' => $count);
|
||||
}, array_keys($data), $data);
|
||||
|
||||
// Close the database connection
|
||||
$db->close();
|
||||
|
||||
// Return the data as JSON
|
||||
echo json_encode($data);
|
||||
die();
|
||||
|
||||
}
|
||||
@@ -175,137 +112,48 @@ function relativeTime($ts)
|
||||
|
||||
|
||||
if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
|
||||
if(isset($_GET['searchterm'])) {
|
||||
if(strtolower(explode(" ", $_GET['searchterm'])[0]) == "not") {
|
||||
$not = "NOT ";
|
||||
$operator = "AND";
|
||||
$_GET['searchterm'] = str_replace("not ", "", $_GET['searchterm']);
|
||||
$_GET['searchterm'] = str_replace("NOT ", "", $_GET['searchterm']);
|
||||
} else {
|
||||
$not = "";
|
||||
$operator = "OR";
|
||||
}
|
||||
$searchquery = "AND (Com_name ".$not."LIKE '%".$_GET['searchterm']."%' ".$operator." Sci_name ".$not."LIKE '%".$_GET['searchterm']."%' ".$operator." Confidence ".$not."LIKE '%".$_GET['searchterm']."%' ".$operator." File_Name ".$not."LIKE '%".$_GET['searchterm']."%' ".$operator." Time ".$not."LIKE '%".$_GET['searchterm']."%')";
|
||||
} else {
|
||||
$searchquery = "";
|
||||
}
|
||||
if(isset($_GET['display_limit']) && is_numeric($_GET['display_limit'])){
|
||||
$statement0 = $db->prepare('SELECT Time, Com_Name, Sci_Name, Confidence, File_Name FROM detections WHERE Date == Date(\'now\', \'localtime\') '.$searchquery.' ORDER BY Time DESC LIMIT '.(intval($_GET['display_limit'])-40).',40');
|
||||
} else {
|
||||
// legacy mode
|
||||
if(isset($_GET['hard_limit']) && is_numeric($_GET['hard_limit'])) {
|
||||
$statement0 = $db->prepare('SELECT Time, Com_Name, Sci_Name, Confidence, File_Name FROM detections WHERE Date == Date(\'now\', \'localtime\') '.$searchquery.' ORDER BY Time DESC LIMIT '.$_GET['hard_limit']);
|
||||
} else {
|
||||
$statement0 = $db->prepare('SELECT Time, Com_Name, Sci_Name, Confidence, File_Name FROM detections WHERE Date == Date(\'now\', \'localtime\') '.$searchquery.' ORDER BY Time DESC');
|
||||
}
|
||||
$result0 = getTodaysDetections($_GET['display_limit'], $_GET['searchterm'], $_GET['hard_limit']);
|
||||
|
||||
}
|
||||
if($statement0 == False){
|
||||
echo "Database is busy";
|
||||
if($result0['success'] == False){
|
||||
echo $result0['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result0 = $statement0->execute();
|
||||
|
||||
$result0 = $result0['data'];
|
||||
?> <table>
|
||||
<?php
|
||||
|
||||
if(!isset($_SESSION['images'])) {
|
||||
$_SESSION['images'] = [];
|
||||
}
|
||||
$iterations = 0;
|
||||
$lines=null;
|
||||
$licenses_urls = array();
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
} elseif (file_exists('./scripts/firstrun.ini')) {
|
||||
$config = parse_ini_file('./scripts/firstrun.ini');
|
||||
}
|
||||
|
||||
|
||||
while($todaytable=$result0->fetchArray(SQLITE3_ASSOC))
|
||||
foreach($result0 as $todaytable)
|
||||
{
|
||||
$iterations++;
|
||||
|
||||
$comname = preg_replace('/ /', '_', $todaytable['Com_Name']);
|
||||
$comname = preg_replace('/\'/', '_', $comname);
|
||||
$filename = "/By_Date/".date('Y-m-d')."/".$comname."/".$todaytable['File_Name'];
|
||||
$filename_formatted = $todaytable['Date']."/".$comname."/".$todaytable['File_Name'];
|
||||
$sciname = preg_replace('/ /', '_', $todaytable['Sci_Name']);
|
||||
$args = "&license=2%2C3%2C4%2C5%2C6%2C9&orientation=square,portrait";
|
||||
$comnameprefix = "%20bird";
|
||||
if (!empty($config["FLICKR_API_KEY"]) && (isset($_GET['display_limit']) || isset($_GET['hard_limit']) || $_GET['kiosk'] == true) ) {
|
||||
//Get the flickr image for this detection
|
||||
$flickr_Image = getFlickrImage($todaytable);
|
||||
|
||||
if(!empty($config["FLICKR_FILTER_EMAIL"])) {
|
||||
if(!isset($_SESSION["FLICKR_FILTER_EMAIL"])) {
|
||||
unset($_SESSION['images']);
|
||||
$_SESSION['FLICKR_FILTER_EMAIL'] = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.people.findByEmail&api_key=".$config["FLICKR_API_KEY"]."&find_email=".$config["FLICKR_FILTER_EMAIL"]."&format=json&nojsoncallback=1"), true)["user"]["nsid"];
|
||||
}
|
||||
$args = "&user_id=".$_SESSION['FLICKR_FILTER_EMAIL'];
|
||||
$comnameprefix = "";
|
||||
} else {
|
||||
if(isset($_SESSION["FLICKR_FILTER_EMAIL"])) {
|
||||
unset($_SESSION["FLICKR_FILTER_EMAIL"]);
|
||||
unset($_SESSION['images']);
|
||||
}
|
||||
if ($flickr_Image['image_found']) {
|
||||
//Remap the data from returned data into an array that is referenced in our HTML
|
||||
//to save have to rewrite or adjust it
|
||||
$flickr_Image_data = $flickr_Image['data'];
|
||||
|
||||
$image = [
|
||||
0 => $flickr_Image_data['Com_Name_clean'],
|
||||
1 => $flickr_Image_data['photos'][0]['image_url'],
|
||||
2 => $flickr_Image_data['photos'][0]['photo_title'],
|
||||
3 => $flickr_Image_data['photos'][0]['modal_text'],
|
||||
4 => $flickr_Image_data['photos'][0]['author_link'],
|
||||
5 => $flickr_Image_data['photos'][0]['license_url']
|
||||
];
|
||||
}
|
||||
|
||||
// if we already searched flickr for this species before, use the previous image rather than doing an unneccesary api call
|
||||
$key = array_search($comname, array_column($_SESSION['images'], 0));
|
||||
if($key !== false) {
|
||||
$image = $_SESSION['images'][$key];
|
||||
} else {
|
||||
// Get license information if we haven't already
|
||||
if (empty($licenses_urls)) {
|
||||
$licenses_url = "https://api.flickr.com/services/rest/?method=flickr.photos.licenses.getInfo&api_key=".$config["FLICKR_API_KEY"]."&format=json&nojsoncallback=1";
|
||||
$licenses_response = file_get_contents($licenses_url);
|
||||
$licenses_data = json_decode($licenses_response, true)["licenses"]["license"];
|
||||
foreach ($licenses_data as $license) {
|
||||
$license_id = $license["id"];
|
||||
$license_name = $license["name"];
|
||||
$license_url = $license["url"];
|
||||
$licenses_urls[$license_id] = $license_url;
|
||||
}
|
||||
}
|
||||
//Fill in the missing variables as they're not created at each loop anymore, getFlickrImage generates this data now as per what the orignal loop did
|
||||
$filename = $flickr_Image_data['filename_path'];
|
||||
$filename_formatted = $flickr_Image_data['filename_formatted'];
|
||||
$sciname = $flickr_Image_data['Sci_Name_clean'];
|
||||
$comname =$flickr_Image_data['Com_Name_clean'];
|
||||
|
||||
// only open the file once per script execution
|
||||
if(!isset($lines)) {
|
||||
$lines = file($home."/BirdNET-Pi/model/labels_flickr.txt");
|
||||
}
|
||||
// convert sci name to English name
|
||||
foreach($lines as $line){
|
||||
if(strpos($line, $todaytable['Sci_Name']) !== false){
|
||||
$engname = trim(explode("_", $line)[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Read the blacklisted image ids from the file into an array
|
||||
$blacklisted_ids = array_map('trim', file($home."/BirdNET-Pi/scripts/blacklisted_images.txt"));
|
||||
|
||||
// Make the API call
|
||||
$flickrjson = json_decode(file_get_contents("https://www.flickr.com/services/rest/?method=flickr.photos.search&api_key=".$config["FLICKR_API_KEY"]."&text=".str_replace(" ", "%20", $engname).$comnameprefix."&sort=relevance".$args."&per_page=5&media=photos&format=json&nojsoncallback=1"), true)["photos"]["photo"];
|
||||
|
||||
// Find the first photo that is not blacklisted or is not the specific blacklisted id
|
||||
$photo = null;
|
||||
foreach ($flickrjson as $flickrphoto) {
|
||||
if ($flickrphoto["id"] !== "4892923285" && !in_array($flickrphoto["id"], $blacklisted_ids)) {
|
||||
$photo = $flickrphoto;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$license_url = "https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=".$config["FLICKR_API_KEY"]."&photo_id=".$photo["id"]."&format=json&nojsoncallback=1";
|
||||
$license_response = file_get_contents($license_url);
|
||||
$license_info = json_decode($license_response, true)["photo"]["license"];
|
||||
$license_url = $licenses_urls[$license_info];
|
||||
|
||||
$modaltext = "https://flickr.com/photos/".$photo["owner"]."/".$photo["id"];
|
||||
$authorlink = "https://flickr.com/people/".$photo["owner"];
|
||||
$imageurl = 'https://farm' .$photo["farm"]. '.static.flickr.com/' .$photo["server"]. '/' .$photo["id"]. '_' .$photo["secret"]. '.jpg';
|
||||
array_push($_SESSION['images'], array($comname,$imageurl,$photo["title"], $modaltext, $authorlink, $license_url));
|
||||
$image = $_SESSION['images'][count($_SESSION['images'])-1];
|
||||
}
|
||||
}
|
||||
?>
|
||||
<?php if(isset($_GET['display_limit']) && is_numeric($_GET['display_limit'])){ ?>
|
||||
<tr class="relative" id="<?php echo $iterations; ?>">
|
||||
|
||||
+53
-69
@@ -1,7 +1,5 @@
|
||||
<?php
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
include_once "./scripts/common.php";
|
||||
|
||||
$startdate = strtotime('last sunday') - (7*86400);
|
||||
$enddate = strtotime('last sunday') - (1*86400);
|
||||
@@ -16,44 +14,38 @@ if(isset($_GET['ascii'])) {
|
||||
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;");
|
||||
}
|
||||
$result1 = $statement1->execute();
|
||||
$weekly_species_counts = getWeeklyReportSpeciesDetectionCounts();
|
||||
|
||||
$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";
|
||||
if($weekly_species_counts['detections']['success'] == False){
|
||||
echo $weekly_species_counts['detections']['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result4 = $statement4->execute();
|
||||
$totalcount = $result4->fetchArray(SQLITE3_ASSOC)['COUNT(*)'];
|
||||
$result1 = $weekly_species_counts['detections']['data'];
|
||||
|
||||
$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";
|
||||
if($weekly_species_counts['totalcount']['success'] == False){
|
||||
echo $weekly_species_counts['totalcount']['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result5 = $statement5->execute();
|
||||
$priortotalcount = $result5->fetchArray(SQLITE3_ASSOC)['COUNT(*)'];
|
||||
$totalcount = $weekly_species_counts['totalcount']['data']['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";
|
||||
if($weekly_species_counts['priortotalcount']['success'] == False){
|
||||
echo $weekly_species_counts['priortotalcount']['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result6 = $statement6->execute();
|
||||
$totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC)['COUNT(DISTINCT(Com_Name))'];
|
||||
$priortotalcount = $weekly_species_counts['priortotalcount']['data']['COUNT(*)'];
|
||||
|
||||
$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";
|
||||
$weekly_species_talley = getWeeklyReportSpeciesTalley();
|
||||
if($weekly_species_talley['totalspeciestally']['success'] == False){
|
||||
echo $weekly_species_talley['totalspeciestally']['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result7= $statement7->execute();
|
||||
$priortotalspeciestally = $result7->fetchArray(SQLITE3_ASSOC)['COUNT(DISTINCT(Com_Name))'];
|
||||
$totalspeciestally = $weekly_species_talley['totalspeciestally']['data']['COUNT(DISTINCT(Com_Name))'];
|
||||
|
||||
if($weekly_species_talley['priortotalspeciestally']['success'] == False){
|
||||
echo $weekly_species_talley['priortotalspeciestally']['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$priortotalspeciestally = $weekly_species_talley['priortotalspeciestally']['data']['COUNT(DISTINCT(Com_Name))'];
|
||||
|
||||
$percentagedifftotal = round( (($totalcount - $priortotalcount) / $priortotalcount) * 100 );
|
||||
|
||||
@@ -72,11 +64,10 @@ if(isset($_GET['ascii'])) {
|
||||
|
||||
$detections = [];
|
||||
$i = 0;
|
||||
while($detection=$result1->fetchArray(SQLITE3_ASSOC))
|
||||
foreach ($result1 as $detection)
|
||||
{
|
||||
$detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
|
||||
}
|
||||
|
||||
echo "# BirdNET-Pi: Week ".date('W', $enddate)." Report\n";
|
||||
|
||||
echo "Total Detections: <b>".$totalcount."</b> (".$percentagedifftotal.")<br>";
|
||||
@@ -90,14 +81,12 @@ if(isset($_GET['ascii'])) {
|
||||
$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)).'"');
|
||||
if($statement2 == False){
|
||||
echo "Database is busy";
|
||||
$statement2 = getWeeklyReportSpeciesDetection($com_name);
|
||||
if($statement2['success'] == False){
|
||||
echo $statement2['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result2 = $statement2->execute();
|
||||
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
|
||||
$priorweekcount = $totalcount['COUNT(*)'];
|
||||
$priorweekcount = $statement2['data']['COUNT(*)'];
|
||||
|
||||
// really percent changed
|
||||
if($priorweekcount > 0){
|
||||
@@ -121,14 +110,12 @@ if(isset($_GET['ascii'])) {
|
||||
$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";
|
||||
$statement3 = getWeeklyReportSpeciesDetection($com_name,false);
|
||||
if($statement3['success'] == False){
|
||||
echo $statement3['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result3 = $statement3->execute();
|
||||
$totalcount = $result3->fetchArray(SQLITE3_ASSOC);
|
||||
$nonthisweekcount = $totalcount['COUNT(*)'];
|
||||
$nonthisweekcount = $statement3['data']['COUNT(*)'];
|
||||
|
||||
if($nonthisweekcount == 0) {
|
||||
$newspeciescount++;
|
||||
@@ -153,26 +140,27 @@ 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
|
||||
|
||||
$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";
|
||||
$weekly_species_counts = getWeeklyReportSpeciesDetectionCounts();
|
||||
|
||||
if($weekly_species_counts['detections']['success'] == False){
|
||||
echo $weekly_species_counts['detections']['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result1 = $statement1->execute();
|
||||
$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'];
|
||||
}
|
||||
|
||||
$detections = [];
|
||||
$i = 0;
|
||||
while($detection=$result1->fetchArray(SQLITE3_ASSOC))
|
||||
foreach ($result1 as $detection)
|
||||
{
|
||||
if($debug == true){
|
||||
if($i > 10) {
|
||||
@@ -201,14 +189,12 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
|
||||
{
|
||||
$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)).'"');
|
||||
if($statement2 == False){
|
||||
echo "Database is busy";
|
||||
$statement2 = getWeeklyReportSpeciesDetection($com_name);
|
||||
if($statement2['success'] == False){
|
||||
echo $statement2['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result2 = $statement2->execute();
|
||||
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
|
||||
$priorweekcount = $totalcount['COUNT(*)'];
|
||||
$priorweekcount = $statement2['data']['COUNT(*)'];
|
||||
|
||||
if ($priorweekcount > 0) {
|
||||
$percentagediff = round( (($scount - $priorweekcount) / $priorweekcount) * 100 );
|
||||
@@ -242,14 +228,12 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
|
||||
$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";
|
||||
$statement3 = getWeeklyReportSpeciesDetection($com_name,false);
|
||||
if($statement3['success'] == False){
|
||||
echo $statement3['message'];
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$result3 = $statement3->execute();
|
||||
$totalcount = $result3->fetchArray(SQLITE3_ASSOC);
|
||||
$nonthisweekcount = $totalcount['COUNT(*)'];
|
||||
$nonthisweekcount = $statement3['data']['COUNT(*)'];
|
||||
|
||||
if($nonthisweekcount == 0) {
|
||||
$newspeciescount++;
|
||||
|
||||
Reference in New Issue
Block a user