From 1c6ac11388ce51c1aee8ad4e909cd28fb5deb3d5 Mon Sep 17 00:00:00 2001 From: Luc Claustres Date: Wed, 4 Sep 2024 16:50:10 +0200 Subject: [PATCH] fix: run time management in time series function --- map/client/utils/utils.time-series.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/map/client/utils/utils.time-series.js b/map/client/utils/utils.time-series.js index 04d40c67c..a29bb0056 100644 --- a/map/client/utils/utils.time-series.js +++ b/map/client/utils/utils.time-series.js @@ -5,10 +5,10 @@ import { isMeasureLayer } from './utils.layers.js' import { getMeasureForFeature } from './utils.features.js' import { getForecastForLocation, getForecastProbe, getForecastForFeature } from './utils.weacast.js' -async function getDataForVariable(data, variable, forecastLevel) { +async function getDataForVariable(data, variable, forecastLevel, runTime) { data = await data - const time = _.get(data, 'time', _.get(data, 'forecastTime')) - const runTime = _.get(data, 'runTime') + const times = _.get(data, 'time', _.get(data, 'forecastTime')) + const runTimes = _.get(data, 'runTime') const properties = _.get(data, 'properties', {}) // Check if we are targetting a specific variable at level (forecast model case) const name = (forecastLevel ? `${variable.name}-${forecastLevel}` : variable.name) @@ -16,10 +16,10 @@ async function getDataForVariable(data, variable, forecastLevel) { // Aggregated variable available for feature ? if (properties[name] && Array.isArray(properties[name])) { // Build data structure as expected by visualisation - values = properties[name].map((value, index) => ({ time: moment.utc(time[name][index]).valueOf(), [name]: value })) + values = properties[name].map((value, index) => ({ time: moment.utc(times[name][index]).valueOf(), [name]: value })) // Keep only selected value if multiple are provided for the same time (eg different forecasts) - if (variable.runTimes && !_.isEmpty(_.get(runTime, name)) && runTime) { - values = values.filter((value, index) => (runTime[name][index] === runTime.toISOString())) + if (variable.runTimes && runTime && !_.isEmpty(_.get(runTimes, name))) { + values = values.filter((value, index) => (runTimes[name][index] === runTime.toISOString())) } else values = _.uniqBy(values, 'time') } return values @@ -100,7 +100,7 @@ export function getTimeSeries({ // FIXME: how to share promise between series ? serie.fetch = () => { serie.probedLocation = fetch() - serie.data = getDataForVariable(serie.probedLocation, variable, forecastLevel) + serie.data = getDataForVariable(serie.probedLocation, variable, forecastLevel, runTime) } return serie })