Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
iCity
EnergyDashboard
Commits
5dd3d98d
Commit
5dd3d98d
authored
Jul 12, 2021
by
Pithon Kabiro
Browse files
Add and edit function documentation
parent
09fdaff6
Changes
1
Hide whitespace changes
Inline
Side-by-side
public/js/appChart.js
View file @
5dd3d98d
...
...
@@ -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
retur
ns the first page of results
* @returns {Promise} A promise that
contai
ns 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
(
p
romiseArray
metadataPlusObsP
romiseArray
)
{
// 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
observation
s when fulfilled
* @param {Promise} observationPromiseArray A
n 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
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment