database views now link to recordings and spectrograms

This commit is contained in:
mcguirepr89
2022-02-13 11:18:01 -05:00
parent 154b876bb4
commit 32966476e7
6 changed files with 296 additions and 88 deletions
+45 -87
View File
@@ -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>
<!--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 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>
</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>