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 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
9 changes: 5 additions & 4 deletions documentation/changelog.rst
Expand Up @@ -20,12 +20,13 @@ Infrastructure / Support



v0.11.1 | September XX, 2022
v0.11.1 | September 5, 2022
============================

Bugfixes
-----------
* Do not fail asset page if none of the sensors has any data [see `PR #492 <http://www.github.com/FlexMeasures/flexmeasures/pull/492>`_]
* Do not fail asset page if none of the sensors has any data [see `PR #493 <http://www.github.com/FlexMeasures/flexmeasures/pull/493>`_]
* 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 Expand Up @@ -72,7 +73,7 @@ Bugfixes
-----------
* Fix some UI styling regressions in e.g. color contrast and hover effects [see `PR #441 <http://www.github.com/FlexMeasures/flexmeasures/pull/441>`_]

v0.10.0 | May 08, 2022
v0.10.0 | May 8, 2022
===========================

New features
Expand Down Expand Up @@ -210,7 +211,7 @@ Infrastructure / Support
* Stop automatically triggering forecasting jobs when API calls save nothing new to the database, thereby saving redundant computation [see `PR #303 <http://www.github.com/FlexMeasures/flexmeasures/pull/303>`_]


v0.7.1 | November 08, 2021
v0.7.1 | November 8, 2021
===========================

Bugfixes
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
condition = (
sensor.event_resolution
for sensor in sensors
if sensor.event_resolution > timedelta(0)
)
minimum_non_zero_resolution_in_ms = (
min(condition).total_seconds() * 1000 if any(condition) else 0
)
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
12 changes: 10 additions & 2 deletions flexmeasures/data/models/generic_assets.py
Expand Up @@ -381,10 +381,18 @@ 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())
condition = (
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
)
minimum_non_zero_resolution = (
min(condition) if any(condition) else timedelta(0)
)
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