comparison plots/plot5 @ 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 #!/usr/local/bin/bash
2 #
3 # $Id: plot5,v 1.1 2010/01/10 06:13:52 grog Exp grog $
4 #
5 # Generate comparative temperature plots for 5 consecutive days.
6 # These may need changing
7 STATION=Dereel
8 TABLE=observations
9 COMMON=/home/grog/src/weather/WH-1080/plots/plot-common3.gnuplot
10 GRAPHFILE=/var/tmp/myplot.foo
11 OUTFILE=/home/grog/public_html/weather/myplot.png
12
13 # Generate some constants.
14 # Calculate time zone offset from UTC
15 # Convert to seconds at UTC
16 NOW=`date +%Y%m%d%H%M`
17 UTC=`TZ=GMT date -j $NOW +%s`
18 # And in local time zone
19 LOCAL=`date -j $NOW +%s`
20 # The difference is the time zone offset.
21 TZOFFSET=`expr $UTC - $LOCAL`
22 # Number of seconds in a day
23 DAYSECS=86400
24 # 2000-1-1 0:0:0 UTC, the gnuplot epoch. Or so it should be, but for
25 # some reason my plots come out offset by 2 hours. Use GNUFUDGE until
26 # I find out why.
27 GNUFUDGE=7200
28 Y2K=`expr 946684800`
29 MY2K=`expr $Y2K + $TZOFFSET + $GNUFUDGE`
30 # End of constant generation
31
32 # Get the last date for this graph.
33 if [ $# -ge 1 ]; then
34 ENDDATE=$1
35 else
36 ENDDATE=`date +%Y-%m-%d`
37 fi
38 # echo S $ENDDATE
39 # Frob these values
40 ENDTIME=`date -j -f "%F %T" "$ENDDATE 0:0:0" +%s`
41 # start 4 days earlier
42 STARTTIME=`expr $ENDTIME - $DAYSECS \* 4`
43 # Adjust to gnu epoch
44 GNUSTART=`expr $STARTTIME - $Y2K - $TZOFFSET - $GNUFUDGE`
45 # echo $ENDTIME - $Y2K - $TZOFFSET - $GNUFUDGE
46
47 # echo end $ENDTIME start $STARTTIME
48 XTICS=10800 # tics every 3 hours
49
50 # echo DATE $STARTDATE ENDDATE $ENDDATE GNUEND $GNUEND DURATION $DURATION XTICS $XTICS
51
52 # **************************************************
53 # End of setup crap
54 # **************************************************
55
56 # Do the query
57 # Offset of day from FOO
58 OFFSET=`expr $Y2K + $TZOFFSET + $GNUFUDGE`
59 # echo O $OFFSET S $STARTTIME
60 for i in 1 2 3 4 5; do
61 DAY=`date -r $STARTTIME +"%Y-%m-%d"`
62 DAY[$i]=`date -r $STARTTIME +"%e %b"`
63 # echo i $i DAY $DAY
64 echo "SELECT unix_timestamp(timestamp(date, time))-$OFFSET, outside_temp from $TABLE WHERE station_id = '$STATION' and date ='$DAY' ORDER by time;" | \
65 mysql weather > $GRAPHFILE.$i
66 STARTTIME=`expr $STARTTIME + $DAYSECS` # next day
67 OFFSET=`expr $OFFSET + $DAYSECS` # next day
68 done
69
70 # And the plot
71
72 GRAPHSIZE="375,250"
73 OUTFILE=$HTML/5days-$ENDDATE-small.png
74 ( cat $COMMON
75 cat << EOF
76 set title "Daily temperature comparison"
77 set ylabel "Temperature (°C)"
78 plot "GRAPHFILE.1" using 1:2 title "${DAY[1]}" with lines smooth bezier, \
79 "GRAPHFILE.2" using 1:2 title "${DAY[2]}" with lines smooth bezier, \
80 "GRAPHFILE.3" using 1:2 title "${DAY[3]}" with lines smooth bezier, \
81 "GRAPHFILE.4" using 1:2 title "${DAY[4]}" with lines smooth bezier, \
82 "GRAPHFILE.5" using 1:2 title "${DAY[5]}" with lines smooth bezier
83 EOF
84 ) | 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:" | \
85 gnuplot
86 chmod 666 $OUTFILE
87
88 GRAPHSIZE="1024,720"
89 OUTFILE=$HTML/5days-$ENDDATE-big.png
90 ( cat $COMMON
91 cat << EOF
92 set title "Daily temperature comparison"
93 set ylabel "Temperature (°C)"
94 plot "GRAPHFILE.1" using 1:2 title "${DAY[1]}" with lines smooth bezier, \
95 "GRAPHFILE.2" using 1:2 title "${DAY[2]}" with lines smooth bezier, \
96 "GRAPHFILE.3" using 1:2 title "${DAY[3]}" with lines smooth bezier, \
97 "GRAPHFILE.4" using 1:2 title "${DAY[4]}" with lines smooth bezier, \
98 "GRAPHFILE.5" using 1:2 title "${DAY[5]}" with lines smooth bezier
99 EOF
100 ) | 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:" | \
101 gnuplot
102 chmod 666 $OUTFILE
103
104 for i in 1 2 3 4 5; do
105 rm $GRAPHFILE.$i
106 done