1616from src .models .predicted_load import PredictedGridAssetLoad
1717
1818
19- class PredictionActionsBase [ReadOnlySession ](ABC ):
19+ class PredictionActionsBase [ReadOnlySession , WriteSession ](ABC ):
2020 """Abstract class which contains methods used by this workflow.
2121
2222 These methods are implemented on a higher level and provided to the functions of this
@@ -27,6 +27,10 @@ class PredictionActionsBase[ReadOnlySession](ABC):
2727 def get_query_api (self ) -> ReadOnlySession :
2828 """Retrieve a read-only session to the database."""
2929
30+ @abstractmethod
31+ def get_write_api (self ) -> WriteSession :
32+ """Retrieve a write session to the database."""
33+
3034 @abstractmethod
3135 async def get_predicted_grid_asset_load (
3236 self , query_api : ReadOnlySession , from_date : datetime , to_date : datetime
@@ -42,6 +46,19 @@ async def get_predicted_grid_asset_load(
4246 list[PredictedGridAssetLoad]: The list of predicted grid asset loads.
4347 """
4448
49+ @abstractmethod
50+ async def audit_predicted_grid_asset_loads (
51+ self ,
52+ write_api : WriteSession ,
53+ predicted_grid_asset_loads : list [PredictedGridAssetLoad ],
54+ ) -> None :
55+ """Audit predicted grid asset loads by storing them in the database.
56+
57+ Args:
58+ write_api (WriteSession): The write connection to the database.
59+ predicted_grid_asset_loads (list[PredictedGridAssetLoad]): The list of predicted grid asset loads to audit.
60+ """
61+
4562
4663def _generate_capacity_limitation_intervals (
4764 interval_id : int ,
@@ -123,7 +140,7 @@ async def get_capacity_limitation_event(
123140 Args:
124141 actions (PredictionActionsBase): The actions to use.
125142 from_date (datetime): The start time (inclusive) from which to fetch OpenADR events.
126- to_date (datetime): The end time (exclusive ) from which to fetch OpenADR events.
143+ to_date (datetime): The end time (inclusive ) from which to fetch OpenADR events.
127144
128145 Returns:
129146 Event | None: The OpenADR3 capacity limitation event. None if no data to base the event on could be retrieved.
@@ -140,4 +157,9 @@ async def get_capacity_limitation_event(
140157 )
141158 return None
142159
160+ write_api = actions .get_write_api ()
161+ await actions .audit_predicted_grid_asset_loads (
162+ write_api , predicted_grid_asset_loads
163+ )
164+
143165 return _generate_capacity_limitation_event (predicted_grid_asset_loads , MAX_CAPACITY )
0 commit comments