From 18693fae06a26984626f7e4de745a8046d9ee975 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Sun, 30 Jun 2024 10:18:32 +0200 Subject: [PATCH] Feat : add species whitelist (#110) * Add white_list to server.py https://github.com/Nachtzuster/BirdNET-Pi/issues/108 * Create whitelist_list.php * Add whitelist to views * Make more explicit the usage * Update views.php * Align with uppercase * Align with "species" https://github.com/Nachtzuster/BirdNET-Pi/issues/108 * Update views.php * Correct python code https://github.com/Nachtzuster/BirdNET-Pi/issues/108 * Align clear_all_data.sh * Align install_services.sh * Embed whitelist_species_list in PREDICTED_SPECIES_LIST * Only embed whitelist in predicted list * Correct python append @dalogue1 https://github.com/Nachtzuster/BirdNET-Pi/issues/108#issuecomment-2183508903 * Update scripts/server.py Co-authored-by: Nachtzuster * Use preexisting functions Co-authored-by: Nachtzuster * Alert not a recommended WoW --------- Co-authored-by: Nachtzuster --- homepage/views.php | 28 ++++++++++ scripts/clear_all_data.sh | 1 + scripts/install_services.sh | 1 + scripts/server.py | 3 ++ scripts/whitelist_list.php | 105 ++++++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+) create mode 100644 scripts/whitelist_list.php diff --git a/homepage/views.php b/homepage/views.php index 8a5cbe1..b2f2205 100644 --- a/homepage/views.php +++ b/homepage/views.php @@ -142,6 +142,7 @@ if(isset($_GET['view'])){ + "; } @@ -204,6 +205,33 @@ if(isset($_GET['view'])){ } include('./scripts/exclude_list.php'); } + if($_GET['view'] == "Whitelisted"){ + ensure_authenticated(); + if(isset($_GET['species']) && isset($_GET['add'])){ + $file = './scripts/whitelist_species_list.txt'; + $str = file_get_contents("$file"); + $str = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $str); + file_put_contents("$file", "$str"); + foreach ($_GET['species'] as $selectedOption) + file_put_contents("./scripts/whitelist_species_list.txt", htmlspecialchars_decode($selectedOption, ENT_QUOTES)."\n", FILE_APPEND); + } elseif (isset($_GET['species']) && isset($_GET['del'])){ + $file = './scripts/whitelist_species_list.txt'; + $str = file_get_contents("$file"); + $str = preg_replace('/^\h*\v+/m', '', $str); + file_put_contents("$file", "$str"); + foreach($_GET['species'] as $selectedOption) { + $content = file_get_contents("./scripts/whitelist_species_list.txt"); + $newcontent = str_replace($selectedOption, "", "$content"); + $newcontent = str_replace(htmlspecialchars_decode($selectedOption, ENT_QUOTES), "", "$content"); + file_put_contents("./scripts/whitelist_species_list.txt", "$newcontent"); + } + $file = './scripts/whitelist_species_list.txt'; + $str = file_get_contents("$file"); + $str = preg_replace('/^\h*\v+/m', '', $str); + file_put_contents("$file", "$str"); + } + include('./scripts/whitelist_list.php'); + } if($_GET['view'] == "File"){ echo ""; } diff --git a/scripts/clear_all_data.sh b/scripts/clear_all_data.sh index 9330ef1..ee9d88d 100755 --- a/scripts/clear_all_data.sh +++ b/scripts/clear_all_data.sh @@ -24,6 +24,7 @@ echo "Re-creating necessary directories" sudo -u ${USER} ln -fs $(dirname $my_dir)/exclude_species_list.txt $my_dir sudo -u ${USER} ln -fs $(dirname $my_dir)/include_species_list.txt $my_dir +sudo -u ${USER} ln -fs $(dirname $my_dir)/whitelist_species_list.txt $my_dir sudo -u ${USER} ln -fs $(dirname $my_dir)/homepage/* ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname $my_dir)/model/labels.txt ${my_dir} sudo -u ${USER} ln -fs $my_dir ${EXTRACTED} diff --git a/scripts/install_services.sh b/scripts/install_services.sh index e944b5a..0ef70bb 100755 --- a/scripts/install_services.sh +++ b/scripts/install_services.sh @@ -66,6 +66,7 @@ create_necessary_dirs() { sudo -u ${USER} ln -fs $my_dir/exclude_species_list.txt $my_dir/scripts sudo -u ${USER} ln -fs $my_dir/include_species_list.txt $my_dir/scripts + sudo -u ${USER} ln -fs $my_dir/whitelist_species_list.txt $my_dir/scripts sudo -u ${USER} ln -fs $my_dir/homepage/* ${EXTRACTED} sudo -u ${USER} ln -fs $my_dir/model/labels.txt ${my_dir}/scripts sudo -u ${USER} ln -fs $my_dir/scripts ${EXTRACTED} diff --git a/scripts/server.py b/scripts/server.py index ea4e563..c7803e0 100755 --- a/scripts/server.py +++ b/scripts/server.py @@ -135,6 +135,9 @@ def predictSpeciesList(lat, lon, week): # if there's a custom user-made include list, we only want to use the species in that if (len(INCLUDE_LIST) == 0): PREDICTED_SPECIES_LIST.append(s[1]) + WHITELIST_LIST = loadCustomSpeciesList(os.path.expanduser("~/BirdNET-Pi/whitelist_species_list.txt")) + for species in WHITELIST_LIST: + PREDICTED_SPECIES_LIST.append(species) def loadCustomSpeciesList(path): diff --git a/scripts/whitelist_list.php b/scripts/whitelist_list.php new file mode 100644 index 0000000..a7a0b11 --- /dev/null +++ b/scripts/whitelist_list.php @@ -0,0 +1,105 @@ + + + +
+
+

All Species Labels

+ +
+ Once the desired species has been highlighted, click it and then click ADD to have it whitelisted. This species will be detected even if below the Species Occurence Frequency Threshold defined in the settings. + This is not a recommended way of working : it is preferable to first try first both Species Occurence models (v1 and v2.4). + + +
+
+ +
+
+ +
+
+ +

+ +
+
+ +
+
+

Whitelisted Species List

+


+ + +
+
+ +
+
+ +