Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add replay button to sensor and asset pages (#463)
Add a replay button that runs through the current date selection and updates the charts shown on the page (asset page or sensor page). This shows how new information is published at certain times and how forecasts and schedules are updated in real time accordingly. * Add replay button to sensor page Signed-off-by: F.N. Claessen <felix@seita.nl> * Add replay time below replay button Signed-off-by: F.N. Claessen <felix@seita.nl> * Include older beliefs in replay Signed-off-by: F.N. Claessen <felix@seita.nl> * Show only most recent beliefs in replay at any given time, and add new slice to simulatedData instead of reslicing result all over (also time function performance) Signed-off-by: F.N. Claessen <felix@seita.nl> * Speed up: no need to resize Signed-off-by: F.N. Claessen <felix@seita.nl> * Make sure vega view is embedded in page before attempting to change its dataset Signed-off-by: F.N. Claessen <felix@seita.nl> * Typo Signed-off-by: F.N. Claessen <felix@seita.nl> * Add replay button to asset page Instead of having multiple columns with event_values, named by sensor_id, we switched to one column containing the sensor_id, in addition to the column holding the event_values. Signed-off-by: F.N. Claessen <felix@seita.nl> * Pass along sensor information as an object Signed-off-by: F.N. Claessen <felix@seita.nl> * black Signed-off-by: F.N. Claessen <felix@seita.nl> * missing type annotations Signed-off-by: F.N. Claessen <felix@seita.nl> * Nicer js formatting Signed-off-by: F.N. Claessen <felix@seita.nl> * Remove obsolete code Signed-off-by: F.N. Claessen <felix@seita.nl> * Refactor: move partition function into replay-utils.js Signed-off-by: F.N. Claessen <felix@seita.nl> * Add dict representation of sensor to JSON representation of BeliefsDataFrame and refactor: move updateBeliefs function into replay-utils.js Signed-off-by: F.N. Claessen <felix@seita.nl> * Remove duplicate swipe functionality on the sensor page (already contained in leftsidepanel block) Signed-off-by: F.N. Claessen <felix@seita.nl> * Refactor: move sensor chart setup to base Signed-off-by: F.N. Claessen <felix@seita.nl> * Refactor: simplify Signed-off-by: F.N. Claessen <felix@seita.nl> * Refactor: rename and simplify Signed-off-by: F.N. Claessen <felix@seita.nl> * Add inline comments Signed-off-by: F.N. Claessen <felix@seita.nl> * Add docstrings to replay-utils.js Signed-off-by: F.N. Claessen <felix@seita.nl> * Rename parameter Signed-off-by: F.N. Claessen <felix@seita.nl> * Remove obsolete variable Signed-off-by: F.N. Claessen <felix@seita.nl> * Rename simulation/playback to replay Signed-off-by: F.N. Claessen <felix@seita.nl> * Rename function Signed-off-by: F.N. Claessen <felix@seita.nl> * Pass beliefs data rather than fetch result to replay function Signed-off-by: F.N. Claessen <felix@seita.nl> * Add docstring to replay function Signed-off-by: F.N. Claessen <felix@seita.nl> * Move beliefTimedelta to replay-utils.js Signed-off-by: F.N. Claessen <felix@seita.nl> * Remove logging statements Signed-off-by: F.N. Claessen <felix@seita.nl> * Changelog entry Signed-off-by: F.N. Claessen <felix@seita.nl> * Add missing semicolons Signed-off-by: F.N. Claessen <felix@seita.nl> * Add inline comments Signed-off-by: F.N. Claessen <felix@seita.nl> * Remove obsolete commented out lines Signed-off-by: F.N. Claessen <felix@seita.nl> * Expand docstring of partition function Signed-off-by: F.N. Claessen <felix@seita.nl> Signed-off-by: F.N. Claessen <felix@seita.nl> Signed-off-by: Felix Claessen <30658763+Flix6x@users.noreply.github.com>
- Loading branch information
Showing
12 changed files
with
432 additions
and
348 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Replay utils | ||
|
||
/** | ||
* Partitions array into two arrays. | ||
* | ||
* Partitions array into two array by pushing elements left or right given some decision function, which is | ||
* evaluated on each element. Successful validations lead to placement on the left side, others on the right. | ||
* | ||
* @param {Array} array Array to be partitioned. | ||
* @param {function} decisionFunction Function that assigns elements to the left or right arrays. | ||
* @return {Array} Array containing the left and right arrays. | ||
*/ | ||
export function partition(array, decisionFunction){ | ||
return array.reduce(function(result, element, i) { | ||
decisionFunction(element, i, array) | ||
? result[0].push(element) | ||
: result[1].push(element); | ||
return result; | ||
}, [[],[]] | ||
); | ||
}; | ||
|
||
/** | ||
* Updates beliefs. | ||
* | ||
* Updates oldBeliefs with the most recent newBeliefs about the same event for the same sensor by the same source. | ||
* | ||
* @param {Array} oldBeliefs Array containing old beliefs. | ||
* @param {Array} newBeliefs Array containing new beliefs. | ||
* @return {Array} Array containing updated beliefs. | ||
*/ | ||
export function updateBeliefs(oldBeliefs, newBeliefs) { | ||
// Group by sensor, event start and source | ||
var oldBeliefsByEventBySource = Object.fromEntries(new Map(oldBeliefs.map(belief => [belief.sensor.id + '_' + belief.event_start + '_' + belief.source.id, belief]))); // array -> dict (already had one belief per event) | ||
|
||
// Group by sensor, event start and source, and select only the most recent new beliefs | ||
var mostRecentNewBeliefsByEventBySource = Object.fromEntries(new Map(newBeliefs.map(belief => [belief.sensor.id + '_' + belief.event_start + '_' + belief.source.id, belief]))); // array -> dict (assumes beliefs are ordered by ascending belief time, with the last belief used as dict value) | ||
|
||
// Return old beliefs updated with most recent new beliefs | ||
return Object.values({...oldBeliefsByEventBySource, ...mostRecentNewBeliefsByEventBySource}) // dict -> array | ||
} | ||
|
||
// Define the step duration for the replay (value in ms) | ||
export var beliefTimedelta = 3600000 |
Oops, something went wrong.