Mercurial > gemma
diff pkg/controllers/gauges.go @ 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 | 232fc90e6ee2 |
children | 18777f6df3ef |
line wrap: on
line diff
--- a/pkg/controllers/gauges.go Thu May 16 17:22:33 2019 +0200 +++ b/pkg/controllers/gauges.go Thu May 16 18:41:43 2019 +0200 @@ -44,7 +44,7 @@ water_level FROM ( SELECT - fk_gauge_id, + location, measure_date, date_issue, false AS predicted, @@ -52,7 +52,7 @@ FROM waterway.gauge_measurements UNION ALL SELECT - fk_gauge_id, + location, measure_date, date_issue, true AS predicted, @@ -60,7 +60,7 @@ FROM waterway.gauge_predictions ) AS gmp WHERE - fk_gauge_id = ( + location = ( $1::char(2), $2::char(3), $3::char(5), @@ -80,7 +80,7 @@ predicted FROM ( SELECT - fk_gauge_id, + location, measure_date, date_issue, water_level, @@ -90,7 +90,7 @@ FROM waterway.gauge_measurements UNION ALL SELECT - fk_gauge_id, + location, measure_date, date_issue, water_level, @@ -106,8 +106,9 @@ SELECT min(measure_date), max(measure_date) -FROM waterway.gauge_measurements WHERE - fk_gauge_id = ( +FROM waterway.gauge_measurements +WHERE + location = ( $1::char(2), $2::char(3), $3::char(5), @@ -127,8 +128,9 @@ avg(water_level) AS mean, min(water_level) AS min, max(water_level) AS max -FROM waterway.gauge_measurements WHERE - fk_gauge_id = ( +FROM waterway.gauge_measurements +WHERE + location = ( $1::char(2), $2::char(3), $3::char(5), @@ -145,14 +147,14 @@ water_level FROM waterway.gauge_measurements WHERE - staging_done AND - fk_gauge_id = ( + location = ( $1::char(2), $2::char(3), $3::char(5), $4::char(5), $5::int - ) + )::isrs + AND staging_done AND measure_date BETWEEN $6 AND $7 ORDER BY measure_date ` @@ -663,7 +665,7 @@ filters := filterAnd{ buildFilterTerm( - "fk_gauge_id = ($%d::char(2), $%d::char(3), $%d::char(5), $%d::char(5), $%d::int)", + "location = ($%d::char(2), $%d::char(3), $%d::char(5), $%d::char(5), $%d::int)", isrs.CountryCode, isrs.LoCode, isrs.FairwaySection, @@ -674,8 +676,9 @@ &filterNot{&filterTerm{format: "predicted"}}, buildFilterTerm( `date_issue = ( - SELECT max(date_issue) FROM waterway.gauge_measurements - WHERE fk_gauge_id = ($%d::char(2), $%d::char(3), $%d::char(5), $%d::char(5), $%d::int))`, + SELECT max(date_issue) + FROM waterway.gauge_measurements gm + WHERE location = ($%d::char(2), $%d::char(3), $%d::char(5), $%d::char(5), $%d::int))`, isrs.CountryCode, isrs.LoCode, isrs.FairwaySection,