]> scm.dxcluster.org Git - dweather.git/commitdiff
fix windrose and other tarting
authorDirk Koopman <djk@tobit.co.uk>
Mon, 4 May 2015 13:33:45 +0000 (14:33 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Mon, 4 May 2015 13:33:45 +0000 (14:33 +0100)
loop.pl
templates/index.html.ep

diff --git a/loop.pl b/loop.pl
index fe9165779d3ac551e9b0a66a9ecb5b943e9f016b..e287ce5913b0370d0aa32345ac6348b42b343541 100755 (executable)
--- a/loop.pl
+++ b/loop.pl
@@ -42,8 +42,9 @@ our $WS = {};                                 # websocket connections
 our $ld = {};
 our @last10minsr = ();
 our @last5daysh = ();
-our $windmins = 5;                             # no of minutes of wind data for the windrose
+our $windmins = 2;                             # no of minutes of wind data for the windrose
 our $histdays = 5;                             # no of days of (half)hour data to search for main graph
+our $updatepermin = 60 / 2.5;  # no of updates per minute
 
 our $loop_count;                               # how many LOOPs we have done, used as start indicator
 
@@ -164,6 +165,7 @@ our $dlog = SMGLog->new("day");
 dbg "before next tick";
 Mojo::IOLoop->next_tick(sub { loop() });       
 dbg "before app start";
+app->secrets([qw(Here's something that's really seakrett)]);
 app->start;
 dbg "after app start";
 
@@ -486,9 +488,13 @@ sub process
                } else {
                        my $o = gen_hash_diff($ld->{last_h}, \%h);
                        if ($o) {
+                               $o->{Dir} ||= $h{Dir};
+                               $o->{Wind} ||= $h{Wind};
+                               $o->{Dir} += 0;
+                               $o->{Wind} += 0;
                                $s = genstr($ts, 'r', $o);
                                push @last10minsr, $s;
-                               shift @last10minsr if @last10minsr > 240;
+                               shift @last10minsr while @last10minsr > ($windmins * $updatepermin);
                        }
                        else {
                                dbg "loop rec not changed" if isdbg 'chan';
index cd8155ac915383febf006cc071da7048e00738d5..2dd444fe94f7404d6aa13e8ce7febd4385a9188d 100644 (file)
                                                if ("h" in js) {
                                                        fill_daychart(js, daychart_days);
                                                }
-                                               if ("r" in js) {
-//                                                     if (js.t > lastt + 15) {
-                                                               if ("Wind" in js.r) {
-                                                                       lastwind = js.r.Wind;
-                                                               } else {
-                                                                       js.r.Wind = lastwind;
-                                                               }
-                                                               if ("Dir" in js.r) {
-                                                                       lastdir = js.r.dir;
-                                                               } else {
-                                                                       js.r.Dir = lastdir;
-                                                               }
-                                                               lastt = js.t;
-                                                               fill_windrose(js, windrose_mins * 24);
-//                                                     }
-                                                       fill_windspeed(js);
-                                                       fill_winddir(js);
+                                               if ("r" in js || "m" in js) {
+                                                       var rr;
+                                                       rr = js.r || js.m;
+                                                       if (!("Dir" in rr)) 
+                                                               rr.Dir = lastdir;
+                                                       if (!("Wind" in rr))
+                                                               rr.Wind = lastwind;
+                                                       fill_windrose(rr, windrose_mins * $updatespermin);
+                                                       fill_windspeed(rr);
+                                                       fill_winddir(rr);
+                                                       lastwind = rr.Wind;
+                                                       lastdir = rr.Dir;
                                                }
                                        }
                                };
                                        name: 'Rainfall',
                                        type: 'column',
                                        yAxis: 1,
+                                       labels: {
+//                                             enabled: true,
+//                                             format: '{point.y:.1f}', // one decimal
+//                                             rotation: -90,
+                                               overflow: 'justify'
+                                       },
                                        data: [ 
                                            <% $s = "";
                                                   for (@main::last5daysh) { 
                                }, 
 
                                series: [ {
-                                       type: 'column',
+                                       type: 'scatter',
                                        name: 'Wind mph',
                                        data: [
                                                <% my ($d, $w);
 
                                pane: {
                                        startAngle: 0,
-                                       endAngle: 359,
+                                       endAngle: 360,
                                        background: [{
                                                backgroundColor: {
                                                        linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 },
                                // the value axis
                                yAxis: {
                                        min: 0,
-                                       max: 360,
+                                       max: 359,
 
                                        minorTickInterval: 'auto',
                                        minorTickWidth: 1,
 
                var conv = 2.23694;
 
-               function fill_windrose(js, points) {
+               function fill_windrose(rr, points) {
                        var p = windrose.series[0].data.length > points;
-                       var rr = js.r;
-                       windrose.series[0].addPoint([rr.Dir, Math.round(rr.Wind*conv)], true, p);
+                       var v = [rr.Dir, (rr.Wind*conv)];
+                       windrose.series[0].addPoint(v, true, p);
                }
 
-               function fill_windspeed(js) {
-                       var rr = js.r;
+               function fill_windspeed(rr) {
                        var point = windspeed.series[0].points[0];
                        point.update(Math.round(rr.Wind*conv));
                }
 
-               function fill_winddir(js) {
-                       var rr = js.r;
+               function fill_winddir(rr) {
                        var point = winddir.series[0].points[0];
                        point.update(rr.Dir);
                }