Experimental event counting algo
[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
6c573755
TM
8#Count:
9seconds=60
10cat "$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"
14done | uniq -c | sed -e 's/^\s*//g' | tr ' ' '\t' > "$1.counts"
15
16
17#Approximate size of graph
7cd5c7da
TM
18size="$(tail -n 1 "$1" | cut -d . -f 1)"
19test $size -gt 3600 && size="$(( $size/10 ))" #For prolonged periods
78c13195 20size="$(( 600 + $size ))"
7cd5c7da 21
6c573755 22#Plot it
7cd5c7da
TM
23gnuplot << EOF
24set output "$1.png"
6c573755 25set terminal png size $size,300
7cd5c7da
TM
26
27set title "Sleep motions"
28set xlabel "time"
29set ylabel "motion"
30
6c573755 31set yrange [-0.5:3]
7cd5c7da
TM
32
33set xdata time
34set timefmt "%s"
35#set format x "%H:%M:%S"
36
7cd5c7da
TM
37set grid
38
39#set pointsize 0.5
6c573755 40plot "$1" using 2:5 with steps, "$1.counts" using 2:(\$1/7) with lines
7cd5c7da
TM
41
42EOF
43
44
45
46
This page took 0.172842 seconds and 4 git commands to generate.