Skip to content

A live bird collage card for your Home Assistant dashboard.

adding history and its needed updates removed viewday.php since history will make it redundant

mcguirepr89db624d5518ca
diff --git a/homepage/top.html b/homepage/top.html
index d2c8b012..c141a28e 100644
--- a/homepage/top.html
+++ b/homepage/top.html
@@ -44,7 +44,7 @@ footer {
<a href="/overview.php" target="content">Overview</a> |
<a href="/viewdb.php" target="content">Database</a> |
<a href="/stats.php" target="content">Species Stats</a> |
- <a href="/viewday.php" target="content">Today</a> |
+ <a href="/history.php" target="content">History</a> |
<a href="/spectrogram.php" target="content">Spectrogram</a>
</p>
</body>
diff --git a/scripts/clear_all_data.sh b/scripts/clear_all_data.sh
index 10eb1efd..d4f72c6d 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 e417ee39..90b517cc 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 00000000..015798ed
--- /dev/null
+++ b/scripts/history.php
@@ -0,0 +1,94 @@
+<?php
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+
+if(isset($_POST['date'])){
+$theDate = $_POST['date'];
+} else {
+$theDate = date('Y-m-d');
+}
+$chart = "Combo-$theDate.png";
+$chart2 = "Combo2-$theDate.png";
+$mysqli = mysqli_connect();
+$mysqli->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();
+?>
+
+<head>
+<link rel="stylesheet" href="style.css">
+
+<style>
+input {
+ width:auto;
+}
+center {
+ display: block;
+ margin-left: auto;
+ margin-right: auto;
+ width: 100%;
+}
+body {
+ background-color: rgb(119, 196, 135);
+}
+button,input {
+ font-size: medium;
+}
+table,th,td {
+ background-color: rgb(219, 255, 235);
+}
+table {
+ width:30%;
+}
+hr {
+ border: 1px solid green;
+ width:80%;
+}
+</style>
+</head>
+<body>
+<form style="margin-left: -150px;text-align:center;" action="" name="submit" method="POST">
+ <input type="date" name="date" value="<?php echo $theDate;?>">
+ <button type="submit" class="block">Submit Date</button>
+</form>
+<div style="margin-left: -150px;">
+ <table>
+ <tr>
+ <th>Total Detections For The Day</th>
+<?php
+while($row=$dayscount->fetch_assoc()){
+?>
+ <td><?php echo $row['COUNT(*)'];?></td>
+<?php
+}?>
+ </tr>
+ </table>
+</div>
+
+<?php
+if (file_exists('/home/pi/BirdSongs/Extracted/Charts/'.$chart)) {
+ echo "<img src=\"/Charts/$chart?nocache=time()\" style=\"height:auto;width: 100%;padding: 5px;margin-left: auto;margin-right: auto;display: block;\">";
+} else {
+ echo "<p style=\"text-align:center;margin-left:-150px;\">No Charts for $theDate</p>";
+}
+echo "<hr>";
+if (file_exists('/home/pi/BirdSongs/Extracted/Charts/'.$chart2)) {
+ echo "<img src=\"/Charts/$chart2?nocache=time()\" style=\"height:auto;width: 100%;padding: 5px;margin-left: auto;margin-right: auto;display: block;\">";
+} else {
+ echo "<p style=\"text-align:center;margin-left:-150px;\">No Charts For $theDate</p>";
+}?>
+</html>
diff --git a/scripts/install_services.sh b/scripts/install_services.sh
index f5bbf0d6..447b5734 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 0488dba2..8db3bf5e 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())
</table>
</div>
</div>
- <h2>Today's Top 10 Species</h2>
<?php
if (file_exists('/home/pi/BirdSongs/Extracted/Charts/'.$chart)) {
echo "<img src=\"/Charts/$chart?nocache=time()\" style=\"width: 100%;padding: 5px;margin-left: auto;margin-right: auto;display: block;\">";
diff --git a/scripts/spectrogram.sh b/scripts/spectrogram.sh
index db36975b..3a5e8141 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 41fd9408..d6ef6fa1 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 c79eaf11..00000000
--- a/scripts/viewday.php
+++ /dev/null
@@ -1,102 +0,0 @@
-<?php
-header("refresh: 300;");
-$myDate = date('d-m-Y');
-$chart = "Combo-$myDate.png";
-$mysqli = mysqli_connect();
-$mysqli->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();
-?>
-
-<!DOCTYPE html>
-<html lang="en">
-
-<head>
- <meta charset="UTF-8">
- <!-- <meta name="viewport" content="width=device-width, initial-scale=1"> -->
- <title>Today's View</title>
- <!-- CSS FOR STYLING THE PAGE -->
-<link rel="stylesheet" href="style.css">
-
-
-<style>
-.center {
- display: block;
- margin-left: auto;
- margin-right: auto;
- width: 100%;
-}
-table,th,td {
- background-color: rgb(219, 255, 235);
-}
-</style>
-</head>
-
-<?php
-if (file_exists('/home/pi/BirdSongs/Extracted/Charts/'.$chart)) {
- echo "<img src=\"/Charts/$chart?nocache=$time()\" style=\"width: 100%;padding: 5px;margin-left: auto;margin-right: auto;display: block;\">";
-} else {
- echo "<p style=\"text-align:center;margin-left:-150px;\">No Detections For Today</p>";
-}
-?>
-<body style="background-color: rgb(119, 196, 135);">
-
- <section>
-<div class="row">
- <div class="column2">
- <table>
- <tr>
- <th></th>
- <th>Today</th>
- <th>Last Hour</th>
- <th>Number of Unique Species Today</th>
- </tr>
- <tr>
-
- <th>Number of Detections</th>
- <td><?php echo $todayscount;?></td>
- <td><?php echo $lasthourcount;?></td>
- <td><?php echo $speciescount;?></td>
- </tr>
- </table>
-
-</div>
-
-</div>
- </section>
-</div>
-
-</html>