Mercurial > gemma
annotate client/src/lib/classifications.js @ 3480:965b2fbb1890
Colorize gauge symbol based on availability of measurements
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Mon, 27 May 2019 15:45:55 +0200 |
parents | 71022e6bd98e |
children | 1457e2b9d900 |
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 |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
15 export default { |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
16 surveyCurrency(bottleneck) { |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
17 if ( |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
18 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
|
19 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
|
20 ) { |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
21 return "white"; |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
22 } |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
23 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
|
24 return "red"; |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
25 } |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
26 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
|
27 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
|
28 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
|
29 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
|
30 return "lime"; |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
31 } 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
|
32 return "yellow"; |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
33 } 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
|
34 return "red"; |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
35 } |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
36 }, |
3480
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
37 gmAvailability(gauge) { |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
38 let gmDate = gauge.get("gm_measuredate"); |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
39 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
|
40 if ( |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
41 gmDate !== undefined && |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
42 gmDate !== null && |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
43 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
|
44 ) { |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
45 if ( |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
46 gmN !== undefined && |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
47 gmN !== null && |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
48 gmN >= 1344 // one value every 15 min in 14 days |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
49 ) { |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
50 return "lime"; |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
51 } |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
52 return "yellow"; |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
53 } |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
54 return "red"; |
965b2fbb1890
Colorize gauge symbol based on availability of measurements
Tom Gottfried <tom@intevation.de>
parents:
3472
diff
changeset
|
55 }, |
3472
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
56 forecastAccuracy(gauge) { |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
57 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
|
58 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
|
59 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
|
60 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
|
61 return "red"; |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
62 } 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
|
63 return "yellow"; |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
64 } else { |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
65 return "lime"; |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
66 } |
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 return "white"; |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
69 } |
71022e6bd98e
client: Use classifications for bottleneck diagrams on map and extracted classification algos
Raimund Renkert <raimund.renkert@intevation.de>
parents:
diff
changeset
|
70 }; |