changeset 4127:8c62809ea87e request_hist_bns

Merged default
author Sascha Wilde <wilde@intevation.de>
date Thu, 01 Aug 2019 17:07:01 +0200
parents ad0c373dff6a (current diff) 52f7264265bb (diff)
children 14706384a464
files schema/gemma.sql
diffstat 9 files changed, 151 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/gauge/Waterlevel.vue	Wed Jul 31 19:08:53 2019 +0200
+++ b/client/src/components/gauge/Waterlevel.vue	Thu Aug 01 17:07:01 2019 +0200
@@ -554,32 +554,33 @@
         .style("font-size", "0.8em");
     },
     getExtent(refWaterLevels) {
+      let rest;
+      if (refWaterLevels) {
+        // set min/max values for the waterlevel axis
+        // including HDC (+ 1/8 HDC-LDC) and LDC (- 1/4 HDC-LDC)
+        rest = [
+          {
+            waterlevel:
+              refWaterLevels.HDC + (refWaterLevels.HDC - refWaterLevels.LDC) / 8
+          },
+          {
+            waterlevel: Math.max(
+              refWaterLevels.LDC -
+                (refWaterLevels.HDC - refWaterLevels.LDC) / 4,
+              0
+            )
+          }
+        ];
+      } else {
+        rest = [];
+      }
       return {
         // set min/max values for the date axis
         date: [
           this.waterlevels[0].date,
           endOfDay(this.waterlevels[this.waterlevels.length - 1].date)
         ],
-        // set min/max values for the waterlevel axis
-        // including HDC (+ 1/8 HDC-LDC) and LDC (- 1/4 HDC-LDC)
-        waterlevel: d3.extent(
-          [
-            ...this.waterlevels,
-            {
-              waterlevel:
-                refWaterLevels.HDC +
-                (refWaterLevels.HDC - refWaterLevels.LDC) / 8
-            },
-            {
-              waterlevel: Math.max(
-                refWaterLevels.LDC -
-                  (refWaterLevels.HDC - refWaterLevels.LDC) / 4,
-                0
-              )
-            }
-          ],
-          d => d.waterlevel
-        )
+        waterlevel: d3.extent([...this.waterlevels, ...rest], d => d.waterlevel)
       };
     },
     getScale({ dimensions, extent }) {
@@ -774,16 +775,18 @@
     },
     drawRefLines({ refWaterLevels, diagram, scale, dimensions, extent }) {
       // filling area between HDC and LDC
-      diagram
-        .append("rect")
-        .attr("class", "hdc-ldc-area")
-        .attr("x", 0)
-        .attr("y", scale.y(refWaterLevels.HDC))
-        .attr("width", dimensions.width)
-        .attr(
-          "height",
-          scale.y(refWaterLevels.LDC) - scale.y(refWaterLevels.HDC)
-        );
+      if (refWaterLevels) {
+        diagram
+          .append("rect")
+          .attr("class", "hdc-ldc-area")
+          .attr("x", 0)
+          .attr("y", scale.y(refWaterLevels.HDC))
+          .attr("width", dimensions.width)
+          .attr(
+            "height",
+            scale.y(refWaterLevels.LDC) - scale.y(refWaterLevels.HDC)
+          );
+      }
 
       const refWaterlevelLine = d3
         .line()
--- a/client/src/components/layers/Layers.vue	Wed Jul 31 19:08:53 2019 +0200
+++ b/client/src/components/layers/Layers.vue	Thu Aug 01 17:07:01 2019 +0200
@@ -86,6 +86,7 @@
       this.$store.commit("application/showLayers", false);
     },
     refreshLayers() {
+      this.$store.commit("gauges/deleteNashSutcliffeCache");
       this.$store.dispatch("map/refreshLayers");
     }
   }
--- a/client/src/store/fairwayavailability.js	Wed Jul 31 19:08:53 2019 +0200
+++ b/client/src/store/fairwayavailability.js	Thu Aug 01 17:07:01 2019 +0200
@@ -18,9 +18,7 @@
 import {
   format,
   subYears,
-  startOfDay,
   startOfMonth,
-  endOfDay,
   endOfMonth,
   startOfYear,
   endOfYear,
@@ -240,13 +238,11 @@
         } else if (type == TYPES.SECTION || type == TYPES.STRETCH) {
           additionalParams = `&depthbreaks=${depthLimit1},${depthLimit2}&widthbreaks=${widthLimit1},${widthLimit2}`;
         }
+        const start = encodeURIComponent("00:00:00+00:00");
+        const end = encodeURIComponent("23:59:59+00:00");
         const URL = `data/${endpoint}/fairway-depth/${encodeURIComponent(
           name
-        )}?from=${encodeURIComponent(
-          format(startOfDay(from), "YYYY-MM-DDTHH:mm:ssZ")
-        )}&to=${encodeURIComponent(
-          format(endOfDay(to), "YYYY-MM-DDTHH:mm:ssZ")
-        )}&mode=${frequency}&los=${LOS}${additionalParams}`;
+        )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}${additionalParams}`;
         HTTP.get(URL, {
           headers: { "X-Gemma-Auth": localStorage.getItem("token") }
         })
@@ -282,6 +278,8 @@
           ? feature.properties.name
           : feature.get("objnam");
         [from, to] = getIntervallBorders(from, to, frequency);
+        const start = encodeURIComponent("00:00:00+00:00");
+        const end = encodeURIComponent("23:59:59+00:00");
         let additionalParams = "";
         let endpoint = type || TYPES.BOTTLENECK;
         if (type === TYPES.BOTTLENECK) {
@@ -294,11 +292,7 @@
         }
         const URL = `data/${endpoint}/availability/${encodeURIComponent(
           name
-        )}?from=${encodeURIComponent(
-          format(startOfDay(from), "YYYY-MM-DDTHH:mm:ssZ")
-        )}&to=${encodeURIComponent(
-          format(endOfDay(to), "YYYY-MM-DDTHH:mm:ssZ")
-        )}&mode=${frequency}&los=${LOS}${additionalParams}`;
+        )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}${additionalParams}`;
         HTTP.get(URL, {
           headers: { "X-Gemma-Auth": localStorage.getItem("token") }
         })
--- a/client/src/store/gauges.js	Wed Jul 31 19:08:53 2019 +0200
+++ b/client/src/store/gauges.js	Thu Aug 01 17:07:01 2019 +0200
@@ -78,6 +78,9 @@
     nashSutcliffe: (state, data) => {
       state.nashSutcliffe = data;
     },
+    deleteNashSutcliffeCache: state => {
+      state.nashSutcliffeOverview = [];
+    },
     addNashSutcliffeOverviewEntry: (state, data) => {
       let existingIndex = state.nashSutcliffeOverview.findIndex(
         d => d.feature.get("id") === data.feature.get("id")
--- a/schema/gemma.sql	Wed Jul 31 19:08:53 2019 +0200
+++ b/schema/gemma.sql	Thu Aug 01 17:07:01 2019 +0200
@@ -883,9 +883,13 @@
     tmp RECORD;
 BEGIN
     FOR tmp IN
-        SELECT * FROM import.track_imports WHERE import_id = imp_id AND NOT deletion
+        SELECT relation, array_agg(key) AS keys
+            FROM import.track_imports
+            WHERE import_id = imp_id AND NOT deletion
+            GROUP BY relation
     LOOP
-        EXECUTE format('DELETE FROM %s WHERE id = $1', tmp.relation) USING tmp.key;
+        EXECUTE format('DELETE FROM %s WHERE id = ANY($1)', tmp.relation)
+            USING tmp.keys;
     END LOOP;
 END;
 $$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/import_tests.sql	Thu Aug 01 17:07:01 2019 +0200
@@ -0,0 +1,81 @@
+-- This is Free Software under GNU Affero General Public License v >= 3.0
+-- without warranty, see README.md and license for details.
+
+-- SPDX-License-Identifier: AGPL-3.0-or-later
+-- License-Filename: LICENSES/AGPL-3.0.txt
+
+-- Copyright (C) 2019 by via donau
+--   – Österreichische Wasserstraßen-Gesellschaft mbH
+-- Software engineering by Intevation GmbH
+
+-- Author(s):
+--  * Tom Gottfried <tom@intevation.de>
+
+--
+-- pgTAP test script for import queue
+--
+
+\set imp_id 99
+PREPARE insert_gms AS WITH
+gms AS (
+    INSERT INTO waterway.gauge_measurements (
+        location,
+        measure_date,
+        country_code,
+        sender,
+        language_code,
+        date_issue,
+        reference_code,
+        water_level,
+        date_info,
+        source_organization
+    ) SELECT
+            ('AT', 'XXX', '00001', 'G0001', 1)::isrs,
+            t,
+            'AT',
+            'test',
+            'DE',
+            current_timestamp,
+            'ZPG',
+            0,
+            current_timestamp,
+            'test'
+        FROM generate_series(
+            current_timestamp - '12 h'::interval,
+            current_timestamp - '6 h'::interval,
+            '15 min'::interval) AS times (t)
+    RETURNING id),
+imps AS (
+    INSERT INTO import.imports (id, kind, username) VALUES (
+        $1, 'test', 'test_admin_ro')
+    RETURNING id)
+INSERT INTO import.track_imports (import_id, relation, key)
+    SELECT imps.id, 'waterway.gauge_measurements', gms.id
+           FROM imps, gms;
+
+EXECUTE insert_gms(:imp_id);
+EXECUTE insert_gms(:imp_id + 1);
+
+SELECT ok((SELECT count(*) FROM waterway.gauge_measurements
+        WHERE id IN(SELECT key
+            FROM import.track_imports
+            WHERE import_id IN(:imp_id, :imp_id + 1))
+    ) = (SELECT count(*)
+        FROM import.track_imports WHERE import_id IN(:imp_id, :imp_id + 1)),
+    'Tracked entries of test imports exist');
+
+SELECT import.del_import(:imp_id);
+
+SELECT ok(0 = (SELECT count(*) FROM waterway.gauge_measurements
+        WHERE id IN(SELECT key
+            FROM import.track_imports
+            WHERE import_id = :imp_id)),
+    'Tracked entries of first test import are deleted');
+
+SELECT ok((SELECT count(*) FROM waterway.gauge_measurements
+        WHERE id IN(SELECT key
+            FROM import.track_imports
+            WHERE import_id = :imp_id + 1)
+    ) = (SELECT count(*)
+        FROM import.track_imports WHERE import_id = :imp_id + 1),
+    'Tracked entries of second test import still exist');
--- a/schema/run_tests.sh	Wed Jul 31 19:08:53 2019 +0200
+++ b/schema/run_tests.sh	Thu Aug 01 17:07:01 2019 +0200
@@ -80,7 +80,7 @@
     -c 'SET client_min_messages TO WARNING' \
     -c "DROP ROLE IF EXISTS $TEST_ROLES" \
     -f "$BASEDIR"/tap_tests_data.sql \
-    -c "SELECT plan(70 + (
+    -c "SELECT plan(73 + (
             SELECT count(*)::int
                 FROM information_schema.tables
                 WHERE table_schema = 'waterway'))" \
@@ -88,4 +88,5 @@
     -f "$BASEDIR"/isrs_tests.sql \
     -f "$BASEDIR"/auth_tests.sql \
     -f "$BASEDIR"/manage_users_tests.sql \
+    -f "$BASEDIR"/import_tests.sql \
     -c 'SELECT * FROM finish()'
--- a/schema/tap_tests_data.sql	Wed Jul 31 19:08:53 2019 +0200
+++ b/schema/tap_tests_data.sql	Thu Aug 01 17:07:01 2019 +0200
@@ -17,6 +17,8 @@
 --
 
 INSERT INTO countries VALUES ('AT'), ('RO'), ('DE');
+INSERT INTO language_codes VALUES ('DE');
+INSERT INTO depth_references VALUES ('ZPG');
 
 INSERT INTO users.responsibility_areas VALUES
     ('AT', ST_geomfromtext('MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)))', 4326)),
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/schema/updates/1101/01.improve_del_import.sql	Thu Aug 01 17:07:01 2019 +0200
@@ -0,0 +1,17 @@
+CREATE OR REPLACE FUNCTION import.del_import(imp_id int) RETURNS void AS
+$$
+DECLARE
+    tmp RECORD;
+BEGIN
+    FOR tmp IN
+        SELECT relation, array_agg(key) AS keys
+            FROM import.track_imports
+            WHERE import_id = imp_id AND NOT deletion
+            GROUP BY relation
+    LOOP
+        EXECUTE format('DELETE FROM %s WHERE id = ANY($1)', tmp.relation)
+            USING tmp.keys;
+    END LOOP;
+END;
+$$
+LANGUAGE plpgsql;