+++ /dev/null
-#!/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"
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;
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
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
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