Commit eba0a6df authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

New function: metadata from multiple datastreams

Retrieves metadata from an array of Datastream URL strings
parent 0c220981
......@@ -167,7 +167,7 @@ const axiosGetRequest = function (urlObservations, urlParamObj) {
* @param {String} urlDatastream A URL that fetches a Datastream from an STA instance
* @returns {Promise} A promise that contains a metadata object for a Datastream when fulfilled
*/
const getDatastreamMetadata = async function (urlDatastream) {
const getMetadataFromSingleDatastream = async function (urlDatastream) {
try {
// Extract properties of interest
const {
......@@ -180,6 +180,29 @@ const getDatastreamMetadata = async function (urlDatastream) {
}
};
/**
* Retrieve metadata from multiple datastreams
* @param {Array} datastreamsUrlArr An array that contains N Datastream URL strings
* @returns {Promise} A promise that contains an array of N Datastream metadata objects when fulfilled
*/
const getMetadataFromMultipleDatastreams = async function (datastreamsUrlArr) {
try {
// Array to store our final result
const datastreamMetadataArr = [];
// Use for/of loop - we need to maintain the order of execution of the async operations
for (const datastreamUrl of datastreamsUrlArr) {
// Metadata from a single Datastream
const datastreamMetadata = await getDatastreamMetadata(datastreamUrl);
datastreamMetadataArr.push(datastreamMetadata);
}
return datastreamMetadataArr;
} catch (err) {
console.error(err);
}
};
/**
* Format the response containing a Datastream's metadata from Sensorthings API
* @param {Object} datastreamMetadata An object containing a Datastream's metadata
......@@ -505,20 +528,21 @@ const getCombinedObservationsFromAllNextLinks = function (
const getMetadataPlusObservationsForChart = async function (
metadataPlusObsPromiseArray
) {
// Array to store our final result
const combinedResolvedPromises = [];
try {
// Array to store our final result
const combinedResolvedPromises = [];
// Use for/of loop - we need to maintain the order of execution of the async operations
for (const promise of metadataPlusObsPromiseArray) {
try {
// Use for/of loop - we need to maintain the order of execution of the async operations
for (const promise of metadataPlusObsPromiseArray) {
// Resolved value of a single promise
const resolvedPromise = await promise;
combinedResolvedPromises.push(resolvedPromise);
} catch (err) {
console.error(err);
}
return combinedResolvedPromises;
} catch (err) {
console.error(err);
}
return combinedResolvedPromises;
};
/**
......@@ -530,20 +554,21 @@ const getMetadataPlusObservationsForChart = async function (
const getObservationsFromMultipleDatastreams = async function (
observationPromiseArray
) {
// Array to store our final result
const observationsAllDatastreamsArr = [];
try {
// Array to store our final result
const observationsAllDatastreamsArr = [];
// Use for/of loop - we need to maintain the order of execution of the async operations
for (const observationPromise of observationPromiseArray) {
try {
// Use for/of loop - we need to maintain the order of execution of the async operations
for (const observationPromise of observationPromiseArray) {
// Observations from a single Datastream
const observations = await observationPromise;
observationsAllDatastreamsArr.push(observations);
} catch (err) {
console.error(err);
}
return observationsAllDatastreamsArr;
} catch (err) {
console.error(err);
}
return observationsAllDatastreamsArr;
};
// Building + phenomenon + sampling rate
......@@ -748,7 +773,7 @@ const drawScatterPlotHC = function (
);
// Create promises
const promiseDatastreamMetadataSeries1 = getDatastreamMetadata(
const promiseDatastreamMetadataSeries1 = getMetadataFromSingleDatastream(
URL_DATASTREAM_SERIES_1
);
const promiseCombinedObservationsSeries1 =
......@@ -756,7 +781,7 @@ const drawScatterPlotHC = function (
axiosGetRequest(URL_OBSERVATIONS_SERIES_1, QUERY_PARAMS_COMBINED)
);
const promiseDatastreamMetadataSeries2 = getDatastreamMetadata(
const promiseDatastreamMetadataSeries2 = getMetadataFromSingleDatastream(
URL_DATASTREAM_SERIES_2
);
const promiseCombinedObservationsSeries2 =
......@@ -799,7 +824,7 @@ export {
getObservationsUrl,
createTemporalFilterString,
axiosGetRequest,
getDatastreamMetadata,
getMetadataFromSingleDatastream,
formatDatastreamMetadataForChart,
formatSTAResponseForHeatMap,
drawHeatMapHC,
......
......@@ -7,7 +7,7 @@ import {
getDatastreamUrl,
getObservationsUrl,
axiosGetRequest,
getDatastreamMetadata,
getMetadataFromSingleDatastream,
formatDatastreamMetadataForChart,
formatSTAResponseForHeatMap,
drawHeatMapHC,
......@@ -289,7 +289,8 @@ const selectChartTypeFromDropDown = async function () {
const URL_OBSERVATIONS = getObservationsUrl(BASE_URL, selectedDatastream);
// Create promises
const promiseDatastreamMetadata = getDatastreamMetadata(URL_DATASTREAM);
const promiseDatastreamMetadata =
getMetadataFromSingleDatastream(URL_DATASTREAM);
const promiseCombinedObservations = getCombinedObservationsFromAllNextLinks(
axiosGetRequest(URL_OBSERVATIONS, QUERY_PARAMS_COMBINED)
);
......
Supports Markdown
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