Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
iCity
EnergyDashboard
Commits
896da742
Commit
896da742
authored
Jul 08, 2021
by
Pithon Kabiro
Browse files
Add function that returns combined observations
parent
7554ee91
Changes
2
Hide whitespace changes
Inline
Side-by-side
public/js/appCesium.js
View file @
896da742
...
...
@@ -9,7 +9,7 @@ import {
drawHeatMapHC
,
formatSTAResponseForLineChart
,
drawLineChartHC
,
follow
NextLink
,
getCombinedObservationsFromAll
NextLink
s
,
}
from
"
./appChart.js
"
;
// Constants
...
...
@@ -20,6 +20,8 @@ Cesium.Ion.defaultAccessToken =
// Flag to determine models that will be loaded
// Set to `true` or `false`
// `true` - load a detailed model of Building 225
// `false` - load a non-detailed model of Building 225
const
LOAD_DETAILED_BLDG225
=
false
;
// Global variable
...
...
@@ -32,7 +34,7 @@ const viewer = new Cesium.Viewer("cesiumGlobeContainer", {
/**
* Load and zoom to the extents of 3DTiles
* @param {String} urlTiles URL
t
o the 3DTiles to be loaded
* @param {String} urlTiles URL o
f
the 3DTiles to be loaded
* @returns {undefined} undefined
*/
const
loadTiles
=
function
(
urlTiles
)
{
...
...
@@ -70,7 +72,7 @@ const loadTiles = function (urlTiles) {
* @param{*}
* @returns {undefined} undefined
*/
const
loadNonDetailed
=
function
()
{
const
loadNonDetailed
Building225
=
function
()
{
// Paths to data sources
const
URL_3DTILES
=
"
data_3d/3dtiles/1_full/tileset.json
"
;
...
...
@@ -104,7 +106,7 @@ const gltfLoad = function (gltfUrl, gltfId) {
* @param{*}
* @returns {undefined} undefined
*/
const
loadDetailed
=
function
()
{
const
loadDetailed
Building225
=
function
()
{
// Paths to data sources
const
URL_3DTILES
=
"
data_3d/3dtiles/2_partial/tileset.json
"
;
const
URL_GLTF
=
"
data_3d/gltf
"
;
...
...
@@ -156,13 +158,11 @@ const loadDetailed = function () {
gltfArray
.
forEach
((
sensor
)
=>
gltfLoad
(
URL_GLTF
,
sensor
));
};
if
(
!
LOAD_DETAILED_BLDG225
)
{
// Default case: load only 3dTiles
loadNonDetailed
();
}
else
{
// Alternative case: load 3dTiles + glTF
loadDetailed
();
}
// Default case: load only 3dTiles
// Alternative case: load 3dTiles + glTF
!
LOAD_DETAILED_BLDG225
?
loadNonDetailedBuilding225
()
:
loadDetailedBuilding225
();
/**
* Activate feature picking for the displayed 3DTiles
...
...
@@ -306,32 +306,15 @@ const activate3DTileFeaturePicking = function () {
);
// Get "ALL" the Observations that satisfy our query
followNextLink
(
axiosGetRequest
(
URL_OBSERVATIONS
,
PARAM_OBJ
))
.
then
((
success
)
=>
{
const
successValue
=
success
.
data
.
value
;
// Array that will hold the combined observations
const
combinedObservations
=
[];
successValue
.
forEach
((
dataObj
)
=>
{
// Each page of results will have a dataArray that holds the observations
const
dataArrays
=
dataObj
.
dataArray
;
combinedObservations
.
push
(...
dataArrays
);
});
// DEBUG: Check total number of observations
console
.
log
(
combinedObservations
.
length
);
// DEBUG: Print the array of observations
console
.
log
(
combinedObservations
);
return
combinedObservations
;
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
})
getCombinedObservationsFromAllNextLinks
(
axiosGetRequest
(
URL_OBSERVATIONS
,
PARAM_OBJ
)
)
.
then
((
observationArr
)
=>
{
drawHeatMapHC
(
formatSTAResponseForHeatMap
(
observationArr
));
drawLineChartHC
(
formatSTAResponseForLineChart
(
observationArr
));
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
});
},
Cesium
.
ScreenSpaceEventType
.
LEFT_CLICK
);
};
...
...
public/js/appChart.js
View file @
896da742
...
...
@@ -8,9 +8,9 @@ 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
* @param {
*
} buildingNumber Integer representing the building ID
* @param {
*
} phenomenon String representing the phenomenon of interest
* @param {
*
} samplingRate String representing the sampling rate of the observations
* @param {
Number | String
} buildingNumber Integer representing the building ID
* @param {
String
} phenomenon String representing the phenomenon of interest
* @param {
String
} samplingRate String representing the sampling rate of the observations
* @returns {Number} Datastream corresponding to the input building
*/
export
const
getDatastreamIdFromBuildingNumber
=
function
(
...
...
@@ -83,7 +83,7 @@ export const getDatastreamIdFromBuildingNumber = function (
/**
* Create URL to fetch the Observations corresponding to a provided Datastream
* @param {String} baseUrl Base UR
l
of the STA server
* @param {String} baseUrl Base UR
L
of the STA server
* @param {Number} datastreamID - Integer representing the Datastream ID
* @returns {String} URL string for fetching the Observations corresponding to a Datastream
*/
...
...
@@ -121,7 +121,7 @@ export const PARAM_OBJ = {
* Perform a GET request using the Axios library
* @param {String} urlObservations A URL that fetches Observations from STA instance
* @param {Object} urlParamObj The URL parameters to be sent together with the GET request
* @returns {
Object} Axios request object
* @returns {
Promise} A promise that returns the first page of results
*/
export
const
axiosGetRequest
=
function
(
urlObservations
,
urlParamObj
)
{
return
axios
.
get
(
urlObservations
,
{
...
...
@@ -159,7 +159,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
* @returns {
Object} Highcharts library heatmap object
* @returns {
undefined} undefined
*/
export
const
drawHeatMapHC
=
function
(
formattedObsArrayForHeatmap
)
{
Highcharts
.
chart
(
"
chart-heatmap
"
,
{
...
...
@@ -269,8 +269,8 @@ 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
* @returns {
Object} Highcharts library line chart object
* @param {Array} formattedObsArrayForLineChart Response from SensorThings API formatted for use in a line chart
* @returns {
undefined} undefined
*/
export
const
drawLineChartHC
=
function
(
formattedObsArrayForLineChart
)
{
// Create the chart
...
...
@@ -295,7 +295,7 @@ export const drawLineChartHC = function (formattedObsArrayForLineChart) {
series
:
[
{
name
:
"
AAPL
"
,
name
:
"
Vorlauf
"
,
data
:
formattedObsArrayForLineChart
,
tooltip
:
{
valueDecimals
:
2
,
...
...
@@ -310,17 +310,17 @@ export const drawLineChartHC = function (formattedObsArrayForLineChart) {
* Follows "@iot.nextLink" links in SensorThingsAPI's response
* Appends new results to existing results
* @async
* @param {
Object
} responsePromise Promise object
* @returns {Object}
-
Object containing results from all the "@iot.nextLink" links
* @param {
Promise
} responsePromise Promise object
resulting from an Axios GET request
* @returns {Object} Object containing results from all the "@iot.nextLink" links
*/
export
const
followNextLink
=
function
(
responsePromise
)
{
const
followNextLink
=
function
(
responsePromise
)
{
if
(
!
responsePromise
)
return
;
return
responsePromise
.
then
(
function
(
lastSuccess
)
{
.
then
((
lastSuccess
)
=>
{
if
(
lastSuccess
.
data
[
"
@iot.nextLink
"
])
{
return
followNextLink
(
axios
.
get
(
lastSuccess
.
data
[
"
@iot.nextLink
"
])
).
then
(
function
(
nextLinkSuccess
)
{
).
then
((
nextLinkSuccess
)
=>
{
nextLinkSuccess
.
data
.
value
=
lastSuccess
.
data
.
value
.
concat
(
nextLinkSuccess
.
data
.
value
);
...
...
@@ -330,36 +330,36 @@ export const followNextLink = function (responsePromise) {
return
lastSuccess
;
}
})
.
catch
(
function
(
err
)
{
.
catch
((
err
)
=>
{
console
.
log
(
err
);
});
};
/
/ Get "ALL" the Observations that satisfy our query
// followNextLink(axiosGetRequest)
// .then((success) => {
// const successValue = success.data.value;
// // Array that will hold the combined observations
//
const
c
ombinedObservations
= [];
// successValue.forEach((dataObj) =>
{
// // Each page of results will have a dataArray that holds the observations
//
const dataArrays = dataObj.dataArray;
//
combined
O
bservations
.push(...dataArrays);
//
})
;
//
// DEBUG: Check total number of observations
//
console.log(combinedO
bservations
.length);
//
// DEBUG: Print the array of observations
//
console.log(
combinedObservations);
// return combinedObservations;
// })
// .catch((err) => {
//
console.log(err
);
//
})
//
.
then((observationA
rr) => {
//
drawHeatMapHC(observationA
rr);
//
drawLineChartHC(observationArr
);
// })
;
/
**
* Retrieve all the Observations from a Datastream after traversing all the "@iot.nextLink" links
* @async
* @param {Promise} getRequestPromise Promise object resulting from an Axios GET request
* @returns {Promise} A promise that contains an array of observations when fulfilled
*/
export
const
getC
ombinedObservations
FromAllNextLinks
=
function
(
getRequestPromise
)
{
return
followNextLink
(
getRequestPromise
)
.
then
((
success
)
=>
{
const
successValue
=
success
.
data
.
value
;
// Array that will hold the
combined
o
bservations
const
combinedObservations
=
[]
;
successValue
.
forEach
((
dataObj
)
=>
{
// Each page of results will have a dataArray that holds the o
bservations
const
dataArrays
=
dataObj
.
dataArray
;
combinedObservations
.
push
(...
dataArrays
);
});
return
new
Promise
((
resolve
,
reject
)
=>
{
resolve
(
combinedObservations
);
}
);
})
.
catch
((
e
rr
)
=>
{
console
.
log
(
e
rr
);
}
);
}
;
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