Commit 01c4ba10 authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

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
parent 1f034295
......@@ -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,
......
......@@ -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(
......
......@@ -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,
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment