import com.dbentrance.extensions.tools.RAWSUtil import com.dbentrance.entrance.Utilities import com.dbentrance.entrance.EntrancePlot import groovy.sql.Sql sql = Sql.newInstance( "jdbc:mysql://localhost/test", "root", "", "com.mysql.jdbc.Driver") database = "test" curTable = "raws_tmp" histTable = "raws_weather" station = "BNDC1" name = "BEN LOMOND" state = "CA" tz = "PT" daylight = true // ---------------------------------------------- RAWSUtil.updateRAWS( sql.getConnection(), database, curTable, histTable, station, tz, daylight) // ---------------------------------------------- println """ RAWS

Refresh

""" println name + "," + state + " (" + station + ")
" println "

" println(Utilities.queryForString(sql.getConnection(), "select date_format(max(dt), \"%a   %b %e, %Y %l:%i %p\") from " + curTable + ";")) println("

Current Temperature:   " + Utilities.queryForDouble(sql.getConnection(), "select temp from " + curTable + "\n" + " where dt = (select max(dt) from " + curTable + ");") + "°
\n" ) ; println("24 Hour High:   " + Utilities.queryForDouble(sql.getConnection(), "select max(temp) from "+curTable) +"°
\n") println("24 Hour Low:   " + Utilities.queryForDouble(sql.getConnection(), "select min(temp) from "+curTable) +"°
\n" ) println ("
") String windDir = RAWSUtil.directionToString( Utilities.queryForInt(sql.getConnection(), "select wind_dir from "+curTable+"\n" + " where dt = (select max(dt) from " + histTable + ");")); String peakDir = RAWSUtil.directionToString( Utilities.queryForInt(sql.getConnection(), "select peak_wind_dir from "+curTable+"\n" + " where dt = (select max(dt) from " + histTable + ");")); println ("Wind "+ Utilities.queryForString(sql.getConnection(), "select format(wind_speed, 0) from "+curTable+"\n" + " where dt = (select max(dt) from " + curTable + ");") + " to " + Utilities.queryForString(sql.getConnection(), "select format(peak_wind_speed, 0) from "+curTable+"\n" + " where dt = (select max(dt) from " + curTable + ");") + " mph "+ "
" + "from the "+ windDir + (!windDir.equals(peakDir) ? " to the "+peakDir : "") ) ; println( "

" ) println("Precipitation - last hour:   " + Utilities.queryForString(sql.getConnection(), " select lpad(format(precip_hr, 2), 6, ' ') from "+curTable+"\n" + " where dt = (select max(dt) from " + curTable + ")\n" ) + " in.
\n" ) println("Precipitation - last 24 hours:   " + Utilities.queryForString(sql.getConnection(), "select \n" + " lpad(format(" + " (select precip from "+curTable+"\n" + " where dt = (select max(dt) from " + curTable + "))\n" + " -\n" + " (select precip from "+curTable+"\n" + " where dt = (select min(dt) from " + curTable + "))\n" + " , 2), 6, ' ')" ) + " in.
\n" ) println("Precipitation - this season:  "+ Utilities.queryForString(sql.getConnection(), "select lpad(format(precip, 2), 6, ' ') from "+curTable+"\n" + " where dt = (select max(dt) from " + curTable + ");") + " in.
\n"); println( "

" ) // ------------------------------------------------------------------------ // the next noon after the current time String noonafter = Utilities.queryForString(sql.getConnection(), "select if(now() < concat(curdate(), ' 12:00'),"+ "concat(curdate(), ' 12:00'),"+ "concat(date_add(curdate(), interval 1 day),' 12:00')"+ ");"); // the noon three days before that one String noonbefore = Utilities.queryForString(sql.getConnection(), "select date_sub('" + noonafter + "', interval 72 hour);" ); rightnow = Utilities.queryForString(sql.getConnection(), "select now()"); // ------------------------------------------------------------------------ // the wind chart println("Wind (mph)") script = """ use @db; plot datetimedirchart x, length, thin red direction, length, thin blue direction WITH scale x "@noonbefore" "@rightnow" 24 hour format x "%d - noon" labelangle 0 page 0 0 275 150 frame 46 5 245 125 no clip version "1.5.1" background black foreground light gray gray horizontal gridlines select dt, peak_wind_speed, peak_wind_dir, wind_speed, wind_dir from @raws_table where station = '@station' and dt >= "@noonbefore" and dt <= "@rightnow" order by dt asc; """ script = script.replace("@db", database) script = script.replace("@noonbefore", noonbefore) script = script.replace("@rightnow", rightnow) script = script.replace("@raws_table", histTable) script = script.replace("@station", station) EntrancePlot.generatePNG(sql.getConnection(), "/usr/local/tomcat/webapps/groovy/bndc1_files/wind.png", script); println("

") println("
"); // ------------------------------------------------------------------------ // the precipitation chart println """

Precipitation (inches/hour)
""" script = """ use @db; plot datetimeychart x, light blue thin droplines with scale x "@noonbefore" "@rightnow" 24 hour format x "%d - noon" -- scale y 0 0.4 0.1 format y decimal "0.00#" labelangle 0 page 0 0 275 150 -- was 320 frame 46 5 245 125 -- was 283 no clip gray horizontal gridlines no sides zerobased background black foreground light gray select dt, if(precip_hr > 0, precip_hr, null) from @raws_table where station = '@station' and dt >= "@noonbefore" and dt <= "@rightnow" order by dt asc; """ script = script.replace("@db", database) script = script.replace("@noonbefore", noonbefore) script = script.replace("@rightnow", rightnow) script = script.replace("@raws_table", histTable) script = script.replace("@station", station) EntrancePlot.generatePNG(sql.getConnection(), "/usr/local/tomcat/webapps/groovy/bndc1_files/precipitation.png", script); rainfall = Utilities.queryForDouble(sql.getConnection(), "select max(precip_hr) from " + histTable + " where dt > '" + noonbefore + "'"); println("

") if(!Double.isNaN(rainfall) && rainfall != 0) { println """
""" } else println("      None.
"); // ------------------------------------------------------------------------ println """

Temperature (F)
""" script = """ use @db; plot datetimeychart x, red line with scale x "@noonbefore" "@rightnow" 24 hour format x "%d - noon" format y decimal "#\u00B0" labelangle 0 page 0 0 275 150 frame 46 5 245 125 no clip gray horizontal gridlines no sides background black foreground light gray select dt, temp from @raws_table where station = '@station' and dt >= "@noonbefore" and dt <= "@rightnow" order by dt asc; """ script = script.replace("@db", database) script = script.replace("@noonbefore", noonbefore) script = script.replace("@rightnow", rightnow) script = script.replace("@raws_table", histTable) script = script.replace("@station", station) EntrancePlot.generatePNG(sql.getConnection(), "/usr/local/tomcat/webapps/groovy/bndc1_files/temperature.png", script); println """


"""