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
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 {
...
@@ -9,7 +9,7 @@ import {
drawHeatMapHC
,
drawHeatMapHC
,
formatSTAResponseForLineChart
,
formatSTAResponseForLineChart
,
drawLineChartHC
,
drawLineChartHC
,
follow
NextLink
,
getCombinedObservationsFromAll
NextLink
s
,
}
from
"
./appChart.js
"
;
}
from
"
./appChart.js
"
;
// Constants
// Constants
...
@@ -20,6 +20,8 @@ Cesium.Ion.defaultAccessToken =
...
@@ -20,6 +20,8 @@ Cesium.Ion.defaultAccessToken =
// Flag to determine models that will be loaded
// Flag to determine models that will be loaded
// Set to `true` or `false`
// 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
;
const
LOAD_DETAILED_BLDG225
=
false
;
// Global variable
// Global variable
...
@@ -32,7 +34,7 @@ const viewer = new Cesium.Viewer("cesiumGlobeContainer", {
...
@@ -32,7 +34,7 @@ const viewer = new Cesium.Viewer("cesiumGlobeContainer", {
/**
/**
* Load and zoom to the extents of 3DTiles
* 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
* @returns {undefined} undefined
*/
*/
const
loadTiles
=
function
(
urlTiles
)
{
const
loadTiles
=
function
(
urlTiles
)
{
...
@@ -70,7 +72,7 @@ const loadTiles = function (urlTiles) {
...
@@ -70,7 +72,7 @@ const loadTiles = function (urlTiles) {
* @param{*}
* @param{*}
* @returns {undefined} undefined
* @returns {undefined} undefined
*/
*/
const
loadNonDetailed
=
function
()
{
const
loadNonDetailed
Building225
=
function
()
{
// Paths to data sources
// Paths to data sources
const
URL_3DTILES
=
"
data_3d/3dtiles/1_full/tileset.json
"
;
const
URL_3DTILES
=
"
data_3d/3dtiles/1_full/tileset.json
"
;
...
@@ -104,7 +106,7 @@ const gltfLoad = function (gltfUrl, gltfId) {
...
@@ -104,7 +106,7 @@ const gltfLoad = function (gltfUrl, gltfId) {
* @param{*}
* @param{*}
* @returns {undefined} undefined
* @returns {undefined} undefined
*/
*/
const
loadDetailed
=
function
()
{
const
loadDetailed
Building225
=
function
()
{
// Paths to data sources
// Paths to data sources
const
URL_3DTILES
=
"
data_3d/3dtiles/2_partial/tileset.json
"
;
const
URL_3DTILES
=
"
data_3d/3dtiles/2_partial/tileset.json
"
;
const
URL_GLTF
=
"
data_3d/gltf
"
;
const
URL_GLTF
=
"
data_3d/gltf
"
;
...
@@ -156,13 +158,11 @@ const loadDetailed = function () {
...
@@ -156,13 +158,11 @@ const loadDetailed = function () {
gltfArray
.
forEach
((
sensor
)
=>
gltfLoad
(
URL_GLTF
,
sensor
));
gltfArray
.
forEach
((
sensor
)
=>
gltfLoad
(
URL_GLTF
,
sensor
));
};
};
if
(
!
LOAD_DETAILED_BLDG225
)
{
// Default case: load only 3dTiles
// Default case: load only 3dTiles
// Alternative case: load 3dTiles + glTF
loadNonDetailed
();
!
LOAD_DETAILED_BLDG225
}
else
{
?
loadNonDetailedBuilding225
()
// Alternative case: load 3dTiles + glTF
:
loadDetailedBuilding225
();
loadDetailed
();
}
/**
/**
* Activate feature picking for the displayed 3DTiles
* Activate feature picking for the displayed 3DTiles
...
@@ -306,32 +306,15 @@ const activate3DTileFeaturePicking = function () {
...
@@ -306,32 +306,15 @@ const activate3DTileFeaturePicking = function () {
);
);
// Get "ALL" the Observations that satisfy our query
// Get "ALL" the Observations that satisfy our query
followNextLink
(
axiosGetRequest
(
URL_OBSERVATIONS
,
PARAM_OBJ
))
getCombinedObservationsFromAllNextLinks
(
.
then
((
success
)
=>
{
axiosGetRequest
(
URL_OBSERVATIONS
,
PARAM_OBJ
)
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
);
})
.
then
((
observationArr
)
=>
{
.
then
((
observationArr
)
=>
{
drawHeatMapHC
(
formatSTAResponseForHeatMap
(
observationArr
));
drawHeatMapHC
(
formatSTAResponseForHeatMap
(
observationArr
));
drawLineChartHC
(
formatSTAResponseForLineChart
(
observationArr
));
drawLineChartHC
(
formatSTAResponseForLineChart
(
observationArr
));
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
});
});
},
Cesium
.
ScreenSpaceEventType
.
LEFT_CLICK
);
},
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";
...
@@ -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
* Retrieve the datastream ID that corresponds to a particular building
* @param {
*
} buildingNumber Integer representing the building ID
* @param {
Number | String
} buildingNumber Integer representing the building ID
* @param {
*
} phenomenon String representing the phenomenon of interest
* @param {
String
} phenomenon String representing the phenomenon of interest
* @param {
*
} 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
(
export
const
getDatastreamIdFromBuildingNumber
=
function
(
...
@@ -83,7 +83,7 @@ export const getDatastreamIdFromBuildingNumber = function (
...
@@ -83,7 +83,7 @@ export const getDatastreamIdFromBuildingNumber = function (
/**
/**
* Create URL to fetch the Observations corresponding to a provided Datastream
* 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
* @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 the Observations corresponding to a Datastream
*/
*/
...
@@ -121,7 +121,7 @@ export const PARAM_OBJ = {
...
@@ -121,7 +121,7 @@ export const PARAM_OBJ = {
* 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 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 {
Object} Axios request object
* @returns {
Promise} A promise that returns the first page of results
*/
*/
export
const
axiosGetRequest
=
function
(
urlObservations
,
urlParamObj
)
{
export
const
axiosGetRequest
=
function
(
urlObservations
,
urlParamObj
)
{
return
axios
.
get
(
urlObservations
,
{
return
axios
.
get
(
urlObservations
,
{
...
@@ -159,7 +159,7 @@ export const formatSTAResponseForHeatMap = function (obsArray) {
...
@@ -159,7 +159,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
* @returns {
Object} Highcharts library heatmap object
* @returns {
undefined} undefined
*/
*/
export
const
drawHeatMapHC
=
function
(
formattedObsArrayForHeatmap
)
{
export
const
drawHeatMapHC
=
function
(
formattedObsArrayForHeatmap
)
{
Highcharts
.
chart
(
"
chart-heatmap
"
,
{
Highcharts
.
chart
(
"
chart-heatmap
"
,
{
...
@@ -269,8 +269,8 @@ export const formatSTAResponseForLineChart = function (obsArray) {
...
@@ -269,8 +269,8 @@ 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
* @returns {
Object} Highcharts library line chart object
* @returns {
undefined} undefined
*/
*/
export
const
drawLineChartHC
=
function
(
formattedObsArrayForLineChart
)
{
export
const
drawLineChartHC
=
function
(
formattedObsArrayForLineChart
)
{
// Create the chart
// Create the chart
...
@@ -295,7 +295,7 @@ export const drawLineChartHC = function (formattedObsArrayForLineChart) {
...
@@ -295,7 +295,7 @@ export const drawLineChartHC = function (formattedObsArrayForLineChart) {
series
:
[
series
:
[
{
{
name
:
"
AAPL
"
,
name
:
"
Vorlauf
"
,
data
:
formattedObsArrayForLineChart
,
data
:
formattedObsArrayForLineChart
,
tooltip
:
{
tooltip
:
{
valueDecimals
:
2
,
valueDecimals
:
2
,
...
@@ -310,17 +310,17 @@ export const drawLineChartHC = function (formattedObsArrayForLineChart) {
...
@@ -310,17 +310,17 @@ export const drawLineChartHC = function (formattedObsArrayForLineChart) {
* Follows "@iot.nextLink" links in SensorThingsAPI's response
* Follows "@iot.nextLink" links in SensorThingsAPI's response
* Appends new results to existing results
* Appends new results to existing results
* @async
* @async
* @param {
Object
} responsePromise Promise object
* @param {
Promise
} responsePromise Promise object
resulting from an Axios GET request
* @returns {Object}
-
Object containing results from all the "@iot.nextLink" links
* @returns {Object} Object containing results from all the "@iot.nextLink" links
*/
*/
export
const
followNextLink
=
function
(
responsePromise
)
{
const
followNextLink
=
function
(
responsePromise
)
{
if
(
!
responsePromise
)
return
;
if
(
!
responsePromise
)
return
;
return
responsePromise
return
responsePromise
.
then
(
function
(
lastSuccess
)
{
.
then
((
lastSuccess
)
=>
{
if
(
lastSuccess
.
data
[
"
@iot.nextLink
"
])
{
if
(
lastSuccess
.
data
[
"
@iot.nextLink
"
])
{
return
followNextLink
(
return
followNextLink
(
axios
.
get
(
lastSuccess
.
data
[
"
@iot.nextLink
"
])
axios
.
get
(
lastSuccess
.
data
[
"
@iot.nextLink
"
])
).
then
(
function
(
nextLinkSuccess
)
{
).
then
((
nextLinkSuccess
)
=>
{
nextLinkSuccess
.
data
.
value
=
lastSuccess
.
data
.
value
.
concat
(
nextLinkSuccess
.
data
.
value
=
lastSuccess
.
data
.
value
.
concat
(
nextLinkSuccess
.
data
.
value
nextLinkSuccess
.
data
.
value
);
);
...
@@ -330,36 +330,36 @@ export const followNextLink = function (responsePromise) {
...
@@ -330,36 +330,36 @@ export const followNextLink = function (responsePromise) {
return
lastSuccess
;
return
lastSuccess
;
}
}
})
})
.
catch
(
function
(
err
)
{
.
catch
((
err
)
=>
{
console
.
log
(
err
);
console
.
log
(
err
);
});
});
};
};
/
/ Get "ALL" the Observations that satisfy our query
/
**
// followNextLink(axiosGetRequest)
* Retrieve all the Observations from a Datastream after traversing all the "@iot.nextLink" links
// .then((success) => {
* @async
// const successValue = success.data.value;
* @param {Promise} getRequestPromise Promise object resulting from an Axios GET request
* @returns {Promise} A promise that contains an array of observations when fulfilled
// // Array that will hold the combined observations
*/
//
const
c
ombinedObservations
= [];
export
const
getC
ombinedObservations
FromAllNextLinks
=
function
(
getRequestPromise
// successValue.forEach((dataObj) =>
{
)
{
// // Each page of results will have a dataArray that holds the observations
return
followNextLink
(
getRequestPromise
)
//
const dataArrays = dataObj.dataArray;
.
then
((
success
)
=>
{
const
successValue
=
success
.
data
.
value
;
//
combined
O
bservations
.push(...dataArrays);
// Array that will hold the
combined
o
bservations
//
})
;
const
combinedObservations
=
[]
;
//
// DEBUG: Check total number of observations
successValue
.
forEach
((
dataObj
)
=>
{
//
console.log(combinedO
bservations
.length);
// Each page of results will have a dataArray that holds the o
bservations
//
// DEBUG: Print the array of observations
const
dataArrays
=
dataObj
.
dataArray
;
//
console.log(
combinedObservations);
combinedObservations
.
push
(...
dataArrays
);
});
// return combinedObservations;
// })
return
new
Promise
((
resolve
,
reject
)
=>
{
// .catch((err) => {
resolve
(
combinedObservations
);
//
console.log(err
);
}
);
//
})
})
//
.
then((observationA
rr) => {
.
catch
((
e
rr
)
=>
{
//
drawHeatMapHC(observationA
rr);
console
.
log
(
e
rr
);
//
drawLineChartHC(observationArr
);
}
);
// })
;
}
;
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