Skip to content

Commit

Permalink
Convert the units of the input data to a target unit.
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
  • Loading branch information
victorgarcia98 committed Apr 24, 2024
1 parent d407a21 commit 64c28ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 64c28ef

Please sign in to comment.