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
0ed38717
Commit
0ed38717
authored
Jul 12, 2021
by
Pithon Kabiro
Browse files
Tweak logic for generating observations promises
parent
d144b3ea
Changes
1
Hide whitespace changes
Inline
Side-by-side
public/js/appChart.js
View file @
0ed38717
...
@@ -139,8 +139,8 @@ export const axiosGetRequest = function (urlObservations, urlParamObj) {
...
@@ -139,8 +139,8 @@ export const axiosGetRequest = function (urlObservations, urlParamObj) {
*/
*/
export
const
formatSTAResponseForHeatMap
=
function
(
obsArray
)
{
export
const
formatSTAResponseForHeatMap
=
function
(
obsArray
)
{
if
(
!
obsArray
)
return
;
if
(
!
obsArray
)
return
;
const
dataSTAFormatted
=
[];
obsArray
.
forEach
((
obs
)
=>
{
const
dataSTAFormatted
=
obsArray
.
map
((
obs
)
=>
{
// Get the date/time string; first element in input array; remove trailing "Z"
// Get the date/time string; first element in input array; remove trailing "Z"
const
obsDateTimeInput
=
obs
[
0
].
slice
(
0
,
-
1
);
const
obsDateTimeInput
=
obs
[
0
].
slice
(
0
,
-
1
);
// Get the "date" part of an observation
// Get the "date" part of an observation
...
@@ -154,8 +154,9 @@ export const formatSTAResponseForHeatMap = function (obsArray) {
...
@@ -154,8 +154,9 @@ export const formatSTAResponseForHeatMap = function (obsArray) {
const
hourOfDay
=
obsDateTime
.
getHours
();
const
hourOfDay
=
obsDateTime
.
getHours
();
// value -> the observation's value; second element in input array
// value -> the observation's value; second element in input array
const
value
=
obs
[
1
];
const
value
=
obs
[
1
];
dataSTAFormatted
.
push
(
[
timestamp
,
hourOfDay
,
value
]
)
;
return
[
timestamp
,
hourOfDay
,
value
];
});
});
return
dataSTAFormatted
;
return
dataSTAFormatted
;
};
};
...
@@ -261,12 +262,13 @@ export const drawHeatMapHC = function (formattedObsArrayForHeatmap) {
...
@@ -261,12 +262,13 @@ export const drawHeatMapHC = function (formattedObsArrayForHeatmap) {
*/
*/
export
const
formatSTAResponseForLineChart
=
function
(
obsArray
)
{
export
const
formatSTAResponseForLineChart
=
function
(
obsArray
)
{
if
(
!
obsArray
)
return
;
if
(
!
obsArray
)
return
;
const
dataSTAFormatted
=
[];
obsArray
.
forEach
((
result
)
=>
{
const
dataSTAFormatted
=
obsArray
.
map
((
result
)
=>
{
const
timestampObs
=
new
Date
(
result
[
0
].
slice
(
0
,
-
1
)).
getTime
();
// slice() removes trailing "Z" character in timestamp
const
timestampObs
=
new
Date
(
result
[
0
].
slice
(
0
,
-
1
)).
getTime
();
// slice() removes trailing "Z" character in timestamp
const
valueObs
=
result
[
1
];
const
valueObs
=
result
[
1
];
dataSTAFormatted
.
push
(
[
timestampObs
,
valueObs
]
)
;
return
[
timestampObs
,
valueObs
];
});
});
return
dataSTAFormatted
;
return
dataSTAFormatted
;
};
};
...
@@ -367,92 +369,6 @@ export const getCombinedObservationsFromAllNextLinks = function (
...
@@ -367,92 +369,6 @@ export const getCombinedObservationsFromAllNextLinks = function (
});
});
};
};
// Datastreams IDs
const
building101_DatastreamId_RL
=
getDatastreamIdFromBuildingNumber
(
"
101
"
,
"
rl
"
,
"
60min
"
);
const
building102_DatastreamId_RL
=
getDatastreamIdFromBuildingNumber
(
"
102
"
,
"
rl
"
,
"
60min
"
);
const
building107_DatastreamId_RL
=
getDatastreamIdFromBuildingNumber
(
"
107
"
,
"
rl
"
,
"
60min
"
);
const
building112_DatastreamId_RL
=
getDatastreamIdFromBuildingNumber
(
"
112, 118
"
,
"
rl
"
,
"
60min
"
);
const
building125_DatastreamId_RL
=
getDatastreamIdFromBuildingNumber
(
"
125
"
,
"
rl
"
,
"
60min
"
);
const
building225_DatastreamId_RL
=
getDatastreamIdFromBuildingNumber
(
"
225
"
,
"
rl
"
,
"
60min
"
);
// Datastream URLs
const
urlObservationsBuilding101_RL
=
getObservationsUrl
(
BASE_URL
,
building101_DatastreamId_RL
);
const
urlObservationsBuilding102_RL
=
getObservationsUrl
(
BASE_URL
,
building102_DatastreamId_RL
);
const
urlObservationsBuilding107_RL
=
getObservationsUrl
(
BASE_URL
,
building107_DatastreamId_RL
);
const
urlObservationsBuilding112_RL
=
getObservationsUrl
(
BASE_URL
,
building112_DatastreamId_RL
);
const
urlObservationsBuilding125_RL
=
getObservationsUrl
(
BASE_URL
,
building125_DatastreamId_RL
);
const
urlObservationsBuilding225_RL
=
getObservationsUrl
(
BASE_URL
,
building225_DatastreamId_RL
);
// Promise objects - Observations / RL
const
observationsPromise101_RL
=
getCombinedObservationsFromAllNextLinks
(
axiosGetRequest
(
urlObservationsBuilding101_RL
,
QUERY_PARAMS_COMBINED
)
);
const
observationsPromise102_RL
=
getCombinedObservationsFromAllNextLinks
(
axiosGetRequest
(
urlObservationsBuilding102_RL
,
QUERY_PARAMS_COMBINED
)
);
const
observationsPromise107_RL
=
getCombinedObservationsFromAllNextLinks
(
axiosGetRequest
(
urlObservationsBuilding107_RL
,
QUERY_PARAMS_COMBINED
)
);
const
observationsPromise112_RL
=
getCombinedObservationsFromAllNextLinks
(
axiosGetRequest
(
urlObservationsBuilding112_RL
,
QUERY_PARAMS_COMBINED
)
);
const
observationsPromise125_RL
=
getCombinedObservationsFromAllNextLinks
(
axiosGetRequest
(
urlObservationsBuilding125_RL
,
QUERY_PARAMS_COMBINED
)
);
const
observationsPromise225_RL
=
getCombinedObservationsFromAllNextLinks
(
axiosGetRequest
(
urlObservationsBuilding225_RL
,
QUERY_PARAMS_COMBINED
)
);
const
observationsPromiseCombined225_RL
=
[
observationsPromise101_RL
,
observationsPromise102_RL
,
observationsPromise107_RL
,
observationsPromise112_RL
,
observationsPromise125_RL
,
observationsPromise225_RL
,
];
/**
/**
* Retrieve all the Observations from an array of Observations promises
* Retrieve all the Observations from an array of Observations promises
* @async
* @async
...
@@ -477,3 +393,34 @@ const getObservationsFromMultipleDatastreams = async function (
...
@@ -477,3 +393,34 @@ const getObservationsFromMultipleDatastreams = async function (
}
}
return
observationsAllDatastreamsArr
;
return
observationsAllDatastreamsArr
;
};
};
// Building + phenomenon + sampling rate
const
buildingsSensorSamplingRateRLArr
=
[
[
"
101
"
,
"
rl
"
,
"
60min
"
],
[
"
102
"
,
"
rl
"
,
"
60min
"
],
[
"
107
"
,
"
rl
"
,
"
60min
"
],
[
"
112, 118
"
,
"
rl
"
,
"
60min
"
],
[
"
125
"
,
"
rl
"
,
"
60min
"
],
[
"
225
"
,
"
rl
"
,
"
60min
"
],
];
// Datastreams IDs
const
datastreamsRLArr
=
buildingsSensorSamplingRateRLArr
.
map
((
bldg
)
=>
getDatastreamIdFromBuildingNumber
(...
bldg
)
);
// Datastreams URLs
const
datastreamsUrlRLArr
=
datastreamsRLArr
.
map
((
datastreamId
)
=>
getObservationsUrl
(
BASE_URL
,
datastreamId
)
);
// Promise objects - Observations / RL
const
observationsPromisesRLArr
=
datastreamsUrlRLArr
.
map
((
obsUrl
)
=>
getCombinedObservationsFromAllNextLinks
(
axiosGetRequest
(
obsUrl
,
QUERY_PARAMS_COMBINED
)
)
);
// getObservationsFromMultipleDatastreams(observationsPromisesRLArr).then((x) =>
// console.log(x)
// );
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