Mercurial > hg > egg-tcls
comparison fetch_weather.pl @ 410:5c97006c89e6
fetch_weather: Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 07 Jan 2017 17:56:11 +0200 |
parents | b05da2077e44 |
children | fe47617e7251 |
comparison
equal
deleted
inserted
replaced
409:3a9e565c1676 | 410:5c97006c89e6 |
---|---|
97 # 2012-02-27T00:00:00Z | 97 # 2012-02-27T00:00:00Z |
98 return time2str("%Y-%m-%dT%TZ", $_[0], "UTC"); | 98 return time2str("%Y-%m-%dT%TZ", $_[0], "UTC"); |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 ### | |
103 ### Helper functions | |
104 ### | |
105 | |
106 my %th_rain_states = | 102 my %th_rain_states = |
107 ( | 103 ( |
108 "Pouta" => "poutaa", | 104 "Pouta" => "poutaa", |
109 "Heikko" => "heikkoa sadetta", | 105 "Heikko" => "heikkoa sadetta", |
110 "Kohtalainen" => "kohtalaista sadetta", | 106 "Kohtalainen" => "kohtalaista sadetta", |
144 } | 140 } |
145 return $tmp; | 141 return $tmp; |
146 } | 142 } |
147 | 143 |
148 | 144 |
145 ### Return either data or if not defined, empty string | |
149 sub plonk_data($) | 146 sub plonk_data($) |
150 { | 147 { |
151 return defined($_[0]) ? $_[0] : ""; | 148 return defined($_[0]) ? $_[0] : ""; |
152 } | 149 } |
153 | 150 |
154 | 151 |
152 ### Same as plonk_data() but also lowercase the data string | |
155 sub plonk_data_lc($) | 153 sub plonk_data_lc($) |
156 { | 154 { |
157 return defined($_[0]) ? lc($_[0]) : ""; | 155 return defined($_[0]) ? lc($_[0]) : ""; |
158 } | 156 } |
159 | 157 |
485 goto skip_it; | 483 goto skip_it; |
486 } | 484 } |
487 # XXX Hashify the array into lat/long keys | 485 # XXX Hashify the array into lat/long keys |
488 | 486 |
489 # This is horrible :S | 487 # This is horrible :S |
490 my $fcrap = $fdata->{"om:featureOfInterest"}{"sams:SF_SpatialSamplingFeature"}{"sams:shape"}{"gml:MultiPoint"}{"gml:pointMember"}; | |
491 my $nrecords = 0; | 488 my $nrecords = 0; |
492 foreach my $xnode (@{$fcrap}) | 489 foreach my $xnode (@{$fdata->{"om:featureOfInterest"}{"sams:SF_SpatialSamplingFeature"}{"sams:shape"}{"gml:MultiPoint"}{"gml:pointMember"}}) |
493 { | 490 { |
494 my $floc = $xnode->{"gml:Point"}; | 491 my $floc = $xnode->{"gml:Point"}; |
495 if ($floc->{"gml:pos"} =~ /^\s*([\+\-]?\d+\.\d*)\s+([\+\-]?\d+\.\d*)\s*$/) | 492 if ($floc->{"gml:pos"} =~ /^\s*([\+\-]?\d+\.\d*)\s+([\+\-]?\d+\.\d*)\s*$/) |
496 { | 493 { |
497 my ($flat, $flong) = ($1, $2); | 494 my ($flat, $flong) = ($1, $2); |
498 | 495 |
499 # Should use a hash - | 496 # Should use a hash - |
500 foreach my $flol (@farray) | 497 foreach my $frec (@farray) |
501 { | 498 { |
502 if ($flol->{"lat"} == $flat && $flol->{"long"} == $flong && | 499 if ($frec->{"lat"} == $flat && $frec->{"long"} == $flong && |
503 $floc->{"gml:name"} ne "") | 500 $floc->{"gml:name"} ne "") |
504 { | 501 { |
505 $nrecords++; | 502 $nrecords++; |
506 $weatherdata->{$floc->{"gml:name"}} = | 503 $weatherdata->{$floc->{"gml:name"}} = |
507 [ | 504 [ |
508 1, | 505 1, |
509 plonk_data($flol->{"time"}), | 506 |
510 plonk_data($flol->{"temperature"}), | 507 plonk_data($frec->{"time"}), |
511 | 508 plonk_data($frec->{"temperature"}), |
512 plonk_data($flol->{"humidity"}), | 509 |
513 plonk_data($flol->{"windspeedms"}), | 510 plonk_data($frec->{"humidity"}), |
514 translate_clouds(plonk_data($flol->{"totalcloudcover"})), | 511 plonk_data($frec->{"windspeedms"}), |
512 translate_clouds(plonk_data($frec->{"totalcloudcover"})), | |
515 ]; | 513 ]; |
516 } | 514 } |
517 } | 515 } |
518 } | 516 } |
519 } | 517 } |