comparison plots/doplots @ 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 # Dereel weather: Generate plots of day's activity
3 # $Id: doplots,v 1.12 2010/02/07 03:24:24 grog Exp $
4 # Comment this out to produce all error messages
5 # SWALLOW="2> /dev/null"
6 # SWALLOW="/tmp/vomit"
7 plotset ()
8 {
9 COMMON=$BIN/plots/plot-common.gnuplot
10 INFILE=$BIN/plots/plot-$PLOT.gnuplot
11 OUTFILE=$HTML/$PLOT-$INTERVAL-$PLOTSIZE.png
12
13 # echo PLOT: $PLOT
14 # echo GRAPHSIZE: $GRAPHSIZE
15 # echo INFILE: $INFILE
16 # echo OUTFILE: $OUTFILE
17 # echo INTERVAL: $INTERVAL
18
19 cat $COMMON $INFILE | \
20 sed "s:MIDNIGHT:$GNUSTART:; s:ENDTIME:$GNUEND:; s:GRAPHFILE:$TEMPFILE:; s:SIZE:$GRAPHSIZE:; s:OUTFILE:$OUTFILE:; s:SMOOTHED: (smoothed):; s:SMOOTH:smooth bezier:; s:XTICS:$XTICS:" \
21 | gnuplot $SWALLOW
22 chmod 666 $OUTFILE
23 OUTFILE=$HTML/$PLOT-$INTERVAL-$PLOTSIZE-raw.png
24 cat $COMMON $INFILE | \
25 sed "s:MIDNIGHT:$GNUSTART:; s:ENDTIME:$GNUEND:; s:GRAPHFILE:$TEMPFILE:; s:SIZE:$GRAPHSIZE:; s:OUTFILE:$OUTFILE:; s:SMOOTHED::; s:SMOOTH:smooth bezier:; s:XTICS:$XTICS:" \
26 | gnuplot $SWALLOW
27 chmod 666 $OUTFILE
28 }
29 PLOTS="humidity temperatures inside-outside-temp inside-temp outside-temp wind pressure rain comparative-pressure comparative-dewpoint comparative-gust comparative-humidity comparative-pressure comparative-temperature comparative-wind comparative-rain BoM-Dereel BoM-Dereel-pressure"
30
31 PATH=$PATH:/usr/local/bin
32
33 export HTML=/home/grog/public_html/weather
34 BIN=/home/grog/src/weather/WH-1080
35
36 DATADIR=/var/tmp/
37 TEMPFILE=$DATADIR/dereel-weather-plot.$$
38
39 # Generate some constants.
40 # Calculate time zone offset from UTC
41 # Convert to seconds at UTC
42 NOW=`date +%G%m%d%H%M`
43 UTC=`TZ=GMT date -j $NOW +%s`
44 # And in local time zone
45 LOCAL=`date -j $NOW +%s`
46 # The difference is the time zone offset.
47 TZOFFSET=`expr $UTC - $LOCAL`
48 # Number of seconds in a day
49 DAYSECS=86400
50 # 2000-1-1 0:0:0 UTC, the gnuplot epoch. Or so it should be, but for
51 # some reason my plots come out offset by 2 hours. Use GNUFUDGE until
52 # I find out why.
53 GNUFUDGE=7200
54 Y2K=`expr 946684800`
55 MY2K=`expr $Y2K + $TZOFFSET + $GNUFUDGE`
56 # End of constant generation
57
58 # Decide what we're going to do.
59 # Date of plot
60 if [ "$1" != "" ]; then # parameter supplied
61 DATE=$1
62 else
63 DATE=`date +%F`
64 fi
65
66 # Before we forget it, offload the 5 day plot
67 $BIN/plots/plot5 $DATE
68 # Which also allows us to calculate midnight
69 STARTTIME=`date -j -f "%F %T" "$DATE 0:0:0" +%s`
70 # Adjust to gnu epoch
71 GNUSTART=`expr $STARTTIME - $Y2K - $TZOFFSET - $GNUFUDGE`
72 # End of plot. By default, 1 day, unless we have a second parm
73 ENDDATE=$2
74 if [ "$ENDDATE" = "" ]; then # 1 day
75 INTERVAL=$DATE
76 GNUEND=`expr $GNUSTART + $DAYSECS`
77 ENDTIME=`expr $STARTTIME + 86400`
78 ENDDATE=`date -r $ENDTIME +%F`
79 else
80 # midnight on the end day
81 INTERVAL=$DATE-$2
82 ENDTIME=`date -j -f "%F %T" "$2 0:0:0" +%s`
83 GNUEND=`expr $ENDTIME - $Y2K - $TZOFFSET - $GNUFUDGE`
84 echo $ENDTIME - $Y2K - $TZOFFSET - $GNUFUDGE
85 fi
86 echo end $ENDTIME start $STARTTIME
87 DURATION=`expr $ENDTIME - $STARTTIME`
88 echo DURATION $DURATION
89 # Decide how often to place the time ticks.
90 if [ $DURATION -eq $DAYSECS ]; then # single day
91 XTICS=10800 # 3 hours
92 elif [ $DURATION -eq 172800 ]; then # 2 days
93 XTICS=21600 # 6 hours
94 elif [ $DURATION -le 345600 ]; then # up to 4 days
95 XTICS=43200 # 6 hours
96 elif [ $DURATION -le 864000 ]; then # up to 10 days
97 XTICS=86400 # 6 hours
98 elif [ $DURATION -le 864000 ]; then # up to 10 days
99 XTICS=86400 # 1 day
100 elif [ $DURATION -le 2592000 ]; then # up to 30 days
101 XTICS=172800 # 2 days
102 else # > 30 days
103 XTICS=`expr $DURATION / 10` # just hack it
104 fi
105
106 echo DATE $DATE ENDDATE $ENDDATE INTERVAL $INTERVAL GNUEND $GNUEND DURATION $DURATION
107
108 # Graph sizes
109 SMALLGRAPH="375,250"
110 BIGGRAPH="1024, 720"
111
112 # XXX handle correct station
113
114 # Get the readings from the database
115 # 1: Time
116 # 2: inside_temp
117 # 3: outside_temp
118 # 4: inside_humidity
119 # 5: outside_humidity
120 # 6: inside_dewpoint
121 # 7: outside_dewpoint
122 # 8: pressure_msl
123 # 9: wind_speed
124 # 10: wind_gust
125 # 11: wind_direction
126 # 12: rain
127 QUERY="SELECT unix_timestamp(timestamp(date, time))-$MY2K, inside_temp, outside_temp, inside_humidity, outside_humidity, inside_dewpoint, outside_dewpoint, pressure_msl, wind_speed, wind_gust, wind_direction, rain FROM observations WHERE date >='$DATE' AND date < '$ENDDATE' ORDER BY date, time"
128 echo $QUERY
129 echo $QUERY | mysql weather > $TEMPFILE
130
131 # Rainfall
132 QUERY="SELECT unix_timestamp(timestamp(date, time))-$MY2K, sum(rain) FROM observations WHERE date >='$DATE' AND date < '$ENDDATE' GROUP BY hour(time)"
133 echo $QUERY
134 echo $QUERY | mysql weather > $DATADIR/dereel-rainfall
135
136 # echo Today: $STARTTIME `date -r $STARTTIME`
137
138 STATIONS="IVICTORI86 IVICTORI94 IVICTORI102 IVICTORI115 IVICMTHE3 IVICREDA2 94852 94863 94866"
139 # Comparative graphs
140 for STATION in $STATIONS; do
141 QUERY="SELECT unix_timestamp(timestamp(date, time))-$MY2K, outside_temp, outside_dewpoint, outside_humidity, pressure_msl, wind_speed, wind_gust, rain from remote_observations WHERE station_id = '$STATION' and date >='$DATE' AND date < '$ENDDATE' ORDER by date, time;"
142 echo $QUERY | mysql weather > $DATADIR/weather-readings.$STATION
143 done
144 # XXX remove this
145 # Local readings
146 QUERY="SELECT unix_timestamp(timestamp(date, time))-$MY2K, outside_temp, outside_dewpoint, outside_humidity, pressure_msl, wind_speed, wind_gust, rain from observations WHERE date >='$DATE' AND date < '$ENDDATE' ORDER by date, time;"
147 echo $QUERY
148 echo $QUERY | mysql weather > $DATADIR/weather-readings.IVICTORI124
149
150 echo $BIN/local-compare $DATE $ENDDATE Dereel
151 $BIN/local-compare $DATE $ENDDATE Dereel
152
153 # small graphs
154 GRAPHSIZE=$SMALLGRAPH
155 PLOTSIZE=small
156 for PLOT in $PLOTS; do
157 plotset
158 done
159 # big graphs
160 GRAPHSIZE=$BIGGRAPH
161 PLOTSIZE=big
162 for PLOT in $PLOTS; do
163 plotset
164 done
165
166 rm $TEMPFILE # $DATADIR/dereel-rainfall
167 for STATION in $STATIONS; do
168 rm -f $DATADIR/weather-readings.$STATION
169 done