diff --git a/model/labels_l18n.zip b/model/labels_l18n.zip index 68a822b..9503754 100644 Binary files a/model/labels_l18n.zip and b/model/labels_l18n.zip differ diff --git a/scripts/daily_plot.py b/scripts/daily_plot.py index 90b517c..7632aed 100755 --- a/scripts/daily_plot.py +++ b/scripts/daily_plot.py @@ -1,9 +1,8 @@ #!/home/pi/BirdNET-Pi/birdnet/bin/python3 -import mysql.connector as sql +import sqlite3 import os import configparser - import pandas as pd import seaborn as sns import matplotlib.pyplot as plt @@ -11,25 +10,14 @@ from matplotlib.colors import LogNorm from datetime import datetime import textwrap -#Extract DB_PWD from thisrun.txt -with open('/home/pi/BirdNET-Pi/thisrun.txt', 'r') as f: - this_run = f.readlines() - db_pwd = str(str(str([i for i in this_run if i.startswith('DB_PWD')]).split('=')[1]).split('\\')[0]) +conn = sqlite3.connect('/home/pi/BirdNET-Pi/scripts/birds.db') +df = pd.read_sql_query("SELECT * from detections", conn) +cursor = conn.cursor() +cursor.execute('SELECT * FROM detections') +table_rows = cursor.fetchall() -db_connection = sql.connect(host='localhost', - database='birds', - user='birder', - password=db_pwd) - - -db_cursor=db_connection.cursor(dictionary=True) - -db_cursor.execute('SELECT * FROM detections') - -table_rows = db_cursor.fetchall() - -df=pd.DataFrame(table_rows) +#df=pd.DataFrame(table_rows) #Convert Date and Time Fields to Panda's format df['Date']=pd.to_datetime(df['Date']) diff --git a/scripts/extract_new_birdsounds.sh b/scripts/extract_new_birdsounds.sh index 029edc6..651b723 100755 --- a/scripts/extract_new_birdsounds.sh +++ b/scripts/extract_new_birdsounds.sh @@ -61,14 +61,13 @@ for h in "${SCAN_DIRS[@]}";do SCIENTIFIC_NAME=""$(echo ${line} \ | awk -F\; '!/birdnet/{print $3}')"" CONFIDENCE=""$(echo ${line} \ - | awk -F\; '{print $5}' \ - | cut -d'.' -f2)"" - CONFIDENCE_SCORE="${CONFIDENCE:0:2}%" + | awk -F\; '{print $5}')"" + + #CONFIDENCE_SCORE="${CONFIDENCE:0:2}%" + CONFIDENCE_SCORE="$(printf %.0f $(echo "scale=2; ${CONFIDENCE} * 100" | bc))" NEWFILE="${COMMON_NAME// /_}-${CONFIDENCE_SCORE}-${OLDFILE//.wav/.${AUDIOFMT}}" echo "NEWFILE=$NEWFILE" NEWSPECIES_BYDATE="${EXTRACTED}/By_Date/${DATE}/${COMMON_NAME// /_}" - NEWSPECIES_BY_COMMON="${EXTRACTED}/By_Common_Name/${COMMON_NAME// /_}" - NEWSPECIES_BY_SCIENCE="${EXTRACTED}/By_Scientific_Name/${SCIENTIFIC_NAME// /_}" # If the extracted file already exists, move on if [[ -f "${NEWSPECIES_BYDATE}/${NEWFILE}" ]];then @@ -85,16 +84,6 @@ for h in "${SCAN_DIRS[@]}";do # it is created [[ -d "${NEWSPECIES_BYDATE}" ]] || mkdir -p "${NEWSPECIES_BYDATE}" - - # If a directory does not already exist for the species (by-species), - # it is created. - [[ -d "${NEWSPECIES_BY_COMMON}" ]] || mkdir -p "${NEWSPECIES_BY_COMMON}" - - # If a directory does not already exist for the species (by-species), - # it is created. - [[ -d "${NEWSPECIES_BY_SCIENCE}" ]] || mkdir -p "${NEWSPECIES_BY_SCIENCE}" - - # If there are already 20 extracted entries for a given species # for today, remove the oldest file and create the new one. # if [[ "$(find ${NEWSPECIES_BYDATE} | wc -l)" -ge 20 ]];then @@ -131,9 +120,6 @@ for h in "${SCAN_DIRS[@]}";do sox "${h}/${OLDFILE}" "${NEWSPECIES_BYDATE}/${NEWFILE}" \ trim "${START}" "${END}" - #ffmpeg -hide_banner -loglevel error -nostdin -i "${h}/${OLDFILE}" \ - # -acodec copy -ss "${START}" -to "${END}"\ - # "${NEWSPECIES_BYDATE}/${NEWFILE}" # Create spectrogram for extraction sox "${NEWSPECIES_BYDATE}/${NEWFILE}" -n remix 1 rate 24k spectrogram \ @@ -141,48 +127,6 @@ for h in "${SCAN_DIRS[@]}";do -c "${NEWSPECIES_BYDATE}/${NEWFILE}" \ -o "${NEWSPECIES_BYDATE}/${NEWFILE}.png" - # Remove the oldest symbolic links that would make the directory have more - # than 20 entries. - if [[ "$(find ${NEWSPECIES_BY_COMMON} | wc -l)" -ge 40 ]];then - echo "20 ${SPECIES}s, already! Removing the oldest by-species and making a new one" - cd ${NEWSPECIES_BY_COMMON} || exit 1 - ls -1t . | tail -n +40 | xargs -r rm -vv - ln -fs "${NEWSPECIES_BYDATE}/${NEWFILE}"\ - "${NEWSPECIES_BY_COMMON}/${NEWFILE}" - ln -fs "${NEWSPECIES_BYDATE}/${NEWFILE}.png"\ - "${NEWSPECIES_BY_COMMON}/${NEWFILE}.png" - echo "Success! New extraction for ${COMMON_NAME}" - else - # Make symbolic link of the extraction to add to By_Common_Name - ln -fs "${NEWSPECIES_BYDATE}/${NEWFILE}"\ - "${NEWSPECIES_BY_COMMON}/${NEWFILE}" - ln -fs "${NEWSPECIES_BYDATE}/${NEWFILE}.png"\ - "${NEWSPECIES_BY_COMMON}/${NEWFILE}.png" - fi - - # Remove the oldest symbolic links that would made the directory have more - # than 20 entries. - if [[ "$(find ${NEWSPECIES_BY_SCIENCE} | wc -l)" -ge 40 ]];then - echo "20 ${SPECIES}s, already! Removing the oldest by-species and making a new one" - cd ${NEWSPECIES_BY_SCIENCE} || exit 1 - ls -1t . | tail -n +40 | xargs -r rm -vv - ln -fs "${NEWSPECIES_BYDATE}/${NEWFILE}"\ - "${NEWSPECIES_BY_SCIENCE}/${NEWFILE}" - ln -fs "${NEWSPECIES_BYDATE}/${NEWFILE}.png"\ - "${NEWSPECIES_BY_SCIENCE}/${NEWFILE}.png" - echo "Success! New extraction for ${COMMON_NAME}" - else - ln -fs "${NEWSPECIES_BYDATE}/${NEWFILE}"\ - "${NEWSPECIES_BY_SCIENCE}/${NEWFILE}" - ln -fs "${NEWSPECIES_BYDATE}/${NEWFILE}.png"\ - "${NEWSPECIES_BY_SCIENCE}/${NEWFILE}.png" - fi - - - # Finally, 'a' is incremented by one to allow multiple extractions per - # species per minute. - #a=$((a + 1)) - done < "${TMPFILE}" # Once each line of the TMPFILE has been processed, the TMPFILE is emptied @@ -192,11 +136,11 @@ for h in "${SCAN_DIRS[@]}";do # Rename files that have been processed so that they are not processed on the # next extraction. [[ -d "${PROCESSED}" ]] || mkdir "${PROCESSED}" - echo "Moving processed files to ${PROCESSED}" + #echo "Moving processed files to ${PROCESSED}" mv ${h}/* ${PROCESSED} &> /dev/null || continue done -echo "Linking Processed files to "${EXTRACTED}/Processed" web directory" +#echo "Linking Processed files to "${EXTRACTED}/Processed" web directory" # After all audio extractions have taken place, a directory is created to house # the original WAVE and .txt files used for this extraction processs. if [[ ! -L ${EXTRACTED}/Processed ]] || [[ ! -e ${EXTRACTED}/Processed ]];then diff --git a/scripts/history.php b/scripts/history.php index 9da8ee7..c8e0237 100644 --- a/scripts/history.php +++ b/scripts/history.php @@ -10,6 +10,14 @@ $theDate = date('Y-m-d'); } $chart = "Combo-$theDate.png"; $chart2 = "Combo2-$theDate.png"; + +$db = new SQLite3('/home/pi/BirdNET-Pi/scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE); + +$statement1 = $db->prepare("SELECT COUNT(*) FROM detections + WHERE Date == \"$theDate\""); +$result1 = $statement1->execute(); +$totalcount = $result1->fetchArray(SQLITE3_ASSOC); + ?> @@ -52,7 +60,7 @@ hr { - +
Total Detections For The Day
diff --git a/scripts/overview.php b/scripts/overview.php index c7fd2e2..d355d39 100644 --- a/scripts/overview.php +++ b/scripts/overview.php @@ -20,10 +20,10 @@ $statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE TIME >= TIME(\ $result3 = $statement3->execute(); $hourcount = $result3->fetchArray(SQLITE3_ASSOC); -$statement4 = $db->prepare('SELECT Com_Name, Sci_Name, Time, Confidence FROM detections LIMIT 1'); +$statement4 = $db->prepare('SELECT Com_Name, Sci_Name, Date, Time, Confidence, File_Name FROM detections ORDER BY Time ASC LIMIT 1'); $result4 = $statement4->execute(); $mostrecent = $result4->fetchArray(SQLITE3_ASSOC); -$comlink = preg_replace('/ /', '_', $mostrecent['Com_Name']); +$comname = preg_replace('/ /', '_', $mostrecent['Com_Name']); $scilink = preg_replace('/ /', '_', $mostrecent['Sci_Name']); $statement5 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections WHERE Date == Date(\'now\')'); @@ -70,8 +70,8 @@ a { - - + + @@ -91,7 +91,7 @@ a { - +
Most Recent Detection">">" target="footer"/> More Info
Number of Detections
@@ -100,7 +100,7 @@ a { - +
Species Detected Today
diff --git a/scripts/server.py b/scripts/server.py index 1a0da1e..7aa6f1d 100755 --- a/scripts/server.py +++ b/scripts/server.py @@ -302,7 +302,7 @@ def handle_client(conn, addr): #print('Time:', date_time_obj.time()) print('Date-time:', date_time_obj) now = date_time_obj - current_date = now.strftime("%Y/%m/%d") + current_date = now.strftime("%Y-%m-%d") current_time = now.strftime("%H:%M:%S") current_iso8601 = now.astimezone(get_localzone()).isoformat() @@ -342,7 +342,7 @@ def handle_client(conn, addr): species = entry[0] Sci_Name,Com_Name = species.split('_') score = entry[1] - Confidence = "{:.0%}".format(score) + Confidence = str(round(score*100)) Lat = str(args.lat) Lon = str(args.lon) Cutoff = str(args.min_conf) diff --git a/scripts/stats.php b/scripts/stats.php index 75c25b4..90e893f 100644 --- a/scripts/stats.php +++ b/scripts/stats.php @@ -3,6 +3,20 @@ ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); +$db = new SQLite3('/home/pi/BirdNET-Pi/scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE); + +$statement = $db->prepare('SELECT Com_Name, COUNT(*), MAX(Confidence), Sci_Name FROM detections GROUP BY Com_Name ORDER BY COUNT(*) DESC'); +$result = $statement->execute(); + +$statement2 = $db->prepare('SELECT Com_Name FROM detections GROUP BY Com_Name ORDER BY Com_Name ASC'); +$result2 = $statement2->execute(); + +if(isset($_POST['species'])){ + $selection = $_POST['species']; + $statement3 = $db->prepare("SELECT Com_Name, Sci_Name, COUNT(*), MAX(Confidence) from detections + WHERE Com_Name = '$selection'"); + $result3 = $statement3->execute(); +} ?> @@ -116,21 +130,6 @@ form {
-

Number of Detections

- - - - - - - - - - - - - -
TotalTodayLast HourNumber of Unique Species

Summary

@@ -138,22 +137,40 @@ form { +fetchArray(SQLITE3_ASSOC)) +{ +$comname = preg_replace('/ /', '_', $results['Com_Name']); +$comlink = "/By_Date/".date('Y-m-d')."/".$comname; +$sciname = preg_replace('/ /', '_', $results['Sci_Name']); +?> - - - - + + + +
Occurrences Max Confidence Score

Species Stats

-

fetch_assoc()) { - $count = $rows['COUNT(*)']; - $maxconf = $rows['MAX(Confidence)']; - $name = $rows['Com_Name']; - $sciname = $rows['Sci_Name']; - $dbname = preg_replace('/ /', '_', $rows['Com_Name']); +while($results=$result3->fetchArray(SQLITE3_ASSOC)){ + $count = $results['COUNT(*)']; + $maxconf = $results['MAX(Confidence)']; + $name = $results['Com_Name']; + $sciname = $results['Sci_Name']; + $dbname = preg_replace('/ /', '_', $results['Com_Name']); $dbname = preg_replace('/\'/', '', $dbname); - $dbsciname = preg_replace('/ /', '_', $rows['Sci_Name']); + $dbsciname = preg_replace('/ /', '_', $results['Sci_Name']); $imagelink = shell_exec("/home/pi/BirdNET-Pi/scripts/get_image.sh $dbsciname"); $imagecitation = shell_exec("/home/pi/BirdNET-Pi/scripts/get_citation.sh $dbsciname"); $str= " - $name - $sciname + $name + $sciname $count $maxconf - Wikipedia, All About Birds + All About Birds "; echo str_pad($str, 4096); diff --git a/scripts/stop_core_services.sh b/scripts/stop_core_services.sh index 0d5eb98..309986c 100755 --- a/scripts/stop_core_services.sh +++ b/scripts/stop_core_services.sh @@ -6,7 +6,7 @@ services=(birdnet_recording.service birdnet_analysis.service birdnet_server.service chart_viewer.service -extraction.timer +extraction.service spectrogram_viewer.service) for i in "${services[@]}";do diff --git a/scripts/update_birdnet2.sh b/scripts/update_birdnet2.sh index e27a8ba..a3bf9ca 100755 --- a/scripts/update_birdnet2.sh +++ b/scripts/update_birdnet2.sh @@ -48,7 +48,6 @@ spectrogram_viewer.service pushed_notifications.service livestream.service icecast2.service -extraction.timer extraction.service chart_viewer.service birdnet_recording.service diff --git a/scripts/viewdb.php b/scripts/viewdb.php index 9175164..7b51e51 100644 --- a/scripts/viewdb.php +++ b/scripts/viewdb.php @@ -4,6 +4,31 @@ ini_set('display_startup_errors', 1); error_reporting(E_ALL); header("refresh: 30;"); + +$db = new SQLite3('/home/pi/BirdNET-Pi/scripts/birds.db', SQLITE3_OPEN_CREATE | SQLITE3_OPEN_READWRITE); + +$statement0 = $db->prepare('SELECT Time, Com_Name, Sci_Name, Confidence, File_Name FROM detections WHERE Date == Date(\'now\') ORDER BY Time DESC'); +$result0 = $statement0->execute(); + +$statement1 = $db->prepare('SELECT COUNT(*) FROM detections'); +$result1 = $statement1->execute(); +$totalcount = $result1->fetchArray(SQLITE3_ASSOC); + +$statement2 = $db->prepare('SELECT COUNT(*) FROM detections WHERE Date == DATE(\'now\')'); +$result2 = $statement2->execute(); +$todaycount = $result2->fetchArray(SQLITE3_ASSOC); + +$statement3 = $db->prepare('SELECT COUNT(*) FROM detections WHERE TIME >= TIME(\'now\', \'localtime\', \'-1 hour\')'); +$result3 = $statement3->execute(); +$hourcount = $result3->fetchArray(SQLITE3_ASSOC); + +$statement4 = $db->prepare('SELECT Com_Name, Sci_Name, Time, Confidence FROM detections LIMIT 1'); +$result4 = $statement4->execute(); +$mostrecent = $result4->fetchArray(SQLITE3_ASSOC); + +$statement5 = $db->prepare('SELECT COUNT(DISTINCT(Com_Name)) FROM detections'); +$result5 = $statement5->execute(); +$speciestally = $result5->fetchArray(SQLITE3_ASSOC); ?> @@ -36,10 +61,10 @@ a { Number of Unique Species - - - - + + + +
@@ -53,11 +78,19 @@ a { Confidence Links +fetchArray(SQLITE3_ASSOC)) +{ +$comname = preg_replace('/ /', '_', $todaytable['Com_Name']); +$comlink = "/By_Date/".date('Y-m-d')."/".$comname."/".$todaytable['File_Name']; +$sciname = preg_replace('/ /', '_', $todaytable['Sci_Name']); +?> - - - - - All About Birds, Wikipedia + + + + + All About Birds, Wikipedia +