Commit d144b3ea authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

New function: observations from multiple datastreams

parent 896da742
...@@ -13,7 +13,7 @@ import { ...@@ -13,7 +13,7 @@ import {
} from "./appChart.js"; } from "./appChart.js";
// Constants // Constants
import { BASE_URL, PARAM_OBJ } from "./appChart.js"; 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";
...@@ -160,9 +160,9 @@ const loadDetailedBuilding225 = function () { ...@@ -160,9 +160,9 @@ const loadDetailedBuilding225 = function () {
// Default case: load only 3dTiles // Default case: load only 3dTiles
// Alternative case: load 3dTiles + glTF // Alternative case: load 3dTiles + glTF
!LOAD_DETAILED_BLDG225 LOAD_DETAILED_BLDG225
? loadNonDetailedBuilding225() ? loadDetailedBuilding225()
: loadDetailedBuilding225(); : loadNonDetailedBuilding225();
/** /**
* Activate feature picking for the displayed 3DTiles * Activate feature picking for the displayed 3DTiles
...@@ -307,7 +307,7 @@ const activate3DTileFeaturePicking = function () { ...@@ -307,7 +307,7 @@ const activate3DTileFeaturePicking = function () {
// Get "ALL" the Observations that satisfy our query // Get "ALL" the Observations that satisfy our query
getCombinedObservationsFromAllNextLinks( getCombinedObservationsFromAllNextLinks(
axiosGetRequest(URL_OBSERVATIONS, PARAM_OBJ) axiosGetRequest(URL_OBSERVATIONS, QUERY_PARAMS_COMBINED)
) )
.then((observationArr) => { .then((observationArr) => {
drawHeatMapHC(formatSTAResponseForHeatMap(observationArr)); drawHeatMapHC(formatSTAResponseForHeatMap(observationArr));
......
...@@ -106,15 +106,18 @@ const createTemporalFilterString = function (dateStart, dateStop) { ...@@ -106,15 +106,18 @@ const createTemporalFilterString = function (dateStart, dateStop) {
}; };
// const BASE_URL_OBSERVATIONS = getObservationsUrl(80); // const BASE_URL_OBSERVATIONS = getObservationsUrl(80);
const PARAM_RESULT_FORMAT = "dataArray"; const QUERY_PARAM_RESULT_FORMAT = "dataArray";
const PARAM_ORDER_BY = "phenomenonTime asc"; const QUERY_PARAM_ORDER_BY = "phenomenonTime asc";
const PARAM_FILTER = createTemporalFilterString("2020-01-01", "2021-01-01"); const QUERY_PARAM_FILTER = createTemporalFilterString(
const PARAM_SELECT = "result,phenomenonTime"; "2020-01-01",
export const PARAM_OBJ = { "2021-01-01"
"$resultFormat": PARAM_RESULT_FORMAT, );
"$orderBy": PARAM_ORDER_BY, const QUERY_PARAM_SELECT = "result,phenomenonTime";
"$filter": PARAM_FILTER, export const QUERY_PARAMS_COMBINED = {
"$select": PARAM_SELECT, "$resultFormat": QUERY_PARAM_RESULT_FORMAT,
"$orderBy": QUERY_PARAM_ORDER_BY,
"$filter": QUERY_PARAM_FILTER,
"$select": QUERY_PARAM_SELECT,
}; };
/** /**
...@@ -338,13 +341,13 @@ const followNextLink = function (responsePromise) { ...@@ -338,13 +341,13 @@ const followNextLink = function (responsePromise) {
/** /**
* Retrieve all the Observations from a Datastream after traversing all the "@iot.nextLink" links * Retrieve all the Observations from a Datastream after traversing all the "@iot.nextLink" links
* @async * @async
* @param {Promise} getRequestPromise 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 when fulfilled * @returns {Promise} A promise that contains an array of Observations from a single Datastream when fulfilled
*/ */
export const getCombinedObservationsFromAllNextLinks = function ( export const getCombinedObservationsFromAllNextLinks = function (
getRequestPromise httpGetRequestPromise
) { ) {
return followNextLink(getRequestPromise) return followNextLink(httpGetRequestPromise)
.then((success) => { .then((success) => {
const successValue = success.data.value; const successValue = success.data.value;
// Array that will hold the combined observations // Array that will hold the combined observations
...@@ -363,3 +366,114 @@ export const getCombinedObservationsFromAllNextLinks = function ( ...@@ -363,3 +366,114 @@ export const getCombinedObservationsFromAllNextLinks = function (
console.log(err); console.log(err);
}); });
}; };
// Datastreams IDs
const building101_DatastreamId_RL = getDatastreamIdFromBuildingNumber(
"101",
"rl",
"60min"
);
const building102_DatastreamId_RL = getDatastreamIdFromBuildingNumber(
"102",
"rl",
"60min"
);
const building107_DatastreamId_RL = getDatastreamIdFromBuildingNumber(
"107",
"rl",
"60min"
);
const building112_DatastreamId_RL = getDatastreamIdFromBuildingNumber(
"112, 118",
"rl",
"60min"
);
const building125_DatastreamId_RL = getDatastreamIdFromBuildingNumber(
"125",
"rl",
"60min"
);
const building225_DatastreamId_RL = getDatastreamIdFromBuildingNumber(
"225",
"rl",
"60min"
);
// Datastream URLs
const urlObservationsBuilding101_RL = getObservationsUrl(
BASE_URL,
building101_DatastreamId_RL
);
const urlObservationsBuilding102_RL = getObservationsUrl(
BASE_URL,
building102_DatastreamId_RL
);
const urlObservationsBuilding107_RL = getObservationsUrl(
BASE_URL,
building107_DatastreamId_RL
);
const urlObservationsBuilding112_RL = getObservationsUrl(
BASE_URL,
building112_DatastreamId_RL
);
const urlObservationsBuilding125_RL = getObservationsUrl(
BASE_URL,
building125_DatastreamId_RL
);
const urlObservationsBuilding225_RL = getObservationsUrl(
BASE_URL,
building225_DatastreamId_RL
);
// Promise objects - Observations / RL
const observationsPromise101_RL = getCombinedObservationsFromAllNextLinks(
axiosGetRequest(urlObservationsBuilding101_RL, QUERY_PARAMS_COMBINED)
);
const observationsPromise102_RL = getCombinedObservationsFromAllNextLinks(
axiosGetRequest(urlObservationsBuilding102_RL, QUERY_PARAMS_COMBINED)
);
const observationsPromise107_RL = getCombinedObservationsFromAllNextLinks(
axiosGetRequest(urlObservationsBuilding107_RL, QUERY_PARAMS_COMBINED)
);
const observationsPromise112_RL = getCombinedObservationsFromAllNextLinks(
axiosGetRequest(urlObservationsBuilding112_RL, QUERY_PARAMS_COMBINED)
);
const observationsPromise125_RL = getCombinedObservationsFromAllNextLinks(
axiosGetRequest(urlObservationsBuilding125_RL, QUERY_PARAMS_COMBINED)
);
const observationsPromise225_RL = getCombinedObservationsFromAllNextLinks(
axiosGetRequest(urlObservationsBuilding225_RL, QUERY_PARAMS_COMBINED)
);
const observationsPromiseCombined225_RL = [
observationsPromise101_RL,
observationsPromise102_RL,
observationsPromise107_RL,
observationsPromise112_RL,
observationsPromise125_RL,
observationsPromise225_RL,
];
/**
* Retrieve all the Observations from an array of Observations promises
* @async
* @param {Promise} observationPromiseArray A promise that contains an array of observations when fulfilled
* @returns {Promise} A promise that contains an array of Observations from multiple Datastreams when fulfilled
*/
const getObservationsFromMultipleDatastreams = async function (
observationPromiseArray
) {
// Array to store our final result
const observationsAllDatastreamsArr = [];
// Use for/of loop - we need to maintain the order of execution of the async operations
for (const observationPromise of observationPromiseArray) {
try {
// Observations from a single Datastream
const observations = await observationPromise;
observationsAllDatastreamsArr.push(observations);
} catch (err) {
console.log(err);
}
}
return observationsAllDatastreamsArr;
};
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