Merge branch 'sqlite-timeout'
This commit is contained in:
+14
-12
@@ -15,24 +15,33 @@ $user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd");
|
||||
$user = trim($user);
|
||||
$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");
|
||||
$home = trim($home);
|
||||
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');
|
||||
}
|
||||
function service_mount() {
|
||||
global $home;
|
||||
$service_mount=trim(shell_exec("systemd-escape -p --suffix=mount ".$home."/BirdSongs/StreamData"));
|
||||
return $service_mount;
|
||||
}
|
||||
if(!isset($_SESSION['behind'])) {
|
||||
$fetch = shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi fetch 2>&1");
|
||||
$authenticated = isset($_SERVER['PHP_AUTH_USER']) && $_SERVER['PHP_AUTH_PW'] == $config['CADDY_PWD'] && $_SERVER['PHP_AUTH_USER'] == 'birdnet';
|
||||
if($authenticated && (!isset($_SESSION['behind']) || !isset($_SESSION['behind_time']) || time() > $_SESSION['behind_time'] + 86400)) {
|
||||
shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi fetch > /dev/null 2>/dev/null &");
|
||||
$str = trim(shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi status"));
|
||||
if (preg_match("/behind '.*?' by (\d+) commit(s?)\b/", $str, $matches)) {
|
||||
$num_commits_behind = $matches[1];
|
||||
$_SESSION['behind'] = $num_commits_behind;
|
||||
}
|
||||
if (preg_match('/\b(\d+)\b and \b(\d+)\b different commits each/', $str, $matches)) {
|
||||
$num1 = (int) $matches[1];
|
||||
$num2 = (int) $matches[2];
|
||||
$sum = $num1 + $num2;
|
||||
$_SESSION['behind'] = $sum;
|
||||
$num_commits_behind = $num1 + $num2;
|
||||
}
|
||||
if (stripos($str, "Your branch is up to date") !== false) {
|
||||
$num_commits_behind = '0';
|
||||
}
|
||||
$_SESSION['behind'] = $num_commits_behind;
|
||||
$_SESSION['behind_time'] = time();
|
||||
}
|
||||
if(isset($_SESSION['behind'])&&intval($_SESSION['behind']) >= 99) {?>
|
||||
<style>
|
||||
@@ -41,13 +50,6 @@ if(isset($_SESSION['behind'])&&intval($_SESSION['behind']) >= 99) {?>
|
||||
}
|
||||
</style>
|
||||
<?php }
|
||||
|
||||
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["LATITUDE"] == "0.000" && $config["LONGITUDE"] == "0.000") {
|
||||
echo "<center style='color:red'><b>WARNING: Your latitude and longitude are not set properly. Please do so now in Tools -> Settings.</center></b>";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
|
||||
function ensure_db_ok ($sql_stmt) {
|
||||
if($sql_stmt == False) {
|
||||
echo "Database is busy";
|
||||
header("refresh:1;");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -251,7 +251,8 @@ if(isset($_GET['sendtest']) && $_GET['sendtest'] == "true") {
|
||||
$config = parse_ini_file($home.'/BirdNET-Pi/scripts/thisrun.ini');
|
||||
}
|
||||
|
||||
$db = new SQLite3($home."/BirdNET-Pi/scripts/birds.db", SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
$db = new SQLite3($home."/BirdNET-Pi/scripts/birds.db", SQLITE3_OPEN_READONLY);
|
||||
$db->busyTimeout(1000);
|
||||
|
||||
$cf = explode("\n",$_GET['apprise_config']);
|
||||
$cf = "'".implode("' '", $cf)."'";
|
||||
|
||||
+6
-7
@@ -7,6 +7,7 @@ $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors',1);
|
||||
ini_set('display_startup_errors',1);
|
||||
require_once 'scripts/common.php';
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
@@ -22,10 +23,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);
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
|
||||
$db->busyTimeout(1000);
|
||||
|
||||
$statement1 = $db->prepare("SELECT COUNT(*) FROM detections
|
||||
WHERE Date == \"$theDate\"");
|
||||
$statement1 = $db->prepare("SELECT COUNT(*) FROM detections WHERE Date == \"$theDate\"");
|
||||
ensure_db_ok($statement1);
|
||||
$result1 = $statement1->execute();
|
||||
$totalcount = $result1->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
@@ -52,10 +54,7 @@ if(isset($_GET['blocation']) ) {
|
||||
$starttime = strtotime("12 AM") + (3600*$i);
|
||||
|
||||
$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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement1);
|
||||
$result1 = $statement1->execute();
|
||||
|
||||
$detections = [];
|
||||
|
||||
+9
-29
@@ -5,6 +5,7 @@ ini_set('session.gc_maxlifetime', 7200);
|
||||
ini_set('user_agent', 'PHP_Flickr/1.0');
|
||||
session_set_cookie_params(7200);
|
||||
session_start();
|
||||
require_once 'scripts/common.php';
|
||||
|
||||
if(!isset($_SESSION['my_timezone'])) {
|
||||
$_SESSION['my_timezone'] = trim(shell_exec('timedatectl show --value --property=Timezone'));
|
||||
@@ -13,11 +14,8 @@ date_default_timezone_set($_SESSION['my_timezone']);
|
||||
$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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
|
||||
$db->busyTimeout(1000);
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
@@ -30,10 +28,7 @@ $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;");
|
||||
}
|
||||
ensure_db_ok($statement2);
|
||||
$result2 = $statement2->execute();
|
||||
$todaycount = $result2->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
@@ -88,10 +83,7 @@ if(isset($_GET['fetch_chart_string']) && $_GET['fetch_chart_string'] == "true")
|
||||
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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement4);
|
||||
$result4 = $statement4->execute();
|
||||
if(!isset($_SESSION['images'])) {
|
||||
$_SESSION['images'] = [];
|
||||
@@ -246,34 +238,22 @@ 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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement);
|
||||
$result = $statement->execute();
|
||||
$totalcount = $result->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;");
|
||||
}
|
||||
ensure_db_ok($statement3);
|
||||
$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;");
|
||||
}
|
||||
ensure_db_ok($statement5);
|
||||
$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;");
|
||||
}
|
||||
ensure_db_ok($statement6);
|
||||
$result6 = $statement6->execute();
|
||||
$totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
|
||||
+18
-38
@@ -6,12 +6,10 @@ $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
|
||||
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
require_once 'scripts/common.php';
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
if($db == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
|
||||
$db->busyTimeout(1000);
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
@@ -29,20 +27,19 @@ if(isset($_GET['deletefile'])) {
|
||||
$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 {
|
||||
$db_writable = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READWRITE);
|
||||
$db->busyTimeout(1000);
|
||||
$statement1 = $db_writable->prepare('DELETE FROM detections WHERE File_Name = :file_name LIMIT 1');
|
||||
ensure_db_ok($statement1);
|
||||
$statement1->bindValue(':file_name', explode("/", $_GET['deletefile'])[2]);
|
||||
$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();
|
||||
$db_writable->close();
|
||||
die();
|
||||
} else {
|
||||
header('WWW-Authenticate: Basic realm="My Realm"');
|
||||
@@ -163,10 +160,7 @@ if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
||||
|
||||
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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement);
|
||||
$result = $statement->execute();
|
||||
$view = "bydate";
|
||||
|
||||
@@ -180,10 +174,7 @@ if(isset($_GET['bydate'])){
|
||||
} else {
|
||||
$statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" ORDER BY Com_Name");
|
||||
}
|
||||
if($statement == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement);
|
||||
$result = $statement->execute();
|
||||
$view = "date";
|
||||
|
||||
@@ -195,10 +186,7 @@ if(isset($_GET['bydate'])){
|
||||
$statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name ASC');
|
||||
}
|
||||
session_start();
|
||||
if($statement == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement);
|
||||
$result = $statement->execute();
|
||||
$view = "byspecies";
|
||||
|
||||
@@ -208,17 +196,15 @@ if(isset($_GET['bydate'])){
|
||||
session_start();
|
||||
$_SESSION['species'] = $species;
|
||||
$statement = $db->prepare("SELECT * FROM detections WHERE Com_Name == \"$species\" ORDER BY Com_Name");
|
||||
ensure_db_ok($statement);
|
||||
$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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement3);
|
||||
$result = $statement->execute();
|
||||
$result3 = $statement3->execute();
|
||||
$view = "species";
|
||||
} else {
|
||||
session_start();
|
||||
session_unset();
|
||||
unset($_SESSION['species']);
|
||||
unset($_SESSION['date']);
|
||||
$view = "choose";
|
||||
}
|
||||
?>
|
||||
@@ -484,10 +470,7 @@ if(isset($_SESSION['date'])) {
|
||||
$statement2 = $db->prepare("SELECT * FROM detections where Com_Name == \"$name\" ORDER BY Date DESC, Time DESC");
|
||||
}
|
||||
}
|
||||
if($statement2 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement2);
|
||||
$result2 = $statement2->execute();
|
||||
$num_rows = 0;
|
||||
while ($result2->fetchArray(SQLITE3_ASSOC)) {
|
||||
@@ -574,10 +557,7 @@ 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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement2);
|
||||
$result2 = $statement2->execute();
|
||||
echo "<table>
|
||||
<tr>
|
||||
|
||||
+8
-25
@@ -7,42 +7,28 @@ $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
|
||||
ini_set('user_agent', 'PHP_Flickr/1.0');
|
||||
error_reporting(0);
|
||||
ini_set('display_errors', 0);
|
||||
require_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_READONLY);
|
||||
$db->busyTimeout(1000);
|
||||
|
||||
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;");
|
||||
}
|
||||
ensure_db_ok($statement);
|
||||
$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;");
|
||||
}
|
||||
ensure_db_ok($statement2);
|
||||
$result2 = $statement2->execute();
|
||||
} 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;");
|
||||
}
|
||||
ensure_db_ok($statement);
|
||||
$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;");
|
||||
}
|
||||
ensure_db_ok($statement2);
|
||||
$result2 = $statement2->execute();
|
||||
}
|
||||
|
||||
@@ -51,10 +37,7 @@ if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
|
||||
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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement3);
|
||||
$result3 = $statement3->execute();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,17 @@ $fetch = shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi fetch 2>&1");
|
||||
$str = trim(shell_exec("sudo -u".$user." git -C ".$home."/BirdNET-Pi status"));
|
||||
if (preg_match("/behind '.*?' by (\d+) commit(s?)\b/", $str, $matches)) {
|
||||
$num_commits_behind = $matches[1];
|
||||
$_SESSION['behind'] = $num_commits_behind;
|
||||
}
|
||||
if (preg_match('/\b(\d+)\b and \b(\d+)\b different commits each/', $str, $matches)) {
|
||||
$num1 = (int) $matches[1];
|
||||
$num2 = (int) $matches[2];
|
||||
$sum = $num1 + $num2;
|
||||
$_SESSION['behind'] = $sum;
|
||||
$num_commits_behind = $num1 + $num2;
|
||||
}
|
||||
if (stripos($str, "Your branch is up to date") !== false) {
|
||||
$num_commits_behind = '0';
|
||||
}
|
||||
$_SESSION['behind'] = $num_commits_behind;
|
||||
$_SESSION['behind_time'] = time();
|
||||
?><html>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<br>
|
||||
|
||||
@@ -10,6 +10,7 @@ session_set_cookie_params(7200);
|
||||
session_start();
|
||||
error_reporting(E_ERROR);
|
||||
ini_set('display_errors',1);
|
||||
require_once 'scripts/common.php';
|
||||
|
||||
if (file_exists('./scripts/thisrun.txt')) {
|
||||
$config = parse_ini_file('./scripts/thisrun.txt');
|
||||
@@ -28,57 +29,36 @@ if (file_exists('./scripts/thisrun.txt')) {
|
||||
</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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
|
||||
$db->busyTimeout(1000);
|
||||
|
||||
$statement1 = $db->prepare('SELECT COUNT(*) FROM detections');
|
||||
if($statement1 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement1);
|
||||
$result1 = $statement1->execute();
|
||||
$totalcount = $result1->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;");
|
||||
}
|
||||
ensure_db_ok($statement2);
|
||||
$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;");
|
||||
}
|
||||
ensure_db_ok($statement3);
|
||||
$result3 = $statement3->execute();
|
||||
$hourcount = $result3->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$statement4 = $db->prepare('SELECT Com_Name, Sci_Name, Time, Confidence FROM detections LIMIT 1');
|
||||
if($statement4 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement4);
|
||||
$result4 = $statement4->execute();
|
||||
$mostrecent = $result4->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;");
|
||||
}
|
||||
ensure_db_ok($statement5);
|
||||
$result5 = $statement5->execute();
|
||||
$todayspeciestally = $result5->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$statement6 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections');
|
||||
if($statement6 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement6);
|
||||
$result6 = $statement6->execute();
|
||||
$totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
@@ -205,10 +185,7 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" ) {
|
||||
}
|
||||
|
||||
}
|
||||
if($statement0 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement0);
|
||||
$result0 = $statement0->execute();
|
||||
|
||||
?> <table>
|
||||
|
||||
+15
-51
@@ -2,6 +2,7 @@
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
require_once 'scripts/common.php';
|
||||
|
||||
$startdate = strtotime('last sunday') - (7*86400);
|
||||
$enddate = strtotime('last sunday') - (1*86400);
|
||||
@@ -10,48 +11,30 @@ $debug = false;
|
||||
|
||||
if(isset($_GET['ascii'])) {
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
|
||||
if($db == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
|
||||
$db->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');
|
||||
if($statement1 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
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).'"');
|
||||
if($statement4 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
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)).'"');
|
||||
if($statement5 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
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).'"');
|
||||
if($statement6 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
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)).'"');
|
||||
if($statement7 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement7);
|
||||
$result7= $statement7->execute();
|
||||
$priortotalspeciestally = $result7->fetchArray(SQLITE3_ASSOC)['COUNT(DISTINCT(Com_Name))'];
|
||||
|
||||
@@ -91,10 +74,7 @@ if(isset($_GET['ascii'])) {
|
||||
|
||||
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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement2);
|
||||
$result2 = $statement2->execute();
|
||||
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
|
||||
$priorweekcount = $totalcount['COUNT(*)'];
|
||||
@@ -122,10 +102,7 @@ if(isset($_GET['ascii'])) {
|
||||
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;");
|
||||
}
|
||||
ensure_db_ok($statement3);
|
||||
$result3 = $statement3->execute();
|
||||
$totalcount = $result3->fetchArray(SQLITE3_ASSOC);
|
||||
$nonthisweekcount = $totalcount['COUNT(*)'];
|
||||
@@ -153,21 +130,14 @@ 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;");
|
||||
}
|
||||
|
||||
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
|
||||
$db->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');
|
||||
}
|
||||
if($statement1 == False){
|
||||
echo "Database is busy";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement1);
|
||||
$result1 = $statement1->execute();
|
||||
|
||||
$detections = [];
|
||||
@@ -202,10 +172,7 @@ 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";
|
||||
header("refresh: 0;");
|
||||
}
|
||||
ensure_db_ok($statement2);
|
||||
$result2 = $statement2->execute();
|
||||
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
|
||||
$priorweekcount = $totalcount['COUNT(*)'];
|
||||
@@ -243,10 +210,7 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
|
||||
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;");
|
||||
}
|
||||
ensure_db_ok($statement3);
|
||||
$result3 = $statement3->execute();
|
||||
$totalcount = $result3->fetchArray(SQLITE3_ASSOC);
|
||||
$nonthisweekcount = $totalcount['COUNT(*)'];
|
||||
|
||||
Reference in New Issue
Block a user