Commit 33c36fee authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

Merge branch 'wip_error-handling-undo' into 'master'

Undo tweak error handling

Undo recently added exception capturing, does not work as expected

See merge request !22
parents 1d5c8408 1e9557c3
Pipeline #5168 passed with stage
in 23 seconds
......@@ -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
......
......@@ -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;
......
......@@ -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(
......
......@@ -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;
},
......
......@@ -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,
};
......@@ -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 {
......
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