Skip to content

Commit 3d98bc2

Browse files
VIKTORVAV99claude
andauthored
feat(DK): reconstruct end_datetime from 5-minute resolution (#8762)
The Energi Data Service datasets encode their granularity in the `Minutes5UTC` timestamp column and expose no explicit interval end. Reconstruct it from the schema-implied resolution (end = start + 5min) for both exchange and wind/solar forecast events. Part of the end_datetime rollout (#8515). Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent ae8c4b7 commit 3d98bc2

2 files changed

Lines changed: 349 additions & 341 deletions

File tree

electricitymap/contrib/parsers/DK.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040

4141
SOURCE = "energidataservice.dk"
4242

43+
# Both datasets are sampled every 5 minutes, as encoded in their `Minutes5UTC`
44+
# timestamp column. The API exposes no explicit interval end, so reconstruct it
45+
# from this schema-implied resolution: end = start + RESOLUTION.
46+
RESOLUTION = timedelta(minutes=5)
47+
4348

4449
def fetch_data(
4550
zone_key: ZoneKey,
@@ -133,11 +138,13 @@ def fetch_exchange(
133138
for datapoint in data["records"]:
134139
if datapoint["PriceArea"] != price_area:
135140
continue
141+
dt = datetime.fromisoformat(datapoint["Minutes5UTC"]).replace(
142+
tzinfo=timezone.utc
143+
)
136144
all_exchange_data.append(
137145
zoneKey=sorted_keys,
138-
datetime=datetime.fromisoformat(datapoint["Minutes5UTC"]).replace(
139-
tzinfo=timezone.utc
140-
),
146+
datetime=dt,
147+
end_datetime=dt + RESOLUTION,
141148
netFlow=flow(sorted_keys, datapoint),
142149
source=SOURCE,
143150
)
@@ -169,6 +176,7 @@ def fetch_wind_solar_forecasts(
169176
zoneKey=zone_key,
170177
production=productionMix,
171178
datetime=date_time,
179+
end_datetime=date_time + RESOLUTION,
172180
source=SOURCE,
173181
sourceType=EventSourceType.forecasted,
174182
)

0 commit comments

Comments
 (0)