#!/bin/bash

# configuration
# fichier rrd - path to the rrd file
rrdfile=/home/maggic/frog/data/frogd.rrd

# repertoire ou seront ecrites les images
# path where you want the images to be generated
htmldir=/home/www/meteowww/graph

# programme, ne pas editer apres cette ligne
# don't edit after this line
let nbsecond=3600*$1
date=$(date +"%Y/%m/%d, %k\\:%M\\:%S (UTC%z)")

/usr/bin/rrdtool graph $htmldir/temp_$1.png --imgformat PNG --lazy -s -$nbsecond --title=Température -v "Température" -E \
          --font TITLE:10:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --font AXIS:8:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --font UNIT:8:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --font LEGEND:8:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          DEF:tempe=$rrdfile:temp:AVERAGE \
          LINE2:tempe#ff0000:"°C" \
	  GPRINT:tempe:LAST:"Actuelle\: %.1lf " \
          GPRINT:tempe:MIN:"Min\: %.1lf " \
          GPRINT:tempe:MAX:"Max\: %.1lf " \
          GPRINT:tempe:AVERAGE:"Moyenne\: %.1lf\j" \
	  COMMENT:"\n" \
 	  COMMENT:"$date\r"


/usr/bin/rrdtool graph $htmldir/press_$1.png --imgformat PNG --lazy -s -$nbsecond --title=Pression -v "Pression" -E \
          --font TITLE:10:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --font AXIS:8:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --font UNIT:8:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --font LEGEND:8:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --units-exponent 0 \
          DEF:presse=$rrdfile:press:AVERAGE \
          LINE2:presse#0000ff:"hPa"  \
	  GPRINT:presse:LAST:"Actuelle\: %.1lf " \
	  GPRINT:presse:MIN:"Min\: %.1lf " \
	  GPRINT:presse:MAX:"Max\: %.1lf " \
	  GPRINT:presse:AVERAGE:"Moyenne\: %.1lf\j" \
	  COMMENT:"\n" \
 	  COMMENT:"$date\r"         

/usr/bin/rrdtool graph $htmldir/hum_$1.png --imgformat PNG --lazy -s -$nbsecond --title=Humidité -v "Humidité" -E \
          --font TITLE:10:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --font AXIS:8:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --font UNIT:8:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          --font LEGEND:8:/usr/X11R6/lib/X11/fonts/TTF/arial.ttf \
          DEF:hume=$rrdfile:hum:AVERAGE \
          LINE2:hume#00a000:"% HR"  \
	  GPRINT:hume:LAST:"Actuelle\: %.1lf " \
	  GPRINT:hume:MIN:"Min\: %.1lf " \
	  GPRINT:hume:MAX:"Max\: %.1lf " \
	  GPRINT:hume:AVERAGE:"Moyenne\: %.1lf\j" \
	  COMMENT:"\n" \
 	  COMMENT:"$date\r"

