Mercurial > ~darius > hgwebdir.cgi > wh1080
view 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 |
line wrap: on
line source
#!/bin/sh # # $Id: myplot,v 1.2 2010/01/10 05:06:54 grog Exp $ # # Kludge page to generate plots # These may need changing STATION=Dereel TABLE=observations STARTDATE="2009-12-23" ENDDATE="2009-12-24" COMMON=/home/grog/src/weather/WH-1080/plots/plot-common.gnuplot GRAPHFILE=/var/tmp/myplot.foo OUTFILE=/home/grog/public_html/weather/myplot.png # Generate some constants. # Calculate time zone offset from UTC # Convert to seconds at UTC NOW=`date +%Y%m%d%H%M` UTC=`TZ=GMT date -j $NOW +%s` # And in local time zone LOCAL=`date -j $NOW +%s` # The difference is the time zone offset. TZOFFSET=`expr $UTC - $LOCAL` # Number of seconds in a day DAYSECS=86400 # 2000-1-1 0:0:0 UTC, the gnuplot epoch. Or so it should be, but for # some reason my plots come out offset by 2 hours. Use GNUFUDGE until # I find out why. GNUFUDGE=7200 Y2K=`expr 946684800` MY2K=`expr $Y2K + $TZOFFSET + $GNUFUDGE` # End of constant generation # Frob these values STARTTIME=`date -j -f "%F %T" "$STARTDATE 0:0:0" +%s` # Adjust to gnu epoch GNUSTART=`expr $STARTTIME - $Y2K - $TZOFFSET - $GNUFUDGE` # midnight on the end day ENDTIME=`date -j -f "%F %T" "$ENDDATE 0:0:0" +%s` GNUEND=`expr $ENDTIME - $Y2K - $TZOFFSET - $GNUFUDGE` # echo $ENDTIME - $Y2K - $TZOFFSET - $GNUFUDGE # echo end $ENDTIME start $STARTTIME DURATION=`expr $ENDTIME - $STARTTIME` # echo DURATION $DURATION # Decide how often to place the time ticks. if [ $DURATION -eq $DAYSECS ]; then # single day XTICS=10800 # 3 hours elif [ $DURATION -eq 172800 ]; then # 2 days XTICS=21600 # 6 hours elif [ $DURATION -le 345600 ]; then # up to 4 days XTICS=43200 # 6 hours elif [ $DURATION -le 864000 ]; then # up to 10 days XTICS=86400 # 6 hours elif [ $DURATION -le 864000 ]; then # up to 10 days XTICS=86400 # 1 day elif [ $DURATION -le 2592000 ]; then # up to 30 days XTICS=172800 # 2 days else # > 30 days XTICS=`expr $DURATION / 10` # just hack it fi # echo DATE $STARTDATE ENDDATE $ENDDATE GNUEND $GNUEND DURATION $DURATION XTICS $XTICS # ************************************************** # End of setup crap # ************************************************** # Do the query MY2KP1=`expr $Y2K + $TZOFFSET + $GNUFUDGE - $DAYSECS` MY2KM1=`expr $Y2K + $TZOFFSET + $GNUFUDGE + $DAYSECS` 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;" | \ mysql weather > $GRAPHFILE.1 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;" | \ mysql weather > $GRAPHFILE.2 # And the plot for GRAPHSIZE in "375,250" "1024, 720"; do OUTFILE=/home/grog/public_html/weather/myplot.$GRAPHSIZE.png ( cat $COMMON cat << EOF set title "Temperature comparison" set ylabel "Temperature (°C)" plot "GRAPHFILE.1" using 1:2 title "23 December" with lines, \ "GRAPHFILE.2" using 1:2 title "24 December" with lines EOF ) | 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:" | \ gnuplot done