diff --git a/public/js/appChart.js b/public/js/appChart.js index 7ff9b4a6e0685f76adc76a62f8d9dc7d129680f8..322e88b47a9c634285ef7a1ceea3810c092347bc 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 b63dc94260e557d4e45d93f5cb519127ef3f2a55..615c0238a117fca5463000d8cf3dfddacfa81cd4 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 2d6cbabab03a296b0d34fb96846f341511cd535f..7b2cca248743999b818759b29171433d99fe08f4 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, +};