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

[reporting] Convert the units of the input data to a target unit. #1044

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions flexmeasures/data/models/reporting/pandas_reporter.py
Expand Up @@ -5,6 +5,7 @@
from copy import deepcopy, copy

from flask import current_app
from flexmeasures.utils.unit_utils import convert_units
import timely_beliefs as tb
import pandas as pd
from flexmeasures.data.models.reporting import Reporter
Expand All @@ -31,6 +32,12 @@ class PandasReporter(Reporter):

data: dict[str, tb.BeliefsDataFrame | pd.DataFrame] = None

def _get_input_target_unit(self, name : str) -> str | None:
for required_input in self._config["required_input"]:
if name in required_input.get("name"):
return required_input.get("unit")
return None

def fetch_data(
self,
start: datetime,
Expand Down Expand Up @@ -71,6 +78,10 @@ def fetch_data(
for source in bdf.sources.unique():
self.data[f"source_{source.id}"] = source

unit = self._get_input_target_unit(name)
if unit is not None:
bdf *= convert_units(1, from_unit=sensor.unit, to_unit=unit, event_resolution=sensor.event_resolution)

# store BeliefsDataFrame as local variable
self.data[name] = bdf

Expand Down
1 change: 1 addition & 0 deletions flexmeasures/data/schemas/io.py
Expand Up @@ -8,6 +8,7 @@

class RequiredInput(Schema):
name = fields.Str(required=True)
unit = fields.Str(required=False)


class Input(Schema):
Expand Down