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:
+13
-21
@@ -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";
|
||||
header("refresh: 0;");
|
||||
$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(*)"];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user