comparison fetch_weather.pl @ 349:f7793ef7c925

fetch_weather: Improve debugging.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 01 Nov 2015 22:04:45 +0200
parents 3fff571a904b
children 19b363586b40
comparison
equal deleted inserted replaced
348:9f64f54c2fb3 349:f7793ef7c925
282 print STDERR $res->decoded_content."\n\n"; 282 print STDERR $res->decoded_content."\n\n";
283 } 283 }
284 else 284 else
285 { 285 {
286 my $data = $xml->{"soap:Body"}{"RoadWeatherResponse"}; 286 my $data = $xml->{"soap:Body"}{"RoadWeatherResponse"};
287 print STDERR "Checking Tiehallinto response from ".$uri."\n" if (opt_get_int("debug") > 0);
287 288
288 # Check if we need to update the static meta data 289 # Check if we need to update the static meta data
289 my $meta_file = opt_get("tiehallinto_static_meta"); 290 my $meta_file = opt_get("tiehallinto_static_meta");
290 my $fetch_meta = (-e $meta_file) ? 0 : 1; 291 my $fetch_meta = (-e $meta_file) ? 0 : 1;
291 292
330 } 331 }
331 332
332 # Parse XML and combine with the station meta data 333 # Parse XML and combine with the station meta data
333 if (defined($data->{"roadweatherdata"})) 334 if (defined($data->{"roadweatherdata"}))
334 { 335 {
336 my $nrecords = 0;
335 foreach my $wdata (@{$data->{"roadweatherdata"}{"roadweather"}}) 337 foreach my $wdata (@{$data->{"roadweatherdata"}{"roadweather"}})
336 { 338 {
337 my $wid = $wdata->{"stationid"}; 339 my $wid = $wdata->{"stationid"};
338 if (defined($meta_data->{$wid})) 340 if (defined($meta_data->{$wid}))
339 { 341 {
342 $nrecords++;
340 $weatherdata->{$meta_data->{$wid}[3]} = 343 $weatherdata->{$meta_data->{$wid}[3]} =
341 [ 344 [
342 1, 345 1,
343 str2time(plonk_data($wdata->{"measurementtime"}{"utc"})), 346 str2time(plonk_data($wdata->{"measurementtime"}{"utc"})),
344 plonk_data($wdata->{"airtemperature1"}), 347 plonk_data($wdata->{"airtemperature1"}),
346 plonk_data($wdata->{"humidity"}), 349 plonk_data($wdata->{"humidity"}),
347 plonk_data($wdata->{"averagewindspeed"}), 350 plonk_data($wdata->{"averagewindspeed"}),
348 ]; 351 ];
349 } 352 }
350 } 353 }
354 print STDERR $nrecords." records from Tiehallinto.\n" if (opt_get_int("debug") > 0);
351 } 355 }
352 else 356 else
353 { 357 {
354 print STDERR "ERROR: Invalid (or unsupported) road weather data blob.\n"; 358 print STDERR "ERROR: Invalid (or unsupported) road weather data blob.\n";
355 print STDERR $res->decoded_content."\n\n"; 359 print STDERR $res->decoded_content."\n\n";
419 { 423 {
420 my $floc = $xnode->{"gml:Point"}; 424 my $floc = $xnode->{"gml:Point"};
421 if ($floc->{"gml:pos"} =~ /^\s*([\+\-]?\d+\.\d*)\s+([\+\-]?\d+\.\d*)\s*$/) 425 if ($floc->{"gml:pos"} =~ /^\s*([\+\-]?\d+\.\d*)\s+([\+\-]?\d+\.\d*)\s*$/)
422 { 426 {
423 my ($flat, $flong) = ($1, $2); 427 my ($flat, $flong) = ($1, $2);
428 my $nrecords = 0;
429
424 # Should use a hash - 430 # Should use a hash -
425 foreach my $flol (@farray) 431 foreach my $flol (@farray)
426 { 432 {
427 if ($flol->{"lat"} == $flat && $flol->{"long"} == $flong) 433 if ($flol->{"lat"} == $flat && $flol->{"long"} == $flong)
428 { 434 {
435 $nrecords++;
429 $weatherdata->{$floc->{"gml:name"}} = 436 $weatherdata->{$floc->{"gml:name"}} =
430 [ 437 [
431 1, 438 1,
432 plonk_data($flol->{"time"}), 439 plonk_data($flol->{"time"}),
433 plonk_data($flol->{"temperature"}), 440 plonk_data($flol->{"temperature"}),
436 plonk_data($flol->{"windspeedms"}), 443 plonk_data($flol->{"windspeedms"}),
437 translate_clouds(plonk_data($flol->{"totalcloudcover"})), 444 translate_clouds(plonk_data($flol->{"totalcloudcover"})),
438 ]; 445 ];
439 } 446 }
440 } 447 }
448 print STDERR $nrecords." records from FMI.\n" if (opt_get_int("debug") > 0);
441 } 449 }
442 } 450 }
443 } else { 451 } else {
444 # defined 452 # defined
445 print STDERR "Invalid XML received:\n"; 453 print STDERR "Invalid XML received:\n";