Mercurial > gemma
view client/src/store/fairwayavailability.js @ 3264:9ae43313b463
Handle some possibly missing elements in NtS response
The NtS XSD does not guarantee that value, value_min and value_max
are present in a response. This led to circumventing the NOT NULL
constraint for the waterlevel value by silently persisting missing
values as zero and filling up missing confidence interval values
especially for measurements with zeros.
author | Tom Gottfried <tom@intevation.de> |
---|---|
date | Wed, 15 May 2019 12:31:57 +0200 |
parents | 3b36bb33f5b0 |
children | c2d753ef5aa1 |
line wrap: on
line source
/* This is Free Software under GNU Affero General Public License v >= 3.0 * without warranty, see README.md and license for details. * * SPDX-License-Identifier: AGPL-3.0-or-later * License-Filename: LICENSES/AGPL-3.0.txt * * Copyright (C) 2018 by via donau * – Österreichische Wasserstraßen-Gesellschaft mbH * Software engineering by Intevation GmbH * * Author(s): * Thomas Junk <thomas.junk@intevation.de> */ import { HTTP } from "@/lib/http"; const init = () => { return { type: "bottlenecks", selectedFairwayAvailabilityFeature: null, from: null, to: null, frequency: null, fwData: null, legend: null, LOS: null }; }; export default { init, namespaced: true, state: init(), mutations: { type: (state, type) => { state.type = type; }, setLOS: (state, LOS) => { state.LOS = LOS; }, setFrequency: (state, frequency) => { state.frequency = frequency; }, setFrom: (state, from) => { state.from = from; }, setTo: (state, to) => { state.to = to; }, setSelectedFairwayAvailability: (state, feature) => { state.selectedFairwayAvailabilityFeature = feature; }, setFwData: (state, fwData) => { state.fwData = fwData; }, setLegend: (state, header) => { const headerEntries = header.split(","); headerEntries.shift(); state.legend = headerEntries.map(x => { return x.split("#")[1].trim(); }); } }, actions: { loadAvailableFairwayDepth: ({ commit }, options) => { return new Promise((resolve, reject) => { const { feature, from, to, frequency, LOS } = options; const start = encodeURIComponent("00:00:00+00:00"); const end = encodeURIComponent("23:59:59+00:00"); const URL = `/data/bottleneck/fairway-depth/${encodeURIComponent( feature.properties.name )}?from=${from}T${start}&to=${to}T${end}&mode=${frequency}&los=${LOS}`; HTTP.get(URL, { headers: { "X-Gemma-Auth": localStorage.getItem("token") } }) .then(response => { const { data } = response; const csv = data.split("\n").filter(x => x !== ""); //omit empty lines commit("setLegend", csv.shift()); let transformed = csv.map(e => { const result = e.split(","); const label = result.shift(); const ldc = result.shift(); const highestLevel = result.pop(); return { label: label, ldc: ldc, highestLevel: highestLevel, lowerLevels: result }; }); commit("setFwData", transformed); resolve(response); }) .catch(error => { reject(error); }); }); } } };