From: Dirk Koopman Date: Mon, 4 May 2015 13:33:45 +0000 (+0100) Subject: fix windrose and other tarting X-Git-Url: http://gb7djk.dxcluster.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=b5935e862dc6dd1a6b6154905bac6db8836132d6;p=dweather.git fix windrose and other tarting --- diff --git a/loop.pl b/loop.pl index fe91657..e287ce5 100755 --- 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'; diff --git a/templates/index.html.ep b/templates/index.html.ep index cd8155a..2dd444f 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -72,23 +72,18 @@ 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; } } }; @@ -188,6 +183,12 @@ name: 'Rainfall', type: 'column', yAxis: 1, + labels: { +// enabled: true, +// format: '{point.y:.1f}', // one decimal +// rotation: -90, + overflow: 'justify' + }, data: [ <% $s = ""; for (@main::last5daysh) { @@ -362,7 +363,7 @@ }, series: [ { - type: 'column', + type: 'scatter', name: 'Wind mph', data: [ <% my ($d, $w); @@ -505,7 +506,7 @@ pane: { startAngle: 0, - endAngle: 359, + endAngle: 360, background: [{ backgroundColor: { linearGradient: { x1: 0, y1: 0, x2: 0, y2: 1 }, @@ -539,7 +540,7 @@ // the value axis yAxis: { min: 0, - max: 360, + max: 359, minorTickInterval: 'auto', minorTickWidth: 1, @@ -597,20 +598,18 @@ 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); }