A live bird collage card for your Home Assistant dashboard.
Sort recordings by ABC, or occurrences
ehpersonal38f203fde9f4ac
diff --git a/scripts/play.php b/scripts/play.phpindex bc16fd19..d24cd392 100644--- a/scripts/play.php+++ b/scripts/play.php@@ -33,7 +33,11 @@ if(isset($_GET['byfilename'])){$date = $_GET['date'];session_start();$_SESSION['date'] = $date;- $statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" ORDER BY Com_Name");+ if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {+ $statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" GROUP BY Com_Name ORDER BY COUNT(*) DESC");+ } else {+ $statement = $db->prepare("SELECT DISTINCT(Com_Name) FROM detections WHERE Date == \"$date\" ORDER BY Com_Name");+ }if($statement == False){echo "Database is busy";header("refresh: 0;");@@ -43,7 +47,11 @@ if(isset($_GET['byfilename'])){#By Species} elseif(isset($_GET['byspecies'])) {- $statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name');+ if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {+ $statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');+ } else {+ $statement = $db->prepare('SELECT DISTINCT(Com_Name) FROM detections ORDER BY Com_Name ASC');+ }session_start();if($statement == False){echo "Database is busy";@@ -87,6 +95,53 @@ if(isset($_GET['byfilename'])){if(!isset($_GET['species']) && !isset($_GET['filename'])){?><div class="play">+<?php if($view == "byspecies" || $view == "date") { ?>+<div style="width: auto;+ text-align: center">+ <form action="" method="GET">+ <input type="hidden" name="view" value="Recordings">+ <input type="hidden" name="<?php echo $view; ?>" value="<?php echo $_GET['date']; ?>">+ <button style="margin-top:10px;font-size:x-large;background:#dbffeb;padding:5px;border: 2px solid black;" type="submit" name="sort" value="alphabetical">+ <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"+ width="35px" height="35px" viewBox="0 0 381.404 381.404" style="enable-background:new 0 0 35 35;"+ xml:space="preserve">+ <g>+ <path d="M34.249,246.497l63.655,25.155V5.1c0-2.818,2.29-5.094,5.103-5.1h51.022c2.811,0.006,5.096,2.282,5.096,5.094v266.559+ l63.658-25.155c2.134-0.824,4.569-0.147,5.943,1.675c1.39,1.839,1.378,4.36-0.022,6.178l-96.136,125.057+ c-0.971,1.261-2.466,1.994-4.053,1.998c-1.573,0-3.074-0.737-4.041-1.998L28.333,254.35c-0.705-0.92-1.058-2.019-1.053-3.106+ c0-1.063,0.336-2.157,1.021-3.082C29.682,246.35,32.115,245.66,34.249,246.497z M354.125,244.402h-21.907l-12.364-29.736h-37.228+ l-12.027,29.736h-21.407l41.452-99.561h21.861L354.125,244.402z M314.653,200.095l-9.91-23.779+ c-1.412-3.374-2.571-6.58-3.599-9.677c-1.144,3.429-2.266,6.528-3.405,9.476l-9.948,23.974h26.862V200.095z M340.509,267.006+ h-83.718V282.3h56.287l-61.786,73.763v10.518h90.071v-15.289h-62.305l61.438-73.472v-10.813H340.509z"/>+ </g>+ </svg>+ </button>+ <button style="margin-top:10px;font-size:x-large;background:#dbffeb;padding:5px;border: 2px solid black;" type="submit" name="sort" value="occurrences">+ <svg version="1.1" id="Capa_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"+ width="35px" height="35px" viewBox="0 0 96.55 96.55" style="enable-background:new 0 0 35 35;" xml:space="preserve"+ >+ <g>+ <g>+ <path d="M73.901,56.376h-26.76c-0.652,0-1.182,0.526-1.182,1.181v14.065c0,0.651,0.529,1.18,1.182,1.18h26.76+ c0.654,0,1.184-0.526,1.184-1.18V57.555C75.084,56.902,74.555,56.376,73.901,56.376z"/>+ <path d="M62.262,80.001H47.141c-0.652,0-1.182,0.528-1.182,1.183v14.063c0,0.653,0.529,1.182,1.182,1.182h15.122+ c0.652,0,1.182-0.526,1.182-1.182V81.182C63.444,80.529,62.916,80.001,62.262,80.001z"/>+ <path d="M84.122,28.251h-36.98c-0.652,0-1.182,0.527-1.182,1.18v14.063c0,0.652,0.529,1.182,1.182,1.182h36.98+ c0.651,0,1.181-0.529,1.181-1.182V29.43C85.301,28.778,84.773,28.251,84.122,28.251z"/>+ <path d="M94.338,0.122H47.141c-0.652,0-1.182,0.529-1.182,1.182v14.063c0,0.654,0.529,1.182,1.182,1.182h47.198+ c0.652,0,1.181-0.527,1.181-1.182V1.303C95.519,0.651,94.992,0.122,94.338,0.122z"/>+ <path d="M39.183,65.595h-8.011V2c0-1.105-0.896-2-2-2h-16.13c-1.104,0-2,0.895-2,2v63.595h-8.01c-0.771,0-1.472,0.443-1.804,1.138+ C0.895,67.427,0.99,68.25,1.472,68.85l18.076,26.954c0.38,0.474,0.953,0.746,1.559,0.746s1.178-0.272,1.558-0.746L40.741,68.85+ c0.482-0.601,0.578-1.423,0.245-2.117C40.654,66.039,39.954,65.595,39.183,65.595z"/>+ </g>+ </g>+ </svg>+ </button>+ </form>+</div>+<?php } ?>++<table><tr><form action="" method="GET">diff --git a/scripts/stats.php b/scripts/stats.phpindex c20bf51b..e69de9d8 100644--- a/scripts/stats.php+++ b/scripts/stats.php@@ -8,19 +8,38 @@ if($db == False) {echo "Database busy";header("refresh: 0;");}-$statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');-if($statement == False) {- echo "Database busy";- header("refresh: 0;");-}-$result = $statement->execute();-$statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name');-if($statement == False) {- echo "Database busy";- header("refresh: 0;");+if(isset($_GET['sort']) && $_GET['sort'] == "occurrences") {++ $statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');+ if($statement == False) {+ echo "Database busy";+ header("refresh: 0;");+ }+ $result = $statement->execute();++ $statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC');+ if($statement == False) {+ echo "Database busy";+ header("refresh: 0;");+ }+ $result2 = $statement2->execute();+} else {++ $statement = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC');+ if($statement == False) {+ echo "Database busy";+ header("refresh: 0;");+ }+ $result = $statement->execute();++ $statement2 = $db->prepare('SELECT Date, Time, File_Name, Com_Name, COUNT(*), MAX(Confidence) FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC');+ if($statement == False) {+ echo "Database busy";+ header("refresh: 0;");+ }+ $result2 = $statement2->execute();}-$result2 = $statement2->execute();@@ -48,6 +67,48 @@ if(isset($_GET['species'])){<body><div class="stats"><div class="column">+ <div style="width: auto;+ text-align: center">+ <form action="" method="GET">+ <input type="hidden" name="view" value="Species Stats">+ <button style="margin-top:10px;font-size:x-large;background:#dbffeb;padding:5px;border: 2px solid black;" type="submit" name="sort" value="alphabetical">+ <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"+ width="35px" height="35px" viewBox="0 0 381.404 381.404" style="enable-background:new 0 0 35 35;"+ xml:space="preserve">+ <g>+ <path d="M34.249,246.497l63.655,25.155V5.1c0-2.818,2.29-5.094,5.103-5.1h51.022c2.811,0.006,5.096,2.282,5.096,5.094v266.559+ l63.658-25.155c2.134-0.824,4.569-0.147,5.943,1.675c1.39,1.839,1.378,4.36-0.022,6.178l-96.136,125.057+ c-0.971,1.261-2.466,1.994-4.053,1.998c-1.573,0-3.074-0.737-4.041-1.998L28.333,254.35c-0.705-0.92-1.058-2.019-1.053-3.106+ c0-1.063,0.336-2.157,1.021-3.082C29.682,246.35,32.115,245.66,34.249,246.497z M354.125,244.402h-21.907l-12.364-29.736h-37.228+ l-12.027,29.736h-21.407l41.452-99.561h21.861L354.125,244.402z M314.653,200.095l-9.91-23.779+ c-1.412-3.374-2.571-6.58-3.599-9.677c-1.144,3.429-2.266,6.528-3.405,9.476l-9.948,23.974h26.862V200.095z M340.509,267.006+ h-83.718V282.3h56.287l-61.786,73.763v10.518h90.071v-15.289h-62.305l61.438-73.472v-10.813H340.509z"/>+ </g>+ </svg>+ </button>+ <button style="margin-top:10px;font-size:x-large;background:#dbffeb;padding:5px;border: 2px solid black;" type="submit" name="sort" value="occurrences">+ <svg version="1.1" id="Capa_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"+ width="35px" height="35px" viewBox="0 0 96.55 96.55" style="enable-background:new 0 0 35 35;" xml:space="preserve"+ >+ <g>+ <g>+ <path d="M73.901,56.376h-26.76c-0.652,0-1.182,0.526-1.182,1.181v14.065c0,0.651,0.529,1.18,1.182,1.18h26.76+ c0.654,0,1.184-0.526,1.184-1.18V57.555C75.084,56.902,74.555,56.376,73.901,56.376z"/>+ <path d="M62.262,80.001H47.141c-0.652,0-1.182,0.528-1.182,1.183v14.063c0,0.653,0.529,1.182,1.182,1.182h15.122+ c0.652,0,1.182-0.526,1.182-1.182V81.182C63.444,80.529,62.916,80.001,62.262,80.001z"/>+ <path d="M84.122,28.251h-36.98c-0.652,0-1.182,0.527-1.182,1.18v14.063c0,0.652,0.529,1.182,1.182,1.182h36.98+ c0.651,0,1.181-0.529,1.181-1.182V29.43C85.301,28.778,84.773,28.251,84.122,28.251z"/>+ <path d="M94.338,0.122H47.141c-0.652,0-1.182,0.529-1.182,1.182v14.063c0,0.654,0.529,1.182,1.182,1.182h47.198+ c0.652,0,1.181-0.527,1.181-1.182V1.303C95.519,0.651,94.992,0.122,94.338,0.122z"/>+ <path d="M39.183,65.595h-8.011V2c0-1.105-0.896-2-2-2h-16.13c-1.104,0-2,0.895-2,2v63.595h-8.01c-0.771,0-1.472,0.443-1.804,1.138+ C0.895,67.427,0.99,68.25,1.472,68.85l18.076,26.954c0.38,0.474,0.953,0.746,1.559,0.746s1.178-0.272,1.558-0.746L40.741,68.85+ c0.482-0.601,0.578-1.423,0.245-2.117C40.654,66.039,39.954,65.595,39.183,65.595z"/>+ </g>+ </g>+ </svg>+ </button>+ </form>+</div><table><?phpwhile($results=$result2->fetchArray(SQLITE3_ASSOC))@@ -116,6 +177,7 @@ while($results=$result3->fetchArray(SQLITE3_ASSOC)){}}?><br><br><br>+<table><?phpwhile($results=$result->fetchArray(SQLITE3_ASSOC))