From: Dirk Koopman Date: Sat, 18 Apr 2015 19:17:37 +0000 (+0100) Subject: speed up load by embedding initial graphs values X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=cbf57212d7962476d2f2e7bb966283ab4fc1e5ba;p=dweather.git speed up load by embedding initial graphs values Rather than sending them via websocket. Which seems incredibly slow. Which is a worry... --- diff --git a/loop.pl b/loop.pl index 2768a00..1a677d5 100755 --- a/loop.pl +++ b/loop.pl @@ -111,11 +111,6 @@ websocket '/weather' => sub { $c->send($ld->{lasthour_h}) if exists $ld->{lasthour_h}; $c->send($ld->{lastmin_h}) if exists $ld->{lastmin_h}; - # send the 5 days worth of data to the graph - say "last10min = " . scalar @last10minsr . " last5day = " . scalar @last5daysh; - $c->send($_) for @last10minsr; - $c->send($_) for @last5daysh; - # disable timeout $c->inactivity_timeout(3615); diff --git a/templates/index.html.ep b/templates/index.html.ep index ec8487d..d54833d 100644 --- a/templates/index.html.ep +++ b/templates/index.html.ep @@ -1,4 +1,5 @@ % my $url = url_for 'weather'; +% my $s; @@ -180,7 +181,15 @@ name: 'Rainfall', type: 'column', yAxis: 1, - data: [], + data: [ + <% $s = ""; + for (@main::last5daysh) { + my $r = $main::json->decode($_); + $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Rain_1h} . "]," if $r; + } + chop $s if length $s; + %><%= $s %> + ], tooltip: { valueSuffix: ' mm' } @@ -189,7 +198,15 @@ name: 'Sea-Level Pressure', type: 'spline', yAxis: 2, - data: [], + data: [ + <% $s = ""; + for (@main::last5daysh) { + my $r = $main::json->decode($_); + $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Pressure} . "]," if $r; + } + chop $s if length $s; + %><%= $s %> + ], marker: { enabled: false }, @@ -201,7 +218,15 @@ }, { name: 'Temperature', type: 'spline', - data: [], + data: [ + <% $s = ""; + for (@main::last5daysh) { + my $r = $main::json->decode($_); + $s .= "[" . $r->{t}*1000 . "," . $r->{h}->{Temp_Out} . "]," if $r; + } + chop $s if length $s; + %><%= $s %> + ], tooltip: { valueSuffix: ' °C' } @@ -325,7 +350,23 @@ series: [ { type: 'scatter', name: 'Wind mph', - data: [] + data: [ + <% my ($d, $w); + $s = ""; + $d = 0; $w = 0; + for (@main::last10minsr) { + my $r = $main::json->decode($_); + 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; + $d = $r->{r}->{Dir}; + $w = $r->{r}->{Wind}; + } + } + chop $s if length $s; + %><%= $s %> + ] }] }); }