@@ -121,7 +121,6 @@ def get_latest_forecast(
121
121
gsp_id : Optional [int ] = None ,
122
122
historic : bool = False ,
123
123
start_target_time : Optional [datetime ] = None ,
124
- forecast_horizon_minutes : Optional [int ] = None ,
125
124
) -> ForecastSQL :
126
125
"""
127
126
Read forecasts
@@ -149,7 +148,6 @@ def get_latest_forecast(
149
148
start_target_time = start_target_time ,
150
149
historic = historic ,
151
150
gsp_ids = gsp_ids ,
152
- forecast_horizon_minutes = forecast_horizon_minutes ,
153
151
)
154
152
155
153
if forecasts is None :
@@ -217,7 +215,6 @@ def get_all_gsp_ids_latest_forecast(
217
215
start_target_time : Optional [datetime ] = None ,
218
216
preload_children : Optional [bool ] = False ,
219
217
historic : bool = False ,
220
- forecast_horizon_minutes : Optional [int ] = None ,
221
218
) -> List [ForecastSQL ]:
222
219
"""
223
220
Read forecasts
@@ -228,9 +225,6 @@ def get_all_gsp_ids_latest_forecast(
228
225
Filter: forecast values target time should be larger than this datetime
229
226
:param preload_children: Option to preload children. This is a speed up, if we need them.
230
227
:param historic: Option to load historic values or not
231
- :param forecast_horizon_minutes: Optional filter on forecast horizon. For example
232
- forecast_horizon_minutes=120, means load the forecast than was made 2 hours before the
233
- target time. Note this only works for non-historic data.
234
228
235
229
return: List of forecasts objects from database
236
230
"""
@@ -244,7 +238,6 @@ def get_all_gsp_ids_latest_forecast(
244
238
preload_children = preload_children ,
245
239
historic = historic ,
246
240
gsp_ids = list (range (0 , N_GSP + 1 )),
247
- forecast_horizon_minutes = forecast_horizon_minutes ,
248
241
)
249
242
250
243
@@ -254,7 +247,6 @@ def get_latest_forecast_for_gsps(
254
247
start_target_time : Optional [datetime ] = None ,
255
248
preload_children : Optional [bool ] = False ,
256
249
historic : bool = False ,
257
- forecast_horizon_minutes : Optional [int ] = None ,
258
250
gsp_ids : List [int ] = None ,
259
251
):
260
252
"""
@@ -267,19 +259,8 @@ def get_latest_forecast_for_gsps(
267
259
:param preload_children: Option to preload children. This is a speed up, if we need them.
268
260
:param historic: Option to load historic values or not
269
261
:param gsp_ids: Option to filter on gsps. If None, then only the lastest forecast is loaded.
270
- :param forecast_horizon_minutes: Optional filter on forecast horizon. For example
271
- forecast_horizon_minutes=120, means load the forecast than was made 2 hours before the
272
- target time. Note this only works for non-historic data.
262
+ List of forecasts objects from database
273
263
274
- return: List of forecasts objects from database
275
-
276
- :param session:
277
- :param start_created_utc:
278
- :param start_target_time:
279
- :param preload_children:
280
- :param historic:
281
- :param gsp_ids:
282
- :return:
283
264
"""
284
265
order_by_cols = []
285
266
@@ -307,20 +288,6 @@ def get_latest_forecast_for_gsps(
307
288
query = query , start_target_time = start_target_time , historic = historic
308
289
)
309
290
310
- if forecast_horizon_minutes is not None :
311
- assert historic is False , Exception (
312
- "Loading a forecast horizon only works on non latest data."
313
- )
314
-
315
- # need to join the ForecastValueSQL table
316
- if start_target_time is None :
317
- query = query .join (ForecastValueSQL )
318
-
319
- query = query .filter (
320
- ForecastValueSQL .target_time - ForecastValueSQL .created_utc
321
- >= text (f"interval '{ forecast_horizon_minutes } minute'" )
322
- )
323
-
324
291
query = query .join (LocationSQL )
325
292
326
293
# option to preload values, makes querying quicker
@@ -377,6 +344,7 @@ def get_forecast_values(
377
344
session : Session ,
378
345
gsp_id : Optional [int ] = None ,
379
346
start_datetime : Optional [datetime ] = None ,
347
+ forecast_horizon_minutes : Optional [int ] = None ,
380
348
only_return_latest : Optional [bool ] = False ,
381
349
) -> List [ForecastValueSQL ]:
382
350
"""
@@ -389,6 +357,11 @@ def get_forecast_values(
389
357
If None is given then all are returned.
390
358
:param only_return_latest: Optional to only return the latest forecast, not all of them.
391
359
Default is False
360
+ :param forecast_horizon_minutes: Optional filter on forecast horizon. For example
361
+ forecast_horizon_minutes=120, means load the forecast than was made 2 hours before the
362
+ target time. Note this only works for non-historic data.
363
+
364
+ return:
392
365
393
366
return: List of forecasts values objects from database
394
367
@@ -408,6 +381,14 @@ def get_forecast_values(
408
381
query = query .filter (ForecastValueSQL .created_utc >= created_utc_filter )
409
382
query = query .filter (ForecastSQL .created_utc >= created_utc_filter )
410
383
384
+ if forecast_horizon_minutes is not None :
385
+
386
+ # this seems to only work for postgres
387
+ query = query .filter (
388
+ ForecastValueSQL .target_time - ForecastValueSQL .created_utc
389
+ >= text (f"interval '{ forecast_horizon_minutes } minute'" )
390
+ )
391
+
411
392
# filter on gsp_id
412
393
if gsp_id is not None :
413
394
query = query .join (ForecastSQL )
0 commit comments