From db624d5518ca9f26272d268fdfa099311a81f042 Mon Sep 17 00:00:00 2001 From: mcguirepr89 Date: Thu, 17 Feb 2022 12:12:01 -0500 Subject: [PATCH] adding history and its needed updates removed viewday.php since history will make it redundant --- homepage/top.html | 2 +- scripts/clear_all_data.sh | 1 + scripts/daily_plot.py | 30 +++-------- scripts/history.php | 94 +++++++++++++++++++++++++++++++++ scripts/install_services.sh | 1 + scripts/overview.php | 3 +- scripts/spectrogram.sh | 3 +- scripts/update_services.sh | 1 + scripts/viewday.php | 102 ------------------------------------ 9 files changed, 107 insertions(+), 130 deletions(-) create mode 100644 scripts/history.php delete mode 100644 scripts/viewday.php diff --git a/homepage/top.html b/homepage/top.html index d2c8b01..c141a28 100644 --- a/homepage/top.html +++ b/homepage/top.html @@ -44,7 +44,7 @@ footer { Overview | Database | Species Stats | - Today | + History | Spectrogram

diff --git a/scripts/clear_all_data.sh b/scripts/clear_all_data.sh index 10eb1ef..d4f72c6 100755 --- a/scripts/clear_all_data.sh +++ b/scripts/clear_all_data.sh @@ -61,6 +61,7 @@ sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/viewday.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/overview.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/stats.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/viewdb.php ${EXTRACTED} +sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/history.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/homepage/images/favicon.ico ${EXTRACTED} sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED} sudo -u ${USER} cp -f $(dirname ${my_dir})/templates/phpsysinfo.ini ${HOME}/phpsysinfo/ diff --git a/scripts/daily_plot.py b/scripts/daily_plot.py index e417ee3..90b517c 100755 --- a/scripts/daily_plot.py +++ b/scripts/daily_plot.py @@ -6,7 +6,6 @@ import configparser import pandas as pd import seaborn as sns -# import numpy as np import matplotlib.pyplot as plt from matplotlib.colors import LogNorm from datetime import datetime @@ -57,7 +56,6 @@ df_plt_top10_today = df_plt_today[df_plt_today.Com_Name.isin(plt_top10_today.ind pal = "Greens" #Set up plot axes and titles -# f, axs = plt.subplots(1, 3, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 2, 5])) f, axs = plt.subplots(1, 2, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 6]), facecolor='#77C487') plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0, hspace=0) @@ -80,16 +78,11 @@ plot=sns.countplot(y='Com_Name', data = df_plt_top10_today, palette = colors, o #Try plot grid lines between bars - problem at the moment plots grid lines on bars - want between bars -# plot.grid(True, axis='y') z=plot.get_ymajorticklabels() plot.set_yticklabels(['\n'.join(textwrap.wrap(ticklabel.get_text(),15)) for ticklabel in plot.get_yticklabels()], fontsize = 10) plot.set(ylabel=None) plot.set(xlabel="Detections") -# huw=df_plt_top10_today.groupby('Com_Name')['Confidence'].mean() -# plot = sns.boxenplot(x=df_plt_top10_today['Confidence']*100,color='Green', y=df_plt_top10_today['Com_Name'], ax=axs[1],order=freq_order) -# plot.set(xlabel="Confidence", ylabel=None,yticklabels=[]) - #Generate crosstab matrix for heatmap plot @@ -114,14 +107,13 @@ for _, spine in plot.spines.items(): plot.set(ylabel=None) plot.set(xlabel="Hour of Day") #Set combined plot layout and titles -# plt.tight_layout() f.subplots_adjust(top=0.9) -plt.suptitle("Last Updated: "+ str(now.strftime("%d-%m-%Y %H:%M"))) +plt.suptitle("Top 10 Last Updated: "+ str(now.strftime("%Y-%m-%d %H:%M"))) #Save combined plot -savename='/home/pi/BirdSongs/Extracted/Charts/Combo-'+str(now.strftime("%d-%m-%Y"))+'.png' +savename='/home/pi/BirdSongs/Extracted/Charts/Combo-'+str(now.strftime("%Y-%m-%d"))+'.png' plt.savefig(savename) -#plt.show() +plt.show() plt.close() @@ -133,9 +125,8 @@ df_plt_Bot10_today = df_plt_today[df_plt_today.Com_Name.isin(plt_Bot10_today.ind pal = "Reds" #Set up plot axes and titles -# f, axs = plt.subplots(1, 3, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 2, 5])) -f, axs = plt.subplots(1, 2, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 6])) +f, axs = plt.subplots(1, 2, figsize = (10, 4), gridspec_kw=dict(width_ratios=[3, 6]), facecolor='#77C487') plt.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=0, hspace=0) #generate y-axis order for all figures based on frequency @@ -156,17 +147,11 @@ plot=sns.countplot(y='Com_Name', data = df_plt_Bot10_today, palette = colors, o #Try plot grid lines between bars - problem at the moment plots grid lines on bars - want between bars -# plot.grid(True, axis='y') z=plot.get_ymajorticklabels() plot.set_yticklabels(['\n'.join(textwrap.wrap(ticklabel.get_text(),15)) for ticklabel in plot.get_yticklabels()], fontsize = 10) plot.set(ylabel=None) plot.set(xlabel="Detections") -# huw=df_plt_Bot10_today.groupby('Com_Name')['Confidence'].mean() -# plot = sns.boxenplot(x=df_plt_Bot10_today['Confidence']*100,color='Green', y=df_plt_Bot10_today['Com_Name'], ax=axs[1],order=freq_order) -# plot.set(xlabel="Confidence", ylabel=None,yticklabels=[]) - - #Generate crosstab matrix for heatmap plot heat = pd.crosstab(df_plt_Bot10_today['Com_Name'],df_plt_Bot10_today['Hour of Day']) @@ -190,12 +175,11 @@ for _, spine in plot.spines.items(): plot.set(ylabel=None) plot.set(xlabel="Hour of Day") #Set combined plot layout and titles -# plt.tight_layout() f.subplots_adjust(top=0.9) -plt.suptitle("Last Updated: "+ str(now.strftime("%d-%m-%Y %H:%M"))) +plt.suptitle("Bottom 10 Last Updated: "+ str(now.strftime("%Y-%m-%d %H:%M"))) #Save combined plot -savename='/home/pi/BirdSongs/Extracted/Charts/Combo2-'+str(now.strftime("%d-%m-%Y"))+'.png' +savename='/home/pi/BirdSongs/Extracted/Charts/Combo2-'+str(now.strftime("%Y-%m-%d"))+'.png' plt.savefig(savename) -# plt.show() +plt.show() plt.close() diff --git a/scripts/history.php b/scripts/history.php new file mode 100644 index 0000000..015798e --- /dev/null +++ b/scripts/history.php @@ -0,0 +1,94 @@ +select_db('birds'); + +if ($mysqli->connect_error) { + die('Connect Error (' . + $mysqli->connect_errno . ') '. + $mysqli->connect_error); +} + +// SQL query to select data from database + +$sql1 = "SELECT COUNT(*) + FROM detections + WHERE DATE = \"$theDate\""; +$dayscount = $mysqli->query($sql1); + +$mysqli->close(); +?> + + + + + + + +
+ + +
+
+ + + +fetch_assoc()){ +?> + + + +
Total Detections For The Day
+
+ +"; +} else { + echo "

No Charts for $theDate

"; +} +echo "
"; +if (file_exists('/home/pi/BirdSongs/Extracted/Charts/'.$chart2)) { + echo ""; +} else { + echo "

No Charts For $theDate

"; +}?> + diff --git a/scripts/install_services.sh b/scripts/install_services.sh index f5bbf0d..447b573 100755 --- a/scripts/install_services.sh +++ b/scripts/install_services.sh @@ -190,6 +190,7 @@ create_necessary_dirs() { sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/overview.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/stats.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/viewdb.php ${EXTRACTED} + sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/history.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/homepage/images/favicon.ico ${EXTRACTED} sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED} sudo -u ${USER} cp -f $(dirname ${my_dir})/templates/phpsysinfo.ini ${HOME}/phpsysinfo/ diff --git a/scripts/overview.php b/scripts/overview.php index 0488dba..8db3bf5 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -3,7 +3,7 @@ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); header("refresh: 300;"); -$myDate = date('d-m-Y'); +$myDate = date('Y-m-d'); $chart = "Combo-$myDate.png"; $mysqli = mysqli_connect(); $mysqli->select_db('birds'); @@ -125,7 +125,6 @@ while($rows=$mostrecent ->fetch_assoc()) -

Today's Top 10 Species

"; diff --git a/scripts/spectrogram.sh b/scripts/spectrogram.sh index db36975..3a5e814 100755 --- a/scripts/spectrogram.sh +++ b/scripts/spectrogram.sh @@ -3,5 +3,4 @@ source /etc/birdnet/birdnet.conf analyzing_now="$(cat /home/pi/BirdNET-Pi/analyzing_now.txt)" spectrogram_png=${EXTRACTED}/spectrogram.png -#sudo -u pi sox "${analyzing_now}" -n spectrogram -t "Currently Analyzing" -c "${analyzing_now}" -o "${spectrogram_png}" -sudo -u pi sox "${analyzing_now}" -n remix 1 rate 24k spectrogram -t "Currently Analyzing" -c "${analyzing_now}" -o "${spectrogram_png}" +sudo -u pi sox "${analyzing_now}" -n remix 1 rate 24k spectrogram -c "${analyzing_now}" -o "${spectrogram_png}" diff --git a/scripts/update_services.sh b/scripts/update_services.sh index 41fd940..d6ef6fa 100755 --- a/scripts/update_services.sh +++ b/scripts/update_services.sh @@ -182,6 +182,7 @@ create_necessary_dirs() { sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/overview.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/stats.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/viewdb.php ${EXTRACTED} + sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/history.php ${EXTRACTED} sudo -u ${USER} ln -fs $(dirname ${my_dir})/homepage/images/favicon.ico ${EXTRACTED} sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED} sudo -u ${USER} cp -f $(dirname ${my_dir})/templates/phpsysinfo.ini ${HOME}/phpsysinfo/ diff --git a/scripts/viewday.php b/scripts/viewday.php deleted file mode 100644 index c79eaf1..0000000 --- a/scripts/viewday.php +++ /dev/null @@ -1,102 +0,0 @@ -select_db('birds'); - -if ($mysqli->connect_error) { - die('Connect Error (' . - $mysqli->connect_errno . ') '. - $mysqli->connect_error); -} - -// SQL query to select data from database - -$sql1 = "SELECT * FROM detections - WHERE Date = CURDATE() - ORDER BY Date DESC, Time DESC"; -$mosttable = $mysqli->query($sql1); - -$sql2 = "SELECT * FROM detections - WHERE Date = CURDATE()"; -$todaystable = $mysqli->query($sql2); -$todayscount=mysqli_num_rows($todaystable); - - -$sql3 = "SELECT * FROM detections - WHERE Date = CURDATE() - AND Time >= DATE_SUB(NOW(),INTERVAL 1 HOUR)"; -$lasthourtable = $mysqli->query($sql3); -$lasthourcount=mysqli_num_rows($lasthourtable); - -$sql4 = "SELECT Com_Name, Date, Time, MAX(Confidence) - FROM detections - WHERE Date = CURDATE() - GROUP BY Com_Name - ORDER BY MAX(Confidence) DESC"; -$specieslist = $mysqli->query($sql4); -$speciescount=mysqli_num_rows($specieslist); - -$mysqli->close(); -?> - - - - - - - - Today's View - - - - - - - -"; -} else { - echo "

No Detections For Today

"; -} -?> - - -
-
-
- - - - - - - - - - - - - - -
TodayLast HourNumber of Unique Species Today
Number of Detections
- -
- -
-
- - -