diff --git a/scripts/overview.php b/scripts/overview.php
index 7afc75e..8aa768f 100644
--- a/scripts/overview.php
+++ b/scripts/overview.php
@@ -152,73 +152,33 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse
die();
}
-function get_chart_data($db, $force_regen = false) {
- if ($force_regen || !isset($_SESSION['chart_data'])) {
- $statement = $db->prepare('SELECT COUNT(*) FROM detections');
- ensure_db_ok($statement);
- $result = $statement->execute();
- $totalcount = $result->fetchArray(SQLITE3_ASSOC);
-
- $statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == DATE(\'now\', \'localtime\')');
- 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\')');
- ensure_db_ok($statement3);
- $result3 = $statement3->execute();
- $hourcount = $result3->fetchArray(SQLITE3_ASSOC);
-
- $statement5 = $db->prepare('SELECT COUNT(DISTINCT(Sci_Name)) FROM detections WHERE Date == Date(\'now\',\'localtime\')');
- ensure_db_ok($statement5);
- $result5 = $statement5->execute();
- $speciestally = $result5->fetchArray(SQLITE3_ASSOC);
-
- $statement6 = $db->prepare('SELECT COUNT(DISTINCT(Sci_Name)) FROM detections');
- ensure_db_ok($statement6);
- $result6 = $statement6->execute();
- $totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC);
-
- // Store the data in session to be reused by other charts
- $_SESSION['chart_data'] = [
- 'totalcount' => $totalcount,
- 'todaycount' => $todaycount,
- 'hourcount' => $hourcount,
- 'speciestally' => $speciestally,
- 'totalspeciestally' => $totalspeciestally
- ];
- }
-
- return $_SESSION['chart_data'];
-}
-
if(isset($_GET['ajax_left_chart']) && $_GET['ajax_left_chart'] == "true") {
- // Force the data to regenerate and store it in session
- $chart_data = get_chart_data($db, true);
+ $chart_data = get_summary();
+ $_SESSION['chart_data'] = $chart_data;
?>
| Total |
- |
+ |
| Today |
- |
+ |
| Last Hour |
- |
+ |
| Species Detected Today |
- |
+ |
| Total Number of Species |
- |
+ |
@@ -229,7 +189,7 @@ if(isset($_GET['ajax_left_chart']) && $_GET['ajax_left_chart'] == "true") {
if(isset($_GET['ajax_center_chart']) && $_GET['ajax_center_chart'] == "true") {
// Retrieve the cached data from session without regenerating
- $chart_data = get_chart_data($db);
+ $chart_data = $_SESSION['chart_data'];
?>
| Total |
@@ -239,11 +199,11 @@ if(isset($_GET['ajax_center_chart']) && $_GET['ajax_center_chart'] == "true") {
Species Today |
- |
- |
- |
- |
- |
+ |
+ |
+ |
+ |
+ |
diff --git a/scripts/todays_detections.php b/scripts/todays_detections.php
index f7e132d..b2bedb3 100644
--- a/scripts/todays_detections.php
+++ b/scripts/todays_detections.php
@@ -25,35 +25,12 @@ if(isset($kiosk) && $kiosk == true) {
$db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);
$db->busyTimeout(1000);
-$statement1 = $db->prepare('SELECT COUNT(*) FROM detections');
-ensure_db_ok($statement1);
-$result1 = $statement1->execute();
-$totalcount = $result1->fetchArray(SQLITE3_ASSOC);
-
-$statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == DATE(\'now\', \'localtime\')');
-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\')');
-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');
-ensure_db_ok($statement4);
-$result4 = $statement4->execute();
-$mostrecent = $result4->fetchArray(SQLITE3_ASSOC);
-
-$statement5 = $db->prepare('SELECT COUNT(DISTINCT(Sci_Name)) FROM detections WHERE Date == Date(\'now\', \'localtime\')');
-ensure_db_ok($statement5);
-$result5 = $statement5->execute();
-$todayspeciestally = $result5->fetchArray(SQLITE3_ASSOC);
-
-$statement6 = $db->prepare('SELECT COUNT(DISTINCT(Sci_Name)) FROM detections');
-ensure_db_ok($statement6);
-$result6 = $statement6->execute();
-$totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC);
+$summary = get_summary();
+$totalcount = $summary['totalcount'];
+$todaycount = $summary['todaycount'];
+$hourcount = $summary['hourcount'];
+$todayspeciestally = $summary['speciestally'];
+$totalspeciestally = $summary['totalspeciestally'];
if(isset($_GET['comname'])) {
$birdName = htmlspecialchars_decode($_GET['comname'], ENT_QUOTES);
@@ -311,16 +288,16 @@ if(isset($_GET['today_stats'])) {
Species Today |
- |
+ |
- |
+ |
@@ -427,11 +404,11 @@ if (get_included_files()[0] === __FILE__) {
Species Today |
- |
- |
- |
- |
- |
+ |
+ |
+ |
+ |
+ |
@@ -488,7 +465,7 @@ document.getElementById("searchterm").onkeydown = (function(e) {
function switchViews(element) {
if(searchterm == ""){
- document.getElementById("detections_table").innerHTML = "Loading detections...
";
+ document.getElementById("detections_table").innerHTML = "Loading detections...
";
} else {
document.getElementById("detections_table").innerHTML = "Loading...
";
}