diff --git a/public/js/appChart.js b/public/js/appChart.js index 64a5e30fb66ba0432e45d19f209011e18bdc2181..eb1329b8cac28ad54bdb4e3aca4064342ab5b8d4 100644 --- a/public/js/appChart.js +++ b/public/js/appChart.js @@ -1,22 +1,48 @@ "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;