add maxwind, pressure to .1, improve ui
authorDirk Koopman <djk@tobit.co.uk>
Wed, 9 Dec 2015 22:27:54 +0000 (22:27 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Wed, 9 Dec 2015 22:27:54 +0000 (22:27 +0000)
Added facility to record the maximum wind gust and time per day.
Change the accuracy of the barometer from int to one dec pl.
Fix the size of the columns in the UI to stop the constant changing of widths
with data changes

loop.pl
templates/index.html.ep

diff --git a/loop.pl b/loop.pl
index bdc06d6e01f6e87d8d0d93f2573b3784706af69e..02a463a7d3f1569eda6f6065b4a6cf4e1007e2ad 100755 (executable)
--- a/loop.pl
+++ b/loop.pl
@@ -348,7 +348,7 @@ sub process
 
                # Common ones
                $tmp = unpack("s", substr $blk,7,2) / 1000;
-               $h{Pressure} = nearest(1, in2mb($tmp));
+               $h{Pressure} = nearest(0.1, in2mb($tmp));
 
                $tmp = unpack("s", substr $blk,9,2) / 10;
                $h{Temp_In} = nearest(0.1, f2c($tmp));
@@ -421,22 +421,31 @@ sub process
                my $ts = time;
                my $s;
                my $dayno = int($ts/86400);
+               my $writeld;
+               my $cycledata;
+               
                if ($dayno > $ld->{last_day}) {
-                       $ld->{Temp_Out_Max} = $ld->{Temp_Out_Min} = $temp;
-                       $ld->{Temp_Out_Max_T} = $ld->{Temp_Out_Min_T} = clocktime($ts, 0);
+                       $ld->{Temp_Out_Max} = $ld->{Temp_Out_Min} = $ld->{Wind_Max} = $temp;
+                       $ld->{Temp_Out_Max_T} = $ld->{Temp_Out_Min_T} = $ld->{Wind_Max_T} = clocktime($ts, 0);
                        $ld->{last_day} = $dayno;
-                       write_ld();
-                       cycle_loop_data_files();
+                       ++$writeld;
+                       ++$cycledata;
                }
                if ($temp > $ld->{Temp_Out_Max}) {
-                       $ld->{Temp_Out_Max} = $temp;
-                       $ld->{Temp_Out_Max_T} = clocktime($ts, 0);
-                       write_ld();
+                       $h{Temp_Out_Max} = $ld->{Temp_Out_Max} = $temp;
+                       $h{Temp_Out_Max_T} = $ld->{Temp_Out_Max_T} = clocktime($ts, 0);
+                       ++$writeld;
                }
                if ($temp < $ld->{Temp_Out_Min}) {
-                       $ld->{Temp_Out_Min} = $temp;
-                       $ld->{Temp_Out_Min_T} = clocktime($ts, 0);
-                       write_ld();
+                       $h{Temp_Out_Min} = $ld->{Temp_Out_Min} = $temp;
+                       $h{Temp_Out_Min_T} = $ld->{Temp_Out_Min_T} = clocktime($ts, 0);
+                       ++$writeld;
+               }
+
+               if ($wind->{w} > $ld->{Wind_Max}) {
+                       $h{Wind_Max} = $ld->{Wind_Max} = $wind->{w};
+                       $h{Wind_Max_T} = $ld->{Wind_Max_T} = clocktime($ts, 0);
+                       ++$writeld;
                }
 
                if ($ts >= $ld->{last_hour} + 1800) {
@@ -450,11 +459,6 @@ sub process
                        $h{Sunrise}  =~ s/(\d{2})(\d{2})/$1:$2/;
                        $h{Sunset}   = sprintf( "%04d", unpack("S", substr $blk,93,2) );
                        $h{Sunset}  =~ s/(\d{2})(\d{2})/$1:$2/;
-                       $h{Temp_Out_Max} = $ld->{Temp_Out_Max};
-                       $h{Temp_Out_Min} = $ld->{Temp_Out_Min};
-                       $h{Temp_Out_Max_T} = $ld->{Temp_Out_Max_T};
-                       $h{Temp_Out_Min_T} = $ld->{Temp_Out_Min_T};
-                       
 
                        if ($loop_count) {      # i.e not the first
                                my $a = wind_average(scalar @{$ld->{wind_hour}} ? @{$ld->{wind_hour}} : {w => $h{Wind}, d => $h{Dir}});
@@ -467,8 +471,15 @@ sub process
                                $h{Dir_1m} = nearest(1, $a->{d});
 
                                ($h{Rain_1m}, $h{Rain_1h}, $h{Rain_24h}) = calc_rain($rain);
+                               
                        }
                        $ld->{last_rain_min} = $ld->{last_rain_hour} = $rain;
+                       $h{Temp_Out_Max} = $ld->{Temp_Out_Max};
+                       $h{Temp_Out_Max_T} = $ld->{Temp_Out_Max_T};
+                       $h{Temp_Out_Min} = $ld->{Temp_Out_Min};
+                       $h{Temp_Out_Min_T} = $ld->{Temp_Out_Min_T};
+                       $h{Wind_Max} = $ld->{Wind_Max};
+                       $h{Wind_Max_T} = $ld->{Wind_Max_T};
 
                        $last_hour_h = {%h};
                        $s = genstr($ts, 'h', \%h);
@@ -484,7 +495,7 @@ sub process
                                push @last5daysh, $s;
                                shift @last5daysh if @last5daysh > 5*24;
                        }
-                       write_ld();
+                       ++$writeld;
                        
                } elsif ($ts >= $ld->{last_min} + 60) {
                        my $a = wind_average(@{$ld->{wind_min}});
@@ -500,11 +511,12 @@ sub process
                                ($h{Rain_1m}, $h{Rain_1h}, $h{Rain_24h}) = calc_rain($rain);
                        }
                        $ld->{last_rain_min} = $rain;
-
                        $h{Temp_Out_Max} = $ld->{Temp_Out_Max};
-                       $h{Temp_Out_Min} = $ld->{Temp_Out_Min};
                        $h{Temp_Out_Max_T} = $ld->{Temp_Out_Max_T};
+                       $h{Temp_Out_Min} = $ld->{Temp_Out_Min};
                        $h{Temp_Out_Min_T} = $ld->{Temp_Out_Min_T};
+                       $h{Wind_Max} = $ld->{Wind_Max};
+                       $h{Wind_Max_T} = $ld->{Wind_Max_T};
 
                        $last_min_h = {%h};
                        $s = genstr($ts, 'm', \%h);
@@ -514,7 +526,7 @@ sub process
                        @{$ld->{wind_min}} = ();
                        
                        output_str($s, 1) if $s;
-                       write_ld();
+                       ++$writeld;
 
                } else {
                        my $o = gen_hash_diff($ld->{last_h}, \%h);
@@ -533,6 +545,8 @@ sub process
                        output_str($s, 0) if $s;
                }
                $ld->{last_h} = \%h;
+               write_ld() if $writeld;
+               cycle_loop_data_files() if $cycledata;
                ++$loop_count;
        } else {
                dbg "CRC check failed for LOOP data!";
index 1b907ee9ae962b9d7b9d7f449ead6c8d6a357b65..c8ef3b52ad6eafc00a3f5857d8bd49e24d42d5ef 100644 (file)
                                <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> m/s</td>
+                                               <th>Wind Minute Avg:</th><td> <span id="Dir_1m"> </span> ° @ <span id="Wind_1m"> </span> m/s </td>
+                                               <th>Day Max Speed:</th><td> <span id="Wind_Max"> </span> m/s @ <span id="Wind_Max_T"> </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>