[Xfce4-commits] <xfce4-weather-plugin:master> Forecast tab: Handle missing values (humidity, fog and cloud data).

Harald Judt noreply at xfce.org
Tue Jan 22 19:18:01 CET 2013


Updating branch refs/heads/master
         to 8fba78189557d56a41bfb6443ef4b9d7b96ef8c8 (commit)
       from 023d3e23a7ff9207f09b5b608915bcd253e9456d (commit)

commit 8fba78189557d56a41bfb6443ef4b9d7b96ef8c8
Author: Harald Judt <h.judt at gmx.at>
Date:   Tue Jan 22 19:05:53 2013 +0100

    Forecast tab: Handle missing values (humidity, fog and cloud data).
    
    Some values are missing in forecasts more than 3 days into the future:
    Humidity, fog, cloud data. Further, because humidity is required for
    the calculations, the dew point cannot be computed. This patch handles
    this case and thus fixes the tooltips of the affected forecast cells.
    
    Example location for reference: Oslo, Norway.

 panel-plugin/weather-data.c    |   16 ++++++++++++----
 panel-plugin/weather-summary.c |   11 +++++++----
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/panel-plugin/weather-data.c b/panel-plugin/weather-data.c
index 74e0839..16e0a1a 100644
--- a/panel-plugin/weather-data.c
+++ b/panel-plugin/weather-data.c
@@ -32,6 +32,8 @@
 #define NIGHT_TIME_START 21
 #define NIGHT_TIME_END 5
 
+/* If some value is not present or cannot be computed, return this instead */
+#define INVALID_VALUE -9999
 
 #define CHK_NULL(s) ((s) ? g_strdup(s) : g_strdup(""))
 
@@ -129,10 +131,14 @@ timeslice_is_interval(xml_time *timeslice)
 static gdouble
 calc_dewpoint(const xml_location *loc)
 {
-    gdouble temp = string_to_double(loc->temperature_value, 0);
-    gdouble humidity = string_to_double(loc->humidity_value, 0);
-    gdouble val = log(humidity / 100);
+    gdouble temp, humidity, val;
+
+    if (G_UNLIKELY(loc->humidity_value == NULL))
+        return INVALID_VALUE;
 
+    temp = string_to_double(loc->temperature_value, 0);
+    humidity = string_to_double(loc->humidity_value, 0);
+    val = log(humidity / 100);
     return (241.2 * val + 4222.03716 * temp / (241.2 + temp))
         / (17.5043 - val - 17.5043 * temp / (241.2 + temp));
 }
@@ -227,7 +233,7 @@ calc_apparent_temperature(const xml_location *loc,
             /* dew point needs to be above a certain limit for
                valid results, see
                http://www.weatheroffice.gc.ca/mainmenu/faq_e.html#weather5 */
-            if (dp < 0)
+            if (dp < 0 || dp == INVALID_VALUE)
                 return temp;
 
             /* dew point needs to be converted to Kelvin (easy job ;-) */
@@ -339,6 +345,8 @@ get_data(const xml_time *timeslice,
 
     case DEWPOINT:
         val = calc_dewpoint(loc);
+        if (val == INVALID_VALUE)
+            return g_strdup("");
         if (units->temperature == FAHRENHEIT)
             val = val * 9.0 / 5.0 + 32.0;
         return g_strdup_printf(ROUND_TO_INT("%.1f"), val);
diff --git a/panel-plugin/weather-summary.c b/panel-plugin/weather-summary.c
index 5d833fd..775186c 100644
--- a/panel-plugin/weather-summary.c
+++ b/panel-plugin/weather-summary.c
@@ -102,10 +102,13 @@ lnk_clicked(GtkTextTag *tag,
 #define APPEND_TOOLTIP_ITEM(description, item)                  \
     value = get_data(fcdata, data->units, item,                 \
                      data->round, data->night_time);            \
-    unit = get_unit(data->units, item);                         \
-    g_string_append_printf(text, description, value,            \
-                           strcmp(unit, "°") ? " " : "",        \
-                           unit);                               \
+    if (strcmp(value, "")) {                                    \
+        unit = get_unit(data->units, item);                     \
+        g_string_append_printf(text, description, value,        \
+                               strcmp(unit, "°") ? " " : "",    \
+                               unit);                           \
+    } else                                                      \
+        g_string_append_printf(text, description, "-", "", ""); \
     g_free(value);
 
 


More information about the Xfce4-commits mailing list