From: Dirk Koopman <djk@tobit.co.uk> Date: Sat, 18 Apr 2015 21:26:19 +0000 (+0100) Subject: fix main graph history slurping X-Git-Url: http://dxspider.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=66549cb3124dc06a95960142da8c364fae031487;p=dweather.git fix main graph history slurping Remove buttons from widgets. Fully parameterise the amount of slurping. --- diff --git a/loop.pl b/loop.pl index 1a677d5..fe91657 100755 --- a/loop.pl +++ b/loop.pl @@ -42,6 +42,8 @@ our $WS = {}; # websocket connections our $ld = {}; our @last10minsr = (); our @last5daysh = (); +our $windmins = 5; # 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 $loop_count; # how many LOOPs we have done, used as start indicator @@ -152,8 +154,11 @@ read_ld(); my $tnow = time; my $dayno = int ($tnow/86400); -@last5daysh = grab_history(SMGLog->new("day"), "h", $tnow-(86400*5), $_) for ($dayno-4, $dayno-3, $dayno-2, $dayno-1, $dayno); -@last10minsr = map {my ($t, $js) = split(/\s/, $_, 2); $js} grab_history(SMGLog->new("debug"), "r", $tnow-(60*3), $dayno); +for (my $i = 0-$histdays; $i < 0; ++$i ) { + push @last5daysh, grab_history(SMGLog->new("day"), "h", $tnow-(86400*$histdays), $dayno+$i+1); +} +@last10minsr = map {my ($t, $js) = split(/\s/, $_, 2); $js} grab_history(SMGLog->new("debug"), "r", $tnow-(60*$windmins), $dayno); +dbg sprintf("last5days = %d last10mins = %d", scalar @last5daysh, scalar @last10minsr); our $dlog = SMGLog->new("day"); dbg "before next tick"; diff --git a/templates/index.html.ep b/templates/index.html.ep index d54833d..cd8155a 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -21,9 +21,9 @@ <script> var ws; var daychart; - var daychart_days = 5; + var daychart_days = <%= $main::histdays %>; var windrose; - var windrose_mins = 10; + var windrose_mins = <%= $main::windmins %>; var windspeed; var winddir; @@ -85,7 +85,7 @@ js.r.Dir = lastdir; } lastt = js.t; - fill_windrose(js, windrose_mins * (60 / 2.5)); + fill_windrose(js, windrose_mins * 24); // } fill_windspeed(js); fill_winddir(js); @@ -177,6 +177,13 @@ floating: true, backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF' }, + exporting: { + buttons: { + contextButton: { + enabled: false + } + } + }, series: [{ name: 'Rainfall', type: 'column', @@ -185,7 +192,7 @@ <% $s = ""; for (@main::last5daysh) { my $r = $main::json->decode($_); - $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Rain_1h} . "]," if $r; + $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Rain_1h} . "]," if $r && exists $r->{t} && exists $r->{h}->{Rain_1h}; } chop $s if length $s; %><%= $s %> @@ -202,7 +209,7 @@ <% $s = ""; for (@main::last5daysh) { my $r = $main::json->decode($_); - $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Pressure} . "]," if $r; + $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Pressure} . "]," if $r && exists $r->{t} && exists $r->{h}->{Pressure}; } chop $s if length $s; %><%= $s %> @@ -222,7 +229,7 @@ <% $s = ""; for (@main::last5daysh) { my $r = $main::json->decode($_); - $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Temp_Out} . "]," if $r; + $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Temp_Out} . "]," if $r && exists $r->{t} && exists $r->{h}->{Temp_Out}; } chop $s if length $s; %><%= $s %> @@ -346,9 +353,16 @@ groupPadding: 0 } }, + exporting: { + buttons: { + contextButton: { + enabled: false + } + } + }, series: [ { - type: 'scatter', + type: 'column', name: 'Wind mph', data: [ <% my ($d, $w); @@ -359,7 +373,7 @@ if ($r) { $r->{r}->{Dir} ||= $d; $r->{r}->{Wind} ||= $w; - $s .= "[" . $r->{r}->{Dir} . "," . main::nearest(0.1, $r->{r}->{Wind}*2.23694) . "]," if $r; + $s .= "[" . $r->{r}->{Dir} . "," . main::nearest(0.1, $r->{r}->{Wind}*2.23694) . "],"; $d = $r->{r}->{Dir}; $w = $r->{r}->{Wind}; } @@ -456,6 +470,13 @@ color: '#DF5353' // red }] }, + exporting: { + buttons: { + contextButton: { + enabled: false + } + } + }, series: [{ name: 'Speed', @@ -539,6 +560,13 @@ text: '° deg' }, }, + exporting: { + buttons: { + contextButton: { + enabled: false + } + } + }, series: [{ name: 'Direction',