From 60cb21f297cafc768f48515d6637cbf9f2d983fb Mon Sep 17 00:00:00 2001 From: Pithon Kabiro Date: Tue, 14 Sep 2021 16:34:04 +0200 Subject: [PATCH] New function: format observations for scatter plot The function paramaters are two observation arrays which are responses from a SensorThings API instance. The logic of the function is based on the premise that the first input observation array is the larger of the two. --- public/js/appChart.js | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/public/js/appChart.js b/public/js/appChart.js index fe00205..e9f9dc0 100644 --- a/public/js/appChart.js +++ b/public/js/appChart.js @@ -792,6 +792,46 @@ const drawScatterPlotHC = function ( }); }; +const formatSTAResponseForScatterPlot = function (obsArrayOne, obsArrayTwo) { + // Check if the arrays have the same length + // We want `obsArrayOne` to be the larger array + const [obsArrayOneChecked, obsArrayTwoChecked] = (() => { + if (obsArrayTwo.length > obsArrayOne.length) { + return [obsArrayTwo, obsArrayOne]; + } else if ( + obsArrayOne.length > obsArrayTwo.length || + obsArrayOne.length === obsArrayTwo.length + ) { + return [obsArrayOne, obsArrayTwo]; + } + })(); + + console.log(obsArrayOneChecked.length); + console.log(obsArrayTwoChecked.length); +}; + +(async () => { + const sensorsOfInterestArr = [ + // ["225", "vl", "60min"], + ["125", "rl", "60min"], + ["weather_station_521", "outside_temp", "60min"], + ]; + + const observationsPlusMetadata = + await getMetadataPlusObservationsFromMultipleDatastreams( + sensorsOfInterestArr + ); + + // Extract the observations and metadata for each sensor + // Array elements in same order as input array + const [ + [obsSensorOneArr, obsSensorTwoArr], + [metadataSensorOne, metadataSensorTwo], + ] = observationsPlusMetadata; + + formatSTAResponseForScatterPlot(obsSensorOneArr, obsSensorTwoArr); +})(); + /** * Test drawing of scatter plot chart */ @@ -823,7 +863,7 @@ const drawScatterPlotHCTest = async function () { }; (async () => { - await drawScatterPlotHCTest(); + // await drawScatterPlotHCTest(); })(); export { -- GitLab