"...3dclient4simstadtapi.git" did not exist on "e05c9f9fca867acdd39eb97bbfb2fc804531c663"
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 ( ...@@ -81,6 +81,12 @@ export const getDatastreamIdFromBuildingNumber = function (
return datastreamIdMatched; 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) { export const getDatastreamUrl = function (baseUrl, datastreamID) {
if (!datastreamID) return; if (!datastreamID) return;
const fullDatastreamURL = `${baseUrl}/Datastreams(${datastreamID})`; const fullDatastreamURL = `${baseUrl}/Datastreams(${datastreamID})`;
...@@ -88,10 +94,10 @@ export const getDatastreamUrl = function (baseUrl, 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 {String} baseUrl Base URL of the STA server
* @param {Number} datastreamID - Integer representing the Datastream ID * @param {Number} datastreamID Integer representing the Datastream ID
* @returns {String} URL string for fetching the Observations corresponding to a Datastream * @returns {String} URL string for fetching Observations
*/ */
export const getObservationsUrl = function (baseUrl, datastreamID) { export const getObservationsUrl = function (baseUrl, datastreamID) {
if (!datastreamID) return; if (!datastreamID) return;
...@@ -128,9 +134,9 @@ export const QUERY_PARAMS_COMBINED = { ...@@ -128,9 +134,9 @@ export const QUERY_PARAMS_COMBINED = {
/** /**
* Perform a GET request using the Axios library * 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 * @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) { export const axiosGetRequest = function (urlObservations, urlParamObj) {
return axios.get(urlObservations, { return axios.get(urlObservations, {
...@@ -138,6 +144,12 @@ export const axiosGetRequest = function (urlObservations, urlParamObj) { ...@@ -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) { export const getDatastreamMetadata = async function (urlDatastream) {
try { try {
// Extract properties of interest // Extract properties of interest
...@@ -182,6 +194,7 @@ export const formatSTAResponseForHeatMap = function (obsArray) { ...@@ -182,6 +194,7 @@ export const formatSTAResponseForHeatMap = function (obsArray) {
/** /**
* Draw a heatmap using Highcharts library * Draw a heatmap using Highcharts library
* @param {Array} formattedObsArrayForHeatmap Response from SensorThings API formatted for use in a heatmap * @param {Array} formattedObsArrayForHeatmap Response from SensorThings API formatted for use in a heatmap
* @param {Object} datastreamMetadata Object containing Datastream metadata
* @returns {undefined} undefined * @returns {undefined} undefined
*/ */
export const drawHeatMapHC = function ( export const drawHeatMapHC = function (
...@@ -299,13 +312,13 @@ export const formatSTAResponseForLineChart = function (obsArray) { ...@@ -299,13 +312,13 @@ export const formatSTAResponseForLineChart = function (obsArray) {
/** /**
* Draw a line chart using Highcharts library * Draw a line chart using Highcharts library
* @param {Array} formattedObsArrayForLineChart Response from SensorThings API formatted for use in a line chart * @param {Array} formattedObsArrayForLineChart Response from SensorThings API formatted for use in a line chart
* @param {Object} datastreamMetadata Object containing Datastream metadata
* @returns {undefined} undefined * @returns {undefined} undefined
*/ */
export const drawLineChartHC = function ( export const drawLineChartHC = function (
formattedObsArrayForLineChart, formattedObsArrayForLineChart,
datastreamMetadata datastreamMetadata
) { ) {
// Create the chart
Highcharts.stockChart("chart-line", { Highcharts.stockChart("chart-line", {
chart: { chart: {
zoomType: "x", zoomType: "x",
...@@ -316,13 +329,13 @@ export const drawLineChartHC = function ( ...@@ -316,13 +329,13 @@ export const drawLineChartHC = function (
}, },
title: { title: {
text: "Inlet flow (Vorlauf)", // text: "Inlet flow (Vorlauf)",
text: `${datastreamMetadata.description}`, text: `${datastreamMetadata.description}`,
"align": "left", "align": "left",
}, },
subtitle: { subtitle: {
text: "Temperature variation by hour in 2020", // text: "Temperature variation by hour in 2020",
text: `${datastreamMetadata.name}`, text: `${datastreamMetadata.name}`,
align: "left", align: "left",
}, },
...@@ -398,15 +411,23 @@ export const getCombinedObservationsFromAllNextLinks = function ( ...@@ -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 ( export const getMetadataPlusObservationsForChart = async function (
promiseArray metadataPlusObsPromiseArray
) { ) {
// Array to store our final result
const combinedResolvedPromises = []; 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 { try {
// Resolved value of a single promise
const resolvedPromise = await promise; const resolvedPromise = await promise;
combinedResolvedPromises.push(resolvedPromise); combinedResolvedPromises.push(resolvedPromise);
} catch (err) { } catch (err) {
console.log(err); console.log(err);
...@@ -418,7 +439,7 @@ export const getMetadataPlusObservationsForChart = async function ( ...@@ -418,7 +439,7 @@ export const getMetadataPlusObservationsForChart = async function (
/** /**
* Retrieve all the Observations from an array of Observations promises * Retrieve all the Observations from an array of Observations promises
* @async * @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 * @returns {Promise} A promise that contains an array of Observations from multiple Datastreams when fulfilled
*/ */
const getObservationsFromMultipleDatastreams = async function ( const getObservationsFromMultipleDatastreams = async function (
......
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