Skip to content

A live bird collage card for your Home Assistant dashboard.

fixed a weirdness in the birdnet_stats.sh script

Patrick McGuire7cd299ebeb67
diff --git a/Birders_Guide_Installer.sh b/Birders_Guide_Installer.sh
index bf8656a4..b59ef516 100755
--- a/Birders_Guide_Installer.sh
+++ b/Birders_Guide_Installer.sh
@@ -116,8 +116,13 @@ stage_2() {
echo "Follow the instructions to fill out the LATITUDE and LONGITUDE variables
and set the passwords for the live audio stream. Save the file after editing
and then close the Mouse Pad editing window to continue."
- mousepad ${my_dir}/Birders_Guide_Installer_Configuration.txt &> /dev/null
- while pgrep mouse &> /dev/null;do
+ if ( env | grep SSH_CONNECTION &> /dev/null );then
+ editor=nano
+ else
+ editor=mousepad
+ fi
+ $editor ${my_dir}/Birders_Guide_Installer_Configuration.txt &> /dev/null
+ while pgrep $editor &> /dev/null;do
sleep 1
done
source ${my_dir}/Birders_Guide_Installer_Configuration.txt || exit 1
diff --git a/scripts/birdnet_analysis.sh b/scripts/birdnet_analysis.sh
index a7cc326f..3f63802a 100755
--- a/scripts/birdnet_analysis.sh
+++ b/scripts/birdnet_analysis.sh
@@ -150,6 +150,8 @@ run_birdnet() {
run_analysis "${1}"
}
+date
+
if [ $(find ${RECS_DIR} -maxdepth 1 -name '*wav' | wc -l) -gt 0 ];then
run_birdnet "${RECS_DIR}"
fi
diff --git a/scripts/birdnet_stats.sh b/scripts/birdnet_stats.sh
index ec7c034d..ddf98664 100755
--- a/scripts/birdnet_stats.sh
+++ b/scripts/birdnet_stats.sh
@@ -7,7 +7,7 @@ setterm --cursor off
TMP_FILE="$(mktemp)"
while true;do
-cat << "EOF"
+ cat << "EOF"
.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.
( _ ____ __ _ )
) |_)o.__||\ ||_ |__(_ __|_ _ ._ _ |_) _ ._ _ .__|_ (
@@ -15,54 +15,64 @@ cat << "EOF"
) / | (
"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"+.+"
EOF
-if [ "$(find ${EXTRACTED} -name '*.wav' | wc -l)" -ge 1 ];then
- a=$( find "${EXTRACTED}" -name '*.wav' \
- | awk -F "/" '{print $NF}' \
- | cut -d'-' -f1 \
- | sort -n \
- | tail -n1 )
-else
- a=0
-fi
-echo
-if [ "${a}" -ge "1" ];then
- SOFAR=$(($(wc -l ${IDFILE}| cut -d' ' -f1)/2))
-else
- SOFAR=0
-fi
-if [ $SOFAR = 1 ];then
- verbage=detection
-else
- verbage=detections
-fi
-echo " -$a $verbage so far"
-echo
-echo " -$SOFAR species identified so far"
-echo
-if [ ${a} -ge 1 ];then
-while read -r line;do
- SPECIES="$(echo "${line}" | awk -F: '/Common Name/ {print $2}')"
- SPECIES="${SPECIES// /_}"
- SPECIES="$(echo ${SPECIES/_} | tr -d "'")"
- [ -z ${SPECIES} ] && continue
-
- ALL_DETECTION_FILES="$(ls -1 ${EXTRACTED}/By_Date/*/${SPECIES})"
- ALL_DETECTION_FILES="$(echo ${ALL_DETECTION_FILES[@]} | tr ' ' '\n')"
- MAX_SCORE="$(echo "${ALL_DETECTION_FILES}"| awk -F% '{print $1}')"
- MAX_SCORE="$(echo "${MAX_SCORE[@]}" | rev |cut -d"-" -f1|rev | sort -r | head -n1)"
-
- DETECTIONS="$(ls -1 ${EXTRACTED}/By_Date/*/${SPECIES} | wc -l)"
- if [ ${DETECTIONS} = 1 ];then
+ if [ "$(find ${EXTRACTED} -name '*.wav' | wc -l)" -ge 1 ];then
+ a=$( find "${EXTRACTED}" -name '*.wav' \
+ | awk -F "/" '{print $NF}' \
+ | cut -d'-' -f1 \
+ | sort -n \
+ | tail -n1 )
+ else
+ a=0
+ fi
+ echo
+ if [ "${a}" -ge "1" ];then
+ SOFAR=$(($(wc -l ${IDFILE}| cut -d' ' -f1)/2))
+ else
+ SOFAR=0
+ fi
+ if [ $SOFAR = 1 ];then
verbage=detection
else
verbage=detections
fi
- echo "${DETECTIONS} $verbage for ${SPECIES//_/ } | max conf ${MAX_SCORE}%"
-done < "${IDFILE}" > ${TMP_FILE}
-sort -rk1 -h "${TMP_FILE}"
-fi
-echo
-echo -n "Listening since "${INSTALL_DATE}""
-sleep 20
-clear
+ echo " -$a $verbage so far"
+ echo
+ echo " -$SOFAR species identified so far"
+ echo
+ if [ ${a} -ge 1 ];then
+ while read -r line;do
+
+ # Get species name
+ SPECIES="$(echo "${line}" | awk -F: '/Common Name/ {print $2}')"
+ SPECIES="${SPECIES// /_}"
+ SPECIES="$(echo ${SPECIES/_} | tr -d "'")"
+ [ -z ${SPECIES} ] && continue
+
+ # Get all detection files
+ ALL_DETECTION_FILES="$(find ${EXTRACTED}/By_Date/*/${SPECIES} -name '*.wav')"
+ ALL_DETECTION_FILES="$(echo ${ALL_DETECTION_FILES[@]} | tr ' ' '\n')"
+
+ # Parse highest confidence score
+ MAX_SCORE="$(echo "${ALL_DETECTION_FILES}"| awk -F% '{print $1}')"
+ MAX_SCORE="$(echo "${MAX_SCORE[@]}" | rev |cut -d"-" -f1|rev | sort -r | head -n1)"
+
+ # Set noun-plurality agreement for grammar
+ DETECTIONS="$(ls -1 ${EXTRACTED}/By_Date/*/${SPECIES} | wc -l)"
+ if [ ${DETECTIONS} = 1 ];then
+ verbage=detection
+ else
+ verbage=detections
+ fi
+
+ # Write results to temporary file
+ echo "${DETECTIONS} $verbage for ${SPECIES//_/ } | max conf ${MAX_SCORE}%"
+ done < "${IDFILE}" > ${TMP_FILE}
+
+ # Print temporary file sorted by # of detections
+ sort -rk1 -h "${TMP_FILE}"
+ fi
+ echo
+ echo -n "Listening since "${INSTALL_DATE}""
+ sleep 20
+ clear
done