A live bird collage card for your Home Assistant dashboard.
common fetch_species_array()
frederik1e770f1fb072
diff --git a/scripts/common.php b/scripts/common.phpindex 26f92c54..b7166859 100644--- a/scripts/common.php+++ b/scripts/common.php@@ -117,6 +117,26 @@ function get_sci_name($com_name) {return $sciname;}+function fetch_species_array($sort_by, $date=null) {+ if (!isset($_db)) {+ $_db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_READONLY);+ $_db->busyTimeout(1000);+ }+ $where = (isset($date)) ? "WHERE Date == \"$date\"" : "";+ if ($sort_by === "occurrences") {+ $statement = $_db->prepare("SELECT Date, Time, File_Name, Com_Name, Sci_Name, COUNT(*) as Count, MAX(Confidence) as MaxConfidence FROM detections $where GROUP BY Sci_Name ORDER BY COUNT(*) DESC");+ } elseif ($sort_by === "confidence") {+ $statement = $_db->prepare("SELECT Date, Time, File_Name, Com_Name, Sci_Name, COUNT(*) as Count, MAX(Confidence) as MaxConfidence FROM detections $where GROUP BY Sci_Name ORDER BY MAX(Confidence) DESC");+ } elseif ($sort_by === "date") {+ $statement = $_db->prepare("SELECT Date, Time, File_Name, Com_Name, Sci_Name, COUNT(*) as Count, MAX(Confidence) as MaxConfidence FROM detections $where GROUP BY Sci_Name ORDER BY MIN(Date) DESC, Time DESC");+ } else {+ $statement = $_db->prepare("SELECT Date, Time, File_Name, Com_Name, Sci_Name, COUNT(*) as Count, MAX(Confidence) as MaxConfidence FROM detections $where GROUP BY Sci_Name ORDER BY Com_Name ASC");+ }+ ensure_db_ok($statement);+ $result = $statement->execute();+ return $result;+}+define('DB', './scripts/flickr.db');class Flickr {