changeset 3480:965b2fbb1890

Colorize gauge symbol based on availability of measurements
author Tom Gottfried <tom@intevation.de>
date Mon, 27 May 2019 15:45:55 +0200
parents afab8d87932c
children 1f8ee1366859
files client/src/components/map/styles.js client/src/lib/classifications.js schema/geoserver_views.sql
diffstat 3 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/map/styles.js	Mon May 27 15:08:44 2019 +0200
+++ b/client/src/components/map/styles.js	Mon May 27 15:45:55 2019 +0200
@@ -238,7 +238,7 @@
       );
     } else {
       // TODO: Get information from feature and check the ranges according to #423, #424, #425
-      let colorWaterlevel = "lime";
+      let colorWaterlevel = classifications.gmAvailability(feature);
       let colorUniformTriangle = "lime";
       let colorComparison = "white";
       let colorAccuracy = classifications.forecastAccuracy(feature);
--- a/client/src/lib/classifications.js	Mon May 27 15:08:44 2019 +0200
+++ b/client/src/lib/classifications.js	Mon May 27 15:45:55 2019 +0200
@@ -34,6 +34,25 @@
       return "red";
     }
   },
+  gmAvailability(gauge) {
+    let gmDate = gauge.get("gm_measuredate");
+    let gmN = gauge.get("gm_n_14d");
+    if (
+      gmDate !== undefined &&
+      gmDate !== null &&
+      Date.parse(gmDate) > Date.now() - 86400000 // latest value within 24 h
+    ) {
+      if (
+        gmN !== undefined &&
+        gmN !== null &&
+        gmN >= 1344 // one value every 15 min in 14 days
+      ) {
+        return "lime";
+      }
+      return "yellow";
+    }
+    return "red";
+  },
   forecastAccuracy(gauge) {
     let fa3d = gauge.get("forecast_accuracy_3d");
     let fa1d = gauge.get("forecast_accuracy_1d");
--- a/schema/geoserver_views.sql	Mon May 27 15:08:44 2019 +0200
+++ b/schema/geoserver_views.sql	Mon May 27 15:45:55 2019 +0200
@@ -12,7 +12,9 @@
         g.date_info,
         g.source_organization,
         r.rwls AS reference_water_levels,
+        wl.measure_date AS gm_measuredate,
         wl.water_level AS gm_waterlevel,
+        wl_14d.n AS gm_n_14d,
         fca.forecast_accuracy_3d,
         fca.forecast_accuracy_1d
     FROM waterway.gauges g
@@ -22,10 +24,20 @@
                 FROM waterway.gauges_reference_water_levels
                 GROUP BY location, validity) AS r
             USING (location, validity)
-        LEFT JOIN (SELECT DISTINCT ON (location) location, water_level
+        LEFT JOIN (SELECT DISTINCT ON (location)
+                    location,
+                    measure_date,
+                    water_level
                 FROM waterway.gauge_measurements
                 ORDER BY location, measure_date DESC) AS wl
             USING (location)
+        LEFT JOIN (SELECT location, count(water_level) AS n
+                FROM waterway.gauge_measurements
+                -- consider all measurements within 14 days plus a tolerance
+                WHERE measure_date
+                    >= current_timestamp - '14 days 00:15'::interval
+                GROUP BY location) AS wl_14d
+            USING (location)
         LEFT JOIN (SELECT location,
                     max(acc) FILTER (WHERE
                         measure_date <= current_timestamp + '1 day'::interval)