Experimental event counting algo
[mirrors/Programs.git] / c / goertzel / sleepplot.sh
1 #!/bin/bash
2
3 test -z "$1" && {
4 echo "Usage: $0 sleeplog.txt"
5 exit 23
6 }
7
8 #Count:
9 seconds=60
10 cat "$1" | cut -f 2,5 | cut -d ' ' -f 1 | grep '1$' | while read line; do
11 time=$(echo $line | cut -d ' ' -f 1);
12 time=$(( $time + $seconds - $time%$seconds ))
13 echo "$time"
14 done | uniq -c | sed -e 's/^\s*//g' | tr ' ' '\t' > "$1.counts"
15
16
17 #Approximate size of graph
18 size="$(tail -n 1 "$1" | cut -d . -f 1)"
19 test $size -gt 3600 && size="$(( $size/10 ))" #For prolonged periods
20 size="$(( 600 + $size ))"
21
22 #Plot it
23 gnuplot << EOF
24 set output "$1.png"
25 set terminal png size $size,300
26
27 set title "Sleep motions"
28 set xlabel "time"
29 set ylabel "motion"
30
31 set yrange [-0.5:3]
32
33 set xdata time
34 set timefmt "%s"
35 #set format x "%H:%M:%S"
36
37 set grid
38
39 #set pointsize 0.5
40 plot "$1" using 2:5 with steps, "$1.counts" using 2:(\$1/7) with lines
41
42 EOF
43
44
45
46
This page took 0.273422 seconds and 4 git commands to generate.