Commit | Line | Data |
---|---|---|
7cd5c7da TM |
1 | #!/bin/bash |
2 | ||
3 | test -z "$1" && { | |
4 | echo "Usage: $0 sleeplog.txt" | |
5 | exit 23 | |
6 | } | |
7 | ||
5769d767 TM |
8 | in="$1"; |
9 | graphout="${in%%.*}.png" | |
10 | test -n "$2" && graphout="$2"; | |
11 | ||
afc6fd9f H |
12 | #Last state |
13 | last="$(tail -n 1 "$in" | cut -d ' ' -f 4)" | |
14 | test "$last" -gt 0 && last="motion" || last="peace"; | |
15 | ||
6c573755 | 16 | #Approximate size of graph |
5769d767 | 17 | size="$(tail -n 1 "$in" | cut -d . -f 1)" |
7cd5c7da | 18 | test $size -gt 3600 && size="$(( $size/10 ))" #For prolonged periods |
78c13195 | 19 | size="$(( 600 + $size ))" |
7cd5c7da | 20 | |
6c573755 | 21 | #Plot it |
7cd5c7da | 22 | gnuplot << EOF |
5769d767 | 23 | set output "$graphout" |
6e6479ce | 24 | set terminal png size $size,400 |
7cd5c7da | 25 | |
afc6fd9f | 26 | set title "Sleep motions (current state: $last)" |
7cd5c7da TM |
27 | set xlabel "time" |
28 | set ylabel "motion" | |
29 | ||
6c573755 | 30 | set yrange [-0.5:3] |
7cd5c7da TM |
31 | |
32 | set xdata time | |
33 | set timefmt "%s" | |
34 | #set format x "%H:%M:%S" | |
35 | ||
7cd5c7da TM |
36 | set grid |
37 | ||
38 | #set pointsize 0.5 | |
5769d767 TM |
39 | plot\ |
40 | "$in" using 2:5 title "Sensor state" with steps,\ | |
42643d9f | 41 | "" using 2:(\$6*2) title "Avg. 10s" with lines,\ |
5769d767 | 42 | "" using 2:(\$7*3) title "Avg. 30s" with lines,\ |
6e6479ce TM |
43 | "" using 2:(\$8*3) title "Avg. 60s" with lines,\ |
44 | "" using 2:(\$9*3) title "Avg. 90s" with lines,\ | |
45 | "" using 2:(\$10*4) title "Avg. 120s" smooth bezier\ | |
7cd5c7da TM |
46 | |
47 | EOF | |
48 | ||
49 | ||
50 | ||
51 |