From 43e3e627bdda6a6928ac0d2101501f0b50970cba Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 28 Apr 2023 10:16:06 +0200 Subject: [PATCH 1/3] Fix example formatting The code block wasn't properly terminated, causing the generated documentation to be completely wrong, interpreting part of the documentation as code. Signed-off-by: Leandro Lucarella --- src/frequenz/sdk/timeseries/_moving_window.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frequenz/sdk/timeseries/_moving_window.py b/src/frequenz/sdk/timeseries/_moving_window.py index c2a8fec8f..7572c3c38 100644 --- a/src/frequenz/sdk/timeseries/_moving_window.py +++ b/src/frequenz/sdk/timeseries/_moving_window.py @@ -73,7 +73,7 @@ class MovingWindow: a = window[time_start:time_end] # and use it to for example calculate the mean mean = a.mean() - ''' + ``` **Example2** (create a polars data frame from a `MovingWindow`): From 074fc3c3e190154cc2305151f8ac99962660f8cb Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 28 Apr 2023 10:16:51 +0200 Subject: [PATCH 2/3] Add proper python markers to examples This makes the examples be properly syntax highlighted when rendered. Signed-off-by: Leandro Lucarella --- src/frequenz/sdk/timeseries/_moving_window.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/frequenz/sdk/timeseries/_moving_window.py b/src/frequenz/sdk/timeseries/_moving_window.py index 7572c3c38..f0d83c264 100644 --- a/src/frequenz/sdk/timeseries/_moving_window.py +++ b/src/frequenz/sdk/timeseries/_moving_window.py @@ -56,7 +56,7 @@ class MovingWindow: **Example1** (calculating the mean of a time interval): - ``` + ```python window = MovingWindow( size=timedelta(minutes=5), resampled_data_recv=resampled_data_recv, @@ -77,7 +77,7 @@ class MovingWindow: **Example2** (create a polars data frame from a `MovingWindow`): - ``` + ```python import polars as pl # create a window that stores two days of data From 5b7deb965e9847519083c8e6ec5bc9cfe549d0df Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 28 Apr 2023 10:21:45 +0200 Subject: [PATCH 3/3] Improve examples formatting When each example is in its own `Example:` block with a proper title, they are also rendered in their own block with a nice title, which makes it much easier to read. Signed-off-by: Leandro Lucarella --- src/frequenz/sdk/timeseries/_moving_window.py | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/frequenz/sdk/timeseries/_moving_window.py b/src/frequenz/sdk/timeseries/_moving_window.py index f0d83c264..0c8c8bae3 100644 --- a/src/frequenz/sdk/timeseries/_moving_window.py +++ b/src/frequenz/sdk/timeseries/_moving_window.py @@ -54,48 +54,48 @@ class MovingWindow: If resampling is not required, the resampler config parameter can be set to None in which case the MovingWindow will not perform any resampling. - **Example1** (calculating the mean of a time interval): - - ```python - window = MovingWindow( - size=timedelta(minutes=5), - resampled_data_recv=resampled_data_recv, - input_sampling_period=timedelta(seconds=1), - ) - - time_start = datetime.now(tz=timezone.utc) - time_end = time_start + timedelta(minutes=5) - - # ... wait for 5 minutes until the buffer is filled - await asyncio.sleep(5) - - # return an numpy array from the window - a = window[time_start:time_end] - # and use it to for example calculate the mean - mean = a.mean() - ``` - - **Example2** (create a polars data frame from a `MovingWindow`): - - ```python - import polars as pl - - # create a window that stores two days of data - # starting at 1.1.23 with samplerate=1 - window = MovingWindow( - size=timedelta(days=2), - resampled_data_recv=sample_receiver, - input_sampling_period=timedelta(seconds=1), - ) - - # wait for one full day until the buffer is filled - asyncio.sleep(60*60*24) - - # create a polars series with one full day of data - time_start = datetime(2023, 1, 1, tzinfo=timezone.utc) - time_end = datetime(2023, 1, 2, tzinfo=timezone.utc) - s = pl.Series("Jan_1", mv[time_start:time_end]) - ``` + Example: Calculate the mean of a time interval + + ```python + window = MovingWindow( + size=timedelta(minutes=5), + resampled_data_recv=resampled_data_recv, + input_sampling_period=timedelta(seconds=1), + ) + + time_start = datetime.now(tz=timezone.utc) + time_end = time_start + timedelta(minutes=5) + + # ... wait for 5 minutes until the buffer is filled + await asyncio.sleep(5) + + # return an numpy array from the window + a = window[time_start:time_end] + # and use it to for example calculate the mean + mean = a.mean() + ``` + + Example: Create a polars data frame from a `MovingWindow` + + ```python + import polars as pl + + # create a window that stores two days of data + # starting at 1.1.23 with samplerate=1 + window = MovingWindow( + size=timedelta(days=2), + resampled_data_recv=sample_receiver, + input_sampling_period=timedelta(seconds=1), + ) + + # wait for one full day until the buffer is filled + asyncio.sleep(60*60*24) + + # create a polars series with one full day of data + time_start = datetime(2023, 1, 1, tzinfo=timezone.utc) + time_end = datetime(2023, 1, 2, tzinfo=timezone.utc) + s = pl.Series("Jan_1", mv[time_start:time_end]) + ``` """ def __init__( # pylint: disable=too-many-arguments