prepare('SELECT Com_Name, Sci_Name, Date, Time, Confidence, File_Name FROM detections ORDER BY Date DESC, Time DESC LIMIT 5'); if($statement4 == False) { echo "Database is busy"; header("refresh: 0;"); } $result4 = $statement4->execute(); if(!isset($_SESSION['images'])) { $_SESSION['images'] = []; } $iterations = 0; $lines; // 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)) { $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 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 { // 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; } } $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"][0]; $modaltext = "https://flickr.com/photos/".$flickrjson["owner"]."/".$flickrjson["id"]; $authorlink = "https://flickr.com/people/".$flickrjson["owner"]; $imageurl = 'https://farm' .$flickrjson["farm"]. '.static.flickr.com/' .$flickrjson["server"]. '/' .$flickrjson["id"]. '_' .$flickrjson["secret"]. '.jpg'; array_push($_SESSION['images'], array($comname,$imageurl,$flickrjson["title"], $modaltext, $authorlink)); $image = $_SESSION['images'][count($_SESSION['images'])-1]; } } ?>

Most Recent Detection:

0) { ?>


Confidence:

No Detections For Today."; } die(); } 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"; header("refresh: 0;"); } $result = $statement->execute(); $totalcount = $result->fetchArray(SQLITE3_ASSOC); $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); $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"; header("refresh: 0;"); } $result5 = $statement5->execute(); $speciestally = $result5->fetchArray(SQLITE3_ASSOC); $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); ?>
Total
Today
Last Hour
Species Detected Today
Total Number of Species
Overview

"; } else { echo "

No Detections For Today

"; } ?>

5 Most Recent Detections

Loading...

Currently Analyzing

"; ?>