From 828d9d8757a1f48849d9308f708ebc0dd8ee0431 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Tue, 28 Jun 2022 11:11:11 -0400
Subject: [PATCH 03/91] Initial notification support
---
scripts/weekly_report.php | 57 +++++++++++++++++++++++++++
scripts/weekly_report_notification.sh | 6 +++
2 files changed, 63 insertions(+)
create mode 100644 scripts/weekly_report_notification.sh
diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php
index 59a7c61..9231ed3 100644
--- a/scripts/weekly_report.php
+++ b/scripts/weekly_report.php
@@ -7,6 +7,63 @@ $startdate = strtotime('last sunday') - (7*86400);
$enddate = strtotime('last sunday') - (1*86400);
$debug = false;
+
+if(isset($_GET['ascii'])) {
+
+ $db = new SQLite3('./scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE);
+ if($db == False){
+ echo "Database is busy";
+ header("refresh: 0;");
+ }
+
+ $statement1 = $db->prepare('SELECT DISTINCT(Com_Name), COUNT(*) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'" GROUP By Com_Name ORDER BY COUNT(*) DESC');
+ if($statement1 == False){
+ echo "Database is busy";
+ header("refresh: 0;");
+ }
+ $result1 = $statement1->execute();
+
+ $detections = [];
+ $i = 0;
+ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
+ {
+ array_push($detections, $detection);
+ }
+
+ echo "# Week ".date('W', $enddate)." Report (".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate).")\n";
+
+ echo "= Top 10 Species =\n";
+
+ $i = 0;
+ foreach($detections as $detection)
+ {
+ $i++;
+
+ if($i <= 10) {
+ $statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$detection["Com_Name"].'" AND Date BETWEEN "'.date("Y-m-d",$startdate - (7*86400)).'" AND "'.date("Y-m-d",$enddate - (7*86400)).'"');
+ if($statement2 == False){
+ echo "Database is busy";
+ header("refresh: 0;");
+ }
+ $result2 = $statement2->execute();
+ $totalcount = $result2->fetchArray(SQLITE3_ASSOC);
+ $priorweekcount = $totalcount['COUNT(*)'];
+
+ $percentagediff = round((1 - $priorweekcount / $detection["COUNT(*)"]) * 100);
+
+ if($percentagediff > 0) {
+ $percentagediff = "+".$percentagediff."%";
+ } else {
+ $percentagediff = "-".abs($percentagediff)."%";
+ }
+
+ echo $detection["Com_Name"]." - ".$detection["COUNT(*)"]." (".$percentagediff.")\n";
+ }
+ }
+
+ die();
+}
+
?>
Week ".date('W', $enddate)." Report".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate)."
";
diff --git a/scripts/weekly_report_notification.sh b/scripts/weekly_report_notification.sh
new file mode 100644
index 0000000..b78983b
--- /dev/null
+++ b/scripts/weekly_report_notification.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+NOTIFICATION=$(curl 'localhost/views.php?view=Weekly%20Report&ascii=true')
+NOTIFICATION=${NOTIFICATION#*#}
+firstLine=`echo "${NOTIFICATION}" | head -1`
+NOTIFICATION=`echo "${NOTIFICATION}" | tail -n +2`
+$HOME/BirdNET-Pi/birdnet/bin/apprise -vv -t "${firstLine}" -b "${NOTIFICATION}" --config=$HOME/BirdNET-Pi/apprise.txt
\ No newline at end of file
From 5896f00a559eb0a83ffb85b2a65b096e89381928 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Tue, 28 Jun 2022 13:04:59 -0400
Subject: [PATCH 04/91] Notification conf and cron setups
---
birdnet.conf-defaults | 1 +
scripts/install_config.sh | 1 +
scripts/install_services.sh | 6 ++++++
scripts/update_birdnet_snippets.sh | 5 +++++
scripts/{weekly_report_notification.sh => weekly_report.sh} | 3 +++
templates/weekly_report.cron | 2 ++
6 files changed, 18 insertions(+)
rename scripts/{weekly_report_notification.sh => weekly_report.sh} (71%)
create mode 100644 templates/weekly_report.cron
diff --git a/birdnet.conf-defaults b/birdnet.conf-defaults
index 88732b9..9baad16 100644
--- a/birdnet.conf-defaults
+++ b/birdnet.conf-defaults
@@ -62,6 +62,7 @@ APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection"
APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence"
APPRISE_NOTIFY_EACH_DETECTION=0
APPRISE_NOTIFY_NEW_SPECIES=0
+APPRISE_WEEKLY_REPORT=0
#---------------------- Flickr Images API Configuration -----------------------#
## If FLICKR_API_KEY is set, the web interface will try and display bird images
diff --git a/scripts/install_config.sh b/scripts/install_config.sh
index dcb78c1..432146f 100755
--- a/scripts/install_config.sh
+++ b/scripts/install_config.sh
@@ -75,6 +75,7 @@ APPRISE_NOTIFICATION_TITLE="New BirdNET-Pi Detection"
APPRISE_NOTIFICATION_BODY="A \$sciname \$comname was just detected with a confidence of \$confidence"
APPRISE_NOTIFY_EACH_DETECTION=0
APPRISE_NOTIFY_NEW_SPECIES=0
+APPRISE_WEEKLY_REPORT=0
#---------------------- Flickr Images API Configuration -----------------------#
## If FLICKR_API_KEY is set, the web interface will try and display bird images
diff --git a/scripts/install_services.sh b/scripts/install_services.sh
index 17c4397..9df1fd2 100755
--- a/scripts/install_services.sh
+++ b/scripts/install_services.sh
@@ -111,6 +111,7 @@ create_necessary_dirs() {
sudo -u ${USER} ln -fs $my_dir/scripts/stats.php ${EXTRACTED}
sudo -u ${USER} ln -fs $my_dir/scripts/todays_detections.php ${EXTRACTED}
sudo -u ${USER} ln -fs $my_dir/scripts/history.php ${EXTRACTED}
+ sudo -u ${USER} ln -fs $my_dir/scripts/weekly_report.php ${EXTRACTED}
sudo -u ${USER} ln -fs $my_dir/homepage/images/favicon.ico ${EXTRACTED}
sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED}
sudo -u ${USER} ln -fs $my_dir/templates/phpsysinfo.ini ${HOME}/phpsysinfo/
@@ -406,6 +407,10 @@ install_cleanup_cron() {
sed "s/\$USER/$USER/g" $my_dir/templates/cleanup.cron >> /etc/crontab
}
+install_weekly_cron() {
+ sed "s/\$USER/$USER/g" $my_dir/templates/weekly_report.cron >> /etc/crontab
+}
+
chown_things() {
chown -R $USER:$USER $HOME/Bird*
}
@@ -431,6 +436,7 @@ install_services() {
install_phpsysinfo
install_livestream_service
install_cleanup_cron
+ install_weekly_cron
create_necessary_dirs
generate_BirdDB
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh
index b03a0d7..3bcb774 100755
--- a/scripts/update_birdnet_snippets.sh
+++ b/scripts/update_birdnet_snippets.sh
@@ -95,6 +95,11 @@ if [[ "$pytest_installation_status" = "not installed" ]];then
fi
[ -L ~/BirdSongs/Extracted/weekly_report.php ] || ln -sf ~/BirdNET-Pi/scripts/weekly_report.php ~/BirdSongs/Extracted
+[ -L /usr/local/bin/weekly_report.sh ] || ln -sf ~/BirdNET-Pi/scripts/weekly_report.php /usr/local/bin/weekly_report.sh
+sed "s/\$USER/$USER/g" $HOME/BirdNET-Pi/templates/weekly_report.cron >> /etc/crontab
+if ! grep APPRISE_WEEKLY_REPORT /etc/birdnet/birdnet.conf &>/dev/null;then
+ sudo -u$USER echo "APPRISE_WEEKLY_REPORT=0" >> /etc/birdnet/birdnet.conf
+fi
sudo systemctl daemon-reload
restart_services.sh
diff --git a/scripts/weekly_report_notification.sh b/scripts/weekly_report.sh
similarity index 71%
rename from scripts/weekly_report_notification.sh
rename to scripts/weekly_report.sh
index b78983b..f52f4d2 100644
--- a/scripts/weekly_report_notification.sh
+++ b/scripts/weekly_report.sh
@@ -1,4 +1,7 @@
#!/usr/bin/env bash
+source /etc/birdnet/birdnet.conf
+echo ${APPRISE_WEEKLY_REPORT}
+
NOTIFICATION=$(curl 'localhost/views.php?view=Weekly%20Report&ascii=true')
NOTIFICATION=${NOTIFICATION#*#}
firstLine=`echo "${NOTIFICATION}" | head -1`
diff --git a/templates/weekly_report.cron b/templates/weekly_report.cron
new file mode 100644
index 0000000..466c749
--- /dev/null
+++ b/templates/weekly_report.cron
@@ -0,0 +1,2 @@
+#birdnet
+0 7 * * 1 $USER /usr/local/bin/weekly_report.sh >/dev/null 2>&1
\ No newline at end of file
From 49e67d2247402a92dc50146c59b7c515a8f48c34 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Tue, 28 Jun 2022 13:09:23 -0400
Subject: [PATCH 05/91] Update update_birdnet_snippets.sh
---
scripts/update_birdnet_snippets.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh
index 3bcb774..a65ec40 100755
--- a/scripts/update_birdnet_snippets.sh
+++ b/scripts/update_birdnet_snippets.sh
@@ -95,7 +95,7 @@ if [[ "$pytest_installation_status" = "not installed" ]];then
fi
[ -L ~/BirdSongs/Extracted/weekly_report.php ] || ln -sf ~/BirdNET-Pi/scripts/weekly_report.php ~/BirdSongs/Extracted
-[ -L /usr/local/bin/weekly_report.sh ] || ln -sf ~/BirdNET-Pi/scripts/weekly_report.php /usr/local/bin/weekly_report.sh
+[ -L /usr/local/bin/weekly_report.sh ] || chmod +x $HOME/BirdNET-Pi/scripts/weekly_report.sh; ln -sf ~/BirdNET-Pi/scripts/weekly_report.php /usr/local/bin/weekly_report.sh
sed "s/\$USER/$USER/g" $HOME/BirdNET-Pi/templates/weekly_report.cron >> /etc/crontab
if ! grep APPRISE_WEEKLY_REPORT /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "APPRISE_WEEKLY_REPORT=0" >> /etc/birdnet/birdnet.conf
From 655b1eaf09c1fee8eaa3fd90f52fdc38791eebe4 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Tue, 28 Jun 2022 13:10:44 -0400
Subject: [PATCH 06/91] Update update_birdnet_snippets.sh
---
scripts/update_birdnet_snippets.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh
index a65ec40..08dc6b2 100755
--- a/scripts/update_birdnet_snippets.sh
+++ b/scripts/update_birdnet_snippets.sh
@@ -95,7 +95,7 @@ if [[ "$pytest_installation_status" = "not installed" ]];then
fi
[ -L ~/BirdSongs/Extracted/weekly_report.php ] || ln -sf ~/BirdNET-Pi/scripts/weekly_report.php ~/BirdSongs/Extracted
-[ -L /usr/local/bin/weekly_report.sh ] || chmod +x $HOME/BirdNET-Pi/scripts/weekly_report.sh; ln -sf ~/BirdNET-Pi/scripts/weekly_report.php /usr/local/bin/weekly_report.sh
+[ -L /usr/local/bin/weekly_report.sh ] || sudo chmod +x $HOME/BirdNET-Pi/scripts/weekly_report.sh; ln -sf ~/BirdNET-Pi/scripts/weekly_report.php /usr/local/bin/weekly_report.sh
sed "s/\$USER/$USER/g" $HOME/BirdNET-Pi/templates/weekly_report.cron >> /etc/crontab
if ! grep APPRISE_WEEKLY_REPORT /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "APPRISE_WEEKLY_REPORT=0" >> /etc/birdnet/birdnet.conf
From ab07e8c0f5e16a41a6c9391f18833b54f6ce567e Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Tue, 28 Jun 2022 13:13:52 -0400
Subject: [PATCH 07/91] Update update_birdnet_snippets.sh
---
scripts/update_birdnet_snippets.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh
index 08dc6b2..f1768fb 100755
--- a/scripts/update_birdnet_snippets.sh
+++ b/scripts/update_birdnet_snippets.sh
@@ -95,7 +95,7 @@ if [[ "$pytest_installation_status" = "not installed" ]];then
fi
[ -L ~/BirdSongs/Extracted/weekly_report.php ] || ln -sf ~/BirdNET-Pi/scripts/weekly_report.php ~/BirdSongs/Extracted
-[ -L /usr/local/bin/weekly_report.sh ] || sudo chmod +x $HOME/BirdNET-Pi/scripts/weekly_report.sh; ln -sf ~/BirdNET-Pi/scripts/weekly_report.php /usr/local/bin/weekly_report.sh
+[ -L /usr/local/bin/weekly_report.sh ] || sudo chmod +x $HOME/BirdNET-Pi/scripts/weekly_report.sh && ln -sf ~/BirdNET-Pi/scripts/weekly_report.php /usr/local/bin/weekly_report.sh
sed "s/\$USER/$USER/g" $HOME/BirdNET-Pi/templates/weekly_report.cron >> /etc/crontab
if ! grep APPRISE_WEEKLY_REPORT /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "APPRISE_WEEKLY_REPORT=0" >> /etc/birdnet/birdnet.conf
From 7cc4506524ecc6218f174091f62e17ea0e9fd2c9 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Tue, 28 Jun 2022 14:09:03 -0400
Subject: [PATCH 08/91] fixes
---
scripts/clear_all_data.sh | 1 +
scripts/update_birdnet_snippets.sh | 3 +--
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/clear_all_data.sh b/scripts/clear_all_data.sh
index d574f5e..7108534 100755
--- a/scripts/clear_all_data.sh
+++ b/scripts/clear_all_data.sh
@@ -34,6 +34,7 @@ sudo -u ${USER} ln -fs $my_dir/overview.php ${EXTRACTED}
sudo -u ${USER} ln -fs $my_dir/stats.php ${EXTRACTED}
sudo -u ${USER} ln -fs $my_dir/todays_detections.php ${EXTRACTED}
sudo -u ${USER} ln -fs $my_dir/history.php ${EXTRACTED}
+sudo -u ${USER} ln -fs $my_dir/weekly_report.php ${EXTRACTED}
sudo -u ${USER} ln -fs $my_dir/homepage/images/favicon.ico ${EXTRACTED}
sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED}
sudo -u ${USER} ln -fs $(dirname $my_dir)/templates/phpsysinfo.ini ${HOME}/phpsysinfo/
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh
index f1768fb..baee18f 100755
--- a/scripts/update_birdnet_snippets.sh
+++ b/scripts/update_birdnet_snippets.sh
@@ -95,8 +95,7 @@ if [[ "$pytest_installation_status" = "not installed" ]];then
fi
[ -L ~/BirdSongs/Extracted/weekly_report.php ] || ln -sf ~/BirdNET-Pi/scripts/weekly_report.php ~/BirdSongs/Extracted
-[ -L /usr/local/bin/weekly_report.sh ] || sudo chmod +x $HOME/BirdNET-Pi/scripts/weekly_report.sh && ln -sf ~/BirdNET-Pi/scripts/weekly_report.php /usr/local/bin/weekly_report.sh
-sed "s/\$USER/$USER/g" $HOME/BirdNET-Pi/templates/weekly_report.cron >> /etc/crontab
+sed "s/\$USER/$USER/g" $HOME/BirdNET-Pi/templates/weekly_report.cron | sudo tee -a /etc/crontab
if ! grep APPRISE_WEEKLY_REPORT /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "APPRISE_WEEKLY_REPORT=0" >> /etc/birdnet/birdnet.conf
fi
From 512f05b9f326506d6cdffd46dcacccb4755f9cd4 Mon Sep 17 00:00:00 2001
From: ehpersonal38
Date: Tue, 28 Jun 2022 14:11:12 -0400
Subject: [PATCH 09/91] perms
---
scripts/weekly_report.sh | 0
1 file changed, 0 insertions(+), 0 deletions(-)
mode change 100644 => 100755 scripts/weekly_report.sh
diff --git a/scripts/weekly_report.sh b/scripts/weekly_report.sh
old mode 100644
new mode 100755
From 0540e18967846f511f934ff0f87ed30afb22e7e3 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Tue, 28 Jun 2022 14:14:28 -0400
Subject: [PATCH 10/91] Update update_birdnet_snippets.sh
---
scripts/update_birdnet_snippets.sh | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh
index baee18f..7357167 100755
--- a/scripts/update_birdnet_snippets.sh
+++ b/scripts/update_birdnet_snippets.sh
@@ -95,7 +95,10 @@ if [[ "$pytest_installation_status" = "not installed" ]];then
fi
[ -L ~/BirdSongs/Extracted/weekly_report.php ] || ln -sf ~/BirdNET-Pi/scripts/weekly_report.php ~/BirdSongs/Extracted
-sed "s/\$USER/$USER/g" $HOME/BirdNET-Pi/templates/weekly_report.cron | sudo tee -a /etc/crontab
+
+if ! grep weekly_report /etc/crontab &>/dev/null;then
+ sed "s/\$USER/$USER/g" $HOME/BirdNET-Pi/templates/weekly_report.cron | sudo tee -a /etc/crontab
+fi
if ! grep APPRISE_WEEKLY_REPORT /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "APPRISE_WEEKLY_REPORT=0" >> /etc/birdnet/birdnet.conf
fi
From ca09725e81b096fe6f6f9d60ef09f0c02eca19ba Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Tue, 28 Jun 2022 14:18:05 -0400
Subject: [PATCH 11/91] Update weekly_report.sh
---
scripts/weekly_report.sh | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/scripts/weekly_report.sh b/scripts/weekly_report.sh
index f52f4d2..db605d2 100755
--- a/scripts/weekly_report.sh
+++ b/scripts/weekly_report.sh
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
source /etc/birdnet/birdnet.conf
-echo ${APPRISE_WEEKLY_REPORT}
-
-NOTIFICATION=$(curl 'localhost/views.php?view=Weekly%20Report&ascii=true')
-NOTIFICATION=${NOTIFICATION#*#}
-firstLine=`echo "${NOTIFICATION}" | head -1`
-NOTIFICATION=`echo "${NOTIFICATION}" | tail -n +2`
-$HOME/BirdNET-Pi/birdnet/bin/apprise -vv -t "${firstLine}" -b "${NOTIFICATION}" --config=$HOME/BirdNET-Pi/apprise.txt
\ No newline at end of file
+if [ ${APPRISE_WEEKLY_REPORT} == 1 ];then
+ NOTIFICATION=$(curl 'localhost/views.php?view=Weekly%20Report&ascii=true')
+ NOTIFICATION=${NOTIFICATION#*#}
+ firstLine=`echo "${NOTIFICATION}" | head -1`
+ NOTIFICATION=`echo "${NOTIFICATION}" | tail -n +2`
+ $HOME/BirdNET-Pi/birdnet/bin/apprise -vv -t "${firstLine}" -b "${NOTIFICATION}" --config=$HOME/BirdNET-Pi/apprise.txt
+fi
\ No newline at end of file
From 23c35e4fe0c83a47182ff73ee7b9b17b4af72ff4 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Wed, 29 Jun 2022 09:01:51 -0400
Subject: [PATCH 12/91] fixing formatting on email
---
scripts/weekly_report.php | 77 +++++++++++++++++++++---------------
scripts/weekly_report.sh | 2 +-
templates/weekly_report.cron | 2 +-
3 files changed, 47 insertions(+), 34 deletions(-)
diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php
index 9231ed3..c0966e6 100644
--- a/scripts/weekly_report.php
+++ b/scripts/weekly_report.php
@@ -1,7 +1,4 @@
fetchArray(SQLITE3_ASSOC))
{
- array_push($detections, $detection);
+ $detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
}
echo "# Week ".date('W', $enddate)." Report (".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate).")\n";
- echo "= Top 10 Species =\n";
+ echo "= Top 10 Species = ";
$i = 0;
- foreach($detections as $detection)
+ foreach($detections as $com_name=>$scount)
{
$i++;
if($i <= 10) {
- $statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$detection["Com_Name"].'" AND Date BETWEEN "'.date("Y-m-d",$startdate - (7*86400)).'" AND "'.date("Y-m-d",$enddate - (7*86400)).'"');
+ $statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$com_name.'" AND Date BETWEEN "'.date("Y-m-d",$startdate - (7*86400)).'" AND "'.date("Y-m-d",$enddate - (7*86400)).'"');
if($statement2 == False){
echo "Database is busy";
header("refresh: 0;");
@@ -49,18 +46,41 @@ if(isset($_GET['ascii'])) {
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
$priorweekcount = $totalcount['COUNT(*)'];
- $percentagediff = round((1 - $priorweekcount / $detection["COUNT(*)"]) * 100);
+ $percentagediff = round((1 - $priorweekcount / $scount) * 100);
if($percentagediff > 0) {
- $percentagediff = "+".$percentagediff."%";
+ $percentagediff = "+".$percentagediff."% ";
} else {
- $percentagediff = "-".abs($percentagediff)."%";
+ $percentagediff = "-".abs($percentagediff)."% ";
}
- echo $detection["Com_Name"]." - ".$detection["COUNT(*)"]." (".$percentagediff.")\n";
+ echo $com_name." - ".$scount." (".$percentagediff.") ";
}
}
+ echo " = Species Detected for the First Time: = ";
+
+ $newspeciescount=0;
+ foreach($detections as $com_name=>$scount)
+ {
+ $statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$com_name.'" AND Date NOT BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'"');
+ if($statement3 == False){
+ echo "Database is busy";
+ header("refresh: 0;");
+ }
+ $result3 = $statement3->execute();
+ $totalcount = $result3->fetchArray(SQLITE3_ASSOC);
+ $nonthisweekcount = $totalcount['COUNT(*)'];
+
+ if($nonthisweekcount == 0) {
+ $newspeciescount++;
+ echo $com_name." - ".$scount." ";
+ }
+ }
+ if($newspeciescount == 0) {
+ echo "No new species were seen this week.";
+ }
+
die();
}
@@ -96,7 +116,7 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
}
}
$i++;
- array_push($detections, $detection);
+ $detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
}
?>
@@ -113,12 +133,11 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
$scount)
{
$i++;
-
if($i <= 10) {
- $statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$detection["Com_Name"].'" AND Date BETWEEN "'.date("Y-m-d",$startdate - (7*86400)).'" AND "'.date("Y-m-d",$enddate - (7*86400)).'"');
+ $statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$com_name.'" AND Date BETWEEN "'.date("Y-m-d",$startdate - (7*86400)).'" AND "'.date("Y-m-d",$enddate - (7*86400)).'"');
if($statement2 == False){
echo "Database is busy";
header("refresh: 0;");
@@ -127,7 +146,7 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
$totalcount = $result2->fetchArray(SQLITE3_ASSOC);
$priorweekcount = $totalcount['COUNT(*)'];
- $percentagediff = round((1 - $priorweekcount / $detection["COUNT(*)"]) * 100);
+ $percentagediff = round((1 - $priorweekcount / $scount) * 100);
if($percentagediff > 0) {
$percentagediff = "+".$percentagediff."% ";
@@ -135,7 +154,7 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
$percentagediff = "-".abs($percentagediff)."% ";
}
- echo "".$detection["Com_Name"]."".$detection["COUNT(*)"]." (".$percentagediff.") ";
+ echo "".$com_name."".$scount." (".$percentagediff.") ";
}
}
?>
@@ -146,23 +165,16 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
- "; ?>
+ "; ?>
$val) {
- if ($val['Com_Name'] === $id) {
- return $key;
- }
- }
- return null;
- }
- foreach($detections as $detection)
+ $newspeciescount=0;
+ foreach($detections as $com_name=>$scount)
{
- $statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$detection["Com_Name"].'" AND Date NOT BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'"');
+ $statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Com_Name == "'.$com_name.'" AND Date NOT BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'"');
if($statement3 == False){
echo "Database is busy";
header("refresh: 0;");
@@ -171,13 +183,14 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
$totalcount = $result3->fetchArray(SQLITE3_ASSOC);
$nonthisweekcount = $totalcount['COUNT(*)'];
- // TODO: add a "no species were seen for the first time this week", if applicable
-
if($nonthisweekcount == 0) {
- $key = array_search($detection["Com_Name"], array_column($detections, 'Com_Name'));
- echo "".$detection["Com_Name"]."".$detections[$key]["COUNT(*)"]." ";
+ $newspeciescount++;
+ echo "".$com_name."".$scount." ";
}
}
+ if($newspeciescount == 0) {
+ echo "No new species were seen this week. ";
+ }
?>
diff --git a/scripts/weekly_report.sh b/scripts/weekly_report.sh
index db605d2..8bfaee7 100755
--- a/scripts/weekly_report.sh
+++ b/scripts/weekly_report.sh
@@ -5,5 +5,5 @@ if [ ${APPRISE_WEEKLY_REPORT} == 1 ];then
NOTIFICATION=${NOTIFICATION#*#}
firstLine=`echo "${NOTIFICATION}" | head -1`
NOTIFICATION=`echo "${NOTIFICATION}" | tail -n +2`
- $HOME/BirdNET-Pi/birdnet/bin/apprise -vv -t "${firstLine}" -b "${NOTIFICATION}" --config=$HOME/BirdNET-Pi/apprise.txt
+ $HOME/BirdNET-Pi/birdnet/bin/apprise -vv -t "${firstLine}" -b "${NOTIFICATION}" --input-format=html --config=$HOME/BirdNET-Pi/apprise.txt
fi
\ No newline at end of file
diff --git a/templates/weekly_report.cron b/templates/weekly_report.cron
index 466c749..1475f25 100644
--- a/templates/weekly_report.cron
+++ b/templates/weekly_report.cron
@@ -1,2 +1,2 @@
#birdnet
-0 7 * * 1 $USER /usr/local/bin/weekly_report.sh >/dev/null 2>&1
\ No newline at end of file
+0 1 * * 1 $USER /usr/local/bin/weekly_report.sh >/dev/null 2>&1
\ No newline at end of file
From 5b147caa8936fb38f20e9b6d2c136a5e0a805058 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Wed, 29 Jun 2022 09:02:53 -0400
Subject: [PATCH 13/91] Update weekly_report.php
---
scripts/weekly_report.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php
index c0966e6..0fbf2e1 100644
--- a/scripts/weekly_report.php
+++ b/scripts/weekly_report.php
@@ -58,7 +58,7 @@ if(isset($_GET['ascii'])) {
}
}
- echo " = Species Detected for the First Time: = ";
+ echo " = Species Detected for the First Time = ";
$newspeciescount=0;
foreach($detections as $com_name=>$scount)
From 7ffc53ef4100842188193c2da1fdf1a88bd95beb Mon Sep 17 00:00:00 2001
From: mcguirepr89
Date: Wed, 29 Jun 2022 09:54:04 -0400
Subject: [PATCH 14/91] setting permissions on each update
---
scripts/update_birdnet_snippets.sh | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh
index c22d0bf..1f61600 100755
--- a/scripts/update_birdnet_snippets.sh
+++ b/scripts/update_birdnet_snippets.sh
@@ -6,6 +6,10 @@ USER=$(awk -F: '/1000/ {print $1}' /etc/passwd)
HOME=$(awk -F: '/1000/ {print $6}' /etc/passwd)
my_dir=$HOME/BirdNET-Pi/scripts
+# Sets proper permissions and ownership
+sudo -E chown -R $USER:$USER $HOME/*
+sudo chmod -R g+wr $HOME/*
+
if ! grep PRIVACY_THRESHOLD /etc/birdnet/birdnet.conf &>/dev/null;then
sudo -u$USER echo "PRIVACY_THRESHOLD=0" >> /etc/birdnet/birdnet.conf
git -C $HOME/BirdNET-Pi rm $my_dir/privacy_server.py
From 1c28e6d0cfef82e7c92fa02572e0a28ddf226db0 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Wed, 29 Jun 2022 10:25:40 -0400
Subject: [PATCH 15/91] config checkbox
---
scripts/config.php | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/scripts/config.php b/scripts/config.php
index 023499e..2aafa7f 100644
--- a/scripts/config.php
+++ b/scripts/config.php
@@ -46,6 +46,11 @@ if(isset($_GET["latitude"])){
} else {
$apprise_notify_new_species_each_day = 0;
}
+ if(isset($_GET['apprise_weekly_report'])) {
+ $apprise_weekly_report = 1;
+ } else {
+ $apprise_weekly_report = 0;
+ }
if(isset($timezone)) {
shell_exec("sudo timedatectl set-timezone ".$timezone);
@@ -101,6 +106,7 @@ if(isset($_GET["latitude"])){
$contents = preg_replace("/APPRISE_NOTIFY_EACH_DETECTION=.*/", "APPRISE_NOTIFY_EACH_DETECTION=$apprise_notify_each_detection", $contents);
$contents = preg_replace("/APPRISE_NOTIFY_NEW_SPECIES=.*/", "APPRISE_NOTIFY_NEW_SPECIES=$apprise_notify_new_species", $contents);
$contents = preg_replace("/APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=.*/", "APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=$apprise_notify_new_species_each_day", $contents);
+ $contents = preg_replace("/APPRISE_WEEKLY_REPORT=.*/", "APPRISE_WEEKLY_REPORT=$apprise_weekly_report", $contents);
$contents = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents);
$contents = preg_replace("/DATABASE_LANG=.*/", "DATABASE_LANG=$language", $contents);
$contents = preg_replace("/FLICKR_FILTER_EMAIL=.*/", "FLICKR_FILTER_EMAIL=$flickr_filter_email", $contents);
@@ -114,6 +120,7 @@ if(isset($_GET["latitude"])){
$contents2 = preg_replace("/APPRISE_NOTIFY_EACH_DETECTION=.*/", "APPRISE_NOTIFY_EACH_DETECTION=$apprise_notify_each_detection", $contents2);
$contents2 = preg_replace("/APPRISE_NOTIFY_NEW_SPECIES=.*/", "APPRISE_NOTIFY_NEW_SPECIES=$apprise_notify_new_species", $contents2);
$contents2 = preg_replace("/APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=.*/", "APPRISE_NOTIFY_NEW_SPECIES_EACH_DAY=$apprise_notify_new_species_each_day", $contents2);
+ $contents2 = preg_replace("/APPRISE_WEEKLY_REPORT=.*/", "APPRISE_WEEKLY_REPORT=$apprise_weekly_report", $contents2);
$contents2 = preg_replace("/FLICKR_API_KEY=.*/", "FLICKR_API_KEY=$flickr_api_key", $contents2);
$contents2 = preg_replace("/DATABASE_LANG=.*/", "DATABASE_LANG=$language", $contents2);
$contents2 = preg_replace("/FLICKR_FILTER_EMAIL=.*/", "FLICKR_FILTER_EMAIL=$flickr_filter_email", $contents2);
@@ -329,9 +336,11 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}
>
Notify each new infrequent species detection (<5 visits per week)
>
- Notify each new species detection of the day
+ Notify each species first detection of the day
>
- Notify each new detection
+ Notify each new detection
+ >
+ Send weekly report
Send Test Notification
From b6bf1bedcaeb06c0e50a0cbe4de01c3e8972b36e Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Wed, 29 Jun 2022 17:09:38 -0400
Subject: [PATCH 16/91] More stats, formatting
---
homepage/views.php | 3 --
scripts/weekly_report.php | 60 +++++++++++++++++++++++++++++++++++++--
2 files changed, 58 insertions(+), 5 deletions(-)
diff --git a/homepage/views.php b/homepage/views.php
index 5618dad..56ae606 100644
--- a/homepage/views.php
+++ b/homepage/views.php
@@ -46,9 +46,6 @@ body::-webkit-scrollbar {
-
diff --git a/scripts/weekly_report.php b/scripts/weekly_report.php
index 0fbf2e1..4968c3f 100644
--- a/scripts/weekly_report.php
+++ b/scripts/weekly_report.php
@@ -1,4 +1,7 @@
execute();
+ $statement4 = $db->prepare('SELECT DISTINCT(Com_Name), COUNT(*) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'"');
+ if($statement4 == False){
+ echo "Database is busy";
+ header("refresh: 0;");
+ }
+ $result4 = $statement4->execute();
+ $totalcount = $result4->fetchArray(SQLITE3_ASSOC)['COUNT(*)'];
+
+ $statement5 = $db->prepare('SELECT DISTINCT(Com_Name), COUNT(*) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate- (7*86400)).'" AND "'.date("Y-m-d",$enddate- (7*86400)).'"');
+ if($statement5 == False){
+ echo "Database is busy";
+ header("refresh: 0;");
+ }
+ $result5 = $statement5->execute();
+ $priortotalcount = $result5->fetchArray(SQLITE3_ASSOC)['COUNT(*)'];
+
+ $statement6 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate).'" AND "'.date("Y-m-d",$enddate).'"');
+ if($statement6 == False){
+ echo "Database is busy";
+ header("refresh: 0;");
+ }
+ $result6 = $statement6->execute();
+ $totalspeciestally = $result6->fetchArray(SQLITE3_ASSOC)['COUNT(DISTINCT(Com_Name))'];
+
+ $statement7 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections WHERE Date BETWEEN "'.date("Y-m-d",$startdate- (7*86400)).'" AND "'.date("Y-m-d",$enddate- (7*86400)).'"');
+ if($statement7 == False){
+ echo "Database is busy";
+ header("refresh: 0;");
+ }
+ $result7= $statement7->execute();
+ $priortotalspeciestally = $result7->fetchArray(SQLITE3_ASSOC)['COUNT(DISTINCT(Com_Name))'];
+
+ $percentagedifftotal = round((1 - $priortotalcount / $totalcount) * 100);
+
+ if($percentagedifftotal > 0) {
+ $percentagedifftotal = "+".$percentagedifftotal."% ";
+ } else {
+ $percentagedifftotal = "-".abs($percentagedifftotal)."% ";
+ }
+
+ $percentagedifftotaldistinctspecies = round((1 - $priortotalspeciestally / $totalspeciestally) * 100);
+ if($percentagedifftotaldistinctspecies > 0) {
+ $percentagedifftotaldistinctspecies = "+".$percentagedifftotaldistinctspecies."% ";
+ } else {
+ $percentagedifftotaldistinctspecies = "-".abs($percentagedifftotaldistinctspecies)."% ";
+ }
+
$detections = [];
$i = 0;
while($detection=$result1->fetchArray(SQLITE3_ASSOC))
@@ -27,7 +77,10 @@ if(isset($_GET['ascii'])) {
$detections[$detection["Com_Name"]] = $detection["COUNT(*)"];
}
- echo "# Week ".date('W', $enddate)." Report (".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate).")\n";
+ echo "# BirdNET-Pi: Week ".date('W', $enddate)." Report\n";
+
+ echo "Total Detections: ".$totalcount." (".$percentagedifftotal.") ";
+ echo "Unique Species Detected: ".$totalspeciestally." (".$percentagedifftotaldistinctspecies.") ";
echo "= Top 10 Species = ";
@@ -81,6 +134,9 @@ if(isset($_GET['ascii'])) {
echo "No new species were seen this week.";
}
+ echo "* data from ".date('F jS, Y',$startdate)." — ".date('F jS, Y',$enddate).". ";
+ echo '* percentages are calculated relative to week '.(date('W', $enddate) - 1).'. ';
+
die();
}
@@ -199,5 +255,5 @@ while($detection=$result1->fetchArray(SQLITE3_ASSOC))
- * percentages are calculated relative to week
+
* percentages are calculated relative to week
\ No newline at end of file
From 4601dd2f09f20a681b1fc3891fc25ef1eaff7b6e Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Wed, 29 Jun 2022 17:40:53 -0400
Subject: [PATCH 17/91] better for testing
---
scripts/update_birdnet_snippets.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/scripts/update_birdnet_snippets.sh b/scripts/update_birdnet_snippets.sh
index 7357167..fe90caf 100755
--- a/scripts/update_birdnet_snippets.sh
+++ b/scripts/update_birdnet_snippets.sh
@@ -100,7 +100,7 @@ if ! grep weekly_report /etc/crontab &>/dev/null;then
sed "s/\$USER/$USER/g" $HOME/BirdNET-Pi/templates/weekly_report.cron | sudo tee -a /etc/crontab
fi
if ! grep APPRISE_WEEKLY_REPORT /etc/birdnet/birdnet.conf &>/dev/null;then
- sudo -u$USER echo "APPRISE_WEEKLY_REPORT=0" >> /etc/birdnet/birdnet.conf
+ sudo -u$USER echo "APPRISE_WEEKLY_REPORT=1" >> /etc/birdnet/birdnet.conf
fi
sudo systemctl daemon-reload
From 88a107ec6ac81e14a687f98f511ca82502162ed5 Mon Sep 17 00:00:00 2001
From: Patrick McGuire <60325264+mcguirepr89@users.noreply.github.com>
Date: Thu, 30 Jun 2022 08:25:47 -0400
Subject: [PATCH 18/91] Update README.md
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index 97f3308..db6e992 100644
--- a/README.md
+++ b/README.md
@@ -126,6 +126,7 @@ I hope that if you find BirdNET-Pi has been worth your time, you will share your
- [PixCams Build Guide](https://pixcams.com/building-a-birdnet-pi-real-time-acoustic-bird-id-station/)
- [Core-Electronics](https://core-electronics.com.au/projects/bird-calls-raspberry-pi) Build Article
- [RaspberryPi.com Blog Post](https://www.raspberrypi.com/news/classify-birds-acoustically-with-birdnet-pi/)
+- [MagPi Issue 119 Showcase Article](https://magpi.raspberrypi.com/issues/119/pdf)
### Internationalization:
From e19c7c6ba38c7bf7bf3a1868ecf9ea85c5fb3513 Mon Sep 17 00:00:00 2001
From: ehpersonal38 <103586016+ehpersonal38@users.noreply.github.com>
Date: Thu, 30 Jun 2022 16:28:52 -0400
Subject: [PATCH 19/91] silence update indicator
---
homepage/style.css | 4 ++++
homepage/views.php | 15 ++++++++-------
scripts/advanced.php | 13 ++++++++++++-
scripts/update_birdnet_snippets.sh | 4 ++++
4 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/homepage/style.css b/homepage/style.css
index db0266f..4b6fe59 100644
--- a/homepage/style.css
+++ b/homepage/style.css
@@ -790,3 +790,7 @@ pre.bash {
width: 100%;
display: inline-block;
}
+
+#toolsbtn {
+ min-width: max-content;
+}
\ No newline at end of file
diff --git a/homepage/views.php b/homepage/views.php
index dd75f00..aada46e 100644
--- a/homepage/views.php
+++ b/homepage/views.php
@@ -16,6 +16,12 @@ if(!isset($_SESSION['behind'])) {
}
-
+
diff --git a/homepage/style.css b/homepage/style.css
index 4b6fe59..8dbc2ce 100644
--- a/homepage/style.css
+++ b/homepage/style.css
@@ -261,6 +261,11 @@ button:hover {
margin-right: auto;
}
+.views {
+ transition: opacity 0.3s;
+ -webkit-transition: opacity 0.3s;
+}
+
.views .centered button {
background-color: rgb(219, 255, 235);
padding: 12px;
diff --git a/homepage/views.php b/homepage/views.php
index 0e8c4a4..a5d3fcf 100644
--- a/homepage/views.php
+++ b/homepage/views.php
@@ -23,7 +23,7 @@ if (file_exists('./scripts/thisrun.txt')) {
$config = parse_ini_file('./scripts/firstrun.ini');
}
?>
-
+
-
+
diff --git a/homepage/style.css b/homepage/style.css
index 8dbc2ce..b5edaf2 100644
--- a/homepage/style.css
+++ b/homepage/style.css
@@ -798,4 +798,13 @@ pre.bash {
#toolsbtn {
min-width: max-content;
+}
+
+#showpassword {
+ cursor:pointer;
+ margin-left:2px;
+ height:5px;
+ line-height:5px;
+ padding:3px;
+ background-color:#9fe29b
}
\ No newline at end of file
diff --git a/homepage/views.php b/homepage/views.php
index d446f63..ea153e5 100644
--- a/homepage/views.php
+++ b/homepage/views.php
@@ -21,7 +21,7 @@ if (file_exists('./scripts/thisrun.txt')) {
$config = parse_ini_file('./scripts/firstrun.ini');
}
?>
-
+