changeset 410:5c97006c89e6

fetch_weather: Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 07 Jan 2017 17:56:11 +0200
parents 3a9e565c1676
children fe47617e7251
files fetch_weather.pl
diffstat 1 files changed, 11 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/fetch_weather.pl	Sat Jan 07 05:15:09 2017 +0200
+++ b/fetch_weather.pl	Sat Jan 07 17:56:11 2017 +0200
@@ -99,10 +99,6 @@
 }
 
 
-###
-### Helper functions
-###
-
 my %th_rain_states =
 (
   "Pouta" => "poutaa",
@@ -146,12 +142,14 @@
 }
 
 
+### Return either data or if not defined, empty string
 sub plonk_data($)
 {
   return defined($_[0]) ? $_[0] : "";
 }
 
 
+### Same as plonk_data() but also lowercase the data string
 sub plonk_data_lc($)
 {
   return defined($_[0]) ? lc($_[0]) : "";
@@ -487,9 +485,8 @@
       # XXX Hashify the array into lat/long keys
 
       # This is horrible :S
-      my $fcrap = $fdata->{"om:featureOfInterest"}{"sams:SF_SpatialSamplingFeature"}{"sams:shape"}{"gml:MultiPoint"}{"gml:pointMember"};
       my $nrecords = 0;
-      foreach my $xnode (@{$fcrap})
+      foreach my $xnode (@{$fdata->{"om:featureOfInterest"}{"sams:SF_SpatialSamplingFeature"}{"sams:shape"}{"gml:MultiPoint"}{"gml:pointMember"}})
       {
         my $floc = $xnode->{"gml:Point"};
         if ($floc->{"gml:pos"} =~ /^\s*([\+\-]?\d+\.\d*)\s+([\+\-]?\d+\.\d*)\s*$/)
@@ -497,21 +494,22 @@
           my ($flat, $flong) = ($1, $2);
 
           # Should use a hash -
-          foreach my $flol (@farray)
+          foreach my $frec (@farray)
           {
-            if ($flol->{"lat"} == $flat && $flol->{"long"} == $flong &&
+            if ($frec->{"lat"} == $flat && $frec->{"long"} == $flong &&
                 $floc->{"gml:name"} ne "")
             {
               $nrecords++;
               $weatherdata->{$floc->{"gml:name"}} =
               [
                 1,
-                plonk_data($flol->{"time"}),
-                plonk_data($flol->{"temperature"}),
+
+                plonk_data($frec->{"time"}),
+                plonk_data($frec->{"temperature"}),
 
-                plonk_data($flol->{"humidity"}),
-                plonk_data($flol->{"windspeedms"}),
-                translate_clouds(plonk_data($flol->{"totalcloudcover"})),
+                plonk_data($frec->{"humidity"}),
+                plonk_data($frec->{"windspeedms"}),
+                translate_clouds(plonk_data($frec->{"totalcloudcover"})),
               ];
             }
           }