LCPDelta 2.2.5__tar.gz → 2.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {lcpdelta-2.2.5/lcpdelta_python_package/src/LCPDelta.egg-info → lcpdelta-2.2.7}/PKG-INFO +1 -1
- {lcpdelta-2.2.5 → lcpdelta-2.2.7/lcpdelta_python_package/src/LCPDelta.egg-info}/PKG-INFO +1 -1
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/LCPDelta.egg-info/SOURCES.txt +3 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/common/api_endpoints.py +3 -3
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/__init__.py +2 -3
- lcpdelta-2.2.7/lcpdelta_python_package/src/lcp_delta/enact/_signalr_connection.py +254 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/api_helper.py +48 -31
- lcpdelta-2.2.7/lcpdelta_python_package/src/lcp_delta/enact/bm_push_client.py +470 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/multi_series_dps_helper.py +9 -251
- lcpdelta-2.2.7/lcpdelta_python_package/src/lcp_delta/enact/services/bm_push_service.py +105 -0
- lcpdelta-2.2.7/lcpdelta_python_package/src/lcp_delta/enact/services/niv_evolution_service.py +47 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/pyproject.toml +3 -2
- lcpdelta-2.2.5/lcpdelta_python_package/src/lcp_delta/enact/services/niv_evolution_service.py +0 -28
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/LICENSE +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/LICENSE-Apache +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/README.md +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/LCPDelta.egg-info/dependency_links.txt +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/LCPDelta.egg-info/requires.txt +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/LCPDelta.egg-info/top_level.txt +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/__init__.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/common/__init__.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/common/api_helper_base.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/common/constants.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/common/credentials_holder.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/common/http/exceptions.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/common/http/retry_policies.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/common/response_objects/usage_info.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/base_endpoints.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/chart_helper.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/configs/__init__.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/configs/base_endpoints_default.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/configs/base_endpoints_dev.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/dps_helper.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/enums.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/helpers.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/loader.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/ancillary_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/bm_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/carbon_calculator_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/contract_evolution_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/day_ahead_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/epex_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/hof_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/index_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/leaderboard_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/news_table_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/nordpool_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/plant_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/series_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/enact/services/skip_rates_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/flextrack/__init__.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/flextrack/api_helper.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/flextrack/services/exporter_service.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/global_helpers.py +0 -0
- {lcpdelta-2.2.5 → lcpdelta-2.2.7}/setup.cfg +0 -0
|
@@ -18,8 +18,10 @@ lcpdelta_python_package/src/lcp_delta/common/http/exceptions.py
|
|
|
18
18
|
lcpdelta_python_package/src/lcp_delta/common/http/retry_policies.py
|
|
19
19
|
lcpdelta_python_package/src/lcp_delta/common/response_objects/usage_info.py
|
|
20
20
|
lcpdelta_python_package/src/lcp_delta/enact/__init__.py
|
|
21
|
+
lcpdelta_python_package/src/lcp_delta/enact/_signalr_connection.py
|
|
21
22
|
lcpdelta_python_package/src/lcp_delta/enact/api_helper.py
|
|
22
23
|
lcpdelta_python_package/src/lcp_delta/enact/base_endpoints.py
|
|
24
|
+
lcpdelta_python_package/src/lcp_delta/enact/bm_push_client.py
|
|
23
25
|
lcpdelta_python_package/src/lcp_delta/enact/chart_helper.py
|
|
24
26
|
lcpdelta_python_package/src/lcp_delta/enact/dps_helper.py
|
|
25
27
|
lcpdelta_python_package/src/lcp_delta/enact/enums.py
|
|
@@ -30,6 +32,7 @@ lcpdelta_python_package/src/lcp_delta/enact/configs/__init__.py
|
|
|
30
32
|
lcpdelta_python_package/src/lcp_delta/enact/configs/base_endpoints_default.py
|
|
31
33
|
lcpdelta_python_package/src/lcp_delta/enact/configs/base_endpoints_dev.py
|
|
32
34
|
lcpdelta_python_package/src/lcp_delta/enact/services/ancillary_service.py
|
|
35
|
+
lcpdelta_python_package/src/lcp_delta/enact/services/bm_push_service.py
|
|
33
36
|
lcpdelta_python_package/src/lcp_delta/enact/services/bm_service.py
|
|
34
37
|
lcpdelta_python_package/src/lcp_delta/enact/services/carbon_calculator_service.py
|
|
35
38
|
lcpdelta_python_package/src/lcp_delta/enact/services/contract_evolution_service.py
|
{lcpdelta-2.2.5 → lcpdelta-2.2.7}/lcpdelta_python_package/src/lcp_delta/common/api_endpoints.py
RENAMED
|
@@ -96,11 +96,11 @@ class EnactApiEndpoints:
|
|
|
96
96
|
def HOF_LATEST_FORECAST(self): return f"{self._base_endpoints.MAIN_BASE_URL}/EnactAPI/HistoryOfForecast/get_latest_forecast"
|
|
97
97
|
|
|
98
98
|
@property
|
|
99
|
-
def
|
|
99
|
+
def BM(self): return f"{self._base_endpoints.MAIN_BASE_URL}/EnactAPI/BOA/Data"
|
|
100
100
|
@property
|
|
101
|
-
def
|
|
101
|
+
def BM_DAILY(self): return f"{self._base_endpoints.MAIN_BASE_URL}/EnactAPI/BOA/dailyData"
|
|
102
102
|
@property
|
|
103
|
-
def
|
|
103
|
+
def BM_DAY_RANGE(self): return f"{self._base_endpoints.MAIN_BASE_URL}/EnactAPI/BOA/rangedData"
|
|
104
104
|
@property
|
|
105
105
|
def ANCILLARY(self): return f"{self._base_endpoints.MAIN_BASE_URL}/EnactAPI/Ancillary/Data"
|
|
106
106
|
@property
|
|
@@ -3,9 +3,7 @@ import sys
|
|
|
3
3
|
|
|
4
4
|
module_prefix = __name__ + "." # "lcp_delta.enact."
|
|
5
5
|
|
|
6
|
-
submodules_to_reload = [
|
|
7
|
-
mod for mod in sys.modules if mod.startswith(module_prefix) and sys.modules[mod]
|
|
8
|
-
]
|
|
6
|
+
submodules_to_reload = [mod for mod in sys.modules if mod.startswith(module_prefix) and sys.modules[mod]]
|
|
9
7
|
|
|
10
8
|
for mod in submodules_to_reload:
|
|
11
9
|
importlib.reload(sys.modules[mod])
|
|
@@ -14,4 +12,5 @@ from ..common.credentials_holder import CredentialsHolder
|
|
|
14
12
|
from .api_helper import APIHelper
|
|
15
13
|
from .dps_helper import DPSHelper
|
|
16
14
|
from .multi_series_dps_helper import MultiSeriesDPSHelper, MultiSeriesPushMetadata, PlantPushMetadata
|
|
15
|
+
from .bm_push_client import BMPushClient, BMPush
|
|
17
16
|
from .chart_helper import ChartHelper
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import inspect
|
|
5
|
+
import threading
|
|
6
|
+
from typing import Any, Callable, Self
|
|
7
|
+
|
|
8
|
+
from pysignalr.client import SignalRClient
|
|
9
|
+
|
|
10
|
+
from lcp_delta.enact.api_helper import APIHelper
|
|
11
|
+
from lcp_delta.common.http.exceptions import EnactApiError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class _SignalRConnection:
|
|
15
|
+
"""Shared connection lifecycle; subclasses own subscriptions and callback dispatch."""
|
|
16
|
+
|
|
17
|
+
def connect(self, timeout: float = 10) -> Self:
|
|
18
|
+
"""Start the background SignalR connection if it is not already running.
|
|
19
|
+
|
|
20
|
+
This method is idempotent while the helper is active, so repeated calls
|
|
21
|
+
do not create additional hub connections.
|
|
22
|
+
"""
|
|
23
|
+
if self._closed:
|
|
24
|
+
raise RuntimeError("This DPS helper has been closed. Create a new helper to reconnect.")
|
|
25
|
+
|
|
26
|
+
if self._connection_task is not None and not self._connection_task.done():
|
|
27
|
+
if not self._client_initialised.wait(timeout=timeout):
|
|
28
|
+
raise TimeoutError("Timed out initialising the SignalR client")
|
|
29
|
+
return self
|
|
30
|
+
|
|
31
|
+
if self._loop is None or not self._loop.is_running():
|
|
32
|
+
self._start_loop_thread()
|
|
33
|
+
|
|
34
|
+
self._stop_requested.clear()
|
|
35
|
+
self._client_initialised.clear()
|
|
36
|
+
future = self._run_in_loop(self._ensure_connection_started())
|
|
37
|
+
future.result(timeout=timeout)
|
|
38
|
+
|
|
39
|
+
if not self._client_initialised.wait(timeout=timeout):
|
|
40
|
+
raise TimeoutError("Timed out initialising the SignalR client")
|
|
41
|
+
|
|
42
|
+
return self
|
|
43
|
+
|
|
44
|
+
async def async_connect(self, timeout: float = 10) -> Self:
|
|
45
|
+
"""Start the SignalR connection without blocking the caller's event loop."""
|
|
46
|
+
if self._closed:
|
|
47
|
+
raise RuntimeError("This DPS helper has been closed. Create a new helper to reconnect.")
|
|
48
|
+
|
|
49
|
+
if self._connection_task is not None and not self._connection_task.done():
|
|
50
|
+
initialised = await asyncio.to_thread(self._client_initialised.wait, timeout)
|
|
51
|
+
if not initialised:
|
|
52
|
+
raise TimeoutError("Timed out initialising the SignalR client")
|
|
53
|
+
return self
|
|
54
|
+
|
|
55
|
+
if self._loop is None or not self._loop.is_running():
|
|
56
|
+
await asyncio.to_thread(self._start_loop_thread)
|
|
57
|
+
|
|
58
|
+
self._stop_requested.clear()
|
|
59
|
+
self._client_initialised.clear()
|
|
60
|
+
await asyncio.wait_for(asyncio.wrap_future(self._run_in_loop(self._ensure_connection_started())), timeout)
|
|
61
|
+
initialised = await asyncio.to_thread(self._client_initialised.wait, timeout)
|
|
62
|
+
if not initialised:
|
|
63
|
+
raise TimeoutError("Timed out initialising the SignalR client")
|
|
64
|
+
|
|
65
|
+
return self
|
|
66
|
+
|
|
67
|
+
def _start_loop_thread(self) -> None:
|
|
68
|
+
"""Create the private asyncio loop thread used by the synchronous API."""
|
|
69
|
+
self._loop_ready.clear()
|
|
70
|
+
self._thread = threading.Thread(target=self._start_loop, daemon=True)
|
|
71
|
+
self._thread.start()
|
|
72
|
+
self._loop_ready.wait()
|
|
73
|
+
|
|
74
|
+
def _start_loop(self) -> None:
|
|
75
|
+
"""Run the private asyncio event loop until shutdown."""
|
|
76
|
+
self._loop = asyncio.new_event_loop()
|
|
77
|
+
asyncio.set_event_loop(self._loop)
|
|
78
|
+
self._loop_ready.set()
|
|
79
|
+
try:
|
|
80
|
+
self._loop.run_forever()
|
|
81
|
+
finally:
|
|
82
|
+
pending = asyncio.all_tasks(self._loop)
|
|
83
|
+
for task in pending:
|
|
84
|
+
task.cancel()
|
|
85
|
+
if pending:
|
|
86
|
+
self._loop.run_until_complete(asyncio.gather(*pending, return_exceptions=True))
|
|
87
|
+
self._loop.close()
|
|
88
|
+
|
|
89
|
+
def _is_running_on_helper_loop(self) -> bool:
|
|
90
|
+
"""Return true when the caller is already executing on the helper loop."""
|
|
91
|
+
try:
|
|
92
|
+
return asyncio.get_running_loop() is self._loop
|
|
93
|
+
except RuntimeError:
|
|
94
|
+
return False
|
|
95
|
+
|
|
96
|
+
def _run_in_loop(self, coro):
|
|
97
|
+
"""Submit a coroutine to the helper's private event loop from any thread."""
|
|
98
|
+
if self._loop is None:
|
|
99
|
+
raise RuntimeError("Event loop not ready")
|
|
100
|
+
return asyncio.run_coroutine_threadsafe(coro, self._loop)
|
|
101
|
+
|
|
102
|
+
async def _connection_supervisor(self) -> None:
|
|
103
|
+
"""Run the SignalR client and recreate it after unexpected disconnects."""
|
|
104
|
+
delay = self.reconnect_initial_delay_seconds
|
|
105
|
+
|
|
106
|
+
while not self._stop_requested.is_set():
|
|
107
|
+
try:
|
|
108
|
+
hub_connection = self._build_hub_connection()
|
|
109
|
+
self._client_initialised.set()
|
|
110
|
+
await hub_connection.run()
|
|
111
|
+
except asyncio.CancelledError:
|
|
112
|
+
raise
|
|
113
|
+
except Exception as exc:
|
|
114
|
+
if self.reconnect and not self._stop_requested.is_set():
|
|
115
|
+
self.logger.warning(
|
|
116
|
+
"SignalR connection lost; automatically reconnecting in %.1f seconds: %s",
|
|
117
|
+
delay,
|
|
118
|
+
exc,
|
|
119
|
+
)
|
|
120
|
+
else:
|
|
121
|
+
self.logger.warning("SignalR connection stopped unexpectedly: %s", exc)
|
|
122
|
+
finally:
|
|
123
|
+
self._connected.clear()
|
|
124
|
+
|
|
125
|
+
if not self.reconnect or self._stop_requested.is_set():
|
|
126
|
+
break
|
|
127
|
+
|
|
128
|
+
if delay:
|
|
129
|
+
await asyncio.sleep(delay)
|
|
130
|
+
delay = min(max(delay * 2, self.reconnect_initial_delay_seconds), self.reconnect_max_delay_seconds)
|
|
131
|
+
|
|
132
|
+
def _build_hub_connection(self) -> SignalRClient:
|
|
133
|
+
"""Create a fresh SignalR client wired with auth and lifecycle handlers."""
|
|
134
|
+
api_helper = self._ensure_api_helper()
|
|
135
|
+
access_token_factory, headers = self._build_access_token_factory()
|
|
136
|
+
|
|
137
|
+
self.hub_connection = SignalRClient(
|
|
138
|
+
api_helper.endpoints.DPS,
|
|
139
|
+
access_token_factory=access_token_factory,
|
|
140
|
+
headers=headers,
|
|
141
|
+
)
|
|
142
|
+
self._handlers_registered_for_client = set()
|
|
143
|
+
|
|
144
|
+
async def on_error(error) -> None:
|
|
145
|
+
self.logger.warning("SignalR error: %s", error)
|
|
146
|
+
|
|
147
|
+
self.hub_connection.on_open(self._on_open)
|
|
148
|
+
self.hub_connection.on_close(self._on_close)
|
|
149
|
+
self.hub_connection.on_error(on_error)
|
|
150
|
+
return self.hub_connection
|
|
151
|
+
|
|
152
|
+
def _ensure_api_helper(self) -> APIHelper:
|
|
153
|
+
"""Create the API helper lazily so construction can be deferred in tests/scripts."""
|
|
154
|
+
if self.api_helper is None:
|
|
155
|
+
self.api_helper = APIHelper(self._username, self._public_api_key)
|
|
156
|
+
return self.api_helper
|
|
157
|
+
|
|
158
|
+
def _fetch_bearer_token(self) -> str:
|
|
159
|
+
"""Refresh and return the bearer token used by SignalR authentication."""
|
|
160
|
+
credentials = self._ensure_api_helper().credentials_holder
|
|
161
|
+
credentials.get_bearer_token()
|
|
162
|
+
return credentials.bearer_token
|
|
163
|
+
|
|
164
|
+
def _build_access_token_factory(self) -> tuple[Callable[[], str], dict[str, str]]:
|
|
165
|
+
"""Create SignalR auth headers while avoiding a duplicate first token request."""
|
|
166
|
+
credentials = self._ensure_api_helper().credentials_holder
|
|
167
|
+
first_token = credentials.bearer_token or self._fetch_bearer_token()
|
|
168
|
+
first_token_available = True
|
|
169
|
+
token_lock = threading.Lock()
|
|
170
|
+
|
|
171
|
+
def access_token_factory() -> str:
|
|
172
|
+
nonlocal first_token_available
|
|
173
|
+
|
|
174
|
+
with token_lock:
|
|
175
|
+
if first_token_available:
|
|
176
|
+
first_token_available = False
|
|
177
|
+
return first_token
|
|
178
|
+
|
|
179
|
+
return self._fetch_bearer_token()
|
|
180
|
+
|
|
181
|
+
return access_token_factory, {"Authorization": f"Bearer {first_token}"}
|
|
182
|
+
|
|
183
|
+
async def _send_with_response(self, method: str, arguments: list[Any], *, timeout: float) -> Any:
|
|
184
|
+
"""Send a SignalR hub method invocation and wait for its callback response."""
|
|
185
|
+
if self.hub_connection is None:
|
|
186
|
+
raise RuntimeError("SignalR client is not initialised")
|
|
187
|
+
|
|
188
|
+
response_future = asyncio.get_running_loop().create_future()
|
|
189
|
+
|
|
190
|
+
async def on_response(message) -> None:
|
|
191
|
+
error = getattr(message, "error", None)
|
|
192
|
+
if error:
|
|
193
|
+
if not response_future.done():
|
|
194
|
+
response_future.set_exception(EnactApiError("SignalRError", error, message))
|
|
195
|
+
return
|
|
196
|
+
|
|
197
|
+
result = getattr(message, "result", message)
|
|
198
|
+
if not response_future.done():
|
|
199
|
+
response_future.set_result(result)
|
|
200
|
+
|
|
201
|
+
try:
|
|
202
|
+
await self.hub_connection.send(method, arguments, on_response)
|
|
203
|
+
return await asyncio.wait_for(response_future, timeout=timeout)
|
|
204
|
+
except asyncio.CancelledError:
|
|
205
|
+
self._remove_pending_invocation_handler(on_response)
|
|
206
|
+
raise
|
|
207
|
+
except Exception:
|
|
208
|
+
self._remove_pending_invocation_handler(on_response)
|
|
209
|
+
raise
|
|
210
|
+
|
|
211
|
+
def _remove_pending_invocation_handler(self, callback: Callable[[Any], Any]) -> None:
|
|
212
|
+
"""Best-effort cleanup for a SignalR invocation callback after a failed wait."""
|
|
213
|
+
invocation_handlers = getattr(self.hub_connection, "_invocation_handlers", None)
|
|
214
|
+
if not isinstance(invocation_handlers, dict):
|
|
215
|
+
return
|
|
216
|
+
|
|
217
|
+
for invocation_id, handler in list(invocation_handlers.items()):
|
|
218
|
+
if handler is callback:
|
|
219
|
+
invocation_handlers.pop(invocation_id, None)
|
|
220
|
+
|
|
221
|
+
async def _leave_signalr_group(self, group_name: str, *, timeout: float) -> None:
|
|
222
|
+
"""Best-effort backend `LeaveGroup` call for one SignalR group."""
|
|
223
|
+
if self.hub_connection is None or not self.is_connected:
|
|
224
|
+
return
|
|
225
|
+
|
|
226
|
+
try:
|
|
227
|
+
await self._send_with_response("LeaveGroup", [group_name], timeout=timeout)
|
|
228
|
+
except Exception:
|
|
229
|
+
self.logger.warning("Failed to leave DPS group %s", group_name, exc_info=True)
|
|
230
|
+
|
|
231
|
+
async def _close_hub_connection(self) -> None:
|
|
232
|
+
"""Best-effort close of the underlying SignalR websocket before task cancellation."""
|
|
233
|
+
connection = self.hub_connection
|
|
234
|
+
if connection is None:
|
|
235
|
+
return
|
|
236
|
+
|
|
237
|
+
for method_name in ("close", "stop", "disconnect"):
|
|
238
|
+
method = getattr(connection, method_name, None)
|
|
239
|
+
if method is None:
|
|
240
|
+
continue
|
|
241
|
+
result = method()
|
|
242
|
+
if inspect.isawaitable(result):
|
|
243
|
+
await result
|
|
244
|
+
return
|
|
245
|
+
|
|
246
|
+
transport = getattr(connection, "_transport", None)
|
|
247
|
+
websocket = getattr(transport, "_ws", None)
|
|
248
|
+
close = getattr(websocket, "close", None)
|
|
249
|
+
if close is None:
|
|
250
|
+
return
|
|
251
|
+
|
|
252
|
+
result = close()
|
|
253
|
+
if inspect.isawaitable(result):
|
|
254
|
+
await result
|
|
@@ -852,7 +852,7 @@ class APIHelper(APIHelperBase):
|
|
|
852
852
|
|
|
853
853
|
period `int` (optional): The period for which to retrieve the BM data. If None and date input is of type datetime, the period is calculated (rounded down to the nearest half-hour).
|
|
854
854
|
|
|
855
|
-
include_accepted_times `bool`: Choose whether object include
|
|
855
|
+
include_accepted_times `bool`: Choose whether object include BM accepted times or not
|
|
856
856
|
|
|
857
857
|
Returns:
|
|
858
858
|
Response: A pandas DataFrame containing the BM data.
|
|
@@ -861,7 +861,7 @@ class APIHelper(APIHelperBase):
|
|
|
861
861
|
`TypeError`: If the period is not an integer or if no period is given and date is not of type datetime.
|
|
862
862
|
"""
|
|
863
863
|
request_body = bm_service.generate_by_period_request(date, period, include_accepted_times)
|
|
864
|
-
response = self._post_request(self.endpoints.
|
|
864
|
+
response = self._post_request(self.endpoints.BM, request_body, long_timeout=True)
|
|
865
865
|
return bm_service.process_by_period_response(response)
|
|
866
866
|
|
|
867
867
|
async def get_bm_data_by_period_async(
|
|
@@ -869,7 +869,7 @@ class APIHelper(APIHelperBase):
|
|
|
869
869
|
) -> pd.DataFrame:
|
|
870
870
|
"""An asynchronous version of `get_bm_data_by_period`."""
|
|
871
871
|
request_body = bm_service.generate_by_period_request(date, period, include_accepted_times)
|
|
872
|
-
response = await self._post_request_async(self.endpoints.
|
|
872
|
+
response = await self._post_request_async(self.endpoints.BM, request_body, long_timeout=True)
|
|
873
873
|
return bm_service.process_by_period_response(response)
|
|
874
874
|
|
|
875
875
|
def get_bm_data_by_day(
|
|
@@ -884,7 +884,7 @@ class APIHelper(APIHelperBase):
|
|
|
884
884
|
same as get_bm_data_by_search except include_accepted_times and include_on_table default is true
|
|
885
885
|
"""
|
|
886
886
|
request_body = bm_service.generate_by_search_request(date, option, search_string, include_accepted_times, include_on_table)
|
|
887
|
-
response = self._get_request(self.endpoints.
|
|
887
|
+
response = self._get_request(self.endpoints.BM_DAILY, request_body, long_timeout=True)
|
|
888
888
|
return bm_service.process_by_search_response(response)
|
|
889
889
|
|
|
890
890
|
async def get_bm_data_by_day_async(
|
|
@@ -897,7 +897,7 @@ class APIHelper(APIHelperBase):
|
|
|
897
897
|
) -> pd.DataFrame:
|
|
898
898
|
"""An asynchronous version of `get_bm_data_by_day`."""
|
|
899
899
|
request_body = bm_service.generate_by_search_request(date, option, search_string, include_accepted_times, include_on_table)
|
|
900
|
-
response = await self._get_request_async(self.endpoints.
|
|
900
|
+
response = await self._get_request_async(self.endpoints.BM_DAILY, request_body, long_timeout=True)
|
|
901
901
|
return bm_service.process_by_search_response(response)
|
|
902
902
|
|
|
903
903
|
def get_bm_data_by_day_range(
|
|
@@ -918,8 +918,8 @@ class APIHelper(APIHelperBase):
|
|
|
918
918
|
|
|
919
919
|
option `str`: The search option; can be set to "plant", "fuel", or "all".
|
|
920
920
|
|
|
921
|
-
search_string `str`: The search string to match against the BM data. If option is "plant", this allows you to filter
|
|
922
|
-
If option is "fuel", this allows you to filter
|
|
921
|
+
search_string `str`: The search string to match against the BM data. If option is "plant", this allows you to filter BM actions by BMU ID (e.g. "CARR" for all Carrington units).
|
|
922
|
+
If option is "fuel", this allows you to filter BM actions by fuel type (e.g. "Coal"). If Option is "all", this must not be passed as an argument.
|
|
923
923
|
|
|
924
924
|
include_accepted_times `bool`: Determine whether the returned object includes a column for accepted times in the response object. Defaults to True.
|
|
925
925
|
|
|
@@ -933,7 +933,7 @@ class APIHelper(APIHelperBase):
|
|
|
933
933
|
more_pages = True
|
|
934
934
|
while more_pages:
|
|
935
935
|
request_body = bm_service.generate_date_range_request(start_date, end_date, include_accepted_times, option, search_string, include_on_table, cursor)
|
|
936
|
-
response = self._get_request(self.endpoints.
|
|
936
|
+
response = self._get_request(self.endpoints.BM_DAY_RANGE, request_body, long_timeout=True)
|
|
937
937
|
page_data = response.get("data", {})
|
|
938
938
|
rows = page_data.get("data", [])
|
|
939
939
|
|
|
@@ -965,7 +965,7 @@ class APIHelper(APIHelperBase):
|
|
|
965
965
|
more_pages = True
|
|
966
966
|
while more_pages:
|
|
967
967
|
request_body = bm_service.generate_date_range_request(start_date, end_date, include_accepted_times, option, search_string, include_on_table, cursor)
|
|
968
|
-
response = await self._get_request_async(self.endpoints.
|
|
968
|
+
response = await self._get_request_async(self.endpoints.BM_DAY_RANGE, request_body, long_timeout=True)
|
|
969
969
|
page_data = response.get("data", {})
|
|
970
970
|
rows = page_data.get("data", [])
|
|
971
971
|
|
|
@@ -996,8 +996,8 @@ class APIHelper(APIHelperBase):
|
|
|
996
996
|
|
|
997
997
|
option `str`: The search option; can be set to "plant", "fuel", or "all".
|
|
998
998
|
|
|
999
|
-
search_string `str`: The search string to match against the BM data. If option is "plant", this allows you to filter
|
|
1000
|
-
If option is "fuel", this allows you to filter
|
|
999
|
+
search_string `str`: The search string to match against the BM data. If option is "plant", this allows you to filter BM actions by BMU ID (e.g. "CARR" for all Carrington units).
|
|
1000
|
+
If option is "fuel", this allows you to filter BM actions by fuel type (e.g. "Coal"). If Option is "all", this must not be passed as an argument.
|
|
1001
1001
|
|
|
1002
1002
|
include_accepted_times `bool`: Determine whether the returned object includes a column for accepted times in the response object. Defaults to false.
|
|
1003
1003
|
|
|
@@ -1006,7 +1006,7 @@ class APIHelper(APIHelperBase):
|
|
|
1006
1006
|
Response: A pandas DataFrame containing the BM data.
|
|
1007
1007
|
"""
|
|
1008
1008
|
request_body = bm_service.generate_by_search_request(date, option, search_string, include_accepted_times, include_on_table)
|
|
1009
|
-
response = self._get_request(self.endpoints.
|
|
1009
|
+
response = self._get_request(self.endpoints.BM_DAILY, request_body, long_timeout=True)
|
|
1010
1010
|
return bm_service.process_by_search_response(response)
|
|
1011
1011
|
|
|
1012
1012
|
async def get_bm_data_by_search_async(
|
|
@@ -1019,7 +1019,7 @@ class APIHelper(APIHelperBase):
|
|
|
1019
1019
|
) -> pd.DataFrame:
|
|
1020
1020
|
"""An asynchronous version of `get_bm_data_by_search`."""
|
|
1021
1021
|
request_body = bm_service.generate_by_search_request(date, option, search_string, include_accepted_times, include_on_table)
|
|
1022
|
-
response = await self._get_request_async(self.endpoints.
|
|
1022
|
+
response = await self._get_request_async(self.endpoints.BM_DAILY, request_body, long_timeout=True)
|
|
1023
1023
|
return bm_service.process_by_search_response(response)
|
|
1024
1024
|
|
|
1025
1025
|
def get_leaderboard_data_legacy(
|
|
@@ -2115,7 +2115,6 @@ class APIHelper(APIHelperBase):
|
|
|
2115
2115
|
options 'List[str]' : List of options to get evolution metrics for. Accepted values:
|
|
2116
2116
|
[
|
|
2117
2117
|
NivOutturn,
|
|
2118
|
-
SystemPrice,
|
|
2119
2118
|
MostExpensiveBidAccepted,
|
|
2120
2119
|
MostExpensiveOfferAccepted,
|
|
2121
2120
|
MostExpensiveUnflaggedBidAccepted,
|
|
@@ -2167,7 +2166,6 @@ class APIHelper(APIHelperBase):
|
|
|
2167
2166
|
options 'List[str]' : List of options to get evolution metrics for. Accepted values:
|
|
2168
2167
|
[
|
|
2169
2168
|
NivOutturn,
|
|
2170
|
-
SystemPrice,
|
|
2171
2169
|
MostExpensiveBidAccepted,
|
|
2172
2170
|
MostExpensiveOfferAccepted,
|
|
2173
2171
|
MostExpensiveUnflaggedBidAccepted,
|
|
@@ -2211,7 +2209,11 @@ class APIHelper(APIHelperBase):
|
|
|
2211
2209
|
options: list[str],
|
|
2212
2210
|
) -> pd.DataFrame:
|
|
2213
2211
|
"""
|
|
2214
|
-
Get
|
|
2212
|
+
Get NIV evolution metrics over an inclusive date range.
|
|
2213
|
+
|
|
2214
|
+
Fetches every daily page automatically (one API usage unit per page).
|
|
2215
|
+
Returns Date, Period, Metric, Timestamp and Value columns. Dates retain
|
|
2216
|
+
the API's dd-MM-yyyy format; timestamps are returned without conversion.
|
|
2215
2217
|
|
|
2216
2218
|
Args:
|
|
2217
2219
|
start_date 'datetime' : start date to request
|
|
@@ -2220,7 +2222,6 @@ class APIHelper(APIHelperBase):
|
|
|
2220
2222
|
options 'List[str]' : List of options to get evolution metrics for. Accepted values:
|
|
2221
2223
|
[
|
|
2222
2224
|
NivOutturn,
|
|
2223
|
-
SystemPrice,
|
|
2224
2225
|
MostExpensiveBidAccepted,
|
|
2225
2226
|
MostExpensiveOfferAccepted,
|
|
2226
2227
|
MostExpensiveUnflaggedBidAccepted,
|
|
@@ -2249,13 +2250,21 @@ class APIHelper(APIHelperBase):
|
|
|
2249
2250
|
while more_pages:
|
|
2250
2251
|
request_body = niv_evolution_service.generate_date_range_request(start_date, end_date, options, cursor)
|
|
2251
2252
|
response = self._get_request(self.endpoints.NIV_EVOLUTION_DATE_RANGE, request_body, long_timeout=True)
|
|
2252
|
-
page_data = response.get("data", {})
|
|
2253
2253
|
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2254
|
+
page_date = cursor or start_date.strftime("%Y-%m-%d")
|
|
2255
|
+
if response is None:
|
|
2256
|
+
raise ValueError(
|
|
2257
|
+
f"NIV evolution API pagination failed for {page_date}."
|
|
2258
|
+
)
|
|
2259
|
+
|
|
2260
|
+
try:
|
|
2261
|
+
day_data = niv_evolution_service.process_response(response["data"])
|
|
2262
|
+
except (ValueError, KeyError, TypeError) as exc:
|
|
2263
|
+
raise ValueError(
|
|
2264
|
+
f"Failed to process NIV evolution page {page_date}: {exc}"
|
|
2265
|
+
) from exc
|
|
2266
|
+
|
|
2267
|
+
all_data.append(day_data)
|
|
2259
2268
|
|
|
2260
2269
|
cursor = response.get("nextCursor")
|
|
2261
2270
|
if not cursor:
|
|
@@ -2264,7 +2273,7 @@ class APIHelper(APIHelperBase):
|
|
|
2264
2273
|
if all_data:
|
|
2265
2274
|
df_all = pd.concat(all_data, ignore_index=True)
|
|
2266
2275
|
else:
|
|
2267
|
-
df_all = pd.DataFrame(columns=
|
|
2276
|
+
df_all = pd.DataFrame(columns=niv_evolution_service.COLUMNS)
|
|
2268
2277
|
return df_all
|
|
2269
2278
|
|
|
2270
2279
|
async def get_niv_evolution_for_date_range_async(
|
|
@@ -2280,13 +2289,21 @@ class APIHelper(APIHelperBase):
|
|
|
2280
2289
|
while more_pages:
|
|
2281
2290
|
request_body = niv_evolution_service.generate_date_range_request(start_date, end_date, options, cursor)
|
|
2282
2291
|
response = await self._get_request_async(self.endpoints.NIV_EVOLUTION_DATE_RANGE, request_body, long_timeout=True)
|
|
2283
|
-
page_data = response.get("data", {})
|
|
2284
2292
|
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2293
|
+
page_date = cursor or start_date.strftime("%Y-%m-%d")
|
|
2294
|
+
if response is None:
|
|
2295
|
+
raise ValueError(
|
|
2296
|
+
f"NIV evolution API pagination failed for {page_date}."
|
|
2297
|
+
)
|
|
2298
|
+
|
|
2299
|
+
try:
|
|
2300
|
+
day_data = niv_evolution_service.process_response(response["data"])
|
|
2301
|
+
except (ValueError, KeyError, TypeError) as exc:
|
|
2302
|
+
raise ValueError(
|
|
2303
|
+
f"Failed to process NIV evolution page {page_date}: {exc}"
|
|
2304
|
+
) from exc
|
|
2305
|
+
|
|
2306
|
+
all_data.append(day_data)
|
|
2290
2307
|
|
|
2291
2308
|
cursor = response.get("nextCursor")
|
|
2292
2309
|
if not cursor:
|
|
@@ -2295,7 +2312,7 @@ class APIHelper(APIHelperBase):
|
|
|
2295
2312
|
if all_data:
|
|
2296
2313
|
df_all = pd.concat(all_data, ignore_index=True)
|
|
2297
2314
|
else:
|
|
2298
|
-
df_all = pd.DataFrame(columns=
|
|
2315
|
+
df_all = pd.DataFrame(columns=niv_evolution_service.COLUMNS)
|
|
2299
2316
|
return df_all
|
|
2300
2317
|
|
|
2301
2318
|
def get_carbon_emissions(
|