Skip to content

Commit 965dee6

Browse files
committed
feat(test): add test cases
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
1 parent 6116133 commit 965dee6

File tree

1 file changed

+193
-3
lines changed

1 file changed

+193
-3
lines changed

flexmeasures/data/schemas/tests/test_forecasting.py

Lines changed: 193 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
["timing_input", "expected_timing_output"],
1010
[
1111
# Case 0: no timing parameters are given
12-
#
12+
#
1313
# User expects to get forecasts for the default FM planning horizon from a single viewpoint.
1414
# Specifically, we expect:
1515
# - predict-period = FM planning horizon
@@ -52,7 +52,7 @@
5252
# - max-forecast-horizon = predict-period (actual horizons are 48, 36, 24 and 12)
5353
# - forecast-frequency = retraining-period (capped by retraining-period, param changes based on config)
5454
# - 4 cycles, 4 belief times
55-
55+
5656
# Case 5: predict-period = 10 days and max-forecast-horizon = 12 hours
5757
#
5858
# User expects to get forecasts for the next 10 days from a new viewpoint every 12 hours.
@@ -76,7 +76,197 @@
7676
# Timing parameter constraints
7777
# - max-forecast-horizon <= predict-period
7878
79-
79+
# Case 1 user expectation:
80+
# - Get forecasts for next 12 hours from a single viewpoint
81+
# - max-forecast-horizon = 12 hours
82+
# - forecast-frequency = 12 hours
83+
# - 1 cycle
84+
(
85+
{"retrain_frequency": "PT12H"},
86+
{
87+
"predict_start": pd.Timestamp(
88+
"2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
89+
).floor("1h"),
90+
"start_date": pd.Timestamp(
91+
"2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
92+
).floor("1h")
93+
- pd.Timedelta(days=30),
94+
"train_period_in_hours": 720,
95+
"predict_period_in_hours": 12,
96+
"max_forecast_horizon": pd.Timedelta(hours=12),
97+
"forecast_frequency": pd.Timedelta(hours=12),
98+
"end_date": pd.Timestamp(
99+
"2025-01-15T12:00:00+01", tz="Europe/Amsterdam"
100+
)
101+
+ pd.Timedelta(hours=12),
102+
"max_training_period": pd.Timedelta(days=365),
103+
"save_belief_time": pd.Timestamp(
104+
"2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
105+
),
106+
"n_cycles": 1,
107+
},
108+
),
109+
# Case 2 user expectation:
110+
# - Same behavior as case 1
111+
# - predict-period = 12 hours
112+
# - forecast-frequency = 12 hours
113+
# - 1 cycle
114+
(
115+
{"max_forecast_horizon": "PT12H"},
116+
{
117+
"predict_start": pd.Timestamp(
118+
"2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
119+
).floor("1h"),
120+
"start_date": pd.Timestamp(
121+
"2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
122+
).floor("1h")
123+
- pd.Timedelta(days=30),
124+
"train_period_in_hours": 720,
125+
"predict_period_in_hours": 12,
126+
"max_forecast_horizon": pd.Timedelta(hours=12),
127+
"forecast_frequency": pd.Timedelta(hours=12),
128+
"end_date": pd.Timestamp(
129+
"2025-01-15T12:00:00+01", tz="Europe/Amsterdam"
130+
)
131+
+ pd.Timedelta(hours=12),
132+
"max_training_period": pd.Timedelta(days=365),
133+
"save_belief_time": pd.Timestamp(
134+
"2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
135+
),
136+
"n_cycles": 1,
137+
},
138+
),
139+
###
140+
# Case 3 user expectation:
141+
# - Keep default planning horizon prediction window
142+
# - New forecast viewpoint every 12 hours
143+
# - max-forecast-horizon remains at planning horizon (48 hours)
144+
# - 1 cycle, 4 belief times
145+
# this fails
146+
# (
147+
# {"forecast_frequency": "PT12H"},
148+
# {
149+
# "predict_start": pd.Timestamp(
150+
# "2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
151+
# ).floor("1h"),
152+
# "start_date": pd.Timestamp(
153+
# "2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
154+
# ).floor("1h")
155+
# - pd.Timedelta(days=30),
156+
# "train_period_in_hours": 720,
157+
# "predict_period_in_hours": 48,
158+
# "max_forecast_horizon": pd.Timedelta(hours=12),
159+
# "forecast_frequency": pd.Timedelta(hours=12),
160+
# "end_date": pd.Timestamp(
161+
# "2025-01-15T12:00:00+01", tz="Europe/Amsterdam"
162+
# )
163+
# + pd.Timedelta(hours=48),
164+
# "max_training_period": pd.Timedelta(days=365),
165+
# "save_belief_time": pd.Timestamp(
166+
# "2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
167+
# ),
168+
# "n_cycles": 1,
169+
# },
170+
# ),
171+
###
172+
# Case 4 user expectation:
173+
# - Default planning horizon predictions, retraining every 12 hours
174+
# - forecast-frequency follows retraining period (12 hours)
175+
# - 4 cycles, 4 belief times
176+
(
177+
{
178+
"retrain_frequency": "PT12H",
179+
"end_date": "2025-01-17T12:00:00+01:00",
180+
},
181+
{
182+
"predict_start": pd.Timestamp(
183+
"2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
184+
).floor("1h"),
185+
"start_date": pd.Timestamp(
186+
"2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
187+
).floor("1h")
188+
- pd.Timedelta(days=30),
189+
"train_period_in_hours": 720,
190+
"predict_period_in_hours": 12,
191+
"max_forecast_horizon": pd.Timedelta(hours=12),
192+
"forecast_frequency": pd.Timedelta(hours=12),
193+
"end_date": pd.Timestamp(
194+
"2025-01-17T12:00:00+01", tz="Europe/Amsterdam"
195+
),
196+
"max_training_period": pd.Timedelta(days=365),
197+
"save_belief_time": pd.Timestamp(
198+
"2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
199+
),
200+
"n_cycles": 4,
201+
},
202+
),
203+
###
204+
# Case 5 user expectation:
205+
# - Predict-period = 10 days
206+
# - max-forecast-horizon = 12 hours
207+
# - forecast-frequency = 12 hours
208+
# - 5 cycles, 20 belief times
209+
# this fails
210+
# (
211+
# {
212+
# "retrain_frequency": "P10D",
213+
# "max_forecast_horizon": "PT12H",
214+
# },
215+
# {
216+
# "predict_start": pd.Timestamp(
217+
# "2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
218+
# ).floor("1h"),
219+
# "start_date": pd.Timestamp(
220+
# "2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
221+
# ).floor("1h")
222+
# - pd.Timedelta(days=30),
223+
# "train_period_in_hours": 720,
224+
# "predict_period_in_hours": 240,
225+
# "max_forecast_horizon": pd.Timedelta(hours=12),
226+
# "forecast_frequency": pd.Timedelta(hours=12),
227+
# "end_date": pd.Timestamp(
228+
# "2025-01-15T12:00:00+01", tz="Europe/Amsterdam"
229+
# )
230+
# + pd.Timedelta(days=10),
231+
# "max_training_period": pd.Timedelta(days=365),
232+
# "save_belief_time": pd.Timestamp(
233+
# "2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
234+
# ),
235+
# "n_cycles": 1,
236+
# },
237+
# ),
238+
# Case 6 user expectation:
239+
# - FM should complain: max-forecast-horizon must be <= predict-period
240+
# this fails
241+
# (
242+
# {
243+
# "retrain_frequency": "PT12H",
244+
# "max_forecast_horizon": "P10D",
245+
# },
246+
# {
247+
# "predict_start": pd.Timestamp(
248+
# "2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
249+
# ).floor("1h"),
250+
# "start_date": pd.Timestamp(
251+
# "2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
252+
# ).floor("1h")
253+
# - pd.Timedelta(days=30),
254+
# "train_period_in_hours": 720,
255+
# "predict_period_in_hours": 12,
256+
# "max_forecast_horizon": pd.Timedelta(days=10),
257+
# "forecast_frequency": pd.Timedelta(days=10),
258+
# "end_date": pd.Timestamp(
259+
# "2025-01-15T12:00:00+01", tz="Europe/Amsterdam"
260+
# )
261+
# + pd.Timedelta(hours=12),
262+
# "max_training_period": pd.Timedelta(days=365),
263+
# "save_belief_time": pd.Timestamp(
264+
# "2025-01-15T12:23:58.387422+01", tz="Europe/Amsterdam"
265+
# ),
266+
# "n_cycles": 1,
267+
# },
268+
# ),
269+
###
80270
# We expect training period of 30 days before predict start and prediction period of 48 hours after predict start, with predict start at server now (floored to hour).
81271
# 1 cycle expected (1 belief time for forecast) given the forecast frequency equal defaulted to prediction period of 48 hours.
82272
(

0 commit comments

Comments
 (0)