view client/src/lib/classifications.js @ 3497:1457e2b9d900

Set threshold for green gauge data availability to 85%. The SRS reads like 100%, but that seems unrealistic and the threshold shall be configurable anyway. In the meantime 85% makes things look nicer...
author Sascha Wilde <wilde@intevation.de>
date Mon, 27 May 2019 18:45:20 +0200
parents 965b2fbb1890
children 4d44eda484dd
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>
 */

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";
    }
  },
  gmAvailability(gauge) {
    let gmDate = gauge.get("gm_measuredate");
    let gmN = gauge.get("gm_n_14d");
    if (
      gmDate !== undefined &&
      gmDate !== null &&
      Date.parse(gmDate) > Date.now() - 86400000 // latest value within 24 h
    ) {
      if (
        gmN !== undefined &&
        gmN !== null &&
        gmN >= 1124 // 1344: one value every 15 min in 14 days, but the Hydra says:
                    // let 85% be enough for now.
      ) {
        return "lime";
      }
      return "yellow";
    }
    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";
  }
};