Skip to content

Commit 7ad907a

Browse files
Add support for multiple components and microgrids (#39)
A simple support for mutliple components and microgrids addressing Issue #19.
2 parents c9af057 + 3584214 commit 7ad907a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,9 @@
1010

1111
## New Features
1212

13+
* The client method `list_multiple_microgrid_components_data` is added to
14+
expose the functionality of supporting arbitrary lists of microgrid-component IDs
15+
and metric IDs. It is intended to be as close as possible on the gRPC function call.
16+
1317
## Bug Fixes
1418

src/frequenz/client/reporting/_client.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,44 @@ async def list_single_component_data(
157157
for entry in page:
158158
yield entry
159159

160+
# pylint: disable=too-many-arguments
161+
async def list_multiple_microgrid_components_data(
162+
self,
163+
*,
164+
microgrid_components: list[tuple[int, list[int]]],
165+
metrics: Metric | list[Metric],
166+
start_dt: datetime,
167+
end_dt: datetime,
168+
page_size: int = 1000,
169+
) -> AsyncIterator[MetricSample]:
170+
"""Iterate over the data for multiple microgrids and components.
171+
172+
Args:
173+
microgrid_components: List of tuples where each tuple contains
174+
microgrid ID and corresponding component IDs.
175+
metrics: The metric name or list of metric names.
176+
start_dt: The start date and time.
177+
end_dt: The end date and time.
178+
page_size: The page size.
179+
180+
Yields:
181+
A named tuple with the following fields:
182+
* microgrid_id: The microgrid ID.
183+
* component_id: The component ID.
184+
* metric: The metric name.
185+
* timestamp: The timestamp of the metric sample.
186+
* value: The metric value.
187+
"""
188+
async for page in self._list_microgrid_components_data_pages(
189+
microgrid_components=microgrid_components,
190+
metrics=[metrics] if isinstance(metrics, Metric) else metrics,
191+
start_dt=start_dt,
192+
end_dt=end_dt,
193+
page_size=page_size,
194+
):
195+
for entry in page:
196+
yield entry
197+
160198
# pylint: disable=too-many-arguments
161199
async def _list_microgrid_components_data_pages(
162200
self,

0 commit comments

Comments
 (0)