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

Do not resample data of sensors recording instantaneous values #491

Merged
Show file tree
Hide file tree
Changes from 4 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 @@ -23,7 +23,7 @@ v0.11.1 | September XX, 2022

Bugfixes
-----------

* Do not fail asset page if one of the shown sensors records instantaneous values [see `PR #491 <http://www.github.com/FlexMeasures/flexmeasures/pull/491>`_]


v0.11.0 | August 28, 2022
Expand Down
17 changes: 12 additions & 5 deletions flexmeasures/data/models/charts/belief_charts.py
@@ -1,6 +1,6 @@
from __future__ import annotations

from datetime import datetime
from datetime import datetime, timedelta

from flexmeasures.data.models.charts.defaults import FIELD_DEFINITIONS
from flexmeasures.utils.flexmeasures_inflection import capitalize
Expand Down Expand Up @@ -72,8 +72,13 @@ def chart_for_multiple_sensors(
**override_chart_specs: dict,
):
sensors_specs = []
min_resolution_in_ms = (
min(sensor.event_resolution for sensor in sensors).total_seconds() * 1000
minimum_non_zero_resolution_in_ms = (
min(
sensor.event_resolution
for sensor in sensors
if sensor.event_resolution > timedelta(0)
).total_seconds()
Flix6x marked this conversation as resolved.
Show resolved Hide resolved
* 1000
)
for sensor in sensors:
unit = sensor.unit if sensor.unit else "a.u."
Expand Down Expand Up @@ -112,7 +117,9 @@ def chart_for_multiple_sensors(
{
"mark": {
"type": "line",
"interpolate": "step-after",
"interpolate": "step-after"
if sensor.event_resolution != timedelta(0)
else "linear",
"clip": True,
},
"encoding": {
Expand Down Expand Up @@ -143,7 +150,7 @@ def chart_for_multiple_sensors(
},
"transform": [
{
"calculate": f"datum.event_start + {min_resolution_in_ms}",
"calculate": f"datum.event_start + {minimum_non_zero_resolution_in_ms}",
"as": "event_end",
},
],
Expand Down
9 changes: 7 additions & 2 deletions flexmeasures/data/models/generic_assets.py
Expand Up @@ -381,10 +381,15 @@ def search_beliefs(
from flexmeasures.data.services.time_series import simplify_index

if sensors:
min_resolution = min(bdf.event_resolution for bdf in bdf_dict.values())
minimum_non_zero_resolution = min(
bdf.event_resolution
for bdf in bdf_dict.values()
if bdf.event_resolution > timedelta(0)
Flix6x marked this conversation as resolved.
Show resolved Hide resolved
)
df_dict = {}
for sensor, bdf in bdf_dict.items():
bdf = bdf.resample_events(min_resolution)
if bdf.event_resolution > timedelta(0):
bdf = bdf.resample_events(minimum_non_zero_resolution)
df = simplify_index(
bdf, index_levels_to_columns=["source"]
).set_index(["source"], append=True)
Expand Down