changeset 4288:767a6500a666

classifications: refactor
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 30 Aug 2019 10:09:35 +0200
parents 4d5cd3b5775a
children acb83c50dfc4
files client/src/lib/classifications.js
diffstat 1 files changed, 26 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/client/src/lib/classifications.js	Fri Aug 30 09:25:13 2019 +0200
+++ b/client/src/lib/classifications.js	Fri Aug 30 10:09:35 2019 +0200
@@ -31,6 +31,29 @@
   return f;
 };
 
+const calcForecastVsRealityForNSC = nsc => {
+  if (nsc && nsc.coeffs.reduce((sum, coeff) => sum + coeff.samples, 0)) {
+    // 24h < configured value
+    if (
+      nsc.coeffs[0].samples &&
+      nsc.coeffs[0].value <
+        store.state.application.config.gm_forecast_vs_reality_nsc_24h
+    )
+      return "DANGER";
+    // 72h < configured value
+    if (
+      nsc.coeffs[2].samples &&
+      nsc.coeffs[2].value <
+        store.state.application.config.gm_forecast_vs_reality_nsc_72h
+    )
+      return "WARNING";
+    // both > configured value
+    return "OK";
+  }
+  // no data available
+  return "NEUTRAL";
+};
+
 export default {
   surveyRecency(bottleneck) {
     if (
@@ -94,25 +117,7 @@
   forecastVsReality(feature) {
     let gauge = getGauge(feature);
     let nsc = gauge.get("nsc_data");
-    if (nsc && nsc.coeffs.reduce((sum, coeff) => sum + coeff.samples, 0)) {
-      // 24h < configured value
-      if (
-        nsc.coeffs[0].samples &&
-        nsc.coeffs[0].value <
-          store.state.application.config.gm_forecast_vs_reality_nsc_24h
-      )
-        return "DANGER";
-      // 72h < configured value
-      if (
-        nsc.coeffs[2].samples &&
-        nsc.coeffs[2].value <
-          store.state.application.config.gm_forecast_vs_reality_nsc_72h
-      )
-        return "WARNING";
-      // both > configured value
-      return "OK";
-    }
-    // no data available
-    return "NEUTRAL";
-  }
+    return calcForecastVsRealityForNSC(nsc);
+  },
+  calcForecastVsRealityForNSC: calcForecastVsRealityForNSC
 };