]> scm.dxcluster.org Git - dweather.git/commitdiff
speed up load by embedding initial graphs values
authorDirk Koopman <djk@tobit.co.uk>
Sat, 18 Apr 2015 19:17:37 +0000 (20:17 +0100)
committerDirk Koopman <djk@tobit.co.uk>
Sat, 18 Apr 2015 19:17:37 +0000 (20:17 +0100)
Rather than sending them via websocket. Which seems incredibly slow.

Which is a worry...

loop.pl
templates/index.html.ep

diff --git a/loop.pl b/loop.pl
index 2768a009e92bbf74401deccf70db33d688b05da0..1a677d52360866d28f8e247bffbf1ca7dd406e21 100755 (executable)
--- 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);
  
index ec8487d4dd757560821ed0d5f24494355a5e633d..d54833ddb60467769593123512d9736da5c81ea7 100644 (file)
@@ -1,4 +1,5 @@
 % my $url = url_for 'weather';
+% my $s;
 <!DOCTYPE html>
 <html>
        <head>
                                        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'
                                        }
                                        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
                                        },
                                }, {
                                        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'
                                        }
                                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 %>
+                                       ]
                                }]
                        });
                }