Parralel integration
authorTomas Mudrunka <tomas@mudrunka.cz>
Fri, 3 Aug 2012 07:32:47 +0000 (09:32 +0200)
committerTomas Mudrunka <tomas@mudrunka.cz>
Fri, 3 Aug 2012 07:32:47 +0000 (09:32 +0200)
c/goertzel/sleepmon.sh
c/goertzel/sleepplot.sh
c/goertzel/sleepstats.sh [new file with mode: 0755]

index 72c827530ab6c3f5c78aca90644be6c72a9d6bc5..729d9bb878d7fab880d9aa78f924c6f74f2a0b25 100755 (executable)
@@ -17,7 +17,9 @@ graphout="${out%%.*}.png"
 
 killall speaker-test &>/dev/null
 speaker-test -t sine &>/dev/null &
-pid_test=$!
+
+touch "$out"
+bash ./sleepstats.sh "$out" &>/dev/null &
 
 tresh=10
 lastdate="$(date +%s)"
@@ -30,6 +32,8 @@ graph=false
 
 export LC_ALL=C
 
+#trap 'kill -9 $(jobs -p);' SIGINT
+
 while getopts "sg" OPT; do
        test "$OPT" == 's' && screen=true;
        test "$OPT" == 'g' && graph=true;
@@ -74,7 +78,7 @@ arecord | ./goertzel -n i -q -l c -t $tresh -d 4 | while read line; do
        lastdate="$date";
        laststate="$statenum";
 done | tee "$out"
-kill $pid_test; sleep 0.2
+kill $(jobs -p); sleep 0.2
 echo
 echo "Your log: $out"
 $graph && {
index ab6822610e2895e0141c16c13eb2e25f931273a3..a47f7e2f92be1efe07f7d135bf38656b29933782 100755 (executable)
@@ -38,7 +38,9 @@ set grid
 #set pointsize 0.5
 plot\
 "$in" using 2:5 title "Sensor state" with steps,\
-"" using 2:((\$6*3+\$7*6+\$8*6+\$9+\$10)/5) title "Avg." with lines\
+"$in.stats" using 1:((\$3*3+\$4*6+\$5*6+\$6+\$7)/5) title "Avg." smooth bezier\
+#"" using 2:((\$6*3+\$7*6+\$8*6+\$9+\$10)/5) title "Avg." with lines,\
+#"$in.stats" using 1:((\$3*3+\$4*6+\$5*6+\$6+\$7)/5) title "Avg." with lines,\
 #"" using 2:(\$6*2) title "Avg. 10s" with lines,\
 #"" using 2:(\$7*3) title "Avg. 30s" with lines,\
 #"" using 2:(\$8*3) title "Avg. 60s" with lines,\
diff --git a/c/goertzel/sleepstats.sh b/c/goertzel/sleepstats.sh
new file mode 100755 (executable)
index 0000000..5a6e9fd
--- /dev/null
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+export LC_ALL=C
+
+historymax=120;
+historylen='10 30 60 90 120'
+laststate=0;
+lastdate=''
+history='';
+
+#statsdone=$(tail -n $historymax "$1".stats | head -n 1 | cut -d ' ' -f 1);
+
+tail -f "$1" --pid=$$ | while read line; do
+       date="$(echo "$line" | cut -d ' ' -f 2)"
+       #test -n "$statsdone" && test "$date" -le "$statsdone" && continue;
+       state="$(echo "$line" | cut -d ' ' -f 5)"
+       test -z "$lastdate" && lastdate="$(( $date - 1 ))"
+
+       #echo $line
+       #echo $lastdate $date $state
+
+       for i in $(seq $lastdate $(( $date - 1 ))); do
+               echo -ne "$i $state\t"
+               history=$(echo -n "$laststate$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)"
+                       printf " %.2f" "$on"
+               done
+               echo
+       done
+
+       #History
+       #after=$(( $date - $lastdate))
+       #test $historymax -gt 0 && {
+       #}
+
+
+       #Prepare invariants for next round
+       lastdate="$date";
+       laststate="$state";
+done > "$1.stats"
This page took 0.159313 seconds and 4 git commands to generate.