max windchill active only in winds > 1.2m/s
[dweather.git] / templates / index.html.ep
index 1b907ee9ae962b9d7b9d7f449ead6c8d6a357b65..1cbb94914967bc115f586934944e9ec2f6e1c852 100644 (file)
@@ -1,5 +1,6 @@
+% use Debug;
 % my $url = url_for 'weather';
-% my $s;
+% my ($s, $lasttemp);
 <!DOCTYPE html>
 <html>
        <head>
 
                <!-- Optional theme -->
                <link rel="stylesheet" href="css/bootstrap-theme.min.css">
+               
+               <!-- auto refresh (really only for the yr.no forecast) -->
+               <meta content="3600" http-equiv="Refresh">
+
 
        </head>
        <body>
 
                var h = new Object();
 
+               var trans = {
+                       "Wind" : function (speed) { return (speed * 2.236936).toFixed(1); },
+                       "Wind_1m" : function (speed) { return (speed * 2.236936).toFixed(1); },
+                       "Wind_Max": function (speed) { return (speed * 2.236936).toFixed(1); }
+               };
+                       
+
                function do_debug(text) {
                        document.getElementById("do_debug").innerHTML = text;
                }
                function fill_html(key,value) {
                        var d = document.getElementById(key);
                        if (d !== null) {
-                               d.innerHTML = value;
+                               var f = trans[key];
+                               if (f && typeof(f) === "function") {
+                                       d.innerHTML = trans[key](value);
+                               } else {
+                                       d.innerHTML = value;
+                               }
                        }
                }
 
@@ -59,6 +76,7 @@
                var lastwind = 0;
                var lastdir = 0;
                var lastt = 0;
+               var lasttemp = -100;
 
                function startws() {
                        ws = new WebSocket('<%= $url->to_abs %>');
                                        zoomType: 'xy'
                                },
                                title: {
-                                       text: 'Five Day Chart'
+                                       text: 'Last Five Days'
                                },
                                xAxis: [{
                                        type: 'datetime',
 //                                     categories: [],
                                        crosshair: true
                                }],
-                               yAxis: [{ // Primary yAxis
+                               yAxis: [{ // Temperature +(ve)
                                        labels: {
                                                format: '{value}°C',
                                                style: {
                                        },
                                        opposite: true
 
-                               }, { // Secondary yAxis
+                               }, { // Rainfall
                                        gridLineWidth: 0,
                                        title: {
                                                text: 'Rainfall',
                                                }
                                        }
 
-                               }, { // Tertiary yAxis
+                               }, { // Pressure
                                        gridLineWidth: 0,
                                        title: {
                                                text: 'Sea-Level Pressure',
                                                style: {
-                                                       color: Highcharts.getOptions().colors[1]
+                                                       color: '#008800'
                                                }
                                        },
                                        labels: {
                                                format: '{value} mb',
                                                style: {
-                                                       color: Highcharts.getOptions().colors[1]
+                                                       color: '#008800'
                                                }
                                        },
                                        opposite: true
-                               }, { // Tertiary yAxis
+                               }, { // Humidity
                                        gridLineWidth: 0,
                                        floor: 0,
                                        ceiling: 100,
                                        title: {
                                                text: 'Humidity',
                                                style: {
-                                                       color: '#008800'
+                                                       color: '#000000'
                                                }
                                        },
                                        labels: {
                                                format: '{value} %',
                                                style: {
-                                                       color: '#008800'
+                                                       color: '#000000'
                                                }
                                        },
 //                                     opposite: true
+                               }, { // Temperature -(ve)
+                                       labels: {
+                                               format: '{value}°C',
+                                               style: {
+                                                       color: '#0000ff'
+                                               }
+                                       },
+//                                     title: {
+//                                             text: 'Temperature',
+//                                             style: {
+//                                                     color: '#0000ff'
+//                                             }
+//                                     },
+                                       opposite: true
+
                                }],
                                tooltip: {
                                        shared: true
                                },
-                               legend: {
-                                       layout: 'vertical',
-                                       align: 'left',
-                                       x: 120,
-                                       verticalAlign: 'top',
-                                       y: 55,
-                                       floating: true,
-                                       backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
-                               },
+//                             legend: {
+//                                     layout: 'vertical',
+//                                     align: 'left',
+//                                     x: 120,
+//                                     verticalAlign: 'top',
+//                                     y: 55,
+//                                     floating: true,
+//                                     backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
+//                             },
                                exporting: {
                                        buttons: {
                                                contextButton: {
                                        name: 'Rainfall',
                                        type: 'column',
                                        yAxis: 1,
+                                       color: Highcharts.getOptions().colors[0],
                                        labels: {
 //                                             enabled: true,
 //                                             format: '{point.y:.1f}', // one decimal
                                        name: 'Sea-Level Pressure',
                                        type: 'spline',
                                        yAxis: 2,
+                                       color: '#008800',
                                        data: [
                                                <% $s = "";
                                                   for (@main::last5daysh) { 
                                                valueSuffix: ' mb'
                                        }
 
-                               }, {
-                                       name: 'Temperature',
+                               },  {
+                                       name: 'Temperature +(ve)',
                                        type: 'spline',
                                        yAxis: 0,
                                        color: '#ff0000',
                                        data: [
-                                               <% $s = "";
+                                               <% $s = ""; undef $lasttemp;
                                                   for (@main::last5daysh) { 
                                                      my $r = $main::json->decode($_);
-                                                     $s .=  "[" . $r->{t}*1000 . "," . $r->{h}->{Temp_Out} . "]," if $r && exists $r->{t} && exists $r->{h}->{Temp_Out};
+                                                          if ($r && exists $r->{t} && exists $r->{h}->{Temp_Out}) {
+                                                                  my $temp = $r->{h}->{Temp_Out};
+                                                                  my $tm = $r->{t}*1000;
+                                                                  $lasttemp = $temp unless defined $lasttemp;
+                                                                  if ($temp > 0) {
+                                                                          $s .= sprintf "[%s,0],", $tm-1 if $lasttemp <= 0;
+                                                                          $s .= sprintf "[%s,%s],", $tm, $temp;
+                                                                  } else {
+                                                                          $s .= sprintf "[%s,%s],", $tm, $lasttemp > 0 ? 0 : "null";
+                                                                  }
+                                                                  $lasttemp = $temp;
+                                                          }
                                                   }
                                                   chop $s if length $s; 
                                                %><%= $s %>
                                }, {
                                        name: 'Humidity',
                                        type: 'spline',
-                                       color: '#008800',
+                                       color: '#000000',
                                        yAxis: 3,
                                        data: [
                                                <% $s = "";
                                        tooltip: {
                                                valueSuffix: ' %'
                                        }
+                               }, {
+                                       name: 'Temperature -(ve)',
+                                       type: 'spline',
+                                       yAxis: 0,
+                                       color: '#0000ff',
+                                       data: [
+                                               <% $s = ""; undef $lasttemp;
+                                                  for (@main::last5daysh) { 
+                                                      my $r = $main::json->decode($_);
+                                                          if ($r && exists $r->{t} && exists $r->{h}->{Temp_Out}) {
+                                                                  my $temp = $r->{h}->{Temp_Out};
+                                                                  my $tm = $r->{t}*1000;
+                                                                  $lasttemp = $temp unless defined $lasttemp;
+                                                                  if ($temp <= 0) {
+                                                                          $s .= sprintf "[%s,0],", $tm-1 if $lasttemp > 0;
+                                                                          $s .= sprintf "[%s,%s],", $tm, $temp;
+                                                                  } else {
+                                                                          $s .= sprintf "[%s,%s],", $tm, $lasttemp <= 0 ? 0 : "null";
+                                                                  }
+                                                                  $lasttemp = $temp;
+                                                          }
+                                                  }
+                                                  chop $s if length $s; 
+                                               %><%= $s %>
+                                       ],
+                                       tooltip: {
+                                               valueSuffix: ' °C'
+                                       }
                                }]
                        });
                }
                function fill_daychart(js, days) {
                        var rainfall = daychart.series[0].data.length > (days * 48);
                        var pressure = daychart.series[1].data.length > (days * 48);
-                       var temp = daychart.series[2].data.length > (days * 48);
+                       var temppos = daychart.series[2].data.length > (days * 48);
+                       var tempneg = daychart.series[4].data.length > (days * 48);
                        var humidity = daychart.series[3].data.length > (days * 48);
 
                        var hr = js.h;
 //                     do_debug(js.tm + " " + t + " " + te + "<br>"); 
                        daychart.series[0].addPoint(ra, true, rainfall);
                        daychart.series[1].addPoint(pr, true, pressure);
-                       daychart.series[2].addPoint(te, true, temp);
+                       if (lasttemp <= -100) {
+                               lasttemp = hr.Temp_Out;
+                       }
+                       if (hr.Temp_Out > 0) {
+                               if (lasttemp <= 0) {
+                                       daychart.series[2].addPoint([t, 0], true, temppos);
+                               }
+                               daychart.series[2].addPoint([t, hr.Temp_Out], true, temppos);
+                       } else {
+                               daychart.series[2].addPoint([t, (lasttemp > 0) ? 0 : null], true, temppos);
+                       }
+                       if (hr.Temp_Out <= 0) {
+                               if (lasttemp > 0) {
+                                       daychart.series[4].addPoint([t, 0], true, tempneg);
+                               }
+                               daychart.series[4].addPoint([t, hr.Temp_Out], true, tempneg);
+                       } else {
+                               daychart.series[4].addPoint([t, (lasttemp <= 0) ? 0 : null], true, tempneg);
+                       }
+                       lasttemp = hr.Temp_Out;
                        daychart.series[3].addPoint(hu, true, humidity);
                }
 
 
                </script>
 
+               <div id="container">
+                       <center>
+                               <h4>Two Day Forecast</h2>
+                               <a href="http://www.yr.no/place/United_Kingdom/England/Graffham~2648243/hour_by_hour.html"><img src="http://www.yr.no/place/United_Kingdom/England/Graffham~2648243/avansert_meteogram.png" alt="meteogram" title="" height="295" width="810"></a>
+                       </center>
+               </div>
+
                <div id="container">
                        <div id="daychart" style="min-width: 400px; height: 400px; margin: 0 auto"> </div>
                </div>
                                <br><br>
                                <table class="table">
                                        <tr>
-                                               <th>Time:</th><td><span id="tm"> </span></td>
-                                               <th>Sunrise:</th><td><span id="Sunrise"> </span></td>
-                                               <th>Sunset:</th><td><span id="Sunset"> </span></td>
-                                               <th>Console Volts:</th><td><span id="Batt_Console"> </span></td>
-                                               <th>TX Battery OK:</th><td><span id="Batt_TX_OK"> </span></td>
+                                               <th width="7%">Time:</th><td width="7%"><span id="tm"> </span></td>
+                                               <th width="7%">Sunrise:</th><td width="7%"><span id="Sunrise"> </span></td>
+                                               <th width="7%">Sunset:</th><td width="7%"><span id="Sunset"> </span></td>
+                                               <th width="7%">Console Volts:</th><td width="7%"><span id="Batt_Console"> </span></td>
+                                               <th width="7%">TX Battery OK:</th><td width="7%"><span id="Batt_TX_OK"> </span></td>
                                        </tr>
                                        <tr>
-                                               <th>Pressure:</th><td><span id="Pressure"> </span></td>
+                                               <th>Pressure:</th><td><span id="Pressure"> </span> mb</td>
                                                <th>Trend:</th><td><span id="Pressure_Trend_txt"> </span></td>
                                        </tr>
                                        <tr>
-                                               <th>Temperature in:</th><td> <span id="Temp_In"> </span></td>
-                                               <th>Humidity:</th><td> <span id="Humidity_In"> </span></td>
+                                               <th>Temperature in:</th><td> <span id="Temp_In"> </span> °C</td>
+                                               <th>Humidity:</th><td> <span id="Humidity_In"> </span> %</td>
                                        </tr>
-                                       <tr><th>Temperature out:</th><td> <span id="Temp_Out"> </span></td>
-                                               <th>Min:</th><td> <span id="Temp_Out_Min"> </span> @ <span id="Temp_Out_Min_T"> </span></td>
-                                               <th>Max:</th><td> <span id="Temp_Out_Max"> </span> @ <span id="Temp_Out_Max_T"> </span></td>
-                                               <th>Humidity:</th><td> <span id="Humidity_Out"> </span></td>
-                                               <th>Dew Point:</th><td> <span id="Dew_Point"> </span></td>
+                                       <tr><th>Temperature out:</th><td> <span id="Temp_Out"> </span> °C</td>
+                                               <th>Min:</th><td> <span id="Temp_Out_Min"> </span> °C @ <span id="Temp_Out_Min_T"> </span></td>
+                                               <th>Max:</th><td> <span id="Temp_Out_Max"> </span> °C @ <span id="Temp_Out_Max_T"> </span></td>
+                                               <th>Humidity:</th><td> <span id="Humidity_Out"> </span> %</td>
+                                               <th>Dew Point:</th><td> <span id="Dew_Point"> </span> °C</td>
                                        </tr>
-                                       <tr><th>Wind:</th><td><span id="Wind"> </span> m/s @ <span id="Dir"> </span> deg</td>
-                                               <th>Wind Dir Minute Avg:</th><td> <span id="Dir_1m">  </span></td>
-                                               <th>Wind Speed Minute Avg:</th><td> <span id="Wind_1m">  </span></td>
+                                       <tr><th>Wind:</th><td><span id="Dir"> </span> ° @ <span id="Wind"> </span> mph</td>
+                                               <th>Wind Minute Avg:</th><td> <span id="Dir_1m"> </span> ° @ <span id="Wind_1m"> </span> mph </td>
+                                               <th>Day Max Speed:</th><td> <span id="Wind_Max"> </span> mph @ <span id="Wind_Max_T"> </span></td>
+                                               <th>Wind Chill:</th><td> <span id="WindChill"> °C</span></td>
                                        </tr>
                                        <tr>
-                                               <th>Rain 30mins:</th><td> <span id="Rain_1h"> </span></td>
-                                               <th>Day:</th><td> <span id="Rain_Day"> </span></td>
-                                               <th>24hrs:</th><td> <span id="Rain_24h"> </span></td>
-                                               <th>Month:</th><td> <span id="Rain_Month"> </span></td>
-                                               <th>Year:</th><td> <span id="Rain_Year"> </span></td>
+                                               <th>Rain 30mins:</th><td> <span id="Rain_1h"> </span> mm</td>
+                                               <th>Day:</th><td> <span id="Rain_Day"> </span> mm</td>
+                                               <th>24hrs:</th><td> <span id="Rain_24h"> </span> mm</td>
+                                               <th>Month:</th><td> <span id="Rain_Month"> </span> mm</td>
+                                               <th>Year:</th><td> <span id="Rain_Year"> </span> mm</td>
                                        </tr>
                                </table>
                        </div>