diff --git a/daemon/birdnet_clean.sh b/daemon/birdnet_clean.sh index f6a4c03..1094ebd 100755 --- a/daemon/birdnet_clean.sh +++ b/daemon/birdnet_clean.sh @@ -28,9 +28,9 @@ mem() { string=$2 substring=$1 if [[ "$string" == *"$substring"* ]]; then - true + echo "true" else - false + echo "false" fi } @@ -49,11 +49,11 @@ junk() { # Get all empty treatment directories junk="$junk $(find ${CHUNK_FOLDER}/out -type d -empty)" # Get all empty record directories - treatement_folder=$(find "${CHUNK_FOLDER}/out/*" -type d ! -empty) + treatement_folder=$(find -wholename "${CHUNK_FOLDER}/out/*" -type d ! -empty) if [[ ! -z ${treatement_folder} ]]; then for folder in $treatement_folder; do echo $folder - if ! $(mem $folder $junk) && $(no_bird_in_model_output $folder); then + if [[ ! $(mem $folder $junk) = "true" ]] && $(no_bird_in_model_output $folder); then junk="$junk $folder" fi done diff --git a/daemon/birdnet_miner.sh b/daemon/birdnet_miner.sh index 4802e22..afced1c 100755 --- a/daemon/birdnet_miner.sh +++ b/daemon/birdnet_miner.sh @@ -2,9 +2,10 @@ # Extract observations from a model output folder # -DEBUG=${DEBUG:-0} +DEBUG=${DEBUG:-1} set -e +# set -x debug() { if [ $DEBUG -eq 1 ]; then @@ -40,7 +41,7 @@ if [[ -z ${LONGITUDE} ]]; then fi model_outputs() { - find -name "model.out.csv" -type f ! -empty + ls ${CHUNK_FOLDER}/out/*/model.out.csv } source_wav() { @@ -59,10 +60,10 @@ record_datetime() { MM=$(echo $record_date | cut -c 5-6) DD=$(echo $record_date | cut -c 7-8) HH=$(echo $record_time | cut -c 1-2) - MM=$(echo $record_time | cut -c 3-4) + MI=$(echo $record_time | cut -c 3-4) SS=$(echo $record_time | cut -c 5-6) SSS="000" - date="$YYYY-$MM-$DD $HH:$MM:$SS.$SSS" + date="$YYYY-$MM-$DD $HH:$MI:$SS.$SSS" echo $date } @@ -102,15 +103,15 @@ save_observations() { debug "Observation already exists: $source_audio, $start, $end, $taxon_id, $location_id" exit 1 else - debug "Inserting observation: $source_audio, $start, $end, $taxon_id, $location_id" + debug "Inserting observation: $source_audio, $start, $end, $taxon_id, $location_id, $datetime" insert_observation "$source_audio" "$start" "$end" "$taxon_id" "$location_id" "$confidence" "$datetime" fi done } main() { - # Remove all junk observations - ./daemon/birdnet_clean.sh + # # Remove all junk observations + # ./daemon/birdnet_clean.sh # Get model outputs for model_output in $(model_outputs); do save_observations $model_output diff --git a/daemon/systemd/templates/birdnet_analyzis.service b/daemon/systemd/templates/birdnet_analyzis.service index 33d618c..abbeb49 100644 --- a/daemon/systemd/templates/birdnet_analyzis.service +++ b/daemon/systemd/templates/birdnet_analyzis.service @@ -4,9 +4,9 @@ Description=BirdNET-stream Analyzis [Service] -User=$USER -Group=$USER -WorkingDirectory=$DIR +User= +Group= +WorkingDirectory= ExecStart=bash ./daemon/birdnet_analyzis.sh Restart=always RestartSec=3 diff --git a/daemon/systemd/templates/birdnet_miner.service b/daemon/systemd/templates/birdnet_miner.service new file mode 100644 index 0000000..ddb8a5d --- /dev/null +++ b/daemon/systemd/templates/birdnet_miner.service @@ -0,0 +1,13 @@ +[Unit] +Description=BirdNET-stream miner service + +[Service] +Type=oneshot +User= +GROUP= +WorkingDirectory= +ExecStart=bash ./daemon/birdnet_miner.sh +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/daemon/systemd/templates/birdnet_miner.timer b/daemon/systemd/templates/birdnet_miner.timer new file mode 100644 index 0000000..fd1ea44 --- /dev/null +++ b/daemon/systemd/templates/birdnet_miner.timer @@ -0,0 +1,9 @@ +[Unit] +Description=BirdNET-stream miner Timer + +[Timer] +OnCalendar=*-*-* *:00 +Unit=birdnet_miner.service + +[Install] +WantedBy=basic.target \ No newline at end of file diff --git a/daemon/systemd/templates/birdnet_recording.service b/daemon/systemd/templates/birdnet_recording.service index 6e38f10..219e4cd 100644 --- a/daemon/systemd/templates/birdnet_recording.service +++ b/daemon/systemd/templates/birdnet_recording.service @@ -4,10 +4,10 @@ Description=BirdNET-stream recording [Service] -User=$USER -Group=$DIR -WorkingDirectory=$DIR -ExecStart=bash ./daemon/birdnet_recording.sh" +User= +Group= +WorkingDirectory= +ExecStart=bash ./daemon/birdnet_recording.sh Restart=always RestartSec=3 Type=simple