Skip to content

Commit

Permalink
Allow omitting start or end datetime in requests
Browse files Browse the repository at this point in the history
Omitting the end date retrieves all historical data until now and
then keep streaming any new data that arrives.

Omitting the start date sets the start date to the earliest time stamp
for which data for the request is available.

Signed-off-by: cwasicki <[email protected]>
  • Loading branch information
cwasicki committed Nov 27, 2024
1 parent b82eef2 commit d6bcd69
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
6 changes: 5 additions & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

## New Features

<!-- Here goes the main new features and examples or instructions on how to use them -->
* 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.

## Bug Fixes

Expand Down
14 changes: 8 additions & 6 deletions src/frequenz/client/reporting/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@ def main() -> None:
"--start",
type=datetime.fromisoformat,
help="Start datetime in YYYY-MM-DDTHH:MM:SS format",
required=True,
required=False,
default=None,
)
parser.add_argument(
"--end",
type=datetime.fromisoformat,
help="End datetime in YYYY-MM-DDTHH:MM:SS format",
required=True,
required=False,
default=None,
)
parser.add_argument(
"--resampling_period_s",
Expand Down Expand Up @@ -97,8 +99,8 @@ async def run(
microgrid_id: int,
component_id: int,
metric_names: list[str],
start_dt: datetime,
end_dt: datetime,
start_dt: datetime | None,
end_dt: datetime | None,
resampling_period_s: int | None,
states: bool,
bounds: bool,
Expand All @@ -112,8 +114,8 @@ async def run(
microgrid_id: microgrid ID
component_id: component ID
metric_names: list of metric names
start_dt: start datetime
end_dt: end datetime
start_dt: start datetime, if None, the earliest available data will be used
end_dt: end datetime, if None starts streaming indefinitely from start_dt
resampling_period_s: The period for resampling the data.
states: include states in the output
bounds: include bounds in the output
Expand Down
28 changes: 14 additions & 14 deletions src/frequenz/client/reporting/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ async def list_single_component_data(
microgrid_id: int,
component_id: int,
metrics: Metric | list[Metric],
start_dt: datetime,
end_dt: datetime,
start_dt: datetime | None,
end_dt: datetime | None,
resampling_period: timedelta | None,
include_states: bool = False,
include_bounds: bool = False,
Expand All @@ -182,8 +182,8 @@ async def list_single_component_data(
microgrid_id: The microgrid ID.
component_id: The component ID.
metrics: The metric name or list of metric names.
start_dt: The start date and time.
end_dt: The end date and time.
start_dt: start datetime, if None, the earliest available data will be used
end_dt: end datetime, if None starts streaming indefinitely from start_dt
resampling_period: The period for resampling the data.
include_states: Whether to include the state data.
include_bounds: Whether to include the bound data.
Expand Down Expand Up @@ -211,8 +211,8 @@ async def list_microgrid_components_data(
*,
microgrid_components: list[tuple[int, list[int]]],
metrics: Metric | list[Metric],
start_dt: datetime,
end_dt: datetime,
start_dt: datetime | None,
end_dt: datetime | None,
resampling_period: timedelta | None,
include_states: bool = False,
include_bounds: bool = False,
Expand All @@ -223,8 +223,8 @@ async def list_microgrid_components_data(
microgrid_components: List of tuples where each tuple contains
microgrid ID and corresponding component IDs.
metrics: The metric name or list of metric names.
start_dt: The start date and time.
end_dt: The end date and time.
start_dt: start datetime, if None, the earliest available data will be used
end_dt: end datetime, if None starts streaming indefinitely from start_dt
resampling_period: The period for resampling the data.
include_states: Whether to include the state data.
include_bounds: Whether to include the bound data.
Expand Down Expand Up @@ -256,8 +256,8 @@ async def _list_microgrid_components_data_batch(
*,
microgrid_components: list[tuple[int, list[int]]],
metrics: list[Metric],
start_dt: datetime,
end_dt: datetime,
start_dt: datetime | None,
end_dt: datetime | None,
resampling_period: timedelta | None,
include_states: bool = False,
include_bounds: bool = False,
Expand All @@ -270,8 +270,8 @@ async def _list_microgrid_components_data_batch(
Args:
microgrid_components: A list of tuples of microgrid IDs and component IDs.
metrics: A list of metrics.
start_dt: The start date and time.
end_dt: The end date and time.
start_dt: start datetime, if None, the earliest available data will be used
end_dt: end datetime, if None starts streaming indefinitely from start_dt
resampling_period: The period for resampling the data.
include_states: Whether to include the state data.
include_bounds: Whether to include the bound data.
Expand All @@ -290,8 +290,8 @@ def dt2ts(dt: datetime) -> PBTimestamp:
return ts

time_filter = PBTimeFilter(
start=dt2ts(start_dt),
end=dt2ts(end_dt),
start=dt2ts(start_dt) if start_dt else None,
end=dt2ts(end_dt) if end_dt else None,
)

incl_states = (
Expand Down

0 comments on commit d6bcd69

Please sign in to comment.