Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
iCity
EnergyDashboard
Commits
7554ee91
Commit
7554ee91
authored
Jun 28, 2021
by
Pithon Kabiro
Browse files
Wrap Axios GET request in a function
parent
18fd9512
Changes
2
Hide whitespace changes
Inline
Side-by-side
public/js/appCesium.js
View file @
7554ee91
...
@@ -4,8 +4,8 @@
...
@@ -4,8 +4,8 @@
import
{
import
{
getDatastreamIdFromBuildingNumber
,
getDatastreamIdFromBuildingNumber
,
getObservationsUrl
,
getObservationsUrl
,
createTemporalFilterString
,
formatSTAResponseForHeatMap
,
formatSTAResponseForHeatMap
,
axiosGetRequest
,
drawHeatMapHC
,
drawHeatMapHC
,
formatSTAResponseForLineChart
,
formatSTAResponseForLineChart
,
drawLineChartHC
,
drawLineChartHC
,
...
@@ -13,12 +13,7 @@ import {
...
@@ -13,12 +13,7 @@ import {
}
from
"
./appChart.js
"
;
}
from
"
./appChart.js
"
;
// Constants
// Constants
import
{
import
{
BASE_URL
,
PARAM_OBJ
}
from
"
./appChart.js
"
;
BASE_URL
,
PARAM_RESULT_FORMAT
,
PARAM_ORDER_BY
,
PARAM_SELECT
,
}
from
"
./appChart.js
"
;
Cesium
.
Ion
.
defaultAccessToken
=
Cesium
.
Ion
.
defaultAccessToken
=
"
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyODgxYzJlNi1kNDZiLTQ3ZmQtYmUxYy0yMWI0OGM3NDA5MzAiLCJpZCI6NDczOSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTUyMzU0MX0.shj2hM3pvsvcmE_wMb2aBDuk_cKWmFmbolltInGImwU
"
;
"
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiIyODgxYzJlNi1kNDZiLTQ3ZmQtYmUxYy0yMWI0OGM3NDA5MzAiLCJpZCI6NDczOSwic2NvcGVzIjpbImFzciIsImdjIl0sImlhdCI6MTU0MTUyMzU0MX0.shj2hM3pvsvcmE_wMb2aBDuk_cKWmFmbolltInGImwU
"
;
...
@@ -305,23 +300,13 @@ const activate3DTileFeaturePicking = function () {
...
@@ -305,23 +300,13 @@ const activate3DTileFeaturePicking = function () {
"
60min
"
"
60min
"
);
);
const
BASE_
URL_OBSERVATIONS
=
getObservationsUrl
(
const
URL_OBSERVATIONS
=
getObservationsUrl
(
BASE_URL
,
BASE_URL
,
clickedBuildingDatastreamId
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
// Get "ALL" the Observations that satisfy our query
followNextLink
(
axiosGetRequest
)
followNextLink
(
axiosGetRequest
(
URL_OBSERVATIONS
,
PARAM_OBJ
)
)
.
then
((
success
)
=>
{
.
then
((
success
)
=>
{
const
successValue
=
success
.
data
.
value
;
const
successValue
=
success
.
data
.
value
;
...
...
public/js/appChart.js
View file @
7554ee91
...
@@ -99,26 +99,35 @@ export const getObservationsUrl = function (baseUrl, datastreamID) {
...
@@ -99,26 +99,35 @@ export const getObservationsUrl = function (baseUrl, datastreamID) {
* @param {String} dateStop Stop date in YYYY-MM-DD format
* @param {String} dateStop Stop date in YYYY-MM-DD format
* @returns {String} Temporal filter string
* @returns {String} Temporal filter string
*/
*/
export
const
createTemporalFilterString
=
function
(
dateStart
,
dateStop
)
{
const
createTemporalFilterString
=
function
(
dateStart
,
dateStop
)
{
if
(
!
dateStart
||
!
dateStop
)
return
;
if
(
!
dateStart
||
!
dateStop
)
return
;
const
filterString
=
`resultTime ge
${
dateStart
}
T00:00:00.000Z and resultTime le
${
dateStop
}
T00:00:00.000Z`
;
const
filterString
=
`resultTime ge
${
dateStart
}
T00:00:00.000Z and resultTime le
${
dateStop
}
T00:00:00.000Z`
;
return
filterString
;
return
filterString
;
};
};
// const BASE_URL_OBSERVATIONS = getObservationsUrl(80);
// const BASE_URL_OBSERVATIONS = getObservationsUrl(80);
export
const
PARAM_RESULT_FORMAT
=
"
dataArray
"
;
const
PARAM_RESULT_FORMAT
=
"
dataArray
"
;
export
const
PARAM_ORDER_BY
=
"
phenomenonTime asc
"
;
const
PARAM_ORDER_BY
=
"
phenomenonTime asc
"
;
// const PARAM_FILTER = createTemporalFilterString("2020-01-01", "2021-01-01");
const
PARAM_FILTER
=
createTemporalFilterString
(
"
2020-01-01
"
,
"
2021-01-01
"
);
export
const
PARAM_SELECT
=
"
result,phenomenonTime
"
;
const
PARAM_SELECT
=
"
result,phenomenonTime
"
;
export
const
PARAM_OBJ
=
{
// const axiosGetRequest = axios.get(BASE_URL_OBSERVATIONS, {
"
$resultFormat
"
:
PARAM_RESULT_FORMAT
,
// params: {
"
$orderBy
"
:
PARAM_ORDER_BY
,
// "$resultFormat": PARAM_RESULT_FORMAT,
"
$filter
"
:
PARAM_FILTER
,
// "$orderBy": PARAM_ORDER_BY,
"
$select
"
:
PARAM_SELECT
,
// "$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
* Format the response from SensorThings API to make it suitable for heatmap
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment