Skip to content

Commit

Permalink
fix: if output df event resolution does not match the one of th outpu…
Browse files Browse the repository at this point in the history
…t sensor, try with the frequency of the events_start.

Signed-off-by: Victor Garcia Reolid <victor@seita.nl>
  • Loading branch information
victorgarcia98 committed May 31, 2023
1 parent 9d5c9e7 commit 75fbdc3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
17 changes: 12 additions & 5 deletions flexmeasures/data/models/reporting/pandas_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from flask import current_app
import timely_beliefs as tb
import pandas as pd

from flexmeasures.data.models.reporting import Reporter
from flexmeasures.data.schemas.reporting.pandas_reporter import (
Expand All @@ -30,9 +31,6 @@ def deserialize_config(self):
# extract PandasReporter specific fields
self.transformations = self.reporter_config.get("transformations")
self.final_df_output = self.reporter_config.get("final_df_output")
self.output_event_resolution = self.reporter_config.get(
"output_event_resolution"
)

def _compute(
self,
Expand Down Expand Up @@ -87,8 +85,17 @@ def _compute(
]
final_output = tb.BeliefsDataFrame(timed_beliefs)

if self.output_event_resolution:
final_output.event_resolution = self.output_event_resolution
# use event_starts frequency when final_output event resolution
# does not correspond with the event resolution of the output sensor
event_frequency = final_output.event_starts.inferred_freq

if event_frequency:
event_frequency = pd.to_timedelta(
pd.tseries.frequencies.to_offset(event_frequency)
).to_pytimedelta()

if final_output.event_resolution != final_output.sensor.event_resolution:
final_output.event_resolution = event_frequency

return final_output

Expand Down
3 changes: 0 additions & 3 deletions flexmeasures/data/schemas/reporting/pandas_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

from timely_beliefs import BeliefsDataFrame

from flexmeasures.data.schemas import DurationField


class PandasMethodCall(Schema):

Expand Down Expand Up @@ -76,7 +74,6 @@ class PandasReporterConfigSchema(ReporterConfigSchema):

transformations = fields.List(fields.Nested(PandasMethodCall()), required=True)
final_df_output = fields.Str(required=True)
output_event_resolution = DurationField(required=False)

@validates_schema
def validate_chaining(self, data, **kwargs):
Expand Down

0 comments on commit 75fbdc3

Please sign in to comment.