Skip to content

Commit

Permalink
fix(parsers): handle missing production values for BE zone
Browse files Browse the repository at this point in the history
  • Loading branch information
VIKTORVAV99 committed May 27, 2024
1 parent 189d1d1 commit a28d430
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions parsers/ENTSOE.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ def parse_production(
# Loop over the grouped data and create production and storage mixes for each datetime.
for dt, values in grouped_data.items():
production, storage = _create_production_and_storage_mixes(
dt, values, expected_length, logger
zoneKey, dt, values, expected_length, logger
)
# If production and storage are None, the datapoint is considered invalid and is skipped
# in order to not crash the parser.
Expand Down Expand Up @@ -805,7 +805,11 @@ def _get_raw_production_events(soup: BeautifulSoup) -> list[dict[str, Any]]:


def _create_production_and_storage_mixes(
dt: datetime, values: list[dict[str, Any]], expected_length: int, logger: Logger
zoneKey: ZoneKey,
dt: datetime,
values: list[dict[str, Any]],
expected_length: int,
logger: Logger,
) -> tuple[ProductionMix, StorageMix] | tuple[None, None]:
"""
Creates a populated ProductionMix and StorageMix object from a list of production values and ensures that the expected length is met.
Expand All @@ -814,10 +818,15 @@ def _create_production_and_storage_mixes(
value_length = len(values)
# Checks that the number of values have the expected length and skips the datapoint if not.
if value_length < expected_length:
logger.warning(
f"Expected {expected_length} production values for {dt}, recived {value_length} instead. Discarding datapoint..."
)
return None, None
if zoneKey == "BE" and value_length == expected_length - 1:
logger.warning(
f"BE only has {value_length} production values for {dt}, but should have {expected_length}. BE doesn't report 0 values for storage so we will continue."
)
else:
logger.warning(
f"Expected {expected_length} production values for {dt}, received {value_length} instead. Discarding datapoint..."
)
return None, None
production = ProductionMix()
storage = StorageMix()
for production_mode in values:
Expand Down

0 comments on commit a28d430

Please sign in to comment.