Commit 5dd3d98d authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

Add and edit function documentation

parent 09fdaff6
......@@ -81,6 +81,12 @@ export const getDatastreamIdFromBuildingNumber = function (
return datastreamIdMatched;
};
/**
* Create URL to fetch the details of single Datastream
* @param {String} baseUrl Base URL of the STA server
* @param {Number} datastreamID Integer representing the Datastream ID
* @returns {String} URL string for fetching a single Datastream
*/
export const getDatastreamUrl = function (baseUrl, datastreamID) {
if (!datastreamID) return;
const fullDatastreamURL = `${baseUrl}/Datastreams(${datastreamID})`;
......@@ -88,10 +94,10 @@ export const getDatastreamUrl = function (baseUrl, datastreamID) {
};
/**
* Create URL to fetch the Observations corresponding to a provided Datastream
* Create URL to fetch Observations
* @param {String} baseUrl Base URL of the STA server
* @param {Number} datastreamID - Integer representing the Datastream ID
* @returns {String} URL string for fetching the Observations corresponding to a Datastream
* @param {Number} datastreamID Integer representing the Datastream ID
* @returns {String} URL string for fetching Observations
*/
export const getObservationsUrl = function (baseUrl, datastreamID) {
if (!datastreamID) return;
......@@ -128,9 +134,9 @@ export const QUERY_PARAMS_COMBINED = {
/**
* Perform a GET request using the Axios library
* @param {String} urlObservations A URL that fetches Observations from STA instance
* @param {String} urlObservations A URL that fetches Observations from an STA instance
* @param {Object} urlParamObj The URL parameters to be sent together with the GET request
* @returns {Promise} A promise that returns the first page of results
* @returns {Promise} A promise that contains the first page of results when fulfilled
*/
export const axiosGetRequest = function (urlObservations, urlParamObj) {
return axios.get(urlObservations, {
......@@ -138,6 +144,12 @@ export const axiosGetRequest = function (urlObservations, urlParamObj) {
});
};
/**
* Retrieve the metadata for a single datastream
* @async
* @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
*/
export const getDatastreamMetadata = async function (urlDatastream) {
try {
// Extract properties of interest
......@@ -182,6 +194,7 @@ export const formatSTAResponseForHeatMap = function (obsArray) {
/**
* Draw a heatmap using Highcharts library
* @param {Array} formattedObsArrayForHeatmap Response from SensorThings API formatted for use in a heatmap
* @param {Object} datastreamMetadata Object containing Datastream metadata
* @returns {undefined} undefined
*/
export const drawHeatMapHC = function (
......@@ -299,13 +312,13 @@ export const formatSTAResponseForLineChart = function (obsArray) {
/**
* Draw a line chart using Highcharts library
* @param {Array} formattedObsArrayForLineChart Response from SensorThings API formatted for use in a line chart
* @param {Object} datastreamMetadata Object containing Datastream metadata
* @returns {undefined} undefined
*/
export const drawLineChartHC = function (
formattedObsArrayForLineChart,
datastreamMetadata
) {
// Create the chart
Highcharts.stockChart("chart-line", {
chart: {
zoomType: "x",
......@@ -316,13 +329,13 @@ export const drawLineChartHC = function (
},
title: {
text: "Inlet flow (Vorlauf)",
// text: "Inlet flow (Vorlauf)",
text: `${datastreamMetadata.description}`,
"align": "left",
},
subtitle: {
text: "Temperature variation by hour in 2020",
// text: "Temperature variation by hour in 2020",
text: `${datastreamMetadata.name}`,
align: "left",
},
......@@ -398,15 +411,23 @@ export const getCombinedObservationsFromAllNextLinks = function (
});
};
/**
* Retrieve the metadata for a Datastream as well as the Observations corresponding to it
* @async
* @param {Promise} metadataPlusObsPromiseArray An array that contains two promises, one for datastream metadata, the other for observations
* @returns {Promise} A promise that contains two arrays when fulfilled, one for datastream metadata and the other for observations
*/
export const getMetadataPlusObservationsForChart = async function (
promiseArray
metadataPlusObsPromiseArray
) {
// Array to store our final result
const combinedResolvedPromises = [];
for (const promise of promiseArray) {
// Use for/of loop - we need to maintain the order of execution of the async operations
for (const promise of metadataPlusObsPromiseArray) {
try {
// Resolved value of a single promise
const resolvedPromise = await promise;
combinedResolvedPromises.push(resolvedPromise);
} catch (err) {
console.log(err);
......@@ -418,7 +439,7 @@ export const getMetadataPlusObservationsForChart = async function (
/**
* Retrieve all the Observations from an array of Observations promises
* @async
* @param {Promise} observationPromiseArray A promise that contains an array of observations when fulfilled
* @param {Promise} observationPromiseArray An array that contains N observation promises
* @returns {Promise} A promise that contains an array of Observations from multiple Datastreams when fulfilled
*/
const getObservationsFromMultipleDatastreams = async function (
......
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