From 01ad44f104a971a43966b2e628f18aebb4d99ffe Mon Sep 17 00:00:00 2001 From: Patrick McGuire Date: Sat, 9 Oct 2021 14:34:38 -0400 Subject: [PATCH] preparing things for mariadb integration -- Changed dateformat for MariaDB in analyze.py --- analyze.py | 18 ++++++++++++++++-- scripts/createdb.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100755 scripts/createdb.sh diff --git a/analyze.py b/analyze.py index 564bc9f..f3e0c0a 100644 --- a/analyze.py +++ b/analyze.py @@ -13,7 +13,7 @@ import librosa import numpy as np import math import time - +from datetime import date, datetime def loadModel(): global INPUT_LAYER_INDEX @@ -217,9 +217,23 @@ def main(): # Write detections to output file min_conf = max(0.01, min(args.min_conf, 0.99)) writeResultsToFile(detections, min_conf, args.o) + now = datetime.now() + + # Write detections to Database for i in detections: print("\n", detections[i][0],"\n") - + with open('BirdDB.txt', 'a') as rfile: + for d in detections: + for entry in detections[d]: + if entry[1] >= min_conf and (entry[0] in WHITE_LIST or len(WHITE_LIST) == 0): + current_date = now.strftime("%Y/%m/%d") + current_time = now.strftime("%H:%M:%S") + rfile.write(str(current_date) + ';' + str(current_time) + ';' + entry[0].replace('_', ';') + ';' \ + + str(entry[1]) +";" + str(args.lat) + ';' + str(args.lon) + ';' + str(min_conf) + ';' + str(week) + ';' \ + + str(sensitivity) +';' + str(args.overlap) + '\n') + print(str(current_date) + ';' + str(current_time) + ';' + entry[0].replace('_', ';') + ';' + str(entry[1]) +";" + str(args.lat) + ';' + str(args.lon) + ';' + str(min_conf) + ';' + str(week) + ';' + str(sensitivity) +';' + str(args.overlap) + '\n') + time.sleep(3) + now = datetime.now() if __name__ == '__main__': diff --git a/scripts/createdb.sh b/scripts/createdb.sh new file mode 100755 index 0000000..3a3c347 --- /dev/null +++ b/scripts/createdb.sh @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# test to create a database from bash +mysql << 'EOF' +CREATE DATABASE IF NOT EXISTS birds; + +USE birds; + +CREATE TABLE IF NOT EXISTS detections ( + Date DATE, + Time TIME, + Sci_Name VARCHAR(100) NOT NULL, + Com_Name VARCHAR(100) NOT NULL, + Confidence FLOAT, + Lat FLOAT, + Lon FLOAT, + Cutoff FLOAT, + Week INT, + Sens FLOAT, + Overlap FLOAT); + +LOAD DATA LOCAL INFILE '/home/pi/Birding-Pi/BirdDB.txt' +INTO TABLE detections +FIELDS TERMINATED BY ';'; +SELECT * FROM detections; +exit +EOF +