Skip to content

Commit 213338a

Browse files
Expose resampling option (#52)
Addressing issue #22 by exposing the resampling option as an optional input.
2 parents b4110f9 + 60af0d5 commit 213338a

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
## New Features
1212

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
13+
* The `ReportingApiClient` exposes the resampling option of the data, with its
14+
resolution represented in second and its default set to `None.
1415

1516
## Bug Fixes
1617

examples/client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def main() -> None:
4949
help="End datetime in YYYY-MM-DDTHH:MM:SS format",
5050
required=True,
5151
)
52+
parser.add_argument("--resolution", type=int, help="Resolution", default=None)
5253
parser.add_argument("--psize", type=int, help="Page size", default=100)
5354
parser.add_argument(
5455
"--display", choices=["iter", "df", "dict"], help="Display format", default="df"
@@ -61,20 +62,22 @@ def main() -> None:
6162
args.metrics,
6263
args.start,
6364
args.end,
65+
args.resolution,
6466
page_size=args.psize,
6567
service_address=args.url,
6668
display=args.display,
6769
)
6870
)
6971

7072

71-
# pylint: disable=too-many-arguments
73+
# pylint: disable=too-many-arguments, too-many-locals
7274
async def run(
7375
microgrid_id: int,
7476
component_id: int,
7577
metric_names: list[str],
7678
start_dt: datetime,
7779
end_dt: datetime,
80+
resolution: int,
7881
page_size: int,
7982
service_address: str,
8083
display: str,
@@ -87,6 +90,7 @@ async def run(
8790
metric_names: list of metric names
8891
start_dt: start datetime
8992
end_dt: end datetime
93+
resolution: resampling resolution in sec
9094
page_size: page size
9195
service_address: service address
9296
display: display format
@@ -112,6 +116,7 @@ def data_iter() -> AsyncIterator[MetricSample]:
112116
metrics=metrics,
113117
start_dt=start_dt,
114118
end_dt=end_dt,
119+
resolution=resolution,
115120
page_size=page_size,
116121
)
117122

src/frequenz/client/reporting/_client.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
from frequenz.api.reporting.v1.reporting_pb2 import (
2525
ListMicrogridComponentsDataResponse as PBListMicrogridComponentsDataResponse,
2626
)
27+
from frequenz.api.reporting.v1.reporting_pb2 import (
28+
ResamplingOptions as PBResamplingOptions,
29+
)
2730
from frequenz.api.reporting.v1.reporting_pb2 import TimeFilter as PBTimeFilter
2831
from frequenz.api.reporting.v1.reporting_pb2_grpc import ReportingStub
2932
from frequenz.client.common.metric import Metric
@@ -130,6 +133,7 @@ async def list_single_component_data(
130133
metrics: Metric | list[Metric],
131134
start_dt: datetime,
132135
end_dt: datetime,
136+
resolution: int | None,
133137
page_size: int = 1000,
134138
) -> AsyncIterator[MetricSample]:
135139
"""Iterate over the data for a single metric.
@@ -140,6 +144,7 @@ async def list_single_component_data(
140144
metrics: The metric name or list of metric names.
141145
start_dt: The start date and time.
142146
end_dt: The end date and time.
147+
resolution: The resampling resolution for the data, represented in seconds.
143148
page_size: The page size.
144149
145150
Yields:
@@ -152,6 +157,7 @@ async def list_single_component_data(
152157
metrics=[metrics] if isinstance(metrics, Metric) else metrics,
153158
start_dt=start_dt,
154159
end_dt=end_dt,
160+
resolution=resolution,
155161
page_size=page_size,
156162
):
157163
for entry in page:
@@ -165,6 +171,7 @@ async def list_microgrid_components_data(
165171
metrics: Metric | list[Metric],
166172
start_dt: datetime,
167173
end_dt: datetime,
174+
resolution: int | None,
168175
page_size: int = 1000,
169176
) -> AsyncIterator[MetricSample]:
170177
"""Iterate over the data for multiple microgrids and components.
@@ -175,6 +182,7 @@ async def list_microgrid_components_data(
175182
metrics: The metric name or list of metric names.
176183
start_dt: The start date and time.
177184
end_dt: The end date and time.
185+
resolution: The resampling resolution for the data, represented in seconds.
178186
page_size: The page size.
179187
180188
Yields:
@@ -190,6 +198,7 @@ async def list_microgrid_components_data(
190198
metrics=[metrics] if isinstance(metrics, Metric) else metrics,
191199
start_dt=start_dt,
192200
end_dt=end_dt,
201+
resolution=resolution,
193202
page_size=page_size,
194203
):
195204
for entry in page:
@@ -203,7 +212,8 @@ async def _list_microgrid_components_data_pages(
203212
metrics: list[Metric],
204213
start_dt: datetime,
205214
end_dt: datetime,
206-
page_size: int = 1000,
215+
resolution: int | None,
216+
page_size: int,
207217
) -> AsyncIterator[ComponentsDataPage]:
208218
"""Iterate over the pages of microgrid components data.
209219
@@ -215,6 +225,7 @@ async def _list_microgrid_components_data_pages(
215225
metrics: A list of metrics.
216226
start_dt: The start date and time.
217227
end_dt: The end date and time.
228+
resolution: The resampling resolution for the data, represented in seconds.
218229
page_size: The page size.
219230
220231
Yields:
@@ -237,6 +248,7 @@ def dt2ts(dt: datetime) -> PBTimestamp:
237248

238249
list_filter = PBListMicrogridComponentsDataRequest.ListFilter(
239250
time_filter=time_filter,
251+
resampling_options=PBResamplingOptions(resolution=resolution),
240252
)
241253

242254
metrics_pb = [metric.to_proto() for metric in metrics]

0 commit comments

Comments
 (0)