Skip to content

Commit

Permalink
Parralel integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Harvie committed Aug 3, 2012
1 parent ef4db4f commit 43f096b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
8 changes: 6 additions & 2 deletions c/goertzel/sleepmon.sh
Expand Up @@ -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)"
Expand All @@ -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;
Expand Down Expand Up @@ -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 && {
Expand Down
4 changes: 3 additions & 1 deletion c/goertzel/sleepplot.sh
Expand Up @@ -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,\
Expand Down
42 changes: 42 additions & 0 deletions c/goertzel/sleepstats.sh
@@ -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"

0 comments on commit 43f096b

Please sign in to comment.