diff --git a/public/js/appCesium.js b/public/js/appCesium.js index 58e213b73f355046e0b98f12ad50089fc9c60c3e..709aae58eefa7a3df531548bdc69df5c18275b04 100644 --- a/public/js/appCesium.js +++ b/public/js/appCesium.js @@ -145,9 +145,11 @@ const loadDetailedBuilding225 = function () { // Default case: load only 3dTiles // Alternative case: load 3dTiles + glTF -LOAD_DETAILED_BLDG225 - ? loadDetailedBuilding225() - : loadNonDetailedBuilding225(); +if (LOAD_DETAILED_BLDG225) { + loadDetailedBuilding225(); +} else { + loadNonDetailedBuilding225(); +} /** * Activate feature picking for the displayed 3DTiles diff --git a/public/js/appChart.js b/public/js/appChart.js index 7ff9b4a6e0685f76adc76a62f8d9dc7d129680f8..fe5aade993914f1cbd4e6f095002c494bc7deb15 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, @@ -228,23 +231,6 @@ const drawChartUsingSelectedOptions = async function () { ) ); - // If there is an error in fetching metadata + observations (Case 1: 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 there is an error in fetching metadata + observations (Case 2: temperature difference, dT) - // a single `undefined` value instead of an array (as we would expect) will be returned - if (typeof observationsTempDiffPlusMetadataArr === "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` - ); - // Extract the combined arrays for observations and metadata / raw observations const [observationsRawNestedArr, metadataRawNestedArr] = observationsRawPlusMetadataArr; 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/chartScatterPlot.mjs b/public/js/src_modules/chartScatterPlot.mjs index 19195375090783b8096b3a75e159f5dfee8cf480..0c3cf1eee0d6b137163d966a90b5d2374afdd3d7 100644 --- a/public/js/src_modules/chartScatterPlot.mjs +++ b/public/js/src_modules/chartScatterPlot.mjs @@ -177,6 +177,36 @@ const createSeriesOptionsForScatterPlot = function ( } }; +/** + * Match a scatter plot's y-axis phenomenon name to its corresponding symbol + * + * @param {String} seriesName A string representing a scatter plot's series name. It is made up of two phenomenon names separated by a comma + * @returns {String} The phenomenon's symbol + */ +const getYAxisUnitOfMeasurementSymbol = function (seriesName) { + const phenomenonNameToSymbolMapping = { + temperature: "\u00B0C", + flow: "m\u00B3/h", + power: "kW", + energy: "MWh", + }; + + // The `series.name` property for the scatter plot is made up of + // two phenomenon names delimited by a comma + // We are interested in the first string + const phenomenonNameYAxis = seriesName.split(",")[0].toLowerCase(); + + if (phenomenonNameYAxis.includes("temperature")) { + return phenomenonNameToSymbolMapping.temperature; + } else if (phenomenonNameYAxis.includes("flow")) { + return phenomenonNameToSymbolMapping.flow; + } else if (phenomenonNameYAxis.includes("power")) { + return phenomenonNameToSymbolMapping.power; + } else if (phenomenonNameYAxis.includes("energy")) { + return phenomenonNameToSymbolMapping.energy; + } +}; + /** * Draw a scatter plot using Highcharts library * @param {Array} formattedObsArrayForSeriesOnePlusSeriesTwo Response from SensorThings API formatted for use in a scatter plot @@ -217,8 +247,7 @@ const drawScatterPlotHighcharts = function ( ); // The unit of measurement symbols for the x-axis is the first element of the array - // Assume that we will be comparing similar phenomena, so we can reuse this symbol - const UNIT_OF_MEASUREMENT_SYMBOL = unitOfMeasurementSymbolsArr[0]; + const unitOfMeasurementXAxisSymbol = unitOfMeasurementSymbolsArr[0]; const MARKER_RADIUS = 2; @@ -302,9 +331,9 @@ const drawScatterPlotHighcharts = function ( const pointString = `<b>${this.point.y.toFixed( 2 - )} ${UNIT_OF_MEASUREMENT_SYMBOL}, ${this.point.x.toFixed( - 2 - )} ${UNIT_OF_MEASUREMENT_SYMBOL}</b>`; + )} ${getYAxisUnitOfMeasurementSymbol( + this.series.name + )}, ${this.point.x.toFixed(2)} ${unitOfMeasurementXAxisSymbol}</b>`; return headerString + pointString; }, 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, +}; diff --git a/public/js/src_modules/fetchedDataProcessing.mjs b/public/js/src_modules/fetchedDataProcessing.mjs index b0d4d18cbec6d09013aa2ddf281bfafe177db535..f939e8a6a8751be0763d3324205b98caa35ecc0e 100644 --- a/public/js/src_modules/fetchedDataProcessing.mjs +++ b/public/js/src_modules/fetchedDataProcessing.mjs @@ -8,16 +8,13 @@ const matchUnitOfMeasurementSymbolStringToSymbol = function ( unitOfMeasurementSymbolString ) { - const unicodeCodePointDegreeSymbol = "\u00B0"; - const unicodeCodePointSuperscriptThree = "\u00B3"; - // Symbol - temperature if (unitOfMeasurementSymbolString === "degC") { - return `${unicodeCodePointDegreeSymbol}C`; + return "\u00B0C"; } // Symbol - flow rate else if (unitOfMeasurementSymbolString === "m3/h") { - return `m${unicodeCodePointSuperscriptThree}/h`; + return "m\u00B3/h"; } // If no symbol exists else {