Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
iCity
EnergyDashboard
Commits
fcb749b0
Commit
fcb749b0
authored
Jun 24, 2021
by
Pithon Kabiro
Browse files
Attempt at generalizing the url requests
parent
a828b374
Changes
1
Hide whitespace changes
Inline
Side-by-side
public/js/appChart.js
View file @
fcb749b0
"
use strict
"
;
"
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
"
;
const
BASE_URL
=
"
http://193.196.39.91:8080/frost-icity-tp31/v1.1/Datastreams(80)/Observations
"
;
/**
* 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_RESULT_FORMAT
=
"
dataArray
"
;
const
PARAM_ORDER_BY
=
"
phenomenonTime asc
"
;
const
PARAM_ORDER_BY
=
"
phenomenonTime asc
"
;
const
PARAM_FILTER
=
const
PARAM_FILTER
=
createTemporalFilterString
(
"
2020-01-01
"
,
"
2021-01-01
"
);
"
resultTime ge 2020-01-01T00:00:00.000Z and resultTime le 2021-01-01T00:00:00.000Z
"
;
const
PARAM_SELECT
=
"
result,phenomenonTime
"
;
const
PARAM_SELECT
=
"
result,phenomenonTime
"
;
// Observations WITH data gap - Bau 112
const
axiosGetRequest
=
axios
.
get
(
BASE_URL_OBSERVATIONS
,
{
const
BASE_URL2
=
params
:
{
"
http://193.196.39.91:8080/frost-icity-tp31-v2/v1.1/Datastreams(78)/Observations
"
;
"
$resultFormat
"
:
PARAM_RESULT_FORMAT
,
const
PARAM_FILTER2
=
"
$orderBy
"
:
PARAM_ORDER_BY
,
"
resultTime ge 2020-06-01T00:00:00.000Z and resultTime le 2021-01-01T00:00:00.000Z
"
;
"
$filter
"
:
PARAM_FILTER
,
"
$select
"
:
PARAM_SELECT
,
},
});
/**
/**
* Format the response from SensorThings API to make it suitable for heatmap
* Format the response from SensorThings API to make it suitable for heatmap
...
@@ -216,16 +242,7 @@ const followNextLink = function (responsePromise) {
...
@@ -216,16 +242,7 @@ const followNextLink = function (responsePromise) {
};
};
// Get "ALL" the Observations that satisfy our query
// Get "ALL" the Observations that satisfy our query
followNextLink
(
followNextLink
(
axiosGetRequest
)
axios
.
get
(
BASE_URL
,
{
params
:
{
"
$resultFormat
"
:
PARAM_RESULT_FORMAT
,
"
$orderBy
"
:
PARAM_ORDER_BY
,
"
$filter
"
:
PARAM_FILTER
,
"
$select
"
:
PARAM_SELECT
,
},
})
)
.
then
((
success
)
=>
{
.
then
((
success
)
=>
{
const
successValue
=
success
.
data
.
value
;
const
successValue
=
success
.
data
.
value
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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