Skip to content

Commit 7eb9c12

Browse files
authored
Make the MovingWindow public and remove public mentions to the RingBuffer (#355)
The ring buffer is not part of the public interface yet, so it shouldn't be shown in the release notes of the user facing documentation. The `MovingWindow` is now exported in the `frequenz.sdk.timeseries` package. The `ResamplerConfig` class is also now made public via the same package, as it is part of the `MovingWindow`'s public interface.
2 parents 55de0b0 + d4f38c7 commit 7eb9c12

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
* The `PartialFailure.success_batteries` property was renamed to `succeeded_batteries`.
3939
* The `succeed_power` property was renamed to `succeeded_power` for both `Success` and `PartialFailure`.
4040

41-
* The serialization feature for the ringbuffer was made more flexible. The `dump` and `load` methods can now work directly with a ringbuffer instance.
42-
4341
* `MovingWindow`
4442

43+
* The class is now publicly available in the `frequenz.sdk.timeseries` package.
44+
4545
* Accept the `size` parameter as `timedelta` instead of `int` (#269).
4646

4747
This change allows users to define the time span of the moving window more intuitively, representing the duration over which samples will be stored.
@@ -56,6 +56,8 @@
5656

5757
* `Resampler`
5858

59+
* The `ResamplerConfig` class is now publicly available in the `frequenz.sdk.timeseries` package.
60+
5961
* The `ResamplerConfig` now takes the resampling period as a `timedelta`. The configuration was renamed from `resampling_period_s` to `resampling_period` accordingly.
6062

6163
* The `SourceProperties` of the resampler now uses a `timedelta` for the input sampling period. The attribute was renamed from `sampling_period_s` to `sampling_period` accordingly.
@@ -90,4 +92,4 @@
9092

9193
* Change `PowerDistributor` to use all batteries when none are working (#258)
9294

93-
* Update the ordered ring buffer to fix the `len()` function so that it returns a value equal to or greater than zero, as expected (#274)
95+
* Update the ordered ring buffer used by the `MovingWindow` to fix the `len()` function so that it returns a value equal to or greater than zero, as expected (#274)

src/frequenz/sdk/timeseries/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,13 @@
3636
"""
3737

3838
from ._base_types import UNIX_EPOCH, Sample, Sample3Phase
39-
40-
__all__ = ["Sample", "Sample3Phase", "UNIX_EPOCH"]
39+
from ._moving_window import MovingWindow
40+
from ._resampling import ResamplerConfig
41+
42+
__all__ = [
43+
"MovingWindow",
44+
"ResamplerConfig",
45+
"Sample",
46+
"Sample3Phase",
47+
"UNIX_EPOCH",
48+
]

src/frequenz/sdk/timeseries/_moving_window.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
from numpy.typing import ArrayLike
1818

1919
from .._internal.asyncio import cancel_and_await
20-
from . import Sample
21-
from ._base_types import UNIX_EPOCH
20+
from ._base_types import UNIX_EPOCH, Sample
2221
from ._resampling import Resampler, ResamplerConfig
2322
from ._ringbuffer import OrderedRingBuffer
2423

@@ -36,7 +35,7 @@ class MovingWindow:
3635
Note that a numpy ndarray is returned and thus users can use
3736
numpys operations directly on a window.
3837
39-
The window uses an ringbuffer for storage and the first element is aligned to
38+
The window uses a ring buffer for storage and the first element is aligned to
4039
a fixed defined point in time. Since the moving nature of the window, the
4140
date of the first and the last element are constantly changing and therefore
4241
the point in time that defines the alignment can be outside of the time window.
@@ -45,10 +44,7 @@ class MovingWindow:
4544
4645
If for example the `align_to` parameter is set to
4746
`datetime(1, 1, 1, tzinfo=timezone.utc)` and the window size is bigger than
48-
one day then the first element will always be aligned to the midnight.
49-
For further information see also the
50-
[`OrderedRingBuffer`][frequenz.sdk.timeseries._ringbuffer.OrderedRingBuffer]
51-
documentation.
47+
one day then the first element will always be aligned to midnight.
5248
5349
Resampling might be required to reduce the number of samples to store, and
5450
it can be set by specifying the resampler config parameter so that the user
@@ -113,8 +109,8 @@ def __init__( # pylint: disable=too-many-arguments
113109
"""
114110
Initialize the MovingWindow.
115111
116-
This method creates the underlying ringbuffer and starts a
117-
new task that updates the ringbuffer with new incoming samples.
112+
This method creates the underlying ring buffer and starts a
113+
new task that updates the ring buffer with new incoming samples.
118114
The task stops running only if the channel receiver is closed.
119115
120116
Args:
@@ -168,7 +164,7 @@ def __init__( # pylint: disable=too-many-arguments
168164
)
169165

170166
async def _run_impl(self) -> None:
171-
"""Awaits samples from the receiver and updates the underlying ringbuffer.
167+
"""Awaits samples from the receiver and updates the underlying ring buffer.
172168
173169
Raises:
174170
asyncio.CancelledError: if the MovingWindow task is cancelled.

src/frequenz/sdk/timeseries/_resampling.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
from typing import AsyncIterator, Callable, Coroutine, Optional, Sequence
1717

1818
from .._internal.asyncio import cancel_and_await
19-
from . import Sample
20-
from ._base_types import UNIX_EPOCH
19+
from ._base_types import UNIX_EPOCH, Sample
2120

2221
_logger = logging.getLogger(__name__)
2322

src/frequenz/sdk/timeseries/_ringbuffer/buffer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import numpy as np
1515
import numpy.typing as npt
1616

17-
from .. import Sample
18-
from .._base_types import UNIX_EPOCH
17+
from .._base_types import UNIX_EPOCH, Sample
1918

2019
FloatArray = TypeVar("FloatArray", List[float], npt.NDArray[np.float64])
2120

0 commit comments

Comments
 (0)