comparison plots/myplot @ 0:9dab44dcb331

Initial commit of Greg's code from http://www.lemis.com/grog/tmp/wh1080.tar.gz
author Daniel O'Connor <darius@dons.net.au>
date Tue, 09 Feb 2010 13:44:25 +1030
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:9dab44dcb331
1 #!/bin/sh
2 #
3 # $Id: myplot,v 1.2 2010/01/10 05:06:54 grog Exp $
4 #
5 # Kludge page to generate plots
6 # These may need changing
7 STATION=Dereel
8 TABLE=observations
9 STARTDATE="2009-12-23"
10 ENDDATE="2009-12-24"
11 COMMON=/home/grog/src/weather/WH-1080/plots/plot-common.gnuplot
12 GRAPHFILE=/var/tmp/myplot.foo
13 OUTFILE=/home/grog/public_html/weather/myplot.png
14
15 # Generate some constants.
16 # Calculate time zone offset from UTC
17 # Convert to seconds at UTC
18 NOW=`date +%Y%m%d%H%M`
19 UTC=`TZ=GMT date -j $NOW +%s`
20 # And in local time zone
21 LOCAL=`date -j $NOW +%s`
22 # The difference is the time zone offset.
23 TZOFFSET=`expr $UTC - $LOCAL`
24 # Number of seconds in a day
25 DAYSECS=86400
26 # 2000-1-1 0:0:0 UTC, the gnuplot epoch. Or so it should be, but for
27 # some reason my plots come out offset by 2 hours. Use GNUFUDGE until
28 # I find out why.
29 GNUFUDGE=7200
30 Y2K=`expr 946684800`
31 MY2K=`expr $Y2K + $TZOFFSET + $GNUFUDGE`
32 # End of constant generation
33
34 # Frob these values
35 STARTTIME=`date -j -f "%F %T" "$STARTDATE 0:0:0" +%s`
36 # Adjust to gnu epoch
37 GNUSTART=`expr $STARTTIME - $Y2K - $TZOFFSET - $GNUFUDGE`
38 # midnight on the end day
39 ENDTIME=`date -j -f "%F %T" "$ENDDATE 0:0:0" +%s`
40 GNUEND=`expr $ENDTIME - $Y2K - $TZOFFSET - $GNUFUDGE`
41 # echo $ENDTIME - $Y2K - $TZOFFSET - $GNUFUDGE
42
43 # echo end $ENDTIME start $STARTTIME
44 DURATION=`expr $ENDTIME - $STARTTIME`
45 # echo DURATION $DURATION
46 # Decide how often to place the time ticks.
47 if [ $DURATION -eq $DAYSECS ]; then # single day
48 XTICS=10800 # 3 hours
49 elif [ $DURATION -eq 172800 ]; then # 2 days
50 XTICS=21600 # 6 hours
51 elif [ $DURATION -le 345600 ]; then # up to 4 days
52 XTICS=43200 # 6 hours
53 elif [ $DURATION -le 864000 ]; then # up to 10 days
54 XTICS=86400 # 6 hours
55 elif [ $DURATION -le 864000 ]; then # up to 10 days
56 XTICS=86400 # 1 day
57 elif [ $DURATION -le 2592000 ]; then # up to 30 days
58 XTICS=172800 # 2 days
59 else # > 30 days
60 XTICS=`expr $DURATION / 10` # just hack it
61 fi
62
63 # echo DATE $STARTDATE ENDDATE $ENDDATE GNUEND $GNUEND DURATION $DURATION XTICS $XTICS
64
65 # **************************************************
66 # End of setup crap
67 # **************************************************
68
69 # Do the query
70 MY2KP1=`expr $Y2K + $TZOFFSET + $GNUFUDGE - $DAYSECS`
71 MY2KM1=`expr $Y2K + $TZOFFSET + $GNUFUDGE + $DAYSECS`
72 echo "SELECT unix_timestamp(timestamp(date, time))-$MY2K, outside_temp from $TABLE WHERE station_id = '$STATION' and date >='$STARTDATE' AND date <= '$STARTDATE' ORDER by date, time;" | \
73 mysql weather > $GRAPHFILE.1
74 echo "SELECT unix_timestamp(timestamp(date, time))-$MY2KM1, outside_temp from $TABLE WHERE station_id = '$STATION' and date >='$ENDDATE' AND date <= '$ENDDATE' ORDER by date, time;" | \
75 mysql weather > $GRAPHFILE.2
76
77 # And the plot
78
79 for GRAPHSIZE in "375,250" "1024, 720"; do
80 OUTFILE=/home/grog/public_html/weather/myplot.$GRAPHSIZE.png
81
82 ( cat $COMMON
83 cat << EOF
84 set title "Temperature comparison"
85 set ylabel "Temperature (°C)"
86 plot "GRAPHFILE.1" using 1:2 title "23 December" with lines, \
87 "GRAPHFILE.2" using 1:2 title "24 December" with lines
88 EOF
89 ) | sed "s:MIDNIGHT:$GNUSTART:; s:ENDTIME:$GNUEND:; s:GRAPHFILE:$GRAPHFILE:g; s:SIZE:$GRAPHSIZE:; s:OUTFILE:$OUTFILE:; s:SMOOTHED: (smoothed):; s:SMOOTH:smooth bezier:; s:XTICS:$XTICS:" | \
90 gnuplot
91 done