Keyboard shortcuts
[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 in="$1";
9 graphout="${in%%.*}.png"
10 test -n "$2" && graphout="$2";
11
12 #Last state
13 last="$(tail -n 1 "$in" | cut -d ' ' -f 5)"
14 test "$last" -gt 0 && last="motion" || last="peace";
15
16 #Approximate size of graph
17 size="$(tail -n 1 "$in" | cut -d . -f 1 | sed -e 's/^0*//' | tee /tmp/lol)"
18 test $size -gt 3600 && size="$(( $size/10 ))" #For prolonged periods
19 size="$(( 600 + $size ))"
20
21 #Plot it
22 gnuplot << EOF
23 set output "$graphout"
24 set terminal png size $size,400
25
26 set title "Sleep motions (current state: $last)"
27 set xlabel "time"
28 set ylabel "motion"
29
30 set yrange [-0.5:3]
31
32 set xdata time
33 set timefmt "%s"
34 #set format x "%H:%M:%S"
35
36 set grid
37
38 #set pointsize 0.5
39 plot\
40 "$in" using 2:5 title "Sensor state" with steps,\
41 "$in.stats" using 1:((\$3*3+\$4*6+\$5*6+\$6+\$7)/5) title "Avg." smooth bezier\
42 #"" using 2:((\$6*3+\$7*6+\$8*6+\$9+\$10)/5) title "Avg." with lines,\
43 #"$in.stats" using 1:((\$3*3+\$4*6+\$5*6+\$6+\$7)/5) title "Avg." with lines,\
44 #"" using 2:(\$6*2) title "Avg. 10s" with lines,\
45 #"" using 2:(\$7*3) title "Avg. 30s" with lines,\
46 #"" using 2:(\$8*3) title "Avg. 60s" with lines,\
47 #"" using 2:(\$9*3) title "Avg. 90s" with lines,\
48 #"" using 2:(\$10*4) title "Avg. 120s" smooth bezier\
49
50
51 EOF
52
53
54
55
This page took 1.634529 seconds and 4 git commands to generate.