]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Command/WeatherCommand.php
Add skip on weather unavailable data when startup timeout makes us miss upstream...
[airbundle] / Command / WeatherCommand.php
index 64cadd006bca5081ab1b62436a418f4de05a7314..c2aae61dc4451ffcb5a8e0e3b1411745bd40168d 100644 (file)
@@ -265,14 +265,16 @@ class WeatherCommand extends DoctrineCommand {
                                                //Get rainrisk
                                                $rainrisk = str_replace('%', '', trim($node->div[0]->div[0]->div[1]))/100;
 
-                                               //Label is Rain when we have a rainfall
-                                               if (($pluviolabel = trim($node->div[1]->div[0]->div[0]->div[1]->p[1])) == 'Rain') {
-                                                       //Get rainfall
-                                                       $rainfall = str_replace(' mm', '', $node->div[1]->div[0]->div[0]->div[1]->p[1]->span[0]);
-                                               //Cloud Cover, no rainfall
-                                               } else {
-                                                       //Set rainfall to 0 (mm)
-                                                       $rainfall = 0;
+                                               //Set rainfall to 0 (mm)
+                                               $rainfall = 0;
+
+                                               //Iterate on each entry
+                                               foreach($node->div[1]->div[0]->div[0]->div[1]->p as $p) {
+                                                       //Lookup for rain entry if present
+                                                       if (trim($p) == 'Rain') {
+                                                               //Get rainfall
+                                                               $rainfall = floatval(str_replace(' mm', '', $p->span[0]));
+                                                       }
                                                }
 
                                                //Store data
@@ -341,11 +343,11 @@ class WeatherCommand extends DoctrineCommand {
                                        $hour = $type=='daily'?$type:$time->format('H');
 
                                        //Check data availability
-                                       //XXX: should never happen
-                                       #if (!isset($data[$zipcode][$dsm][$hour])) {
-                                       #       //Skip unavailable data
-                                       #       continue;
-                                       #}
+                                       //XXX: sometimes startup delay causes weather data to be unavailable for session first hour
+                                       if (!isset($data[$zipcode][$dsm][$hour])) {
+                                               //Skip unavailable data
+                                               continue;
+                                       }
 
                                        //Set info alias
                                        $info = $data[$zipcode][$dsm][$hour];