mirror of
https://github.com/Akkudoktor-EOS/EOS.git
synced 2026-10-20 04:41:57 +00:00
fix(elecprice): survive a day-ahead source that has not published yet
Every morning before the day-ahead auction is published, /v1/prediction/update answered 400 and no prediction was produced at all. The provider asks for prices starting at the run day, because an existing history sets past_days to 0. The optimization horizon always reaches past the last published price, so an update is always considered necessary - and SMARD publishes the next day around midday. Between midnight and publication the requested window therefore contains nothing, and ElecPriceSMARD raised "SMARD response contains no usable day-ahead prices", which failed the whole prediction update rather than only that provider. ElecPriceEnergyCharts and its SMARD subclass now keep their existing history and let the ETS/median branch extrapolate the remaining slots, the same fallback FeedInTariffEnergyCharts already had. A cold start without any history stays fatal. ElecPriceSMARD also separates the two cases it used to conflate: a period the source has not published yet now reports the latest value it does have, and only a response without a single price still reads as unusable. Fixes the cache noise this produced as well. cache_in_file claimed its cache entry before calling the wrapped function, so a raising function left an empty file behind and every later call within the TTL logged "Read failed: Ran out of input" before refetching. The entry is now created only after the call returns.
This commit is contained in:
@@ -75,3 +75,46 @@ def test_chunk_selection_includes_preceding_overlapping_chunk(provider):
|
||||
|
||||
def test_smard_provider_is_enabled(provider):
|
||||
assert provider.enabled()
|
||||
|
||||
|
||||
@patch("akkudoktoreos.prediction.elecpricesmard.requests.get")
|
||||
def test_unpublished_period_names_the_latest_published_value(mock_get, provider):
|
||||
"""A day-ahead source that lags is not a broken response.
|
||||
|
||||
SMARD publishes the next day around midday. Until then a run whose horizon
|
||||
already reaches into that day asks for a window SMARD cannot serve yet. The
|
||||
error has to say that, because the caller keeps its history and extrapolates
|
||||
in that case rather than treating the API as broken.
|
||||
"""
|
||||
chunk_start = 1785103200000
|
||||
# The chunk holds prices, but all of them end before the requested window.
|
||||
mock_get.side_effect = [
|
||||
_response({"timestamps": [chunk_start]}),
|
||||
_response(
|
||||
{
|
||||
"meta_data": {"version": 1, "created": 1785500527370},
|
||||
"series": [[chunk_start, 86.04], [chunk_start + 900000, 84.5]],
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
with pytest.raises(ValueError, match="has not published day-ahead prices"):
|
||||
provider._request_forecast(start_date="2026-07-28", force_update=True)
|
||||
|
||||
|
||||
@patch("akkudoktoreos.prediction.elecpricesmard.requests.get")
|
||||
def test_empty_series_still_reports_an_unusable_response(mock_get, provider):
|
||||
"""A chunk without a single price is a different problem and says so."""
|
||||
chunk_start = 1785103200000
|
||||
mock_get.side_effect = [
|
||||
_response({"timestamps": [chunk_start]}),
|
||||
_response(
|
||||
{
|
||||
"meta_data": {"version": 1, "created": 1785500527370},
|
||||
"series": [[chunk_start, None]],
|
||||
}
|
||||
),
|
||||
]
|
||||
|
||||
with pytest.raises(ValueError, match="no usable day-ahead prices"):
|
||||
provider._request_forecast(start_date="2026-07-27", force_update=True)
|
||||
|
||||
Reference in New Issue
Block a user