Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/frequenz/sdk/timeseries/_moving_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ async def sink_buffer(sample: Sample[Quantity]) -> None:
asyncio.create_task(self._resampler.resample(), name="resample")
)

def gaps(self) -> list[Gap]:
"""
Return a list of gaps in the `MovingWindow`.

Returns:
A list of gaps in the `MovingWindow`.
"""
return self._buffer.gaps()

def __len__(self) -> int:
"""
Return the size of the `MovingWindow`s underlying buffer.
Expand Down
17 changes: 17 additions & 0 deletions src/frequenz/sdk/timeseries/_ringbuffer/buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def contains(self, timestamp: datetime) -> bool:

return False

def duration(self) -> timedelta:
"""Return the length of the gap.

Returns:
Length of the gap.
"""
return self.end - self.start


class OrderedRingBuffer(Generic[FloatArray]):
"""Time aware ringbuffer that keeps its entries sorted by time."""
Expand Down Expand Up @@ -108,6 +116,15 @@ def gaps(self) -> List[Gap]:
"""
return self._gaps

@property
def gaps(self) -> List[Gap]:
"""Return the list of gaps.

Returns:
The list of gaps.
"""
return self._gaps

@property
def maxlen(self) -> int:
"""Get the max length.
Expand Down