view client/src/lib/classifications.js @ 4279:30f26bf7ff24

Reordering of elements In order to improve user experience the configuration of avail, forceast vs. real and accuracy was changed in such a way, that it now mirrors the optics of the displayed triangle. The order in the identify tool was changed accordingly 1) avail 2) forcast vs. real 3) accuracy "Currency" was cleaned up to "recency"
author Thomas Junk <thomas.junk@intevation.de>
date Thu, 29 Aug 2019 15:04:02 +0200
parents e4d6c6339cb4
children 767a6500a666
line wrap: on
line source

/* 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>
 * Markus Kottländer <markus.kottlaender@intevation.de>
 */
import store from "@/store/index";

const getGauge = f => {
  if (f.getId().indexOf("bottlenecks") > -1) {
    const GaugeProxy = (function(feature) {
      const gauge = feature.get("gauge_obj");
      const get = function(propName) {
        if (gauge) return gauge.get(propName);
        return feature.get(propName);
      };
      return {
        get: get
      };
    })(f);
    return GaugeProxy;
  }
  return f;
};

export default {
  surveyRecency(bottleneck) {
    if (
      bottleneck.get("revisiting_time") === null ||
      bottleneck.get("revisiting_time") === 0
    ) {
      return "NEUTRAL";
    }
    if (bottleneck.get("date_max") === null) {
      return "DANGER";
    }
    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);
    let revTimeMultiplier =
      store.state.application.config.bn_revtime_multiplier;
    if (diff <= revTime) {
      return "OK";
    } else if (revTime < diff && diff <= revTime * revTimeMultiplier) {
      return "WARNING";
    } else if (revTime * revTimeMultiplier < diff) {
      return "DANGER";
    }
  },
  gmAvailability(feature) {
    let gauge = getGauge(feature);
    let gmDate = gauge.get("gm_measuredate");
    let gmN = gauge.get("gm_n_14d");
    if (
      gmDate !== undefined &&
      gmDate !== null &&
      // latest measurement within configured hours
      Date.parse(gmDate) >
        Date.now() -
          store.state.application.config.gm_latest_hours * 60 * 60 * 1000
    ) {
      // at least configured amount of measurements in last 14 days
      const valuesAtLeast = store.state.application.config.gm_min_values_14d;
      if (gmN !== undefined && gmN !== null && gmN >= valuesAtLeast) {
        return "OK";
      }
      return "WARNING";
    }
    return "DANGER";
  },
  forecastAccuracy(feature) {
    let gauge = getGauge(feature);
    let fa3d = gauge.get("forecast_accuracy_3d");
    let fa1d = gauge.get("forecast_accuracy_1d");
    if (typeof fa3d == "number" && typeof fa1d == "number") {
      if (fa1d > store.state.application.config.gm_forecast_offset_24h) {
        return "DANGER";
      } else if (fa3d > store.state.application.config.gm_forecast_offset_72h) {
        return "WARNING";
      } else {
        return "OK";
      }
    }
    return "NEUTRAL";
  },
  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";
  }
};