-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add capacity, oldest and newest timestamp to moving window #598
Add capacity, oldest and newest timestamp to moving window #598
Conversation
7e367e2
to
8103652
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I suggest to rename the newest and oldest timestamp functions in the ringbuffer too. Furthermore can you also please update the code in the MovingWindow
that uses this functions to use the new ones?
39bfa84
to
92b8f20
Compare
@matthias-wende-frequenz Updated. |
Removing myself as a reviewer, as @matthias-wende-frequenz already picked up on it. |
@@ -313,9 +352,9 @@ def __getitem__(self, key: SupportsIndex | datetime | slice) -> float | ArrayLik | |||
key = slice(slice(key.start, key.stop).indices(self.__len__())) | |||
elif isinstance(key.start, datetime) or isinstance(key.stop, datetime): | |||
if key.start is None: | |||
key = slice(self._buffer.time_bound_oldest, key.stop) | |||
key = slice(self._buffer.oldest_timestamp, key.stop) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can remove the ._buffer
now ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't want to touch it since I am reworking this functionality at the moment for #214 where I remove this part. Also they are not exactly the same as they differ for empty arrays (which is not a concern here due to the check couple of lines above).
@@ -173,11 +173,11 @@ def _timestamp_to_rel_index(self, timestamp: datetime) -> int: | |||
|
|||
# distance between the input ts and the ts of oldest known samples (in samples) | |||
dist_to_oldest = int( | |||
(timestamp - self._buffer.time_bound_oldest) / self._sampling_period | |||
(timestamp - self._buffer.oldest_timestamp) / self._sampling_period |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here. no need to access the property through the _buffer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two more small comments. Otherwise it's good to go!
@matthias-wende-frequenz Removed the oldest timestamp method. |
Reworked based on #641. Blocking until the above is merged. |
The capacity is the maximum number of values that the moving window can hold. Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Signed-off-by: cwasicki <126617870+cwasicki@users.noreply.github.com>
Rebased |
The capacity of the moving window is exposed, which is the maximum number of values that the moving window can hold.
Also the oldest and newest timestamps are exposed by the moving window.