annotate client/src/lib/classifications.js @ 3632:943c454d5633 single-beam

Merged default into single-beam branch.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 11 Jun 2019 14:46:14 +0200
parents bcf9713ee359
children 2596a028dc3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
1 /* This is Free Software under GNU Affero General Public License v >= 3.0
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
2 * without warranty, see README.md and license for details.
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
3 *
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
4 * SPDX-License-Identifier: AGPL-3.0-or-later
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
5 * License-Filename: LICENSES/AGPL-3.0.txt
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
6 *
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
7 * Copyright (C) 2018 by via donau
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
8 * – Österreichische Wasserstraßen-Gesellschaft mbH
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
9 * Software engineering by Intevation GmbH
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
10 *
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
11 * Author(s):
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
12 * Raimund Renkert <raimund.renkert@intevation.de>
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
13 * Markus Kottländer <markus.kottlaender@intevation.de>
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14 */
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
15 import store from "@/store/index";
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
16
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
17 const getGauge = f => {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
18 if (f.getId().indexOf("bottlenecks") > -1) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
19 return f.get("gauge_obj");
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
20 }
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
21 return f;
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
22 };
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
23
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 export default {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 surveyCurrency(bottleneck) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
26 if (
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
27 bottleneck.get("revisiting_time") === null ||
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 bottleneck.get("revisiting_time") === 0
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
29 ) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
30 return "white";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
31 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 if (bottleneck.get("date_max") === null) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 return "red";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
34 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
35 let revTime = bottleneck.get("revisiting_time") * 30.5;
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 let latest = Date.parse(bottleneck.get("date_max").replace("Z", ""));
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
37 var diff = Math.floor((Date.now() - latest) / 86400000);
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
38 let revTimeMultiplier =
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
39 store.state.application.config.bn_revtime_multiplier;
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 if (diff <= revTime) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 return "lime";
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
42 } else if (revTime < diff && diff <= revTime * revTimeMultiplier) {
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 return "yellow";
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
44 } else if (revTime * revTimeMultiplier < diff) {
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
45 return "red";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
46 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
47 },
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
48 gmAvailability(feature) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
49 let gauge = getGauge(feature);
3480
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
50 let gmDate = gauge.get("gm_measuredate");
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
51 let gmN = gauge.get("gm_n_14d");
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
52 if (
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
53 gmDate !== undefined &&
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
54 gmDate !== null &&
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
55 // latest measurement within configured hours
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
56 Date.parse(gmDate) >
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
57 Date.now() -
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
58 store.state.application.config.gm_latest_hours * 60 * 60 * 1000
3480
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
59 ) {
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
60 // at least configured amount of measurements in last 14 days
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
61 const valuesAtLeast = store.state.application.config.gm_min_values_14d;
3498
4d44eda484dd make the linter happier
Thomas Junk <thomas.junk@intevation.de>
parents: 3497
diff changeset
62 if (gmN !== undefined && gmN !== null && gmN >= valuesAtLeast) {
3480
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
63 return "lime";
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
64 }
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
65 return "yellow";
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
66 }
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
67 return "red";
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
68 },
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
69 forecastAccuracy(feature) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
70 let gauge = getGauge(feature);
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 let fa3d = gauge.get("forecast_accuracy_3d");
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 let fa1d = gauge.get("forecast_accuracy_1d");
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 if (typeof fa3d == "number" && typeof fa1d == "number") {
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
74 if (fa1d > store.state.application.config.gm_forecast_offset_24h) {
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 return "red";
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
76 } else if (fa3d > store.state.application.config.gm_forecast_offset_72h) {
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
77 return "yellow";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
78 } else {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 return "lime";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
81 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
82 return "white";
3501
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
83 },
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
84 forecastVsReality(feature) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
85 let gauge = getGauge(feature);
3501
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
86 let nsc = gauge.get("nsc_data");
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
87 if (nsc && nsc.coeffs.reduce((sum, coeff) => sum + coeff.samples, 0)) {
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
88 // 24h < configured value
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
89 if (
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
90 nsc.coeffs[0].samples &&
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
91 nsc.coeffs[0].value <
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
92 store.state.application.config.gm_forecast_vs_reality_nsc_24h
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
93 )
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
94 return "red";
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
95 // 72h < configured value
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
96 if (
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
97 nsc.coeffs[2].samples &&
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
98 nsc.coeffs[2].value <
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
99 store.state.application.config.gm_forecast_vs_reality_nsc_72h
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
100 )
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
101 return "yellow";
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
102 // both > configured value
3501
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
103 return "lime";
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
104 }
3503
b6dd09044951 client: spuc12: added comments
Markus Kottlaender <markus@intevation.de>
parents: 3501
diff changeset
105 // no data available
3501
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
106 return "white";
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
107 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
108 };