Mercurial > gemma
annotate client/src/store/gauges.js @ 2823:b150e5b37afe
Import queue: As it is important to keep the in-memory and the persistent model in sync try harder to store the final state change if it fails.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 27 Mar 2019 12:12:12 +0100 |
parents | 12f053763be2 |
children | c2b90cb426ed |
rev | line source |
---|---|
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
1 /* This is Free Software under GNU Affero General Public License v >= 3.0 |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
2 * without warranty, see README.md and license for details. |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
3 * |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
4 * SPDX-License-Identifier: AGPL-3.0-or-later |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
5 * License-Filename: LICENSES/AGPL-3.0.txt |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
6 * |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
7 * Copyright (C) 2018 by via donau |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
8 * – Österreichische Wasserstraßen-Gesellschaft mbH |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
9 * Software engineering by Intevation GmbH |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
10 * |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
11 * Author(s): |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
12 * Markus Kottländer <markus@intevation.de> |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
13 */ |
2596
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
14 import { HTTP } from "@/lib/http"; |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
15 import { WFS } from "ol/format.js"; |
2764
f0846d200ce4
client: waterlevel diagram: remove past predictions from waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
16 import { isPast } from "date-fns"; |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
17 |
2710
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
18 let dateFrom = new Date(); |
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
19 dateFrom.setDate(dateFrom.getDate() - 30); |
2775
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2764
diff
changeset
|
20 let dateTo = new Date(); |
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2764
diff
changeset
|
21 dateTo.setDate(dateTo.getDate() + 3); |
2710
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
22 |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
23 const init = () => { |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
24 return { |
2596
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
25 gauges: [], |
2643
27933e66e848
client: gauges: use isrs_code as unique id for gauges
Markus Kottlaender <markus@intevation.de>
parents:
2604
diff
changeset
|
26 selectedGaugeISRS: null, |
2710
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
27 waterlevels: [], |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
28 longtermWaterlevels: [], |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
29 yearWaterlevels: [], |
2751
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
30 nashSutcliffe: null, |
2710
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
31 dateFrom: dateFrom, |
2775
2feb9f8f6c66
client: waterlevel diagram: implemented display of forecast data
Markus Kottlaender <markus@intevation.de>
parents:
2764
diff
changeset
|
32 dateTo: dateTo |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
33 }; |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
34 }; |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
35 |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
36 export default { |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
37 init, |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
38 namespaced: true, |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
39 state: init(), |
2604
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
40 getters: { |
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
41 selectedGauge: state => { |
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
42 return state.gauges.find( |
2643
27933e66e848
client: gauges: use isrs_code as unique id for gauges
Markus Kottlaender <markus@intevation.de>
parents:
2604
diff
changeset
|
43 g => g.properties.isrs_code === state.selectedGaugeISRS |
2604
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
44 ); |
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
45 } |
85f9bf4a6eba
client: gauge waterlevel diagram: draw reference waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2596
diff
changeset
|
46 }, |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
47 mutations: { |
2596
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
48 gauges: (state, gauges) => { |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
49 state.gauges = gauges; |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
50 }, |
2643
27933e66e848
client: gauges: use isrs_code as unique id for gauges
Markus Kottlaender <markus@intevation.de>
parents:
2604
diff
changeset
|
51 selectedGaugeISRS: (state, isrs) => { |
27933e66e848
client: gauges: use isrs_code as unique id for gauges
Markus Kottlaender <markus@intevation.de>
parents:
2604
diff
changeset
|
52 state.selectedGaugeISRS = isrs; |
2596
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
53 }, |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
54 waterlevels: (state, data) => { |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
55 state.waterlevels = data; |
2710
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
56 }, |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
57 longtermWaterlevels: (state, data) => { |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
58 state.longtermWaterlevels = data; |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
59 }, |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
60 yearWaterlevels: (state, data) => { |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
61 state.yearWaterlevels = data; |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
2751
diff
changeset
|
62 }, |
2751
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
63 nashSutcliffe: (state, data) => { |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
64 state.nashSutcliffe = data; |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
65 }, |
2710
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
66 dateFrom: (state, dateFrom) => { |
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
67 state.dateFrom = dateFrom; |
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
68 }, |
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
69 dateTo: (state, dateTo) => { |
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
70 state.dateTo = dateTo; |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
71 } |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
72 }, |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
73 actions: { |
2643
27933e66e848
client: gauges: use isrs_code as unique id for gauges
Markus Kottlaender <markus@intevation.de>
parents:
2604
diff
changeset
|
74 selectedGaugeISRS: ({ commit }, isrs) => { |
27933e66e848
client: gauges: use isrs_code as unique id for gauges
Markus Kottlaender <markus@intevation.de>
parents:
2604
diff
changeset
|
75 commit("selectedGaugeISRS", isrs); |
2596
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
76 commit("application/showGauges", true, { root: true }); |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
77 }, |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
78 loadGauges: ({ commit }) => { |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
79 return new Promise((resolve, reject) => { |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
80 var gaugesFeatureCollectionRequest = new WFS().writeGetFeature({ |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
81 srsName: "EPSG:4326", |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
82 featureNS: "gemma", |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
83 featurePrefix: "gemma", |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
84 featureTypes: ["gauges_geoserver"], |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
85 outputFormat: "application/json" |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
86 }); |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
87 HTTP.post( |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
88 "/internal/wfs", |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
89 new XMLSerializer().serializeToString(gaugesFeatureCollectionRequest), |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
90 { |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
91 headers: { |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
92 "X-Gemma-Auth": localStorage.getItem("token"), |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
93 "Content-type": "text/xml; charset=UTF-8" |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
94 } |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
95 } |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
96 ) |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
97 .then(response => { |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
98 commit("gauges", response.data.features); |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
99 resolve(response); |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
100 }) |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
101 .catch(error => { |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
102 reject(error); |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
103 }); |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
104 }); |
8774054959a7
client: added Gauges dialog/tool to show waterlevel diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2590
diff
changeset
|
105 }, |
2744
7dcca9649a61
client: waterlevel diagram: use selectedGaugeISRS to load waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2716
diff
changeset
|
106 loadWaterlevels({ state, commit }) { |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
107 // include the last day |
2710
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
108 let dateTo = new Date(state.dateTo.getTime() + 86400); |
2657
b6865a08c905
client: waterlevel diagram: use real test data
Markus Kottlaender <markus@intevation.de>
parents:
2643
diff
changeset
|
109 |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
110 return new Promise((resolve, reject) => { |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
111 HTTP.get( |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
112 `/data/waterlevels/${ |
2744
7dcca9649a61
client: waterlevel diagram: use selectedGaugeISRS to load waterlevels
Markus Kottlaender <markus@intevation.de>
parents:
2716
diff
changeset
|
113 state.selectedGaugeISRS |
2710
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
114 }?from=${state.dateFrom |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
115 .toISOString() |
2710
f393fabfdd35
client: waterlevel diagram: chart extent based on selected dates instead of data
Markus Kottlaender <markus@intevation.de>
parents:
2701
diff
changeset
|
116 .substr(0, 23)}&to=${dateTo.toISOString().substr(0, 23)}`, |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
117 { |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
118 headers: { "X-Gemma-Auth": localStorage.getItem("token") } |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
119 } |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
120 ) |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
121 .then(response => { |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
122 let data = response.data |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
123 .split("\n") |
2793
16d08532c420
client: waterlevel diagram: added prediction's min max values to parsing of waterlevel csv
Markus Kottlaender <markus@intevation.de>
parents:
2791
diff
changeset
|
124 .filter((wl, i) => wl && i) // remove empty rows and first row |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
125 .map(wl => { |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
126 wl = wl.split(","); |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
127 return { |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
128 date: new Date(wl[0]), |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
129 waterlevel: Number(wl[1]), |
2793
16d08532c420
client: waterlevel diagram: added prediction's min max values to parsing of waterlevel csv
Markus Kottlaender <markus@intevation.de>
parents:
2791
diff
changeset
|
130 min: Number(wl[2]), |
16d08532c420
client: waterlevel diagram: added prediction's min max values to parsing of waterlevel csv
Markus Kottlaender <markus@intevation.de>
parents:
2791
diff
changeset
|
131 max: Number(wl[3]), |
16d08532c420
client: waterlevel diagram: added prediction's min max values to parsing of waterlevel csv
Markus Kottlaender <markus@intevation.de>
parents:
2791
diff
changeset
|
132 predicted: wl[4] === "f" ? false : true |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
133 }; |
2764
f0846d200ce4
client: waterlevel diagram: remove past predictions from waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
134 }) |
f0846d200ce4
client: waterlevel diagram: remove past predictions from waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2761
diff
changeset
|
135 .filter(wl => !(wl.predicted && isPast(wl.date))); |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
136 data = data.sort((a, b) => a.date - b.date); |
2692
966c94e699fa
client: waterlevel diagram: simulate loading time and removed old demo code
Markus Kottlaender <markus@intevation.de>
parents:
2657
diff
changeset
|
137 commit("waterlevels", data); |
966c94e699fa
client: waterlevel diagram: simulate loading time and removed old demo code
Markus Kottlaender <markus@intevation.de>
parents:
2657
diff
changeset
|
138 resolve(data); |
2701
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
139 }) |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
140 .catch(error => { |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
141 commit("waterlevels", []); |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
142 reject(error); |
e622689d73bd
client: waterlevel diagram: use endpoint
Markus Kottlaender <markus@intevation.de>
parents:
2692
diff
changeset
|
143 }); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
144 }); |
2751
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
145 }, |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
146 loadLongtermWaterlevels({ state, commit }) { |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
147 return new Promise((resolve, reject) => { |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
148 HTTP.get(`/data/longterm-waterlevels/${state.selectedGaugeISRS}`, { |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
149 headers: { "X-Gemma-Auth": localStorage.getItem("token") } |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
150 }) |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
151 .then(response => { |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
152 const now = new Date(); |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
153 let data = response.data |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
154 .split("\n") |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
155 .filter((wl, i) => wl && i) // remove empty rows and first row |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
156 .map(wl => { |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
157 wl = wl.split(","); |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
158 let dayAndMonth = wl[0].split("-").map(n => Number(n)); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
159 let date = new Date( |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
160 now.getFullYear(), |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
161 dayAndMonth[1] - 1, |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
162 dayAndMonth[0] |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
163 ); |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
164 return { |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
165 date: date, |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
166 min: Number(wl[1]), |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
167 max: Number(wl[2]), |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
168 mean: Number(wl[3]), |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
169 median: Number(wl[4]), |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
170 q25: Number(wl[5]), |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
171 q75: Number(wl[6]) |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
172 }; |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
173 }); |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
174 data = data.sort((a, b) => a.date - b.date); |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
175 commit("longtermWaterlevels", data); |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
176 resolve(data); |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
177 }) |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
178 .catch(error => { |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
179 commit("longtermWaterlevels", []); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
180 reject(error); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
181 }); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
182 }); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
183 }, |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
184 loadYearWaterlevels({ state, commit }, year) { |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
185 return new Promise((resolve, reject) => { |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
186 HTTP.get(`/data/year-waterlevels/${state.selectedGaugeISRS}/${year}`, { |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
187 headers: { "X-Gemma-Auth": localStorage.getItem("token") } |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
188 }) |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
189 .then(response => { |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
190 const now = new Date(); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
191 let data = response.data |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
192 .split("\n") |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
193 .filter((wl, i) => wl && i) // remove empty rows and first row |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
194 .map(wl => { |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
195 wl = wl.split(","); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
196 let dayAndMonth = wl[0].split("-").map(n => Number(n)); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
197 let date = new Date( |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
198 now.getFullYear(), |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
199 dayAndMonth[1] - 1, |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
200 dayAndMonth[0] |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
201 ); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
202 return { |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
203 date: date, |
2815
12f053763be2
client: spuc8: finished drawing charts, optimized code
Markus Kottlaender <markus@intevation.de>
parents:
2813
diff
changeset
|
204 mean: Number(wl[1]) |
2813
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
205 }; |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
206 }); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
207 data = data.sort((a, b) => a.date - b.date); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
208 commit("yearWaterlevels", data); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
209 resolve(data); |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
210 }) |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
211 .catch(error => { |
49c1570919ae
client: spuc8: use new endpoints to fetch year based and longterm waterlevel data
Markus Kottlaender <markus@intevation.de>
parents:
2793
diff
changeset
|
212 commit("yearWaterlevels", []); |
2791
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
213 reject(error); |
2b79c0871138
client: spuc8: draw diagrams
Markus Kottlaender <markus@intevation.de>
parents:
2775
diff
changeset
|
214 }); |
2761
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
2751
diff
changeset
|
215 }); |
71e7237110ba
client: spuc8: prepared diagram
Markus Kottlaender <markus@intevation.de>
parents:
2751
diff
changeset
|
216 }, |
2751
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
217 loadNashSutcliffe({ state, commit }) { |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
218 return new Promise((resolve, reject) => { |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
219 HTTP.get(`/data/nash-sutcliffe/${state.selectedGaugeISRS}`, { |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
220 headers: { "X-Gemma-Auth": localStorage.getItem("token") } |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
221 }) |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
222 .then(response => { |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
223 commit("nashSutcliffe", response.data); |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
224 resolve(response.data); |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
225 }) |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
226 .catch(error => { |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
227 commit("nashSutcliffe", null); |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
228 reject(error); |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
229 }); |
5da81634bdc4
client: waterlevel diagram: implemented nash-sutcliffe
Markus Kottlaender <markus@intevation.de>
parents:
2744
diff
changeset
|
230 }); |
2590
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
231 } |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
232 } |
1686ec185155
client: added gauge waterlevel example diagram
Markus Kottlaender <markus@intevation.de>
parents:
diff
changeset
|
233 }; |