From 96df8e781dfe5fc43f3c0f074c917dfe6a492bae Mon Sep 17 00:00:00 2001
From: Alexandre <44178713+alexbelgium@users.noreply.github.com>
Date: Mon, 30 Sep 2024 20:50:59 +0200
Subject: [PATCH] Feat : sort species by max confidence (#198)
* Add sort by occurence button
* sort_conf icon
* Optimized svg
---
homepage/images/sort_conf.svg | 52 +++++++++++++++++++++++++++++++++++
scripts/play.php | 19 +++++++++++--
2 files changed, 69 insertions(+), 2 deletions(-)
create mode 100644 homepage/images/sort_conf.svg
diff --git a/homepage/images/sort_conf.svg b/homepage/images/sort_conf.svg
new file mode 100644
index 0000000..41c9e07
--- /dev/null
+++ b/homepage/images/sort_conf.svg
@@ -0,0 +1,52 @@
+
diff --git a/scripts/play.php b/scripts/play.php
index 075fcd5..a40988d 100644
--- a/scripts/play.php
+++ b/scripts/play.php
@@ -138,6 +138,8 @@ if(isset($_GET['bydate'])){
$_SESSION['date'] = $date;
if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
$statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" GROUP BY Com_Name ORDER BY COUNT(*) DESC");
+ } elseif(isset($_GET['sort']) && $_GET['sort'] == "confidence") {
+ $statement = $db->prepare("SELECT Com_Name, Sci_Name, MAX(Confidence) as MaxConfidence FROM detections WHERE Date == \"$date\" GROUP BY Com_Name ORDER BY MaxConfidence DESC");
} else {
$statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" ORDER BY Com_Name");
}
@@ -149,6 +151,8 @@ if(isset($_GET['bydate'])){
} elseif(isset($_GET['byspecies'])) {
if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {
$statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');
+ } elseif(isset($_GET['sort']) && $_GET['sort'] == "confidence") {
+ $statement = $db->prepare('SELECT Com_Name, Sci_Name, MAX(Confidence) as MaxConfidence FROM detections GROUP BY Com_Name ORDER BY MaxConfidence DESC');
} else {
$statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name ASC');
}
@@ -410,6 +414,9 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
+
@@ -429,10 +436,14 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
#By Species
} elseif($view == "byspecies") {
$birds = array();
+ $confidence = array();
while($results=$result->fetchArray(SQLITE3_ASSOC))
{
$name = $results['Com_Name'];
$birds[] = $name;
+ if ($_GET['sort'] == "confidence") {
+ $confidence[] = ' (' . round($results['MaxConfidence'] * 100) . '%)';
+ }
}
if(count($birds) > 45) {
@@ -451,7 +462,7 @@ if(!isset($_GET['species']) && !isset($_GET['filename'])){
if ($index < count($birds)) {
?>