annotate client/src/lib/classifications.js @ 3550:c0f8f9ba21a7

import_review: sections&stretches accept old and new format in DB
author Thomas Junk <thomas.junk@intevation.de>
date Fri, 31 May 2019 13:59:54 +0200
parents a606d003730c
children bcf9713ee359
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>
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
13 */
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
14
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
15 const getGauge = f => {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
16 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
17 return f.get("gauge_obj");
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
18 }
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
19 return f;
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
3472
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
22 export default {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
23 surveyCurrency(bottleneck) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
24 if (
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
25 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
26 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
27 ) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
28 return "white";
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 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
31 return "red";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
32 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
33 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
34 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
35 var diff = Math.floor((Date.now() - latest) / 86400000);
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
36 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
37 return "lime";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
38 } else if (revTime < diff && diff <= revTime * 1.5) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
39 return "yellow";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
40 } else if (revTime * 1.5 < diff) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
41 return "red";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
42 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
43 },
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
44 gmAvailability(feature) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
45 let gauge = getGauge(feature);
3480
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
46 let gmDate = gauge.get("gm_measuredate");
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
47 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
48 if (
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
49 gmDate !== undefined &&
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
50 gmDate !== null &&
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
51 Date.parse(gmDate) > Date.now() - 86400000 // latest value within 24 h
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
52 ) {
3498
4d44eda484dd make the linter happier
Thomas Junk <thomas.junk@intevation.de>
parents: 3497
diff changeset
53 // 1344: one value every 15 min in 14 days, but the Hydra says:
4d44eda484dd make the linter happier
Thomas Junk <thomas.junk@intevation.de>
parents: 3497
diff changeset
54 // let 85% be enough for now.
4d44eda484dd make the linter happier
Thomas Junk <thomas.junk@intevation.de>
parents: 3497
diff changeset
55 const valuesAtLeast = 1124;
4d44eda484dd make the linter happier
Thomas Junk <thomas.junk@intevation.de>
parents: 3497
diff changeset
56 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
57 return "lime";
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
58 }
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
59 return "yellow";
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
60 }
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
61 return "red";
965b2fbb1890 Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents: 3472
diff changeset
62 },
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
63 forecastAccuracy(feature) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
64 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
65 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
66 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
67 if (typeof fa3d == "number" && typeof fa1d == "number") {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
68 if (fa1d > 15) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
69 return "red";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
70 } else if (fa3d > 15) {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
71 return "yellow";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
72 } else {
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
73 return "lime";
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
74 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
75 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
76 return "white";
3501
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
77 },
3507
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
78 forecastVsReality(feature) {
a606d003730c client: spuc12: implemented diagram for reference gauge of bottlenecks
Markus Kottlaender <markus@intevation.de>
parents: 3503
diff changeset
79 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
80 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
81 if (nsc && nsc.coeffs.reduce((sum, coeff) => sum + coeff.samples, 0)) {
3503
b6dd09044951 client: spuc12: added comments
Markus Kottlaender <markus@intevation.de>
parents: 3501
diff changeset
82 // 24h < 12.5
3501
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
83 if (nsc.coeffs[0].samples && nsc.coeffs[0].value < -12.5) return "red";
3503
b6dd09044951 client: spuc12: added comments
Markus Kottlaender <markus@intevation.de>
parents: 3501
diff changeset
84 // 72h < 12.5
3501
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
85 if (nsc.coeffs[2].samples && nsc.coeffs[2].value < -12.5) return "yellow";
3503
b6dd09044951 client: spuc12: added comments
Markus Kottlaender <markus@intevation.de>
parents: 3501
diff changeset
86 // both > 12.5
3501
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
87 return "lime";
c5c7cc24fe72 client: spuc12: implemented nash sutcliffe for forcast vs reality accuracy indicator
Markus Kottlaender <markus@intevation.de>
parents: 3498
diff changeset
88 }
3503
b6dd09044951 client: spuc12: added comments
Markus Kottlaender <markus@intevation.de>
parents: 3501
diff changeset
89 // 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
90 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
91 }
71022e6bd98e client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff changeset
92 };