annotate client/src/lib/classifications.js @ 4288:767a6500a666

classifications: refactor
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 30 Aug 2019 10:09:35 +0200
parents 30f26bf7ff24
children e8af2ed8666e
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) {
4270
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
19 const GaugeProxy = (function(feature) {
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
20 const gauge = feature.get("gauge_obj");
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
21 const get = function(propName) {
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
22 if (gauge) return gauge.get(propName);
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
23 return feature.get(propName);
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
24 };
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
25 return {
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
26 get: get
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
27 };
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
28 })(f);
e4d6c6339cb4 identify_tool: accuracy legend improved
Thomas Junk <thomas.junk@intevation.de>
parents: 4266
diff changeset
29 return GaugeProxy;
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
30 }
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
31 return f;
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
32 };
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
33
4288
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
34 const calcForecastVsRealityForNSC = nsc => {
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
35 if (nsc && nsc.coeffs.reduce((sum, coeff) => sum + coeff.samples, 0)) {
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
36 // 24h < configured value
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
37 if (
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
38 nsc.coeffs[0].samples &&
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
39 nsc.coeffs[0].value <
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
40 store.state.application.config.gm_forecast_vs_reality_nsc_24h
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
41 )
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
42 return "DANGER";
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
43 // 72h < configured value
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
44 if (
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
45 nsc.coeffs[2].samples &&
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
46 nsc.coeffs[2].value <
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
47 store.state.application.config.gm_forecast_vs_reality_nsc_72h
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
48 )
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
49 return "WARNING";
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
50 // both > configured value
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
51 return "OK";
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
52 }
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
53 // no data available
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
54 return "NEUTRAL";
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
55 };
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
56
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
57 export default {
4279
30f26bf7ff24 Reordering of elements
Thomas Junk <thomas.junk@intevation.de>
parents: 4270
diff changeset
58 surveyRecency(bottleneck) {
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
59 if (
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
60 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
61 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
62 ) {
4265
2596a028dc3a Feature_info: display partial legend information for bottlenecks
Thomas Junk <thomas.junk@intevation.de>
parents: 3617
diff changeset
63 return "NEUTRAL";
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
64 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
65 if (bottleneck.get("date_max") === null) {
4265
2596a028dc3a Feature_info: display partial legend information for bottlenecks
Thomas Junk <thomas.junk@intevation.de>
parents: 3617
diff changeset
66 return "DANGER";
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
67 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 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
69 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
70 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
71 let revTimeMultiplier =
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
72 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
73 if (diff <= revTime) {
4265
2596a028dc3a Feature_info: display partial legend information for bottlenecks
Thomas Junk <thomas.junk@intevation.de>
parents: 3617
diff changeset
74 return "OK";
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
75 } else if (revTime < diff && diff <= revTime * revTimeMultiplier) {
4265
2596a028dc3a Feature_info: display partial legend information for bottlenecks
Thomas Junk <thomas.junk@intevation.de>
parents: 3617
diff changeset
76 return "WARNING";
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
77 } else if (revTime * revTimeMultiplier < diff) {
4265
2596a028dc3a Feature_info: display partial legend information for bottlenecks
Thomas Junk <thomas.junk@intevation.de>
parents: 3617
diff changeset
78 return "DANGER";
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
79 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
80 },
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
81 gmAvailability(feature) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
82 let gauge = getGauge(feature);
3480
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
83 let gmDate = gauge.get("gm_measuredate");
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
84 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
85 if (
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
86 gmDate !== undefined &&
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
87 gmDate !== null &&
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
88 // latest measurement within configured hours
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
89 Date.parse(gmDate) >
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
90 Date.now() -
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
91 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
92 ) {
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
93 // 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
94 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
95 if (gmN !== undefined && gmN !== null && gmN >= valuesAtLeast) {
4266
fbe2f1aa2757 styles: refactor color coding accuracy colors
Thomas Junk <thomas.junk@intevation.de>
parents: 4265
diff changeset
96 return "OK";
3480
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
97 }
4266
fbe2f1aa2757 styles: refactor color coding accuracy colors
Thomas Junk <thomas.junk@intevation.de>
parents: 4265
diff changeset
98 return "WARNING";
3480
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
99 }
4266
fbe2f1aa2757 styles: refactor color coding accuracy colors
Thomas Junk <thomas.junk@intevation.de>
parents: 4265
diff changeset
100 return "DANGER";
3480
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
101 },
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
102 forecastAccuracy(feature) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
103 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
104 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
105 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
106 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
107 if (fa1d > store.state.application.config.gm_forecast_offset_24h) {
4266
fbe2f1aa2757 styles: refactor color coding accuracy colors
Thomas Junk <thomas.junk@intevation.de>
parents: 4265
diff changeset
108 return "DANGER";
3617
bcf9713ee359 client: configuration: prepared fetching data accuracy values from backend
Markus Kottlaender <markus@intevation.de>
parents: 3507
diff changeset
109 } else if (fa3d > store.state.application.config.gm_forecast_offset_72h) {
4266
fbe2f1aa2757 styles: refactor color coding accuracy colors
Thomas Junk <thomas.junk@intevation.de>
parents: 4265
diff changeset
110 return "WARNING";
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
111 } else {
4266
fbe2f1aa2757 styles: refactor color coding accuracy colors
Thomas Junk <thomas.junk@intevation.de>
parents: 4265
diff changeset
112 return "OK";
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
113 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
114 }
4266
fbe2f1aa2757 styles: refactor color coding accuracy colors
Thomas Junk <thomas.junk@intevation.de>
parents: 4265
diff changeset
115 return "NEUTRAL";
3501
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
116 },
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
117 forecastVsReality(feature) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
118 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
119 let nsc = gauge.get("nsc_data");
4288
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
120 return calcForecastVsRealityForNSC(nsc);
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
121 },
767a6500a666 classifications: refactor
Thomas Junk <thomas.junk@intevation.de>
parents: 4279
diff changeset
122 calcForecastVsRealityForNSC: calcForecastVsRealityForNSC
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
123 };