Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
iCity
EnergyDashboard
Commits
49bbba3e
Commit
49bbba3e
authored
3 years ago
by
Pithon Kabiro
Browse files
Options
Download
Email Patches
Plain Diff
Use single module imports and exports
parent
ffc450c0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
public/js/appCesium.js
+2
-4
public/js/appCesium.js
public/js/appChart.js
+32
-18
public/js/appChart.js
with
34 additions
and
22 deletions
+34
-22
public/js/appCesium.js
+
2
-
4
View file @
49bbba3e
"
use strict
"
;
"
use strict
"
;
// Functions
import
{
import
{
BASE_URL
,
QUERY_PARAMS_COMBINED
,
getDatastreamIdFromBuildingNumber
,
getDatastreamIdFromBuildingNumber
,
getDatastreamUrl
,
getDatastreamUrl
,
getObservationsUrl
,
getObservationsUrl
,
...
@@ -16,9 +17,6 @@ import {
...
@@ -16,9 +17,6 @@ import {
getMetadataPlusObservationsForChart
,
getMetadataPlusObservationsForChart
,
}
from
"
./appChart.js
"
;
}
from
"
./appChart.js
"
;
// Constants
import
{
BASE_URL
,
QUERY_PARAMS_COMBINED
}
from
"
./appChart.js
"
;
Cesium
.
Ion
.
defaultAccessToken
=
Cesium
.
Ion
.
defaultAccessToken
=
"
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyODgxYzJlNi1kNDZiLTQ3ZmQtYmUxYy0yMWI0OGM3NDA5MzAiLCJpZCI6NDczOSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTUyMzU0MX0.shj2hM3pvsvcmE_wMb2aBDuk_cKWmFmbolltInGImwU
"
;
"
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyODgxYzJlNi1kNDZiLTQ3ZmQtYmUxYy0yMWI0OGM3NDA5MzAiLCJpZCI6NDczOSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTUyMzU0MX0.shj2hM3pvsvcmE_wMb2aBDuk_cKWmFmbolltInGImwU
"
;
...
...
This diff is collapsed.
Click to expand it.
public/js/appChart.js
+
32
-
18
View file @
49bbba3e
"
use strict
"
;
"
use strict
"
;
// DEBUG:
const
BASE_URL
=
"
http://193.196.39.91:8080/frost-icity-tp31/v1.1
"
;
// Observations WITHOUT data gap - Bau 225 / Datastream ID = 80
// Observations WITH data gap - Bau 112 / Datastream ID = 78
export
const
BASE_URL
=
"
http://193.196.39.91:8080/frost-icity-tp31/v1.1
"
;
/**
/**
* Retrieve the datastream ID that corresponds to a particular building
* Retrieve the datastream ID that corresponds to a particular building
...
@@ -13,7 +9,7 @@ export const BASE_URL = "http://193.196.39.91:8080/frost-icity-tp31/v1.1";
...
@@ -13,7 +9,7 @@ export const BASE_URL = "http://193.196.39.91:8080/frost-icity-tp31/v1.1";
* @param {String} samplingRate String representing the sampling rate of the observations
* @param {String} samplingRate String representing the sampling rate of the observations
* @returns {Number} Datastream corresponding to the input building
* @returns {Number} Datastream corresponding to the input building
*/
*/
export
const
getDatastreamIdFromBuildingNumber
=
function
(
const
getDatastreamIdFromBuildingNumber
=
function
(
buildingNumber
,
buildingNumber
,
phenomenon
,
phenomenon
,
samplingRate
samplingRate
...
@@ -104,7 +100,7 @@ export const getDatastreamIdFromBuildingNumber = function (
...
@@ -104,7 +100,7 @@ export const getDatastreamIdFromBuildingNumber = function (
* @param {Number} datastreamID Integer representing the Datastream ID
* @param {Number} datastreamID Integer representing the Datastream ID
* @returns {String} URL string for fetching a single Datastream
* @returns {String} URL string for fetching a single Datastream
*/
*/
export
const
getDatastreamUrl
=
function
(
baseUrl
,
datastreamID
)
{
const
getDatastreamUrl
=
function
(
baseUrl
,
datastreamID
)
{
if
(
!
datastreamID
)
return
;
if
(
!
datastreamID
)
return
;
const
fullDatastreamURL
=
`
${
baseUrl
}
/Datastreams(
${
datastreamID
}
)`
;
const
fullDatastreamURL
=
`
${
baseUrl
}
/Datastreams(
${
datastreamID
}
)`
;
return
fullDatastreamURL
;
return
fullDatastreamURL
;
...
@@ -116,7 +112,7 @@ export const getDatastreamUrl = function (baseUrl, datastreamID) {
...
@@ -116,7 +112,7 @@ export const getDatastreamUrl = function (baseUrl, datastreamID) {
* @param {Number} datastreamID Integer representing the Datastream ID
* @param {Number} datastreamID Integer representing the Datastream ID
* @returns {String} URL string for fetching Observations
* @returns {String} URL string for fetching Observations
*/
*/
export
const
getObservationsUrl
=
function
(
baseUrl
,
datastreamID
)
{
const
getObservationsUrl
=
function
(
baseUrl
,
datastreamID
)
{
if
(
!
datastreamID
)
return
;
if
(
!
datastreamID
)
return
;
const
fullObservationsURL
=
`
${
baseUrl
}
/Datastreams(
${
datastreamID
}
)/Observations`
;
const
fullObservationsURL
=
`
${
baseUrl
}
/Datastreams(
${
datastreamID
}
)/Observations`
;
return
fullObservationsURL
;
return
fullObservationsURL
;
...
@@ -142,7 +138,7 @@ const QUERY_PARAM_FILTER = createTemporalFilterString(
...
@@ -142,7 +138,7 @@ const QUERY_PARAM_FILTER = createTemporalFilterString(
"
2021-01-01
"
"
2021-01-01
"
);
);
const
QUERY_PARAM_SELECT
=
"
result,phenomenonTime
"
;
const
QUERY_PARAM_SELECT
=
"
result,phenomenonTime
"
;
export
const
QUERY_PARAMS_COMBINED
=
{
const
QUERY_PARAMS_COMBINED
=
{
"
$resultFormat
"
:
QUERY_PARAM_RESULT_FORMAT
,
"
$resultFormat
"
:
QUERY_PARAM_RESULT_FORMAT
,
"
$orderBy
"
:
QUERY_PARAM_ORDER_BY
,
"
$orderBy
"
:
QUERY_PARAM_ORDER_BY
,
"
$filter
"
:
QUERY_PARAM_FILTER
,
"
$filter
"
:
QUERY_PARAM_FILTER
,
...
@@ -155,7 +151,7 @@ export const QUERY_PARAMS_COMBINED = {
...
@@ -155,7 +151,7 @@ export const QUERY_PARAMS_COMBINED = {
* @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 contains the first page of results when fulfilled
* @returns {Promise} A promise that contains the first page of results when fulfilled
*/
*/
export
const
axiosGetRequest
=
function
(
urlObservations
,
urlParamObj
)
{
const
axiosGetRequest
=
function
(
urlObservations
,
urlParamObj
)
{
return
axios
.
get
(
urlObservations
,
{
return
axios
.
get
(
urlObservations
,
{
params
:
urlParamObj
,
params
:
urlParamObj
,
});
});
...
@@ -167,7 +163,7 @@ export const axiosGetRequest = function (urlObservations, urlParamObj) {
...
@@ -167,7 +163,7 @@ export const axiosGetRequest = function (urlObservations, urlParamObj) {
* @param {String} urlDatastream A URL that fetches a Datastream from an STA instance
* @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
* @returns {Promise} A promise that contains a metadata object for a Datastream when fulfilled
*/
*/
export
const
getDatastreamMetadata
=
async
function
(
urlDatastream
)
{
const
getDatastreamMetadata
=
async
function
(
urlDatastream
)
{
try
{
try
{
// Extract properties of interest
// Extract properties of interest
const
{
const
{
...
@@ -185,7 +181,7 @@ export const getDatastreamMetadata = async function (urlDatastream) {
...
@@ -185,7 +181,7 @@ export const getDatastreamMetadata = async function (urlDatastream) {
* @param {Object} datastreamMetadata An object containing a Datastream's metadata
* @param {Object} datastreamMetadata An object containing a Datastream's metadata
* @returns {Object} An object containing the formatted metadata that is suitable for use in a line chart or heatmap
* @returns {Object} An object containing the formatted metadata that is suitable for use in a line chart or heatmap
*/
*/
export
const
formatDatastreamMetadataForChart
=
function
(
datastreamMetadata
)
{
const
formatDatastreamMetadataForChart
=
function
(
datastreamMetadata
)
{
const
{
const
{
description
:
datastreamDescription
,
description
:
datastreamDescription
,
name
:
datastreamName
,
name
:
datastreamName
,
...
@@ -221,7 +217,7 @@ export const formatDatastreamMetadataForChart = function (datastreamMetadata) {
...
@@ -221,7 +217,7 @@ export const formatDatastreamMetadataForChart = function (datastreamMetadata) {
* @param {Array} obsArray Response from SensorThings API as array
* @param {Array} obsArray Response from SensorThings API as array
* @returns {Array} Array of formatted observations suitable for use in a heatmap
* @returns {Array} Array of formatted observations suitable for use in a heatmap
*/
*/
export
const
formatSTAResponseForHeatMap
=
function
(
obsArray
)
{
const
formatSTAResponseForHeatMap
=
function
(
obsArray
)
{
if
(
!
obsArray
)
return
;
if
(
!
obsArray
)
return
;
const
dataSTAFormatted
=
obsArray
.
map
((
obs
)
=>
{
const
dataSTAFormatted
=
obsArray
.
map
((
obs
)
=>
{
...
@@ -250,7 +246,7 @@ export const formatSTAResponseForHeatMap = function (obsArray) {
...
@@ -250,7 +246,7 @@ export const formatSTAResponseForHeatMap = function (obsArray) {
* @param {Object} formattedDatastreamMetadata Object containing Datastream metadata
* @param {Object} formattedDatastreamMetadata Object containing Datastream metadata
* @returns {undefined} undefined
* @returns {undefined} undefined
*/
*/
export
const
drawHeatMapHC
=
function
(
const
drawHeatMapHC
=
function
(
formattedObsArrayForHeatmap
,
formattedObsArrayForHeatmap
,
formattedDatastreamMetadata
formattedDatastreamMetadata
)
{
)
{
...
@@ -377,7 +373,7 @@ export const drawHeatMapHC = function (
...
@@ -377,7 +373,7 @@ export const drawHeatMapHC = function (
* @param {Array} obsArray Response from SensorThings API as array
* @param {Array} obsArray Response from SensorThings API as array
* @returns {Array} Array of formatted observations suitable for use in a line chart
* @returns {Array} Array of formatted observations suitable for use in a line chart
*/
*/
export
const
formatSTAResponseForLineChart
=
function
(
obsArray
)
{
const
formatSTAResponseForLineChart
=
function
(
obsArray
)
{
if
(
!
obsArray
)
return
;
if
(
!
obsArray
)
return
;
const
dataSTAFormatted
=
obsArray
.
map
((
result
)
=>
{
const
dataSTAFormatted
=
obsArray
.
map
((
result
)
=>
{
...
@@ -395,7 +391,7 @@ export const formatSTAResponseForLineChart = function (obsArray) {
...
@@ -395,7 +391,7 @@ export const formatSTAResponseForLineChart = function (obsArray) {
* @param {Object} formattedDatastreamMetadata Object containing Datastream metadata
* @param {Object} formattedDatastreamMetadata Object containing Datastream metadata
* @returns {undefined} undefined
* @returns {undefined} undefined
*/
*/
export
const
drawLineChartHC
=
function
(
const
drawLineChartHC
=
function
(
formattedObsArrayForLineChart
,
formattedObsArrayForLineChart
,
formattedDatastreamMetadata
formattedDatastreamMetadata
)
{
)
{
...
@@ -473,7 +469,7 @@ const followNextLink = function (responsePromise) {
...
@@ -473,7 +469,7 @@ const followNextLink = function (responsePromise) {
* @param {Promise} httpGetRequestPromise Promise object resulting from an Axios GET request
* @param {Promise} httpGetRequestPromise Promise object resulting from an Axios GET request
* @returns {Promise} A promise that contains an array of Observations from a single Datastream when fulfilled
* @returns {Promise} A promise that contains an array of Observations from a single Datastream when fulfilled
*/
*/
export
const
getCombinedObservationsFromAllNextLinks
=
function
(
const
getCombinedObservationsFromAllNextLinks
=
function
(
httpGetRequestPromise
httpGetRequestPromise
)
{
)
{
return
followNextLink
(
httpGetRequestPromise
)
return
followNextLink
(
httpGetRequestPromise
)
...
@@ -502,7 +498,7 @@ export const getCombinedObservationsFromAllNextLinks = function (
...
@@ -502,7 +498,7 @@ export const getCombinedObservationsFromAllNextLinks = function (
* @param {Promise} metadataPlusObsPromiseArray An array that contains two promises, one for datastream metadata, the other for observations
* @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
* @returns {Promise} A promise that contains two arrays when fulfilled, one for datastream metadata and the other for observations
*/
*/
export
const
getMetadataPlusObservationsForChart
=
async
function
(
const
getMetadataPlusObservationsForChart
=
async
function
(
metadataPlusObsPromiseArray
metadataPlusObsPromiseArray
)
{
)
{
// Array to store our final result
// Array to store our final result
...
@@ -576,3 +572,21 @@ const observationsPromisesRLArr = datastreamsUrlRLArr.map((obsUrl) =>
...
@@ -576,3 +572,21 @@ const observationsPromisesRLArr = datastreamsUrlRLArr.map((obsUrl) =>
// getObservationsFromMultipleDatastreams(observationsPromisesRLArr).then((x) =>
// getObservationsFromMultipleDatastreams(observationsPromisesRLArr).then((x) =>
// console.log(x)
// console.log(x)
// );
// );
export
{
BASE_URL
,
QUERY_PARAMS_COMBINED
,
getDatastreamIdFromBuildingNumber
,
getDatastreamUrl
,
getObservationsUrl
,
createTemporalFilterString
,
axiosGetRequest
,
getDatastreamMetadata
,
formatDatastreamMetadataForChart
,
formatSTAResponseForHeatMap
,
drawHeatMapHC
,
formatSTAResponseForLineChart
,
drawLineChartHC
,
getCombinedObservationsFromAllNextLinks
,
getMetadataPlusObservationsForChart
,
};
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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
Menu
Explore
Projects
Groups
Snippets