Skip to content

A live bird collage card for your Home Assistant dashboard.

database views now link to recordings and spectrograms

mcguirepr8932966476e739
diff --git a/scripts/clear_all_data.sh b/scripts/clear_all_data.sh
index 1e4ea473..10eb1efd 100755
--- a/scripts/clear_all_data.sh
+++ b/scripts/clear_all_data.sh
@@ -59,6 +59,7 @@ fi
sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/spectrogram.php ${EXTRACTED}
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})/homepage/images/favicon.ico ${EXTRACTED}
sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED}
diff --git a/scripts/install_services.sh b/scripts/install_services.sh
index afeaf390..ff73340d 100755
--- a/scripts/install_services.sh
+++ b/scripts/install_services.sh
@@ -182,6 +182,7 @@ create_necessary_dirs() {
sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/spectrogram.php ${EXTRACTED}
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})/homepage/images/favicon.ico ${EXTRACTED}
sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED}
diff --git a/scripts/overview.php b/scripts/overview.php
index cc6df56a..55d69ad4 100644
--- a/scripts/overview.php
+++ b/scripts/overview.php
@@ -53,6 +53,10 @@ $mysqli->close();
<style>
+a {
+ text-decoration: none;
+ color:black;
+}
.center {
display: block;
margin-left: 5px;
@@ -76,11 +80,12 @@ $mysqli->close();
<?php // LOOP TILL END OF DATA
while($rows=$mostrecent ->fetch_assoc())
{
+ $dbname = preg_replace('/ /', '_', $rows['Com_Name']);
?>
<table>
<tr>
<th>Most Recent Detection</th>
- <td><?php echo $rows['Com_Name'];?></td>
+ <td><a href="/By_Common_Name/<?php echo $dbname;?>"><?php echo $rows['Com_Name'];?></a></td>
<td><?php echo $rows['Date'];?></td>
<td><?php echo $rows['Time'];?></td>
</tr>
diff --git a/scripts/stats.php b/scripts/stats.php
new file mode 100644
index 00000000..6de8c03e
--- /dev/null
+++ b/scripts/stats.php
@@ -0,0 +1,242 @@
+<?php
+ini_set('display_errors', 1);
+ini_set('display_startup_errors', 1);
+error_reporting(E_ALL);
+
+$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
+$sql = "SELECT COUNT(*) AS 'Total' FROM detections
+ ORDER BY Date DESC, Time DESC";
+$totalcount = $mysqli->query($sql);
+
+$sql1 = "SELECT Com_Name, COUNT(*), MAX(Confidence)
+ FROM detections
+ GROUP BY Com_Name
+ ORDER BY COUNT(*) DESC";
+$stats = $mysqli->query($sql1);
+
+$sql2 = "SELECT COUNT(*) AS 'Total' FROM detections
+ WHERE Date = CURDATE()";
+$todayscount = $mysqli->query($sql2);
+
+$sql3 = "SELECT COUNT(*) AS 'Total' FROM detections
+ WHERE Date = CURDATE()
+ AND Time >= DATE_SUB(NOW(),INTERVAL 1 HOUR)";
+$lasthourcount = $mysqli->query($sql3);
+
+$sql4 = "SELECT Com_Name, Date, Time, MAX(Confidence)
+ FROM detections
+ GROUP BY Com_Name
+ ORDER BY MAX(Confidence) DESC";
+$specieslist = $mysqli->query($sql4);
+$speciescount = mysqli_num_rows($specieslist);
+
+$sql5 = "SELECT Com_Name,COUNT(*)
+ AS 'Total'
+ FROM detections
+ GROUP BY Com_Name
+ ORDER BY Total DESC";
+$speciestally = $mysqli->query($sql5);
+
+$getspecies = "SELECT Com_Name from detections
+ GROUP BY Com_Name";
+$result = $mysqli->query($getspecies);
+
+if(isset($_POST['species'])){
+ $selection = $_POST['species'];
+ $specificspecies = "SELECT Com_Name, Sci_Name, COUNT(*), MAX(Confidence) from detections
+ WHERE Com_Name = \"$selection\"";
+ $specificstats = $mysqli->query($specificspecies);}
+
+$mysqli->close();
+?>
+
+<!DOCTYPE html>
+<html lang="en">
+
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>BirdNET-Pi DB</title>
+ <link rel="stylesheet" href="style.css">
+<style>
+/* Chrome, Safari, Edge, Opera */
+input::-webkit-outer-spin-button,
+input::-webkit-inner-spin-button {
+ -webkit-appearance: none;
+ margin: 0;
+}
+
+/* Firefox */
+input[type=number] {
+ -moz-appearance: textfield;
+}
+* {
+ font-family: 'Arial', 'Gill Sans', 'Gill Sans MT',
+ ' Calibri', 'Trebuchet MS', 'sans-serif';
+ box-sizing: border-box;
+}
+/* Create two unequal columns that floats next to each other */
+.column {
+ float: left;
+ padding: 10px;
+}
+.first {
+ width: calc(50% - 70px);
+}
+.second {
+ width: calc(50% - 30px);
+}
+.
+/* Clear floats after the columns */
+.row:after {
+ content: "";
+ display: table;
+ clear: both;
+}
+body {
+ background-color: rgb(119, 196, 135);
+}
+a {
+ color:black;
+ text-decoration: none;
+}
+.block {
+ display: block;
+ width:50%;
+ border: none;
+ padding: 10px 10px;
+ font-size: medium;
+ cursor: pointer;
+ text-align: center;
+}
+
+select {
+ font-size:large;
+ width: 60%;
+}
+
+select option {
+ font-size:large;
+}
+
+form {
+ margin-left:20px;
+}
+
+@media screen and (max-width: 800px) {
+ select {
+ width:100%;
+ }
+ h3 {
+ margin-bottom:0px;
+ text-align:center;
+ }
+ form {
+ text-align:left;
+ margin-left:0px;
+ }
+ .column {
+ float: none;
+ width: 100%;
+ }
+ input, label {
+ width:100%;
+ {
+}
+ </style>
+</head>
+<body style="background-color: rgb(119, 196, 135);">
+
+ <section>
+<div class="row">
+ <div class="column first">
+ <h3>Number of Detections</h3>
+ <table>
+ <tr>
+ <th>Total</th>
+ <th>Today</th>
+ <th>Last Hour</th>
+ <th>Number of Unique Species</th>
+ </tr>
+ <tr>
+ <td><?php while ($row = $totalcount->fetch_assoc()) { echo $row['Total']; };?></td>
+ <td><?php while ($row = $todayscount->fetch_assoc()) { echo $row['Total']; };?></td>
+ <td><?php while ($row = $lasthourcount->fetch_assoc()) { echo $row['Total']; };?></td>
+ <td><?php echo $speciescount;?></td>
+ </tr>
+ </table>
+ <h3>Summary</h3>
+ <table>
+ <tr>
+ <th>Common Name</th>
+ <th>Occurrences</th>
+ <th>Max Confidence Score</th>
+ </tr>
+<?php // LOOP TILL END OF DATA
+while($rows=$stats ->fetch_assoc())
+{
+ $MAX = sprintf("%.1f%%", $rows['MAX(Confidence)'] * 100)
+?>
+ <tr>
+ <td><a href="../By_Common_Name/<?php echo preg_replace('/ /', '_', $rows['Com_Name']);?>"><?php echo $rows['Com_Name'];?></a></td>
+ <td><?php echo $rows['COUNT(*)'];?></td>
+ <td><?php echo $MAX;?></td>
+
+ </tr>
+<?php
+}
+?>
+ </table>
+ </div>
+ <div class="column">
+<form action="stats.php" method="POST">
+ <h3>Species Stats</h3>
+ <select name="species" >
+ <option value="<?php if(isset($_POST['species'])){echo $selection;}?>"><?php if(isset($_POST['species'])){echo $selection;}else{echo "--Choose Species--";}?></option>
+ <?php
+ while($row = $result->fetch_assoc()) {
+ ?>
+ <option value='<?php echo $row['Com_Name'];?>'><?php echo $row['Com_Name'];?></option>"
+<?php
+}
+?>
+ </select>
+ </p>
+ <button type="submit" class="block"/>Show Species Statistics</button>
+</form>
+<?php if(isset($_POST['species'])){
+ echo "<h3>";echo $_POST['species'];echo "</h3>
+ <table>
+ <tr>
+ <th>Common Name</th>
+ <th>Scientific Name</th>
+ <th>Occurrences</th>
+ <th>Highest Confidence Score</th>
+ </tr>";
+while($rows = $specificstats->fetch_assoc()) {
+ $dbname = preg_replace('/ /', '_', $rows['Com_Name']);
+ $dbsciname = preg_replace('/ /', '_', $rows['Sci_Name']);
+ echo "<tr>
+ <td>";echo "<a href=\"../By_Common_Name/$dbname\"/>";echo $rows['Com_Name']; echo "</a></td>
+ <td>";echo "<a href=\"../By_Scientific_Name/$dbsciname\"/>";echo $rows['Sci_Name']; echo "</a></td>
+ <td>";echo $rows['COUNT(*)'];echo "</td>
+ <td>";echo $rows['MAX(Confidence)'];echo "</td>
+ </tr>";
+}}
+?>
+ </table>
+ </div>
+</div>
+</div>
+ </section>
+</html>
+
diff --git a/scripts/update_services.sh b/scripts/update_services.sh
index 7e208c5f..3dcd03b4 100755
--- a/scripts/update_services.sh
+++ b/scripts/update_services.sh
@@ -174,6 +174,7 @@ create_necessary_dirs() {
sudo -u ${USER} ln -fs $(dirname ${my_dir})/scripts/spectrogram.php ${EXTRACTED}
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})/homepage/images/favicon.ico ${EXTRACTED}
sudo -u ${USER} ln -fs ${HOME}/phpsysinfo ${EXTRACTED}
diff --git a/scripts/viewdb.php b/scripts/viewdb.php
index fa787518..cbc80a31 100644
--- a/scripts/viewdb.php
+++ b/scripts/viewdb.php
@@ -8,44 +8,44 @@ $mysqli = mysqli_connect();
$mysqli->select_db('birds');
if ($mysqli->connect_error) {
- die('Connect Error (' .
- $mysqli->connect_errno . ') '.
- $mysqli->connect_error);
+ die('Connect Error (' .
+ $mysqli->connect_errno . ') '.
+ $mysqli->connect_error);
}
// SQL query to select data from database
$sql = "SELECT COUNT(*) AS 'Total' FROM detections
- ORDER BY Date DESC, Time DESC";
+ ORDER BY Date DESC, Time DESC";
$totalcount = $mysqli->query($sql);
$sql1 = "SELECT Date, Time, Sci_Name, Com_Name, MAX(Confidence)
- FROM detections
- WHERE Date = CURDATE()
- GROUP BY Date, Time, Sci_Name, Com_Name
- ORDER BY Time DESC";
+ FROM detections
+ WHERE Date = CURDATE()
+ GROUP BY Date, Time, Sci_Name, Com_Name
+ ORDER BY Time DESC";
$mosttable = $mysqli->query($sql1);
$sql2 = "SELECT COUNT(*) AS 'Total' FROM detections
- WHERE Date = CURDATE()";
+ WHERE Date = CURDATE()";
$todayscount = $mysqli->query($sql2);
$sql3 = "SELECT COUNT(*) AS 'Total' FROM detections
- WHERE Date = CURDATE()
- AND Time >= DATE_SUB(NOW(),INTERVAL 1 HOUR)";
+ WHERE Date = CURDATE()
+ AND Time >= DATE_SUB(NOW(),INTERVAL 1 HOUR)";
$lasthourcount = $mysqli->query($sql3);
$sql4 = "SELECT Com_Name, Date, Time, MAX(Confidence)
- FROM detections
- GROUP BY Com_Name
- ORDER BY MAX(Confidence) DESC";
+ FROM detections
+ GROUP BY Com_Name
+ ORDER BY MAX(Confidence) DESC";
$specieslist = $mysqli->query($sql4);
$speciescount = mysqli_num_rows($specieslist);
$sql5 = "SELECT Com_Name,COUNT(*)
- AS 'Total'
- FROM detections
- GROUP BY Com_Name
- ORDER BY Total DESC";
+ AS 'Total'
+ FROM detections
+ GROUP BY Com_Name
+ ORDER BY Total DESC";
$speciestally = $mysqli->query($sql5);
$mysqli->close();
@@ -59,6 +59,12 @@ $mysqli->close();
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>BirdNET-Pi DB</title>
<link rel="stylesheet" href="style.css">
+ <style>
+a {
+ text-decoration:none;
+ color:black;
+}
+</style>
</head>
<body style="background-color: rgb(119, 196, 135);">
@@ -68,16 +74,16 @@ $mysqli->close();
<div class="column2">
<table>
<tr>
- <th>Total</th>
- <th>Today</th>
- <th>Last Hour</th>
- <th>Number of Unique Species</th>
+ <th>Total</th>
+ <th>Today</th>
+ <th>Last Hour</th>
+ <th>Number of Unique Species</th>
</tr>
<tr>
- <td><?php while ($row = $totalcount->fetch_assoc()) { echo $row['Total']; };?></td>
- <td><?php while ($row = $todayscount->fetch_assoc()) { echo $row['Total']; };?></td>
- <td><?php while ($row = $lasthourcount->fetch_assoc()) { echo $row['Total']; };?></td>
- <td><?php echo $speciescount;?></td>
+ <td><?php while ($row = $totalcount->fetch_assoc()) { echo $row['Total']; };?></td>
+ <td><?php while ($row = $todayscount->fetch_assoc()) { echo $row['Total']; };?></td>
+ <td><?php while ($row = $lasthourcount->fetch_assoc()) { echo $row['Total']; };?></td>
+ <td><?php echo $speciescount;?></td>
</tr>
</table>
</div>
@@ -86,76 +92,28 @@ $mysqli->close();
<!-- TABLE CONSTRUCTION-->
<table>
<tr>
- <th>Time</th>
- <th>Scientific Name</th>
- <th>Common Name</th>
- <th>Confidence</th>
+ <th>Time</th>
+ <th>Scientific Name</th>
+ <th>Common Name</th>
+ <th>Confidence</th>
</tr>
<!-- PHP CODE TO FETCH DATA FROM ROWS-->
<?php // LOOP TILL END OF DATA
while($rows=$mosttable ->fetch_assoc())
{
- $Confidence = sprintf("%.1f%%", $rows['MAX(Confidence)'] * 100);
+ $Confidence = sprintf("%.1f%%", $rows['MAX(Confidence)'] * 100);
+ $dbname = preg_replace('/ /', '_', $rows['Com_Name']);
+ $dbsciname = preg_replace('/ /', '_', $rows['Sci_Name']);
?>
<tr>
- <!--FETCHING DATA FROM EACH
- ROW OF EVERY COLUMN-->
- <td><?php echo $rows['Time'];?></td>
- <td><?php echo $rows['Sci_Name'];?></td>
- <td><?php echo $rows['Com_Name'];?></td>
- <td><?php echo $Confidence;?></td>
- </tr>
-<?php
-}
-?>
- </table>
-<div class="row">
- <div class="column">
- <h3>Detected Species by Confidence</h3>
- <table>
- <tr>
- <th>Species</th>
- <th>Date</th>
- <th>Time</th>
- <th>Max Confidence Score</th>
- </tr>
-<?php // LOOP TILL END OF DATA
-while($rows=$specieslist ->fetch_assoc())
-{
- $MAX = sprintf("%.1f%%", $rows['MAX(Confidence)'] * 100)
-?>
- <tr>
- <td><?php echo $rows['Com_Name'];?></td>
- <td><?php echo $rows['Date'];?></td>
- <td><?php echo $rows['Time'];?></td>
- <td><?php echo $MAX;?></td>
-
+ <!--FETCHING DATA FROM EACH
+ ROW OF EVERY COLUMN-->
+ <td><?php echo $rows['Time'];?></td>
+ <td><a href="/By_Scientific_Name/<?php echo $dbsciname;?>"/><?php echo $rows['Sci_Name'];?></a></td>
+ <td><a href="/By_Common_Name/<?php echo $dbname;?>"/><?php echo $rows['Com_Name'];?></a></td>
+ <td><?php echo $Confidence;?></td>
</tr>
<?php
}
?>
</table>
- </div>
- <div class="column">
- <h3>Species List by Detections</h3>
- <table>
- <tr>
- <th>Species</th>
- <th>Detections</th>
- </tr>
-<?php // LOOP TILL END OF DATA
-while($rows=$speciestally ->fetch_assoc())
-{
-?>
- <tr>
- <td><?php echo $rows['Com_Name'];?></td>
- <td><?php echo $rows['Total'];?></td>
- </tr>
-<?php
-}
-?>
-
-</div>
- </section>
-</html>
-