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

Attempt at generalizing the url requests

No related merge requests found
Showing with 38 additions and 21 deletions
+38 -21
"use strict";
// Request parameters
// DEBUG:
// Observations WITHOUT data gap - Bau 225 / Datastream ID = 80
// Observations WITH data gap - Bau 112 / Datastream ID = 78
// Observations WITHOUT data gap - Bau 225
const BASE_URL =
"http://193.196.39.91:8080/frost-icity-tp31/v1.1/Datastreams(80)/Observations";
const BASE_URL = "http://193.196.39.91:8080/frost-icity-tp31/v1.1";
/**
* Create URL to fetch the Observations corresponding to a provided Datastream
* @param {*} datastreamID - integer representing the Datastream ID
* @returns {String}
*/
const getObservationsUrl = function (datastreamID) {
if (!datastreamID) return;
const fullDatastreamURL = `${BASE_URL}/Datastreams(${datastreamID})/Observations`;
return fullDatastreamURL;
};
/**
* Create a temporal filter string for the fetched Observations
* @param {*} dateStart - start date in YYYY-MM-DD format
* @param {*} dateStop - stop date in YYYY-MM-DD format
* @returns {String}
*/
const createTemporalFilterString = function (dateStart, dateStop) {
if (!dateStart || !dateStop) return;
const filterString = `resultTime ge ${dateStart}T00:00:00.000Z and resultTime le ${dateStop}T00:00:00.000Z`;
return filterString;
};
const BASE_URL_OBSERVATIONS = getObservationsUrl(80);
const PARAM_RESULT_FORMAT = "dataArray";
const PARAM_ORDER_BY = "phenomenonTime asc";
const PARAM_FILTER =
"resultTime ge 2020-01-01T00:00:00.000Z and resultTime le 2021-01-01T00:00:00.000Z";
const PARAM_FILTER = createTemporalFilterString("2020-01-01", "2021-01-01");
const PARAM_SELECT = "result,phenomenonTime";
// Observations WITH data gap - Bau 112
const BASE_URL2 =
"http://193.196.39.91:8080/frost-icity-tp31-v2/v1.1/Datastreams(78)/Observations";
const PARAM_FILTER2 =
"resultTime ge 2020-06-01T00:00:00.000Z and resultTime le 2021-01-01T00:00:00.000Z";
const axiosGetRequest = axios.get(BASE_URL_OBSERVATIONS, {
params: {
"$resultFormat": PARAM_RESULT_FORMAT,
"$orderBy": PARAM_ORDER_BY,
"$filter": PARAM_FILTER,
"$select": PARAM_SELECT,
},
});
/**
* Format the response from SensorThings API to make it suitable for heatmap
......@@ -216,16 +242,7 @@ const followNextLink = function (responsePromise) {
};
// Get "ALL" the Observations that satisfy our query
followNextLink(
axios.get(BASE_URL, {
params: {
"$resultFormat": PARAM_RESULT_FORMAT,
"$orderBy": PARAM_ORDER_BY,
"$filter": PARAM_FILTER,
"$select": PARAM_SELECT,
},
})
)
followNextLink(axiosGetRequest)
.then((success) => {
const successValue = success.data.value;
......
Supports Markdown
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