diff client/src/lib/classifications.js @ 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
children 965b2fbb1890
line wrap: on
line diff
--- /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";
+  }
+};