Skip to content

Commit b51373d

Browse files
committed
Rename time bound properties in ring buffer
Signed-off-by: cwasicki <[email protected]>
1 parent 8e85f63 commit b51373d

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/frequenz/sdk/timeseries/_moving_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,9 @@ def __getitem__(self, key: SupportsIndex | datetime | slice) -> float | ArrayLik
326326
key = slice(slice(key.start, key.stop).indices(self.__len__()))
327327
elif isinstance(key.start, datetime) or isinstance(key.stop, datetime):
328328
if key.start is None:
329-
key = slice(self._buffer.time_bound_oldest, key.stop)
329+
key = slice(self._buffer.oldest_timestamp, key.stop)
330330
if key.stop is None:
331-
key = slice(key.start, self._buffer.time_bound_newest)
331+
key = slice(key.start, self._buffer.newest_timestamp)
332332

333333
_logger.debug("Returning slice for [%s:%s].", key.start, key.stop)
334334

src/frequenz/sdk/timeseries/_periodic_feature_extractor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ def _timestamp_to_rel_index(self, timestamp: datetime) -> int:
173173

174174
# distance between the input ts and the ts of oldest known samples (in samples)
175175
dist_to_oldest = int(
176-
(timestamp - self._buffer.time_bound_oldest) / self._sampling_period
176+
(timestamp - self._buffer.oldest_timestamp) / self._sampling_period
177177
)
178178

179179
_logger.debug("Shifting ts: %s", timestamp)
180-
_logger.debug("Oldest timestamp in buffer: %s", self._buffer.time_bound_oldest)
180+
_logger.debug("Oldest timestamp in buffer: %s", self._buffer.oldest_timestamp)
181181
_logger.debug("Distance to the oldest sample: %i", dist_to_oldest)
182182

183183
return dist_to_oldest
@@ -275,7 +275,7 @@ def _get_relative_positions(
275275

276276
# check if the newest time bound, i.e. the sample that is currently written,
277277
# is inside the interval
278-
rb_current_position = self._buffer.time_bound_newest
278+
rb_current_position = self._buffer.newest_timestamp
279279
rel_next_position = (
280280
self._timestamp_to_rel_index(rb_current_position) + 1
281281
) % self._period
@@ -339,7 +339,7 @@ def _get_buffer_bounds(
339339

340340
# get the start and end position inside the ringbuffer
341341
end_pos = (
342-
self._timestamp_to_rel_index(self._buffer.time_bound_newest) + 1
342+
self._timestamp_to_rel_index(self._buffer.newest_timestamp) + 1
343343
) - dist_to_start
344344

345345
# Note that these check is working since we are using the positions
@@ -356,7 +356,7 @@ def _get_buffer_bounds(
356356

357357
# add the offset to the oldest sample in the ringbuffer and wrap around
358358
# to get the start and end positions in the ringbuffer
359-
rb_offset = self._buffer.datetime_to_index(self._buffer.time_bound_oldest)
359+
rb_offset = self._buffer.datetime_to_index(self._buffer.oldest_timestamp)
360360
start_pos = self._buffer.wrap(end_pos + self._period + rb_offset)
361361
end_pos = self._buffer.wrap(end_pos + rb_offset)
362362

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,19 @@ def update(self, sample: Sample[QuantityT]) -> None:
156156
self._update_gaps(timestamp, prev_newest, sample.value is None)
157157

158158
@property
159-
def time_bound_oldest(self) -> datetime:
159+
def oldest_timestamp(self) -> datetime:
160160
"""
161-
Return the time bounds of the ring buffer.
161+
The timestamp of the oldest sample of the ring buffer.
162162
163163
Returns:
164164
The timestamp of the oldest sample of the ring buffer.
165165
"""
166166
return self._datetime_oldest
167167

168168
@property
169-
def time_bound_newest(self) -> datetime:
169+
def newest_timestamp(self) -> datetime:
170170
"""
171-
Return the time bounds of the ring buffer.
171+
The timestamp of the newest sample of the ring buffer.
172172
173173
Returns:
174174
The timestamp of the newest sample of the ring buffer.

0 commit comments

Comments
 (0)