Commit 55d51bc2 authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

New function: create temp diff metadata

Refactor the logic for creating the metadata for the temperature
difference (dT, VL-RL) of a single building into a new function
parent 7af254fe
...@@ -69,6 +69,59 @@ const calculateVorlaufMinusRuecklaufTemperatureObservations = function ( ...@@ -69,6 +69,59 @@ 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
const [, [metadataVorlauf, metadataRuecklauf]] = observationsPlusMetadataArr;
// From Vorlauf metadata, extract `name` and `unitOfMeasurement`
const {
name: datastreamNameVorlauf,
unitOfMeasurement: unitOfMeasurementVorlauf,
} = metadataVorlauf;
// From Ruecklauf metadata, extract `name`
const { name: datastreamNameRuecklauf } = metadataRuecklauf;
// Extract the phenomenon names from the Datastream names
const phenomenonNameVorlauf = extractPhenomenonNameFromDatastreamName(
datastreamNameVorlauf
);
const phenomenonNameRuecklauf = extractPhenomenonNameFromDatastreamName(
datastreamNameRuecklauf
);
// Create our custom datastream description text
// The resulting datastream description string has two `temperature` substrings;
// replace the first occurence with an empty string
const descriptionTempDifference =
`Computed dT: ${phenomenonNameVorlauf} minus ${phenomenonNameRuecklauf}`.replace(
"temperature",
""
);
// Create our custom datastream name text
const nameTempDifference = `BOSCH_${buildingId} / dT Temperature difference (VL-RL) DS:${samplingRate}`;
return {
descriptionTempDifference,
nameTempDifference,
unitOfMeasurementVorlauf,
};
};
/** /**
* Calculate the temperature difference, dT, between Vorlauf temperature [VL] and * Calculate the temperature difference, dT, between Vorlauf temperature [VL] and
* Rücklauf temperature [RL] (i.e., dT = VL - RL). In addition, create synthetic metadata * Rücklauf temperature [RL] (i.e., dT = VL - RL). In addition, create synthetic metadata
...@@ -104,9 +157,6 @@ export const calculateVorlaufMinusRuecklaufTemperature = async function ( ...@@ -104,9 +157,6 @@ export const calculateVorlaufMinusRuecklaufTemperature = async function (
// Note: we skip the second element // Note: we skip the second element
const [buildingId, , samplingRate] = bldgDataPtSamplingRateNestedArr[0]; const [buildingId, , samplingRate] = bldgDataPtSamplingRateNestedArr[0];
const BUILDING_ID = buildingId;
const SAMPLING_RATE = samplingRate;
const observationsPlusMetadata = const observationsPlusMetadata =
await getMetadataPlusObservationsFromSingleOrMultipleDatastreams( await getMetadataPlusObservationsFromSingleOrMultipleDatastreams(
baseUrl, baseUrl,
...@@ -114,37 +164,23 @@ export const calculateVorlaufMinusRuecklaufTemperature = async function ( ...@@ -114,37 +164,23 @@ export const calculateVorlaufMinusRuecklaufTemperature = async function (
bldgDataPtSamplingRateNestedArr bldgDataPtSamplingRateNestedArr
); );
// dT observations (timestamp + value)
const vorlaufMinusRuecklaufTemperatureObs = const vorlaufMinusRuecklaufTemperatureObs =
calculateVorlaufMinusRuecklaufTemperatureObservations( calculateVorlaufMinusRuecklaufTemperatureObservations(
observationsPlusMetadata observationsPlusMetadata
); );
// Extract Vorlauf temperature, Ruecklauf temperature and metadata // dT metadata
const [, [metadataVorlauf, metadataRuecklauf]] = observationsPlusMetadata; const {
descriptionTempDifference,
// From Ruecklauf metadata, extract `name` nameTempDifference,
const { name: datastreamNameRuecklauf } = metadataRuecklauf; unitOfMeasurementVorlauf,
} = createVorlaufMinusRuecklaufTemperatureMetadata(
// Extract the phenomenon names from the Datastream names buildingId,
const phenomenonNameVorlauf = extractPhenomenonNameFromDatastreamName( samplingRate,
datastreamNameVorlauf observationsPlusMetadata
);
const phenomenonNameRuecklauf = extractPhenomenonNameFromDatastreamName(
datastreamNameRuecklauf
);
// Create our custom datastream description text
// The resulting datastream description string has two `temperature` substrings;
// replace the first occurence with an empty string
const descriptionTempDifference =
`Computed dT: ${phenomenonNameVorlauf} minus ${phenomenonNameRuecklauf}`.replace(
"temperature",
""
); );
// Create our custom datastream name text
const nameTempDifference = `BOSCH_${BUILDING_ID} / dT Temperature difference (VL-RL) DS:${SAMPLING_RATE}`;
// The datastream object that we return needs to have these property names // The datastream object that we return needs to have these property names
const description = descriptionTempDifference; const description = descriptionTempDifference;
const name = nameTempDifference; const name = nameTempDifference;
......
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