Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

## Upgrading

* The CLI tool is moved to dedicated folder.

<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->

## New Features

* Support data requests for multiple component IDs from command line.
* Support for passing formula strings as a `cid` argument from the command line.

<!-- Here goes the main new features and examples or instructions on how to use them -->

## Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ dependencies = [
dynamic = ["version"]

[project.scripts]
reporting-cli = "frequenz.client.reporting.__main__:main"
reporting-cli = "frequenz.client.reporting.cli.__main__:main"

[[project.authors]]
name = "Frequenz Energy-as-a-Service GmbH"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@ def main() -> None:
help="URL of the Reporting service",
default="localhost:50051",
)
parser.add_argument("--mid", type=int, help="Microgrid ID", required=True)
parser.add_argument("--cid", type=int, help="Component ID", required=True)
parser.add_argument(
"--mid",
type=int,
help="Microgrid ID",
required=True,
)
parser.add_argument(
"--cid",
nargs="+",
type=str,
help="Component IDs or formulae",
)
parser.add_argument(
"--metrics",
type=str,
Expand Down Expand Up @@ -97,7 +107,7 @@ def main() -> None:
async def run(
*,
microgrid_id: int,
component_id: int,
component_id: list[str],
metric_names: list[str],
start_dt: datetime | None,
end_dt: datetime | None,
Expand Down Expand Up @@ -130,30 +140,47 @@ async def run(

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

def data_iter() -> AsyncIterator[MetricSample]:
cids = [int(cid.strip()) for cid in component_id if cid.strip().isdigit()]
formulas = [cid.strip() for cid in component_id if not cid.strip().isdigit()]
microgrid_components = [(microgrid_id, cids)]

async def data_iter() -> AsyncIterator[MetricSample]:
"""Iterate over single metric.

Just a wrapper around the client method for readability.

Returns:
Iterator over single metric samples
Yields:
Single metric samples
"""
resampling_period = (
timedelta(seconds=resampling_period_s)
if resampling_period_s is not None
else None
)

return client.list_single_component_data(
microgrid_id=microgrid_id,
component_id=component_id,
async for sample in client.list_microgrid_components_data(
microgrid_components=microgrid_components,
metrics=metrics,
start_dt=start_dt,
end_dt=end_dt,
resampling_period=resampling_period,
include_states=states,
include_bounds=bounds,
)
):
yield sample

for formula in formulas:
assert resampling_period is not None
for metric in metrics:
async for sample in client.receive_aggregated_data(
microgrid_id=microgrid_id,
metric=metric,
aggregation_formula=formula,
start=start_dt,
end=end_dt,
resampling_period=resampling_period,
):
yield sample

if fmt == "iter":
# Iterate over single metric generator
Expand Down
Loading