common fetch_species_array()
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user