diff --git a/public/js/src_modules/calculateTemperatureDiff.mjs b/public/js/src_modules/calculateTemperatureDiff.mjs index eec34cbc480ecee9268d16d0ecd9979b409d9bca..615c0238a117fca5463000d8cf3dfddacfa81cd4 100644 --- a/public/js/src_modules/calculateTemperatureDiff.mjs +++ b/public/js/src_modules/calculateTemperatureDiff.mjs @@ -1,6 +1,10 @@ "use strict"; -import { checkForAndDeleteUniqueObservationsFromLargerArray } from "./chartHelpers.mjs"; +import { + checkForAndDeleteUniqueObservationsFromLargerArray, + extractSamplingRateFromDatastreamName, + extractBuildingIdFromDatastreamName, +} from "./chartHelpers.mjs"; import { getMetadataPlusObservationsFromSingleOrMultipleDatastreams } from "./fetchData.mjs"; @@ -73,14 +77,10 @@ const calculateVorlaufMinusRuecklaufTemperatureObservations = function ( * Create synthetic metadata for the temperature difference, dT, between Vorlauf temperature [VL] and * Rücklauf temperature [RL] (i.e., dT = VL - RL) of a single building * - * @param {String} buildingId The building ID - * @param {String} samplingRate The sampling rate * @param {Array} observationsPlusMetadataArr A 1*2 array, where the first element is an array made up of two arrays of observations and the second element is an array of two metadata objects * @returns {Object} A metadata object for dT, made up of three properties: description, name and unit of measurement */ const createVorlaufMinusRuecklaufTemperatureMetadata = function ( - buildingId, - samplingRate, observationsPlusMetadataArr ) { // Extract metadata; second element of array, note that we skip the first element @@ -112,8 +112,23 @@ const createVorlaufMinusRuecklaufTemperatureMetadata = function ( "" ); + // Create an array of the VL datastream name, this array has only one element. + // We need this structure since the functions `extractBuildingIdFromDatastreamName` + // and `extractSamplingRateFromDatastreamName` expect an array of datastream names + const datastreamNameVorlaufArr = [datastreamNameVorlauf]; + + // Extract the building ID from the datastream name + const buildingId = extractBuildingIdFromDatastreamName( + datastreamNameVorlaufArr + ); + + // Extract the sampling rate from the datastream name + const samplingRate = extractSamplingRateFromDatastreamName( + datastreamNameVorlaufArr + ); + // Create our custom datastream name text - const nameTempDifference = `BOSCH_${buildingId} / dT Temperature difference (VL-RL) DS:${samplingRate}`; + const nameTempDifference = `${buildingId} / dT Temperature difference (VL-RL) DS:${samplingRate}`; return { descriptionTempDifference, @@ -153,10 +168,6 @@ export const calculateVorlaufMinusRuecklaufTemperature = async function ( // Note: We have to use a for/of loop here due to the asynchronous nature of our code for (const bldgDataPtSamplingRateNestedArr of buildingDataPointSamplingRateNestedTwiceArr) { - // Use the first element of the nested array to extract building ID + sampling rate - // Note: we skip the second element - const [buildingId, , samplingRate] = bldgDataPtSamplingRateNestedArr[0]; - const observationsPlusMetadata = await getMetadataPlusObservationsFromSingleOrMultipleDatastreams( baseUrl, @@ -176,8 +187,6 @@ export const calculateVorlaufMinusRuecklaufTemperature = async function ( nameTempDifference, unitOfMeasurementVorlauf, } = createVorlaufMinusRuecklaufTemperatureMetadata( - buildingId, - samplingRate, observationsPlusMetadata ); diff --git a/public/js/src_modules/chartHelpers.mjs b/public/js/src_modules/chartHelpers.mjs index 1e335336fb7ab179cb4f63e94fe074a774c733e6..1ef57452f34c79c8ad086d2ccf4a9911cdc54f80 100644 --- a/public/js/src_modules/chartHelpers.mjs +++ b/public/js/src_modules/chartHelpers.mjs @@ -383,6 +383,8 @@ export { checkForAndDeleteUniqueObservationsFromLargerArray, createCombinedTextDelimitedByAmpersand, createCombinedTextDelimitedByComma, + extractSamplingRateFromDatastreamName, + extractBuildingIdFromDatastreamName, createFullTitleForLineOrColumnChart, createTitleForHeatmap, createSubtitleForChart, diff --git a/public/js/src_modules/dropDownListHelpers.mjs b/public/js/src_modules/dropDownListHelpers.mjs index 7e76d45d1c6aa0887b005874c41aa6846e22d99e..3f2a8ffca7993aca7491faf1063bf615b000b661 100644 --- a/public/js/src_modules/dropDownListHelpers.mjs +++ b/public/js/src_modules/dropDownListHelpers.mjs @@ -115,7 +115,7 @@ const getSelectedOptionsFromAllDropDownLists = function () { throw new Error("Please ensure that the chart type is selected"); } else if (selectedBuildingDataPointOptionsSplitArr.length === 0) { throw new Error("Please ensure that at least one data point is selected"); - } else if (selectedSamplingRateArr.length === 0) { + } else if (selectedAggregationOptionsArr.length === 0) { throw new Error("Please ensure that the aggregation type is selected"); } else if (selectedSamplingRateArr.length === 0) { throw new Error("Please ensure that the sampling rate is selected");