Commit 8b900e1d authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

Edit function: get values of current options

Check the length of the correct array
parent 55d51bc2
"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
);
......
......@@ -383,6 +383,8 @@ export {
checkForAndDeleteUniqueObservationsFromLargerArray,
createCombinedTextDelimitedByAmpersand,
createCombinedTextDelimitedByComma,
extractSamplingRateFromDatastreamName,
extractBuildingIdFromDatastreamName,
createFullTitleForLineOrColumnChart,
createTitleForHeatmap,
createSubtitleForChart,
......
......@@ -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");
......
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