changeset 3472:71022e6bd98e

client: Use classifications for bottleneck diagrams on map and extracted classification algos
author Raimund Renkert <raimund.renkert@intevation.de>
date Mon, 27 May 2019 12:09:13 +0200
parents 48d09fb1d6c7
children d66cae5be0a1
files client/src/components/map/styles.js client/src/lib/classifications.js
diffstat 2 files changed, 58 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/components/map/styles.js	Mon May 27 12:03:07 2019 +0200
+++ b/client/src/components/map/styles.js	Mon May 27 12:09:13 2019 +0200
@@ -2,6 +2,7 @@
 import Point from "ol/geom/Point";
 import { getCenter } from "ol/extent";
 import store from "@/store/index";
+import classifications from "../../lib/classifications";
 
 const styles = {
   blue1: new Style({
@@ -237,21 +238,10 @@
       );
     } else {
       // TODO: Get information from feature and check the ranges according to #423, #424, #425
-      let colorWaterlevel = "white";
-      let colorBottleneck = "lime";
-      let colorComparison = "lime";
-      let colorAccuracy = "white";
-      let fa3d = feature.get("forecast_accuracy_3d");
-      let fa1d = feature.get("forecast_accuracy_1d");
-      if (typeof fa3d == "number" && typeof fa1d == "number") {
-        if (fa1d > 15) {
-          colorAccuracy = "red";
-        } else if (fa3d > 15) {
-          colorAccuracy = "yellow";
-        } else {
-          colorAccuracy = "lime";
-        }
-      }
+      let colorWaterlevel = "lime";
+      let colorUniformTriangle = "lime";
+      let colorComparison = "white";
+      let colorAccuracy = classifications.forecastAccuracy(feature);
       let maps = store.state.map.openLayersMaps;
       let geom = feature.getGeometry();
       if (!(geom instanceof Point)) {
@@ -285,7 +275,8 @@
           m.getLayer("BOTTLENECKS").getVisible() &&
           feature.getId().indexOf("bottlenecks") > -1
         ) {
-          let frame = `<polyline points='16,0 32,32 0,32 16,0' stroke='grey' stroke-width='1' fill='${colorBottleneck}'/>`;
+          colorUniformTriangle = classifications.surveyCurrency(feature);
+          let frame = `<polyline points='16,0 32,32 0,32 16,0' stroke='grey' stroke-width='1' fill='${colorUniformTriangle}'/>`;
           let svg = `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' width='32' height='32'><g>${frame}</g></svg>`;
           s.push(
             new Style({
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/client/src/lib/classifications.js	Mon May 27 12:09:13 2019 +0200
@@ -0,0 +1,51 @@
+/* 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):
+ * Raimund Renkert <raimund.renkert@intevation.de>
+ */
+
+export default {
+  surveyCurrency(bottleneck) {
+    if (
+      bottleneck.get("revisiting_time") === null ||
+      bottleneck.get("revisiting_time") === 0
+    ) {
+      return "white";
+    }
+    if (bottleneck.get("date_max") === null) {
+      return "red";
+    }
+    let revTime = bottleneck.get("revisiting_time") * 30.5;
+    let latest = Date.parse(bottleneck.get("date_max").replace("Z", ""));
+    var diff = Math.floor((Date.now() - latest) / 86400000);
+    if (diff <= revTime) {
+      return "lime";
+    } else if (revTime < diff && diff <= revTime * 1.5) {
+      return "yellow";
+    } else if (revTime * 1.5 < diff) {
+      return "red";
+    }
+  },
+  forecastAccuracy(gauge) {
+    let fa3d = gauge.get("forecast_accuracy_3d");
+    let fa1d = gauge.get("forecast_accuracy_1d");
+    if (typeof fa3d == "number" && typeof fa1d == "number") {
+      if (fa1d > 15) {
+        return "red";
+      } else if (fa3d > 15) {
+        return "yellow";
+      } else {
+        return "lime";
+      }
+    }
+    return "white";
+  }
+};