1
1
""" Save forecasts to the database """
2
2
import logging
3
- from typing import List
3
+ from typing import List , Optional
4
4
5
5
from sqlalchemy .orm .session import Session
6
6
10
10
logger = logging .getLogger (__name__ )
11
11
12
12
13
- def save (forecasts : List [ForecastSQL ], session : Session ):
13
+ def save (
14
+ forecasts : List [ForecastSQL ],
15
+ session : Session ,
16
+ update_national : Optional [bool ] = True ,
17
+ update_gsp : Optional [bool ] = True ,
18
+ ):
14
19
"""
15
20
Save forecast to database
16
21
@@ -19,6 +24,8 @@ def save(forecasts: List[ForecastSQL], session: Session):
19
24
20
25
:param forecasts: list of sql forecasts
21
26
:param session: database session
27
+ :param update_national: Optional (default true), to update the national forecast
28
+ :param update_gsp: Optional (default true), to update all the GSP forecasts
22
29
"""
23
30
24
31
# save objects to database
@@ -27,7 +34,9 @@ def save(forecasts: List[ForecastSQL], session: Session):
27
34
session .commit ()
28
35
29
36
logger .debug ("Updating to latest" )
30
- update_all_forecast_latest (session = session , forecasts = forecasts )
37
+ update_all_forecast_latest (
38
+ session = session , forecasts = forecasts , update_national = update_national , update_gsp = update_gsp
39
+ )
31
40
session .commit ()
32
41
33
42
0 commit comments