From 6f1986abd4d89053ef9276bf07fdb558a59205df Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:03:04 +0100 Subject: [PATCH 1/9] Add RARE_SPECIES_THRESHOLD --- scripts/advanced.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/scripts/advanced.php b/scripts/advanced.php index 765016cb2..fd484d49a 100644 --- a/scripts/advanced.php +++ b/scripts/advanced.php @@ -196,6 +196,15 @@ $contents = preg_replace("/RAW_SPECTROGRAM=.*/", "RAW_SPECTROGRAM=0", $contents); } + if(isset($_GET["rare_species_threshold"])) { + $rare_species_threshold = $_GET["rare_species_threshold"]; + if(strcmp($rare_species_threshold, $config['RARE_SPECIES_THRESHOLD']) !== 0) { + $contents = preg_replace("/RARE_SPECIES_THRESHOLD=.*/", "RARE_SPECIES_THRESHOLD=$rare_species_threshold", $contents); + } + } else { + $contents = preg_replace("/RARE_SPECIES_THRESHOLD=.*/", "RARE_SPECIES_THRESHOLD=30", $contents); + } + if(isset($_GET["custom_image"])) { $custom_image = $_GET["custom_image"]; if(strcmp($custom_image,$config['CUSTOM_IMAGE']) !== 0) { @@ -434,6 +443,10 @@ function collectrtspUrls() { >

This allows you to remove the axes and labels of the spectrograms that are generated by Sox for each detection for a cleaner appearance.

+ + +
+

This setting defines after how many days since last detection a species is considered rare. Default is 30 days.


From 7e4454dd719a3136f337dabe55bb07e7bc903267 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:03:48 +0100 Subject: [PATCH 2/9] Add RARE_SPECIES_THRESHOLD --- scripts/install_config.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/install_config.sh b/scripts/install_config.sh index 5fdf4521d..57dd458a1 100755 --- a/scripts/install_config.sh +++ b/scripts/install_config.sh @@ -270,6 +270,9 @@ RAW_SPECTROGRAM=0 CUSTOM_IMAGE= CUSTOM_IMAGE_TITLE="" +## RARE_SPECIES_THRESHOLD defines after how many days a species is considered as rare and highlighted on overview page +RARE_SPECIES_THRESHOLD=30 + ## These are just for debugging LAST_RUN= THIS_RUN= From 79e56f512ee2feb70082871bafa88df17b00feec Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Tue, 26 Nov 2024 10:05:22 +0100 Subject: [PATCH 3/9] Add table for new and rare species --- scripts/overview.php | 133 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/scripts/overview.php b/scripts/overview.php index 3abc40e9d..aaad22aa7 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -313,6 +313,139 @@ function setModalText(iter, title, text, authorlink, photolink, licenseurl) {
+prepare(" +SELECT d_today.Com_Name, d_today.Sci_Name, d_today.Date, d_today.Time, d_today.Confidence, d_today.File_Name, + MAX(d_today.Confidence) as MaxConfidence, + (SELECT MAX(Date) FROM detections d_prev WHERE d_prev.Com_Name = d_today.Com_Name AND d_prev.Date < DATE('now', 'localtime')) as LastSeenDate, + (SELECT COUNT(*) FROM detections d_occ WHERE d_occ.Com_Name = d_today.Com_Name AND d_occ.Date = DATE('now', 'localtime') AND d_occ.Time >= d_today.Time) as OccurrenceCount +FROM detections d_today +WHERE d_today.Date = DATE('now', 'localtime') +GROUP BY d_today.Com_Name +"); +ensure_db_ok($statement); +$result = $statement->execute(); + +$new_species = []; +$rare_species = []; +$rare_species_threshold = isset($config['RARE_SPECIES_THRESHOLD']) ? $config['RARE_SPECIES_THRESHOLD'] : 30; +while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + $last_seen_date = $row['LastSeenDate']; + if ($last_seen_date === NULL) { + $new_species[] = $row; + } else { + $date1 = new DateTime($last_seen_date); + $date2 = new DateTime('now'); + $interval = $date1->diff($date2); + $days_ago = $interval->days; + if ($days_ago > $rare_species_threshold) { + $row['DaysAgo'] = $days_ago; + $rare_species[] = $row; + } + } +} + +if (!isset($_SESSION['images'])) { + $_SESSION['images'] = []; +} +$flickr = null; + +function display_species($species_list, $title, $show_last_seen=false) { + global $config, $_SESSION, $flickr; + $species_count = count($species_list); + if ($species_count > 0): ?> +
+

detected today!

+ 5): ?> +
+ + + get_uid_from_db()['uid']) { + unset($_SESSION['images']); + $_SESSION["FLICKR_FILTER_EMAIL"] = $flickr->get_uid_from_db()['uid']; + } + + // Check if the Flickr image has been cached in the session + $key = array_search($comname, array_column($_SESSION['images'], 0)); + if ($key !== false) { + $image = $_SESSION['images'][$key]; + } else { + // Retrieve the image from Flickr API and cache it + $flickr_cache = $flickr->get_image($todaytable['Sci_Name']); + array_push($_SESSION["images"], array($comname, $flickr_cache["image_url"], $flickr_cache["title"], $flickr_cache["photos_url"], $flickr_cache["author_url"], $flickr_cache["license_url"])); + $image = $_SESSION['images'][count($_SESSION['images']) - 1]; + } + $image_url = $image[1] ?? ""; // Get the image URL if available + } + + if ($show_last_seen && isset($todaytable['DaysAgo'])) { + $days_ago = $todaytable['DaysAgo']; + if ($days_ago > 30) { + $months_ago = floor($days_ago / 30); + $last_seen_text = "
Last: {$months_ago}mo ago"; + } else { + $last_seen_text = "
Last: {$days_ago}d ago"; + } + + } + + $time_occurrence_text = "
{$todaytable['Time']}"; + if (isset($todaytable['OccurrenceCount']) && $todaytable['OccurrenceCount'] > 1) { + $time_occurrence_text .= " ({$todaytable['OccurrenceCount']}x)"; + } + ?> + + + + + + +
+ + +
+ + +

+ + + + + + +
+
+
Confidence:
+ +
+
Date: Tue, 26 Nov 2024 10:06:12 +0100 Subject: [PATCH 4/9] Custom duration for minigraphs --- scripts/overview.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/overview.php b/scripts/overview.php index aaad22aa7..3d4d14e07 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -610,11 +610,11 @@ function startAutoRefresh() { }