# HG changeset patch # User Tom Gottfried # Date 1558964755 -7200 # Node ID 965b2fbb18909f398918bb475cae52e093987464 # Parent afab8d87932c667f98102b4bf02db0a98381fafd Colorize gauge symbol based on availability of measurements diff -r afab8d87932c -r 965b2fbb1890 client/src/components/map/styles.js --- 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); diff -r afab8d87932c -r 965b2fbb1890 client/src/lib/classifications.js --- 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"); diff -r afab8d87932c -r 965b2fbb1890 schema/geoserver_views.sql --- 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)