view client/src/lib/classifications.js @ 4017:639bdb17c3f2

Fixed offset for fairway box This was broken by changeset: 4080:bf86f9a08733 user: Thomas Junk <thomas.junk@intevation.de> Date: Thu Jul 18 15:04:30 2019 +0200 summary: improve fairwaydiagram printing positioning For the record: I think the current implementation exceptionally flawed. Instead of adding extra offset parameters to the diagram elements the whole building block with all contained elements should be translated in one step, that would be less cluttered and less error prone...
author Sascha Wilde <wilde@intevation.de>
date Fri, 19 Jul 2019 16:59:25 +0200
parents bcf9713ee359
children 2596a028dc3a
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) {
    return f.get("gauge_obj");
  }
  return f;
};

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);
    let revTimeMultiplier =
      store.state.application.config.bn_revtime_multiplier;
    if (diff <= revTime) {
      return "lime";
    } else if (revTime < diff && diff <= revTime * revTimeMultiplier) {
      return "yellow";
    } else if (revTime * revTimeMultiplier < diff) {
      return "red";
    }
  },
  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 "lime";
      }
      return "yellow";
    }
    return "red";
  },
  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 "red";
      } else if (fa3d > store.state.application.config.gm_forecast_offset_72h) {
        return "yellow";
      } else {
        return "lime";
      }
    }
    return "white";
  },
  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 "red";
      // 72h < configured value
      if (
        nsc.coeffs[2].samples &&
        nsc.coeffs[2].value <
          store.state.application.config.gm_forecast_vs_reality_nsc_72h
      )
        return "yellow";
      // both > configured value
      return "lime";
    }
    // no data available
    return "white";
  }
};