Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

559 enhance replay feature with ruler showing current time #560

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion documentation/changelog.rst
Expand Up @@ -13,7 +13,7 @@ v0.12.0 | October XX, 2022
New features
-------------

* Hit the replay button to visually replay what happened, available on the sensor and asset pages [see `PR #463 <http://www.github.com/FlexMeasures/flexmeasures/pull/463>`_]
* Hit the replay button to visually replay what happened, available on the sensor and asset pages [see `PR #463 <http://www.github.com/FlexMeasures/flexmeasures/pull/463>`_ and `PR #560 <http://www.github.com/FlexMeasures/flexmeasures/pull/560>`_]
* Ability to provide your own custom scheduling function [see `PR #505 <http://www.github.com/FlexMeasures/flexmeasures/pull/505>`_]
* Visually distinguish forecasts/schedules (dashed lines) from measurements (solid lines), and expand the tooltip with timing info regarding the forecast/schedule horizon or measurement lag [see `PR #503 <http://www.github.com/FlexMeasures/flexmeasures/pull/503>`_]
* The asset page also allows to show sensor data from other assets that belong to the same account [see `PR #500 <http://www.github.com/FlexMeasures/flexmeasures/pull/500>`_]
Expand Down
64 changes: 35 additions & 29 deletions flexmeasures/data/models/charts/belief_charts.py
Expand Up @@ -2,7 +2,7 @@

from datetime import datetime, timedelta

from flexmeasures.data.models.charts.defaults import FIELD_DEFINITIONS
from flexmeasures.data.models.charts.defaults import FIELD_DEFINITIONS, REPLAY_RULER
from flexmeasures.utils.flexmeasures_inflection import capitalize


Expand Down Expand Up @@ -32,36 +32,41 @@ def bar_chart(
chart_specs = {
"description": "A simple bar chart showing sensor data.",
"title": capitalize(sensor.name) if sensor.name != sensor.sensor_type else None,
"mark": {
"type": "bar",
"clip": True,
},
"encoding": {
"x": event_start_field_definition,
"x2": FIELD_DEFINITIONS["event_end"],
"y": event_value_field_definition,
"color": FIELD_DEFINITIONS["source_name"],
"detail": FIELD_DEFINITIONS["source"],
"opacity": {"value": 0.7},
"tooltip": [
FIELD_DEFINITIONS["full_date"],
{
**event_value_field_definition,
**dict(title=f"{capitalize(sensor.sensor_type)}"),
},
FIELD_DEFINITIONS["source_name_and_id"],
FIELD_DEFINITIONS["source_model"],
],
},
"transform": [
"layer": [
{
"calculate": f"datum.event_start + {resolution_in_ms}",
"as": "event_end",
},
{
"calculate": "datum.source.name + ' (ID: ' + datum.source.id + ')'",
"as": "source_name_and_id",
"mark": {
"type": "bar",
"clip": True,
},
"encoding": {
"x": event_start_field_definition,
"x2": FIELD_DEFINITIONS["event_end"],
"y": event_value_field_definition,
"color": FIELD_DEFINITIONS["source_name"],
"detail": FIELD_DEFINITIONS["source"],
"opacity": {"value": 0.7},
"tooltip": [
FIELD_DEFINITIONS["full_date"],
{
**event_value_field_definition,
**dict(title=f"{capitalize(sensor.sensor_type)}"),
},
FIELD_DEFINITIONS["source_name_and_id"],
FIELD_DEFINITIONS["source_model"],
],
},
"transform": [
{
"calculate": f"datum.event_start + {resolution_in_ms}",
"as": "event_end",
},
{
"calculate": "datum.source.name + ' (ID: ' + datum.source.id + ')'",
"as": "source_name_and_id",
},
],
},
REPLAY_RULER,
],
}
for k, v in override_chart_specs.items():
Expand Down Expand Up @@ -223,6 +228,7 @@ def chart_for_multiple_sensors(
},
],
},
REPLAY_RULER,
],
"width": "container",
}
Expand Down
12 changes: 12 additions & 0 deletions flexmeasures/data/models/charts/defaults.py
Expand Up @@ -57,6 +57,18 @@
title="Source",
),
}
REPLAY_RULER = {
"data": {"name": "replay"},
"mark": {
"type": "rule",
},
"encoding": {
"x": {
"field": "belief_time",
"type": "temporal",
},
},
}
SHADE_LAYER = {
"mark": {
"type": "bar",
Expand Down
7 changes: 6 additions & 1 deletion flexmeasures/ui/templates/base.html
Expand Up @@ -511,11 +511,16 @@
* the view with removing only a few data points (representing obsolete beliefs) and inserting only
* a few data points (representing the most recent new beliefs) actually made it slower.
*/
vegaView.change(datasetName, vega.changeset().remove(vega.truthy).insert(replayedData)).run().finalize();
vegaView.change(datasetName, vega.changeset().remove(vega.truthy).insert(replayedData));
vegaView.change('replay', vega.changeset().remove(vega.truthy).insert({'belief_time': beliefTime}));
vegaView.run().finalize();

document.getElementById('replay-time').innerHTML = beliefTime;
await timer(25);
}
// Remove replay ruler
vegaView.change('replay', vega.changeset().remove(vega.truthy).insert({'belief_time': null})).run().finalize();

// Stop replay when finished
toggle.classList.remove('playing');
toggle.classList.add('stopped');
Expand Down