changeset 4097:472aedc8927d timezone

Merged default into timezone branch.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Fri, 26 Jul 2019 09:54:08 +0200
parents 23f88a6c1e88 (current diff) 287dfd4dbdb6 (diff)
children cfa0a5775d70
files pkg/controllers/gauges.go schema/updates/1010/01.timezones-imports.sql
diffstat 5 files changed, 57 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/Pdftool.vue	Thu Jul 25 17:11:30 2019 +0200
+++ b/client/src/components/Pdftool.vue	Fri Jul 26 09:54:08 2019 +0200
@@ -53,6 +53,17 @@
             </select>
           </div>
         </div>
+        <div class="d-flex flex-fill-row">
+          <small class="my-auto text-muted">
+            <translate>Scale to 1:</translate>
+          </small>
+          <input
+            class="form-control form-control-sm w-100 ml-2"
+            placeholder="10000"
+            v-model.number="form.scale"
+            type="number"
+          />
+        </div>
         <button
           @click="download"
           :key="'downloadBtn'"
@@ -126,7 +137,8 @@
         format: "landscape",
         paperSize: "a4",
         downloadType: "download",
-        resolution: "80"
+        resolution: "80",
+        scale: null
       },
       templates: [
         {
@@ -257,7 +269,6 @@
        *
        */
       this.readyToGenerate = false;
-
       console.log(
         "will generate pdf with",
         this.form.paperSize,
@@ -287,13 +298,14 @@
       this.pdf.doc = new jsPDF(this.form.format, "mm", this.form.paperSize);
       this.rendercompleteListener = map.once("rendercomplete", event => {
         let canvas = event.context.canvas;
-        let view = map.getView();
-        let proj = view.getProjection();
-        let metersPerPixel = // average meters (reality) per pixel (map)
-          getPointResolution(proj, view.getResolution(), view.getCenter()) *
-          proj.getMetersPerUnit();
         let scaleDenominator = Math.round(
-          1000 * pixelsPerMapMillimeter * metersPerPixel
+          1000 *
+            pixelsPerMapMillimeter *
+            this.getMeterPerPixel(
+              this.openLayersMap()
+                .getView()
+                .getResolution()
+            )
         );
         console.log("scaleDenominator = ", scaleDenominator);
         var snapshot = canvas.toDataURL("image/jpeg");
@@ -424,11 +436,30 @@
         map.getView().setResolution(this.resolution);
         this.readyToGenerate = true;
       });
+
       const size = map.getSize();
       const [width, height] = mapSizeForPrint;
       map.setSize(mapSizeForPrint);
       const scaling = Math.min(width / size[0], height / size[1]);
-      map.getView().setResolution(this.resolution / scaling);
+      map
+        .getView()
+        .setResolution(
+          this.form.scale
+            ? this.getResolutionFromScale()
+            : this.resolution / scaling
+        );
+    },
+    getResolutionFromScale() {
+      const scaling = Math.round(this.form.scale / 1000);
+      return scaling / this.getMeterPerPixel(this.form.resolution / 25.4);
+    },
+    getMeterPerPixel(f) {
+      var map = this.openLayersMap();
+      let view = map.getView();
+      let proj = view.getProjection();
+      return (
+        getPointResolution(proj, f, view.getCenter()) * proj.getMetersPerUnit()
+      );
     },
     cancel() {
       this.openLayersMap().un(
--- a/pkg/controllers/gauges.go	Thu Jul 25 17:11:30 2019 +0200
+++ b/pkg/controllers/gauges.go	Fri Jul 26 09:54:08 2019 +0200
@@ -636,7 +636,7 @@
 			}
 		}
 
-		cs[i].Value = common.NashSutcliffe(predicted, observed)
+		cs[i].Value = sanitizeFloat64(common.NashSutcliffe(predicted, observed))
 		cs[i].Samples = len(predicted)
 
 		predicted = predicted[:0]
@@ -652,6 +652,18 @@
 	return
 }
 
+func sanitizeFloat64(x float64) float64 {
+	switch {
+	case math.IsNaN(x):
+		return 0
+	case math.IsInf(x, +1):
+		return math.MaxFloat64
+	case math.IsInf(x, -1):
+		return -math.MaxFloat64
+	}
+	return x
+}
+
 func waterlevels(rw http.ResponseWriter, req *http.Request) {
 	gauge := mux.Vars(req)["gauge"]
 
--- a/schema/gemma.sql	Thu Jul 25 17:11:30 2019 +0200
+++ b/schema/gemma.sql	Fri Jul 26 09:54:08 2019 +0200
@@ -826,8 +826,8 @@
         id         int PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY,
         state      import_state NOT NULL DEFAULT 'queued',
         kind       varchar   NOT NULL,
-        enqueued   timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
-        due        timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
+        enqueued   timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
+        due        timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
         retry_wait interval
             CHECK(retry_wait IS NULL
                 OR retry_wait >= interval '0 microseconds'),
@@ -850,7 +850,7 @@
     CREATE TABLE import_logs (
         import_id int NOT NULL REFERENCES imports(id)
             ON DELETE CASCADE,
-        time timestamp with time zone NOT NULL DEFAULT now(),
+        time timestamp zone NOT NULL DEFAULT now(),
         kind log_type NOT NULL DEFAULT 'info',
         msg TEXT NOT NULL
     )
--- a/schema/updates/1010/01.timezones-imports.sql	Thu Jul 25 17:11:30 2019 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,3 +0,0 @@
-ALTER TABLE import.imports     ALTER COLUMN enqueued TYPE timestamp with time zone;
-ALTER TABLE import.imports     ALTER COLUMN due      TYPE timestamp with time zone;
-ALTER TABLE import.import_logs ALTER COLUMN time     TYPE timestamp with time zone;
--- a/schema/version.sql	Thu Jul 25 17:11:30 2019 +0200
+++ b/schema/version.sql	Fri Jul 26 09:54:08 2019 +0200
@@ -1,1 +1,1 @@
-INSERT INTO gemma_schema_version(version) VALUES (1010);
+INSERT INTO gemma_schema_version(version) VALUES (1009);