New sleepmon statistics
authorTomas Mudrunka <tomas@mudrunka.cz>
Fri, 3 Aug 2012 02:30:36 +0000 (04:30 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Fri, 3 Aug 2012 02:30:36 +0000 (04:30 +0200)
c/goertzel/sleepcount.sh [deleted file]
c/goertzel/sleepmon.sh
c/goertzel/sleepplot.sh

diff --git a/c/goertzel/sleepcount.sh b/c/goertzel/sleepcount.sh
deleted file mode 100755 (executable)
index 920e42b..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/bash
-seconds="$2"
-START=$(head -n 1 "$1" | cut -f 2)
-STARTOK=$({ tail -n 1 "$1.counts.$seconds" || echo 0; } | cut -f 1)
-STOP=$( tail -n 1 "$1" | cut -f 2)
-
-fuser "$1.counts.$seconds" &>/dev/null && exit 23;
-
-test "$STARTOK" -gt "$START" && START="$STARTOK";
-seq $START $STOP | while read MAX; do
-       MIN=$(( $MAX - $seconds  ))
-       echo -ne "$MAX\t"
-       cat "$1" | cut -f 2,5 | grep -v '\s0' | cut -f 1 | egrep $(echo $(seq $MIN $MAX) | tr ' ' '|') | wc -l
-done >> "$1.counts.$seconds"
index 0d32b65c56f2e7678a52539496d338375d802b5b..9ac62f9f7ce623abf46d5848f0a3e10799908475 100755 (executable)
@@ -17,7 +17,11 @@ out=/tmp/sleeplog-"$(date +%F_%T)".txt
 speaker-test -t sine &>/dev/null &
 pid_test=$!
 tresh=10
-lastdate=0
+lastdate="$(date +%s)"
+laststate=0
+history='';
+historymax=120;
+historylen='10 30 120'
 screen=false
 while getopts "s" OPT; do
        test "$OPT" == 's' && screen=true;
@@ -27,21 +31,37 @@ arecord | ./goertzel -n i -q -l c -t $tresh -d 4 | while read line; do
        date="$(date +%s)"
        time="$(echo "$line" | cut -f 1)"
        level="$(echo "$line" | cut -f 2)"
-       echo -ne "$time\t$date\t$(date '+%F%t%T')\t"
-       test "$level" -gt "$tresh" && {
-               echo -n "0 Nothing detected...";
+       test "$level" -gt "$tresh" && state=false || state=true
+       $state && statenum=1 || statenum=0;
+       $state && statename='MOTION!' || statename='Nothing';
+
+       echo -ne "$time\t$date $(date '+%F %T') $statenum"
+
+       #History
+       after=$(( $date - $lastdate))
+       test $historymax -gt 0 && {
+               history=$(echo -n "$(yes | tr '\ny' $laststate | head -c $after)$history" | head -c $historymax)
+               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"
+               done
+       }
+
+       #Debug
+       echo -e "\t($statename $level After $after secs)";
+
+       #Fun with values
+       $state && {
                $screen && xset dpms force off || true;
        } || {
-               echo -n "1 Motion detected!!!!";
                $screen && xset dpms force on;
        }
-       test "$lastdate" != 0 && {
-               after=$(( $date - $lastdate))
-               echo -ne "\t$level After $after secs";
-       }
-       echo;
-       ./sleepplot.sh "$out" &>/dev/null
+       ./sleepplot.sh "$out" &>/dev/null &
+
+       #Prepare invariants for next round
        lastdate="$date";
+       laststate="$statenum";
 done | tee "$out"
 kill $pid_test
 echo
index fe1c9af740fd739a5a727d3c0f38e9a7fb6284b3..3dcfec65f9d6de53ab04f2aa7f13b04c057118ed 100755 (executable)
@@ -5,12 +5,6 @@ test -z "$1" && {
        exit 23
 }
 
-#Count events:
-seconds='60 300'
-for i in $seconds; do
-       ./sleepcount.sh "$1" "$i" &
-done
-
 #Approximate size of graph
 size="$(tail -n 1 "$1" | cut -d . -f 1)"
 test $size -gt 3600 && size="$(( $size/10 ))" #For prolonged periods
@@ -34,10 +28,10 @@ set timefmt "%s"
 set grid
 
 #set pointsize 0.5
-#"$1.counts.$seconds" using 1:(\$2/5) title "Activations in last $seconds seconds" smooth csplines
 plot "$1" using 2:5 title "Sensor state" with steps,\
-"$1.counts.60" using 1:(\$2/5) title "Activations in last 60 seconds" smooth csplines,\
-"$1.counts.300" using 1:(\$2/10) title "Activations in last 300 seconds" smooth csplines\
+"" using 2:(\$6*3) title "Avg last last 10 seconds" with lines,\
+"" using 2:(\$7*3) title "Avg last last 30 seconds" with lines,\
+"" using 2:(\$8*3) title "Avg last last 120 seconds" with lines\
 
 EOF
 
This page took 0.153344 seconds and 4 git commands to generate.