changeset 5388:60bba8e6322b extented-report

Add import for updating stats. Rationale: Due to performance optimization it seems advised to decouple updating the stats for the DQL report from the actual consumption while generating the report. -- Therefore we have a new import kind "statsupdate" which is selectable for sysadmins only. It could be scheduled as any other import. The available names for which stats to update are dynamically queried from the backend.
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 02 Jul 2021 13:56:51 +0200
parents 8e30b926b94d
children 661e8a2deed9
files client/src/components/importconfiguration/ImportDetails.vue client/src/components/importconfiguration/ScheduledImports.vue client/src/components/importconfiguration/types/Statsupdate.vue client/src/store/importschedule.js
diffstat 4 files changed, 126 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/importconfiguration/ImportDetails.vue	Fri Jul 02 00:42:05 2021 +0200
+++ b/client/src/components/importconfiguration/ImportDetails.vue	Fri Jul 02 13:56:51 2021 +0200
@@ -57,6 +57,9 @@
             <option :value="$options.IMPORTTYPES.REPORT">
               <translate>Data Quality Report</translate>
             </option>
+            <option :value="$options.IMPORTTYPES.STATSUPDATE">
+              <translate>Update Stats</translate>
+            </option>
           </optgroup>
         </select>
       </div>
--- a/client/src/components/importconfiguration/ScheduledImports.vue	Fri Jul 02 00:42:05 2021 +0200
+++ b/client/src/components/importconfiguration/ScheduledImports.vue	Fri Jul 02 13:56:51 2021 +0200
@@ -116,6 +116,11 @@
       @urlChanged="setUrl"
       :url="url"
     />
+    <Statsupdate
+      v-if="import_ == $options.IMPORTTYPES.STATSUPDATE && !directImport"
+      @statsUpdateChanged="setStatsUpdate"
+      :statsUpdate="statsUpdate"
+    />
     <Waterwayarea
       v-if="import_ == $options.IMPORTTYPES.WATERWAYAREA"
       @urlChanged="setUrl"
@@ -501,6 +506,7 @@
     Faiwaydimensions: () => import("./types/Fairwaydimensions"),
     Fairwaymarks: () => import("./types/Fairwaymarks"),
     Gaugemeasurement: () => import("./types/Gaugemeasurement"),
+    Statsupdate: () => import("./types/Statsupdate"),
     Waterwayarea: () => import("./types/Waterwayarea"),
     Waterwaygauges: () => import("./types/Waterwaygauges"),
     Waterwayaxis: () => import("./types/Waterwayaxis")
@@ -693,6 +699,9 @@
       this.uploadLabel = files[0].name;
       this.uploadFile = files[0];
     },
+    setStatsUpdate(value) {
+      this.statsUpdate = value;
+    },
     setUrl(value) {
       this.url = value;
     },
@@ -783,6 +792,7 @@
       this.trys = this.currentSchedule.trys;
       this.waitRetry = this.currentSchedule.waitRetry;
       this.selectedMark = this.currentSchedule.selectedMark;
+      this.statsUpdate = this.currentSchedule.statsUpdate;
       this.retry =
         this.currentSchedule.trys === null ||
         this.currentSchedule.trys === undefined ||
@@ -916,6 +926,9 @@
       if (this.import_ === this.$options.IMPORTTYPES.REPORT) {
         data["name"] = "data-quality-report";
       }
+      if (this.import_ === this.$options.IMPORTTYPES.STATSUPDATE) {
+        data["name"] = this.statsUpdate;
+      }
       data["send-email"] = this.eMailNotification;
       this.triggerActive = false;
       const type =
@@ -1010,6 +1023,9 @@
       if (this.import_ === this.$options.IMPORTTYPES.REPORT) {
         config["name"] = "data-quality-report";
       }
+      if (this.import_ === this.$options.IMPORTTYPES.STATSUPDATE) {
+        config["name"] = this.statsUpdate;
+      }
       config["send-email"] = this.eMailNotification;
       if (!this.id) {
         data["config"] = config;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/components/importconfiguration/types/Statsupdate.vue	Fri Jul 02 13:56:51 2021 +0200
@@ -0,0 +1,95 @@
+<template>
+  <div>
+    <div class="d-flex px-2">
+      <div class="flex-column w-100">
+        <div class="flex-row text-left">
+          <small class="text-muted">
+            <translate>Stats Update</translate>
+          </small>
+        </div>
+        <div class="w-50">
+          <select
+            v-model="selectedStatsUpdate"
+            class="ml-1 mr-1 form-control form-control-sm"
+          >
+            <option
+              v-for="(option, index) in this.statsUpdates"
+              :key="index"
+              :value="option"
+              >{{ option }}</option
+            >
+          </select>
+        </div>
+      </div>
+    </div>
+    <div v-if="!statsUpdate" class="d-flex px-2">
+      <small
+        ><translate class="text-danger"
+          >Please select stats to update</translate
+        ></small
+      >
+    </div>
+  </div>
+</template>
+
+<script>
+/* 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) 2018 by via donau
+ *   – Österreichische Wasserstraßen-Gesellschaft mbH
+ * Software engineering by Intevation GmbH
+ *
+ * Author(s):
+ * Thomas Junk <thomas.junk@intevation.de>
+ */
+import { HTTP } from "@/lib/http";
+import { displayError } from "@/lib/errors";
+
+export default {
+  name: "statsupdate",
+  props: ["statsUpdate"],
+  data() {
+    return {
+      statsUpdates: []
+    };
+  },
+  mounted() {
+    HTTP.get("/data/stats-updates", {
+      headers: {
+        "X-Gemma-Auth": localStorage.getItem("token")
+      }
+    })
+      .then(response => {
+        this.statsUpdates = response.data["stats-updates"];
+      })
+      .catch(error => {
+        let message = "Backend not reachable";
+        if (error.response) {
+          const { status, data } = error.response;
+          message = `${status}: ${data.message || data}`;
+        }
+        displayError({
+          title: this.$gettext("Backend Error"),
+          message: message
+        });
+      });
+  },
+  computed: {
+    selectedStatsUpdate: {
+      get() {
+        return this.statsUpdate;
+      },
+      set(value) {
+        this.selected = value;
+        this.$emit("statsUpdateChanged", value);
+      }
+    }
+  }
+};
+</script>
+
+<style></style>
--- a/client/src/store/importschedule.js	Fri Jul 02 00:42:05 2021 +0200
+++ b/client/src/store/importschedule.js	Fri Jul 02 13:56:51 2021 +0200
@@ -32,7 +32,8 @@
   APPROVEDGAUGEMEASUREMENTS: "approvedgaugemeasurements",
   WATERWAYPROFILES: "waterwayprofiles",
   FAIRWAYMARKS: "fairwaymarks",
-  REPORT: "report"
+  REPORT: "report",
+  STATSUPDATE: "statsupdate"
 };
 
 const KINDIMPORTTYPE = {
@@ -46,7 +47,8 @@
   wg: "waterwaygauges",
   dmv: "distancemarksvirtual",
   dma: "distancemarksashore",
-  report: "report"
+  report: "report",
+  statsupdate: "statsupdate"
 };
 
 const IMPORTTYPEKIND = {
@@ -60,7 +62,8 @@
   waterwaygauges: "wg",
   distancemarksvirtual: "dmv",
   distancemarksashore: "dma",
-  report: "report"
+  report: "report",
+  statsupdate: "statsupdate"
 };
 
 const FAIRWAYMARKKINDS = {
@@ -113,7 +116,8 @@
     sourceOrganization: null,
     trys: null,
     waitRetry: null,
-    selectedMark: null
+    selectedMark: null,
+    statsUpdate: null
   };
 };
 
@@ -274,6 +278,10 @@
           sourceOrganization
         );
       }
+      if (kind === IMPORTTYPES.STATSUPDATE) {
+        const { name } = config;
+        Vue.set(state.currentSchedule, "statsUpdate", name);
+      }
     }
   },
   actions: {