From: Harvie Date: Fri, 3 Aug 2012 04:59:17 +0000 (+0200) Subject: sleeplog format update X-Git-Url: http://git.harvie.cz/?p=mirrors%2FPrograms.git;a=commitdiff_plain;h=3afb9fca6a37d4deea62d7b894fb953e8b538614 sleeplog format update --- diff --git a/c/goertzel/sleepmon.sh b/c/goertzel/sleepmon.sh index b050509..72c8275 100755 --- a/c/goertzel/sleepmon.sh +++ b/c/goertzel/sleepmon.sh @@ -28,6 +28,8 @@ historylen='10 30 60 90 120' screen=false graph=false +export LC_ALL=C + while getopts "sg" OPT; do test "$OPT" == 's' && screen=true; test "$OPT" == 'g' && graph=true; @@ -44,7 +46,7 @@ arecord | ./goertzel -n i -q -l c -t $tresh -d 4 | while read line; do $state && statenum=1 || statenum=0; $state && statename='MOTION!' || statename='Nothing'; - echo -ne "$time\t$date $(date '+%F %T') $statenum" + printf "%.2f\t %s %s %d" "$time" "$date" "$(date '+%F %T')" "$statenum" #History after=$(( $date - $lastdate)) @@ -53,12 +55,12 @@ arecord | ./goertzel -n i -q -l c -t $tresh -d 4 | while read line; do for len in $historylen; do on="$(echo -n ${history::$len} | tr -d 0 | wc -c)" on="$(echo "scale=2; $on/$len" | bc)" - LC_ALL=C printf " %.2f" "$on" + printf " %.2f" "$on" done } #Debug - printf "\t(%s %3d After %4d secs)\n" "$statename" "$level" "$after"; + printf " (%s %3d After %4d secs)\n" "$statename" "$level" "$after"; #Fun with values $state && { diff --git a/c/goertzel/sleepplot.sh b/c/goertzel/sleepplot.sh index 0e8ed5e..ea0bac2 100755 --- a/c/goertzel/sleepplot.sh +++ b/c/goertzel/sleepplot.sh @@ -10,11 +10,11 @@ graphout="${in%%.*}.png" test -n "$2" && graphout="$2"; #Last state -last="$(tail -n 1 "$in" | cut -d ' ' -f 4)" +last="$(tail -n 1 "$in" | cut -d ' ' -f 5)" test "$last" -gt 0 && last="motion" || last="peace"; #Approximate size of graph -size="$(tail -n 1 "$in" | cut -d . -f 1)" +size="$(tail -n 1 "$in" | cut -d . -f 1 | sed -e 's/^0*//' | tee /tmp/lol)" test $size -gt 3600 && size="$(( $size/10 ))" #For prolonged periods size="$(( 600 + $size ))"