annotate client/src/store/diagram.js @ 3198:b0328646e34f

statistics: include los selection
author Thomas Junk <thomas.junk@intevation.de>
date Wed, 08 May 2019 15:26:59 +0200
parents 0d76a0476a5b
children cb67ee72485b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
1 /* This is Free Software under GNU Affero General Public License v >= 3.0
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
2 * without warranty, see README.md and license for details.
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
3 *
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
4 * SPDX-License-Identifier: AGPL-3.0-or-later
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
5 * License-Filename: LICENSES/AGPL-3.0.txt
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
6 *
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
7 * Copyright (C) 2018 by via donau
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
8 * – Österreichische Wasserstraßen-Gesellschaft mbH
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
9 * Software engineering by Intevation GmbH
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
10 *
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
11 * Author(s):
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
12 * Thomas Junk <thomas.junk@intevation.de>
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
13 */
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
14
3185
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
15 import { HTTP } from "@/lib/http";
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
16
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
17 const MOCKDATA = `#label,# >= LDC [h],# < 200.00 [h],# >= 200.00 [h],# >= 230.00 [h],# >= 250.00 [h]
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
18 01-2019, 22.000,1.000, 4.000,6.000, 20.000
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
19 02-2019, 24.000,0.000,0.000,0.000, 23.000
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
20 03-2019, 30.000,0.000,0.000,0.000, 30.000
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
21 04-2019, 30.000,0.000,0.000,0.000, 30.000
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
22 05-2019, 30.000,0.000,0.000,0.000, 30.000`;
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
23
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
24 const init = () => {
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
25 return {
3185
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
26 selectedFairwayAvailabilityFeature: null,
3191
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
27 from: null,
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
28 to: null,
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
29 frequency: null,
3185
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
30 fwData: null,
3198
b0328646e34f statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents: 3196
diff changeset
31 legend: null,
b0328646e34f statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents: 3196
diff changeset
32 LOS: null
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
33 };
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
34 };
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
35
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
36 const diagram = {
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
37 init,
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
38 namespaced: true,
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
39 state: init(),
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
40 mutations: {
3198
b0328646e34f statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents: 3196
diff changeset
41 setLOS: (state, LOS) => {
b0328646e34f statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents: 3196
diff changeset
42 state.LOS = LOS;
b0328646e34f statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents: 3196
diff changeset
43 },
3191
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
44 setFrequency: (state, frequency) => {
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
45 state.frequency = frequency;
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
46 },
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
47 setFrom: (state, from) => {
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
48 state.from = from;
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
49 },
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
50 setTo: (state, to) => {
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
51 state.to = to;
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
52 },
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
53 setSelectedFairwayAvailability: (state, feature) => {
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
54 state.selectedFairwayAvailabilityFeature = feature;
3185
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
55 },
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
56 setFwData: (state, fwData) => {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
57 state.fwData = fwData;
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
58 },
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
59 setLegend: (state, header) => {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
60 const headerEntries = header.split(",");
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
61 headerEntries.shift();
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
62 state.legend = headerEntries.map(x => {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
63 return x.split("#")[1].trim();
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
64 });
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
65 }
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
66 },
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
67 actions: {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
68 loadAvailableFairwayDepth: ({ commit }, options) => {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
69 return new Promise((resolve, reject) => {
3198
b0328646e34f statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents: 3196
diff changeset
70 const { feature, from, to, frequency, LOS } = options;
3196
0d76a0476a5b diagram_store: fix encodeURIComponent
Thomas Junk <thomas.junk@intevation.de>
parents: 3195
diff changeset
71 const start = encodeURIComponent("00:00:00+07:00");
0d76a0476a5b diagram_store: fix encodeURIComponent
Thomas Junk <thomas.junk@intevation.de>
parents: 3195
diff changeset
72 const end = encodeURIComponent("23:59:59+07:00");
0d76a0476a5b diagram_store: fix encodeURIComponent
Thomas Junk <thomas.junk@intevation.de>
parents: 3195
diff changeset
73 const URL = `/data/bottleneck/fairway-depth/${encodeURIComponent(
3191
c0cd5dfec153 statistics: persist fields to vuex
Thomas Junk <thomas.junk@intevation.de>
parents: 3185
diff changeset
74 feature.properties.name
3198
b0328646e34f statistics: include los selection
Thomas Junk <thomas.junk@intevation.de>
parents: 3196
diff changeset
75 )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}`;
3185
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
76 HTTP.get(URL, {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
77 headers: { "X-Gemma-Auth": localStorage.getItem("token") }
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
78 })
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
79 .then(response => {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
80 const data = MOCKDATA;
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
81 const csv = data.split("\n");
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
82 commit("setLegend", csv.shift());
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
83 let transformed = csv.map(e => {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
84 const result = e.split(",");
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
85 const label = result.shift();
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
86 const ldc = result.shift();
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
87 const highestLevel = result.pop();
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
88 return {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
89 label: label,
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
90 ldc: ldc,
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
91 highestLevel: highestLevel,
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
92 lowerLevels: result
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
93 };
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
94 });
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
95 commit("setFwData", transformed);
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
96 resolve(response);
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
97 })
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
98 .catch(error => {
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
99 reject(error);
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
100 });
505414dfe3e7 available_fairway_depth: move statistic dialog to store
Thomas Junk <thomas.junk@intevation.de>
parents: 3184
diff changeset
101 });
3184
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
102 }
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
103 }
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
104 };
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
105
1ba2a7d22fbb available_fairway_depth: display selected feature
Thomas Junk <thomas.junk@intevation.de>
parents:
diff changeset
106 export { diagram };