Commit 896da742 authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

Add function that returns combined observations

parent 7554ee91
......@@ -9,7 +9,7 @@ import {
drawHeatMapHC,
formatSTAResponseForLineChart,
drawLineChartHC,
followNextLink,
getCombinedObservationsFromAllNextLinks,
} 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 to the 3DTiles to be loaded
* @param {String} urlTiles URL of 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 loadNonDetailedBuilding225 = 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 loadDetailedBuilding225 = 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);
};
......
......@@ -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 URl of the STA server
* @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
*/
......@@ -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 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) => {
// drawHeatMapHC(observationArr);
// 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 getCombinedObservationsFromAllNextLinks = function (
getRequestPromise
) {
return followNextLink(getRequestPromise)
.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);
});
return new Promise((resolve, reject) => {
resolve(combinedObservations);
});
})
.catch((err) => {
console.log(err);
});
};
Markdown is supported
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