From 01c4ba1056f3b37f8821d666c97657fc1c2049b1 Mon Sep 17 00:00:00 2001 From: Pithon Kabiro <pithon.kabiro@hft-stuttgart.de> Date: Fri, 22 Oct 2021 19:27:16 +0200 Subject: [PATCH] Edit function: calculate temp diff observations Remove the logic that throws an error if there is a problem fetching metadata and observations. It is currently not working as expected --- public/js/appChart.js | 5 +++- .../src_modules/calculateTemperatureDiff.mjs | 10 ------- public/js/src_modules/fetchData.mjs | 29 ++++++++++++++++++- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/public/js/appChart.js b/public/js/appChart.js index 7ff9b4a..322e88b 100644 --- a/public/js/appChart.js +++ b/public/js/appChart.js @@ -7,7 +7,10 @@ import { import { calculateVorlaufMinusRuecklaufTemperature } from "./src_modules/calculateTemperatureDiff.mjs"; -import { getMetadataPlusObservationsFromSingleOrMultipleDatastreams } from "./src_modules/fetchData.mjs"; +import { + getMetadataPlusObservationsFromSingleOrMultipleDatastreams, + isFetchingRawMetadataPlusObservationsSuccessful, +} from "./src_modules/fetchData.mjs"; import { formatDatastreamMetadataForChart, diff --git a/public/js/src_modules/calculateTemperatureDiff.mjs b/public/js/src_modules/calculateTemperatureDiff.mjs index b63dc94..615c023 100644 --- a/public/js/src_modules/calculateTemperatureDiff.mjs +++ b/public/js/src_modules/calculateTemperatureDiff.mjs @@ -175,16 +175,6 @@ export const calculateVorlaufMinusRuecklaufTemperature = async function ( bldgDataPtSamplingRateNestedArr ); - // If there is an error in fetching metadata + observations, - // the returned array will have this structure: [[undefined, undefined], undefined] - // Note that the second element is not an array as we would expect but is a - // a single `undefined` value - if (typeof observationsPlusMetadata[0][0] === "undefined") { - throw new Error( - `There was a problem in calculating the temperature difference (dT).\nThis is most likely due to a problem in fetching metadata and observations` - ); - } - // dT observations (timestamp + value) const vorlaufMinusRuecklaufTemperatureObs = calculateVorlaufMinusRuecklaufTemperatureObservations( diff --git a/public/js/src_modules/fetchData.mjs b/public/js/src_modules/fetchData.mjs index 2d6cbab..7b2cca2 100644 --- a/public/js/src_modules/fetchData.mjs +++ b/public/js/src_modules/fetchData.mjs @@ -274,4 +274,31 @@ const getMetadataPlusObservationsFromSingleOrMultipleDatastreams = } }; -export { getMetadataPlusObservationsFromSingleOrMultipleDatastreams }; +/** + * Check whether the raw observations and metadata have been successfully fetched, otherwise throw an error + * + * @param {Array} observationsRawPlusMetadataArr A 1*2 array (the first element is an array that contans N Observations arrays; and the second element is an array of N Datastream metadata objects) + * @returns {Boolean} true, if the raw metadata and observations are successfully retrieved, otherwise an error is thrown + */ +const isFetchingRawMetadataPlusObservationsSuccessful = function ( + observationsRawPlusMetadataArr +) { + // If there is an error in fetching metadata + observations (raw observations) + // the returned array will have this structure: [[undefined, undefined], undefined] + // Note that the second element is not an array as we would expect but is a + // a single `undefined` value + if (typeof observationsRawPlusMetadataArr[0][0] === "undefined") { + throw new Error( + `There was a problem in fetching metadata and observations` + ); + } + // If metadata + observations fetched successfully + else { + return true; + } +}; + +export { + getMetadataPlusObservationsFromSingleOrMultipleDatastreams, + isFetchingRawMetadataPlusObservationsSuccessful, +}; -- GitLab