Print current state to plot
[mirrors/Programs.git] / c / goertzel / sleepplot.sh
CommitLineData
7cd5c7da
TM
1#!/bin/bash
2
3test -z "$1" && {
4 echo "Usage: $0 sleeplog.txt"
5 exit 23
6}
7
5769d767
TM
8in="$1";
9graphout="${in%%.*}.png"
10test -n "$2" && graphout="$2";
11
afc6fd9f
H
12#Last state
13last="$(tail -n 1 "$in" | cut -d ' ' -f 4)"
14test "$last" -gt 0 && last="motion" || last="peace";
15
6c573755 16#Approximate size of graph
5769d767 17size="$(tail -n 1 "$in" | cut -d . -f 1)"
7cd5c7da 18test $size -gt 3600 && size="$(( $size/10 ))" #For prolonged periods
78c13195 19size="$(( 600 + $size ))"
7cd5c7da 20
6c573755 21#Plot it
7cd5c7da 22gnuplot << EOF
5769d767 23set output "$graphout"
6e6479ce 24set terminal png size $size,400
7cd5c7da 25
afc6fd9f 26set title "Sleep motions (current state: $last)"
7cd5c7da
TM
27set xlabel "time"
28set ylabel "motion"
29
6c573755 30set yrange [-0.5:3]
7cd5c7da
TM
31
32set xdata time
33set timefmt "%s"
34#set format x "%H:%M:%S"
35
7cd5c7da
TM
36set grid
37
38#set pointsize 0.5
5769d767
TM
39plot\
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
47EOF
48
49
50
51
This page took 0.146509 seconds and 4 git commands to generate.