Skip to content

Commit 5fa8a62

Browse files
authored
Support for streaming (frequenz-floss#116)
This adds support for streaming: By omitting the end date in the request, the client will return any historical data from timestamp until now and keep streaming new data as it arrives. Also the start date can be omitted which let's the data start at the earliest time stamp that is available.
2 parents b82eef2 + d6bcd69 commit 5fa8a62

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

RELEASE_NOTES.md

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

1111
## New Features
1212

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
13+
* Support for streaming: By omitting the end date in the request,
14+
the client will return any historical data from timestamp until now and
15+
keep streaming new data as it arrives.
16+
* Also the start date can be omitted which let's the data start at the
17+
earliest time stamp that is available.
1418

1519
## Bug Fixes
1620

src/frequenz/client/reporting/__main__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ def main() -> None:
4949
"--start",
5050
type=datetime.fromisoformat,
5151
help="Start datetime in YYYY-MM-DDTHH:MM:SS format",
52-
required=True,
52+
required=False,
53+
default=None,
5354
)
5455
parser.add_argument(
5556
"--end",
5657
type=datetime.fromisoformat,
5758
help="End datetime in YYYY-MM-DDTHH:MM:SS format",
58-
required=True,
59+
required=False,
60+
default=None,
5961
)
6062
parser.add_argument(
6163
"--resampling_period_s",
@@ -97,8 +99,8 @@ async def run(
9799
microgrid_id: int,
98100
component_id: int,
99101
metric_names: list[str],
100-
start_dt: datetime,
101-
end_dt: datetime,
102+
start_dt: datetime | None,
103+
end_dt: datetime | None,
102104
resampling_period_s: int | None,
103105
states: bool,
104106
bounds: bool,
@@ -112,8 +114,8 @@ async def run(
112114
microgrid_id: microgrid ID
113115
component_id: component ID
114116
metric_names: list of metric names
115-
start_dt: start datetime
116-
end_dt: end datetime
117+
start_dt: start datetime, if None, the earliest available data will be used
118+
end_dt: end datetime, if None starts streaming indefinitely from start_dt
117119
resampling_period_s: The period for resampling the data.
118120
states: include states in the output
119121
bounds: include bounds in the output

src/frequenz/client/reporting/_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ async def list_single_component_data(
170170
microgrid_id: int,
171171
component_id: int,
172172
metrics: Metric | list[Metric],
173-
start_dt: datetime,
174-
end_dt: datetime,
173+
start_dt: datetime | None,
174+
end_dt: datetime | None,
175175
resampling_period: timedelta | None,
176176
include_states: bool = False,
177177
include_bounds: bool = False,
@@ -182,8 +182,8 @@ async def list_single_component_data(
182182
microgrid_id: The microgrid ID.
183183
component_id: The component ID.
184184
metrics: The metric name or list of metric names.
185-
start_dt: The start date and time.
186-
end_dt: The end date and time.
185+
start_dt: start datetime, if None, the earliest available data will be used
186+
end_dt: end datetime, if None starts streaming indefinitely from start_dt
187187
resampling_period: The period for resampling the data.
188188
include_states: Whether to include the state data.
189189
include_bounds: Whether to include the bound data.
@@ -211,8 +211,8 @@ async def list_microgrid_components_data(
211211
*,
212212
microgrid_components: list[tuple[int, list[int]]],
213213
metrics: Metric | list[Metric],
214-
start_dt: datetime,
215-
end_dt: datetime,
214+
start_dt: datetime | None,
215+
end_dt: datetime | None,
216216
resampling_period: timedelta | None,
217217
include_states: bool = False,
218218
include_bounds: bool = False,
@@ -223,8 +223,8 @@ async def list_microgrid_components_data(
223223
microgrid_components: List of tuples where each tuple contains
224224
microgrid ID and corresponding component IDs.
225225
metrics: The metric name or list of metric names.
226-
start_dt: The start date and time.
227-
end_dt: The end date and time.
226+
start_dt: start datetime, if None, the earliest available data will be used
227+
end_dt: end datetime, if None starts streaming indefinitely from start_dt
228228
resampling_period: The period for resampling the data.
229229
include_states: Whether to include the state data.
230230
include_bounds: Whether to include the bound data.
@@ -256,8 +256,8 @@ async def _list_microgrid_components_data_batch(
256256
*,
257257
microgrid_components: list[tuple[int, list[int]]],
258258
metrics: list[Metric],
259-
start_dt: datetime,
260-
end_dt: datetime,
259+
start_dt: datetime | None,
260+
end_dt: datetime | None,
261261
resampling_period: timedelta | None,
262262
include_states: bool = False,
263263
include_bounds: bool = False,
@@ -270,8 +270,8 @@ async def _list_microgrid_components_data_batch(
270270
Args:
271271
microgrid_components: A list of tuples of microgrid IDs and component IDs.
272272
metrics: A list of metrics.
273-
start_dt: The start date and time.
274-
end_dt: The end date and time.
273+
start_dt: start datetime, if None, the earliest available data will be used
274+
end_dt: end datetime, if None starts streaming indefinitely from start_dt
275275
resampling_period: The period for resampling the data.
276276
include_states: Whether to include the state data.
277277
include_bounds: Whether to include the bound data.
@@ -290,8 +290,8 @@ def dt2ts(dt: datetime) -> PBTimestamp:
290290
return ts
291291

292292
time_filter = PBTimeFilter(
293-
start=dt2ts(start_dt),
294-
end=dt2ts(end_dt),
293+
start=dt2ts(start_dt) if start_dt else None,
294+
end=dt2ts(end_dt) if end_dt else None,
295295
)
296296

297297
incl_states = (

0 commit comments

Comments
 (0)