Skip to content

Commit 2f17930

Browse files
authored
Support requests for multiple components and formulas via CLI tool (frequenz-floss#134)
Support data requests for multiple component IDs and passing formula strings as a `cid` argument to the command line tool.
2 parents 49e48fc + 91e0df8 commit 2f17930

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@
66

77
## Upgrading
88

9+
* The CLI tool is moved to dedicated folder.
10+
911
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
1012

1113
## New Features
1214

15+
* Support data requests for multiple component IDs from command line.
16+
* Support for passing formula strings as a `cid` argument from the command line.
17+
1318
<!-- Here goes the main new features and examples or instructions on how to use them -->
1419

1520
## Bug Fixes

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies = [
3838
dynamic = ["version"]
3939

4040
[project.scripts]
41-
reporting-cli = "frequenz.client.reporting.__main__:main"
41+
reporting-cli = "frequenz.client.reporting.cli.__main__:main"
4242

4343
[[project.authors]]
4444
name = "Frequenz Energy-as-a-Service GmbH"

src/frequenz/client/reporting/__main__.py renamed to src/frequenz/client/reporting/cli/__main__.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,18 @@ def main() -> None:
2424
help="URL of the Reporting service",
2525
default="localhost:50051",
2626
)
27-
parser.add_argument("--mid", type=int, help="Microgrid ID", required=True)
28-
parser.add_argument("--cid", type=int, help="Component ID", required=True)
27+
parser.add_argument(
28+
"--mid",
29+
type=int,
30+
help="Microgrid ID",
31+
required=True,
32+
)
33+
parser.add_argument(
34+
"--cid",
35+
nargs="+",
36+
type=str,
37+
help="Component IDs or formulae",
38+
)
2939
parser.add_argument(
3040
"--metrics",
3141
type=str,
@@ -97,7 +107,7 @@ def main() -> None:
97107
async def run(
98108
*,
99109
microgrid_id: int,
100-
component_id: int,
110+
component_id: list[str],
101111
metric_names: list[str],
102112
start_dt: datetime | None,
103113
end_dt: datetime | None,
@@ -130,30 +140,47 @@ async def run(
130140

131141
metrics = [Metric[mn] for mn in metric_names]
132142

133-
def data_iter() -> AsyncIterator[MetricSample]:
143+
cids = [int(cid.strip()) for cid in component_id if cid.strip().isdigit()]
144+
formulas = [cid.strip() for cid in component_id if not cid.strip().isdigit()]
145+
microgrid_components = [(microgrid_id, cids)]
146+
147+
async def data_iter() -> AsyncIterator[MetricSample]:
134148
"""Iterate over single metric.
135149
136150
Just a wrapper around the client method for readability.
137151
138-
Returns:
139-
Iterator over single metric samples
152+
Yields:
153+
Single metric samples
140154
"""
141155
resampling_period = (
142156
timedelta(seconds=resampling_period_s)
143157
if resampling_period_s is not None
144158
else None
145159
)
146160

147-
return client.list_single_component_data(
148-
microgrid_id=microgrid_id,
149-
component_id=component_id,
161+
async for sample in client.list_microgrid_components_data(
162+
microgrid_components=microgrid_components,
150163
metrics=metrics,
151164
start_dt=start_dt,
152165
end_dt=end_dt,
153166
resampling_period=resampling_period,
154167
include_states=states,
155168
include_bounds=bounds,
156-
)
169+
):
170+
yield sample
171+
172+
for formula in formulas:
173+
assert resampling_period is not None
174+
for metric in metrics:
175+
async for sample in client.receive_aggregated_data(
176+
microgrid_id=microgrid_id,
177+
metric=metric,
178+
aggregation_formula=formula,
179+
start=start_dt,
180+
end=end_dt,
181+
resampling_period=resampling_period,
182+
):
183+
yield sample
157184

158185
if fmt == "iter":
159186
# Iterate over single metric generator

0 commit comments

Comments
 (0)