Mercurial > gemma
comparison schema/geoserver_views.sql @ 3302:ec6163c6687d
'Historicise' gauges on import
Gauge data sets will be updated or a new version will be inserted
depending on temporal validity and a timestamp marking the last
update in the RIS-Index of a data set. The trigger on date_info is
removed because the value is actually an attribut coming from the
RIS-Index.
Gauge measurements and predictions are associated to the version with
matching temporal validity. Bottlenecks are always associated to the
actual version of the gauge, although this might change as soon as
bottlenecks are 'historicised', too.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Thu, 16 May 2019 18:41:43 +0200 |
parents | 831193935739 |
children | b90b17d0b5a9 |
comparison
equal
deleted
inserted
replaced
3301:6514b943654e | 3302:ec6163c6687d |
---|---|
14 json_strip_nulls(json_object_agg(coalesce(r.depth_reference,'empty'), | 14 json_strip_nulls(json_object_agg(coalesce(r.depth_reference,'empty'), |
15 r.value)) | 15 r.value)) |
16 AS reference_water_levels | 16 AS reference_water_levels |
17 FROM waterway.gauges g | 17 FROM waterway.gauges g |
18 LEFT JOIN waterway.gauges_reference_water_levels r | 18 LEFT JOIN waterway.gauges_reference_water_levels r |
19 ON r.gauge_id = g.location | 19 USING (location, validity) |
20 GROUP BY g.location; | 20 WHERE NOT g.erased |
21 GROUP BY g.location, g.validity; | |
21 | 22 |
22 CREATE OR REPLACE VIEW waterway.distance_marks_geoserver AS | 23 CREATE OR REPLACE VIEW waterway.distance_marks_geoserver AS |
23 SELECT location_code, | 24 SELECT location_code, |
24 isrs_asText(location_code) AS location, | 25 isrs_asText(location_code) AS location, |
25 geom::Geometry(POINT, 4326), | 26 geom::Geometry(POINT, 4326), |
42 fairway_availability_latest AS ( | 43 fairway_availability_latest AS ( |
43 SELECT DISTINCT ON (bottleneck_id) bottleneck_id, date_info, critical | 44 SELECT DISTINCT ON (bottleneck_id) bottleneck_id, date_info, critical |
44 FROM waterway.fairway_availability | 45 FROM waterway.fairway_availability |
45 ORDER BY bottleneck_id, date_info DESC), | 46 ORDER BY bottleneck_id, date_info DESC), |
46 waterlevel_latest AS ( | 47 waterlevel_latest AS ( |
47 SELECT DISTINCT ON (fk_gauge_id) fk_gauge_id, water_level | 48 SELECT DISTINCT ON (location) location, water_level |
48 FROM waterway.gauge_measurements | 49 FROM waterway.gauge_measurements |
49 ORDER BY fk_gauge_id, measure_date DESC) | 50 ORDER BY location, measure_date DESC) |
50 SELECT | 51 SELECT |
51 b.id, | 52 b.id, |
52 b.bottleneck_id, | 53 b.bottleneck_id, |
53 b.objnam, | 54 b.objnam, |
54 b.nobjnm, | 55 b.nobjnm, |
69 fal.date_info AS fa_date_info, | 70 fal.date_info AS fa_date_info, |
70 fal.critical AS fa_critical, | 71 fal.critical AS fa_critical, |
71 wl.water_level AS gm_waterlevel | 72 wl.water_level AS gm_waterlevel |
72 FROM waterway.bottlenecks b | 73 FROM waterway.bottlenecks b |
73 LEFT JOIN waterway.gauges g | 74 LEFT JOIN waterway.gauges g |
74 ON b.fk_g_fid = g.location | 75 ON b.gauge_location = g.location AND b.gauge_validity = g.validity |
75 LEFT JOIN waterway.gauges_reference_water_levels r | 76 LEFT JOIN waterway.gauges_reference_water_levels r |
76 ON g.location = r.gauge_id | 77 USING (location, validity) |
77 LEFT JOIN fairway_availability_latest fal | 78 LEFT JOIN fairway_availability_latest fal |
78 ON b.id = fal.bottleneck_id | 79 ON b.id = fal.bottleneck_id |
79 LEFT JOIN waterlevel_latest wl | 80 LEFT JOIN waterlevel_latest wl |
80 ON b.fk_g_fid = wl.fk_gauge_id | 81 USING (location) |
81 GROUP BY b.id, g.location, fal.date_info, fal.critical, wl.water_level; | 82 WHERE NOT g.erased |
83 GROUP BY b.id, g.location, g.validity, | |
84 fal.date_info, fal.critical, wl.water_level; | |
82 | 85 |
83 CREATE OR REPLACE VIEW waterway.stretches_geoserver AS | 86 CREATE OR REPLACE VIEW waterway.stretches_geoserver AS |
84 SELECT | 87 SELECT |
85 id, | 88 id, |
86 name, | 89 name, |