Commit | Line | Data |
---|---|---|
7cd5c7da TM |
1 | #!/bin/bash |
2 | ||
3 | test -z "$1" && { | |
4 | echo "Usage: $0 sleeplog.txt" | |
5 | exit 23 | |
6 | } | |
7 | ||
6c573755 TM |
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 | |
7cd5c7da TM |
18 | size="$(tail -n 1 "$1" | cut -d . -f 1)" |
19 | test $size -gt 3600 && size="$(( $size/10 ))" #For prolonged periods | |
78c13195 | 20 | size="$(( 600 + $size ))" |
7cd5c7da | 21 | |
6c573755 | 22 | #Plot it |
7cd5c7da TM |
23 | gnuplot << EOF |
24 | set output "$1.png" | |
6c573755 | 25 | set terminal png size $size,300 |
7cd5c7da TM |
26 | |
27 | set title "Sleep motions" | |
28 | set xlabel "time" | |
29 | set ylabel "motion" | |
30 | ||
6c573755 | 31 | set yrange [-0.5:3] |
7cd5c7da TM |
32 | |
33 | set xdata time | |
34 | set timefmt "%s" | |
35 | #set format x "%H:%M:%S" | |
36 | ||
7cd5c7da TM |
37 | set grid |
38 | ||
39 | #set pointsize 0.5 | |
6c573755 | 40 | plot "$1" using 2:5 with steps, "$1.counts" using 2:(\$1/7) with lines |
7cd5c7da TM |
41 | |
42 | EOF | |
43 | ||
44 | ||
45 | ||
46 |