Commit 7554ee91 authored by Pithon Kabiro's avatar Pithon Kabiro
Browse files

Wrap Axios GET request in a function

parent 18fd9512
......@@ -4,8 +4,8 @@
import {
getDatastreamIdFromBuildingNumber,
getObservationsUrl,
createTemporalFilterString,
formatSTAResponseForHeatMap,
axiosGetRequest,
drawHeatMapHC,
formatSTAResponseForLineChart,
drawLineChartHC,
......@@ -13,12 +13,7 @@ import {
} from "./appChart.js";
// Constants
import {
BASE_URL,
PARAM_RESULT_FORMAT,
PARAM_ORDER_BY,
PARAM_SELECT,
} from "./appChart.js";
import { BASE_URL, PARAM_OBJ } from "./appChart.js";
Cesium.Ion.defaultAccessToken =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyODgxYzJlNi1kNDZiLTQ3ZmQtYmUxYy0yMWI0OGM3NDA5MzAiLCJpZCI6NDczOSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTUyMzU0MX0.shj2hM3pvsvcmE_wMb2aBDuk_cKWmFmbolltInGImwU";
......@@ -305,23 +300,13 @@ const activate3DTileFeaturePicking = function () {
"60min"
);
const BASE_URL_OBSERVATIONS = getObservationsUrl(
const URL_OBSERVATIONS = getObservationsUrl(
BASE_URL,
clickedBuildingDatastreamId
);
const PARAM_FILTER = createTemporalFilterString("2020-01-01", "2021-01-01");
const axiosGetRequest = axios.get(BASE_URL_OBSERVATIONS, {
params: {
"$resultFormat": PARAM_RESULT_FORMAT,
"$orderBy": PARAM_ORDER_BY,
"$filter": PARAM_FILTER,
"$select": PARAM_SELECT,
},
});
// Get "ALL" the Observations that satisfy our query
followNextLink(axiosGetRequest)
followNextLink(axiosGetRequest(URL_OBSERVATIONS, PARAM_OBJ))
.then((success) => {
const successValue = success.data.value;
......
......@@ -99,26 +99,35 @@ export const getObservationsUrl = function (baseUrl, datastreamID) {
* @param {String} dateStop Stop date in YYYY-MM-DD format
* @returns {String} Temporal filter string
*/
export const createTemporalFilterString = function (dateStart, dateStop) {
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);
export const PARAM_RESULT_FORMAT = "dataArray";
export const PARAM_ORDER_BY = "phenomenonTime asc";
// const PARAM_FILTER = createTemporalFilterString("2020-01-01", "2021-01-01");
export const PARAM_SELECT = "result,phenomenonTime";
// const axiosGetRequest = axios.get(BASE_URL_OBSERVATIONS, {
// params: {
// "$resultFormat": PARAM_RESULT_FORMAT,
// "$orderBy": PARAM_ORDER_BY,
// "$filter": PARAM_FILTER,
// "$select": PARAM_SELECT,
// },
// });
const PARAM_RESULT_FORMAT = "dataArray";
const PARAM_ORDER_BY = "phenomenonTime asc";
const PARAM_FILTER = createTemporalFilterString("2020-01-01", "2021-01-01");
const PARAM_SELECT = "result,phenomenonTime";
export const PARAM_OBJ = {
"$resultFormat": PARAM_RESULT_FORMAT,
"$orderBy": PARAM_ORDER_BY,
"$filter": PARAM_FILTER,
"$select": PARAM_SELECT,
};
/**
* 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
*/
export const axiosGetRequest = function (urlObservations, urlParamObj) {
return axios.get(urlObservations, {
params: urlParamObj,
});
};
/**
* Format the response from SensorThings API to make it suitable for heatmap
......
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