view plots/doplots @ 5:b22a888eb975

Remove page1_*_pressure - it appears to be old code and is unused.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 11 Feb 2010 12:44:56 +1030
parents 9dab44dcb331
children
line wrap: on
line source

#!/bin/sh
# Dereel weather: Generate plots of day's activity
# $Id: doplots,v 1.12 2010/02/07 03:24:24 grog Exp $
# Comment this out to produce all error messages
# SWALLOW="2> /dev/null"
# SWALLOW="/tmp/vomit"
plotset ()
{ 
  COMMON=$BIN/plots/plot-common.gnuplot
  INFILE=$BIN/plots/plot-$PLOT.gnuplot
  OUTFILE=$HTML/$PLOT-$INTERVAL-$PLOTSIZE.png

#  echo PLOT: $PLOT
#  echo GRAPHSIZE: $GRAPHSIZE
#  echo INFILE: $INFILE
#  echo OUTFILE: $OUTFILE
#  echo INTERVAL: $INTERVAL

  cat $COMMON $INFILE | \
      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:"  \
	| gnuplot $SWALLOW
  chmod 666 $OUTFILE
  OUTFILE=$HTML/$PLOT-$INTERVAL-$PLOTSIZE-raw.png
  cat $COMMON $INFILE | \
      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:"  \
	| gnuplot $SWALLOW
  chmod 666 $OUTFILE
}
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"

PATH=$PATH:/usr/local/bin

export HTML=/home/grog/public_html/weather
BIN=/home/grog/src/weather/WH-1080

DATADIR=/var/tmp/
TEMPFILE=$DATADIR/dereel-weather-plot.$$

# Generate some constants.  
# Calculate time zone offset from UTC
# Convert to seconds at UTC
NOW=`date +%G%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

# Decide what we're going to do.
# Date of plot
if [ "$1" != "" ]; then		# parameter supplied
    DATE=$1
else
    DATE=`date +%F`
fi

# Before we forget it, offload the 5 day plot
$BIN/plots/plot5 $DATE
# Which also allows us to calculate midnight
STARTTIME=`date -j -f "%F %T" "$DATE 0:0:0" +%s`
# Adjust to gnu epoch
GNUSTART=`expr $STARTTIME - $Y2K - $TZOFFSET - $GNUFUDGE`
# End of plot.  By default, 1 day, unless we have a second parm
ENDDATE=$2
if [ "$ENDDATE" = "" ]; then           # 1 day
  INTERVAL=$DATE
  GNUEND=`expr $GNUSTART + $DAYSECS`
  ENDTIME=`expr $STARTTIME + 86400`
  ENDDATE=`date -r $ENDTIME  +%F`
else
  # midnight on the end day
  INTERVAL=$DATE-$2
  ENDTIME=`date -j -f "%F %T" "$2 0:0:0" +%s`
  GNUEND=`expr $ENDTIME - $Y2K - $TZOFFSET - $GNUFUDGE`
echo  $ENDTIME - $Y2K - $TZOFFSET - $GNUFUDGE
fi
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 $DATE ENDDATE $ENDDATE INTERVAL $INTERVAL GNUEND $GNUEND DURATION $DURATION

# Graph sizes
SMALLGRAPH="375,250"
BIGGRAPH="1024, 720"

# XXX handle correct station

# Get the readings from the database
# 1: Time
# 2: inside_temp
# 3: outside_temp
# 4: inside_humidity
# 5: outside_humidity
# 6: inside_dewpoint
# 7: outside_dewpoint
# 8: pressure_msl
# 9: wind_speed
# 10: wind_gust
# 11: wind_direction
# 12: rain
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"
echo $QUERY
echo $QUERY | mysql weather > $TEMPFILE

# Rainfall
QUERY="SELECT unix_timestamp(timestamp(date, time))-$MY2K, sum(rain) FROM observations WHERE date >='$DATE' AND date < '$ENDDATE' GROUP BY hour(time)"
echo $QUERY
echo $QUERY | mysql weather > $DATADIR/dereel-rainfall

# echo Today: $STARTTIME `date -r $STARTTIME`

STATIONS="IVICTORI86 IVICTORI94 IVICTORI102 IVICTORI115 IVICMTHE3 IVICREDA2 94852 94863 94866"
# Comparative graphs
for STATION in $STATIONS; do
  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;"
  echo $QUERY | mysql weather > $DATADIR/weather-readings.$STATION
done
# XXX remove this
# Local readings
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;"
echo $QUERY
echo $QUERY | mysql weather > $DATADIR/weather-readings.IVICTORI124

echo $BIN/local-compare $DATE $ENDDATE Dereel
$BIN/local-compare $DATE $ENDDATE Dereel

# small graphs
GRAPHSIZE=$SMALLGRAPH
PLOTSIZE=small
for PLOT in $PLOTS; do 
  plotset
done
# big graphs
GRAPHSIZE=$BIGGRAPH
PLOTSIZE=big
for PLOT in $PLOTS; do 
  plotset
done

rm $TEMPFILE # $DATADIR/dereel-rainfall
for STATION in $STATIONS; do
  rm -f $DATADIR/weather-readings.$STATION
done