-
Notifications
You must be signed in to change notification settings - Fork 97
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
(2->1) Add method to get RecordingSession
via Video
through Labels
#1278
base: liezl/acg-add-recording-session
Are you sure you want to change the base?
(2->1) Add method to get RecordingSession
via Video
through Labels
#1278
Conversation
UpdateThe issue described below ended up being caused by a change in the data structure for There's a pretty annoying and seemingly not easy to get rid of problem with Traceback
|
Codecov Report
@@ Coverage Diff @@
## liezl/acg-add-recording-session #1278 +/- ##
===================================================================
+ Coverage 73.57% 73.60% +0.02%
===================================================================
Files 135 135
Lines 24318 24366 +48
===================================================================
+ Hits 17893 17935 +42
- Misses 6425 6431 +6
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
RecordingSession
via Video
through Labels
RecordingSession
via Video
through Labels
…talmolab/sleap into liezl/ars-add-sessions-to-cache
WalkthroughThis update enhances the Changes
TipsChat with CodeRabbit Bot (
|
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.
Review Status
Actionable comments generated: 3
Files selected for processing (3)
- sleap/io/cameras.py (4 hunks)
- sleap/io/dataset.py (8 hunks)
- tests/io/test_dataset.py (2 hunks)
Additional comments (Suppressed): 13
sleap/io/cameras.py (4)
17-18: The commented import statement indicates a circular import issue. This can lead to problems in the code execution and is generally considered a bad practice. It's mentioned that an Observer pattern might be implemented to resolve this, which could be a good solution as it would allow
Labels
to be notified of changes without directly importing it. Please ensure this is addressed before merging.403-407: A new attribute
labels
has been added to theRecordingSession
class. This attribute is optional and can hold an instance of theLabels
class. Ensure that all instances whereRecordingSession
is instantiated are updated to include this new attribute if necessary.513-515: The labels cache is being updated when a video is added to the
RecordingSession
. This is a good practice as it ensures that the cache is always up-to-date with the latest state of theRecordingSession
.537-539: Similar to the addition of a video, the labels cache is also updated when a video is removed from the
RecordingSession
. This maintains the consistency of the cache with the current state of theRecordingSession
.tests/io/test_dataset.py (2)
1-21: No significant changes in the import statements. The import statement for
load_labels_json_old
fromsleap.io.legacy
has been removed, which is not used in the new hunks.999-1004: The test case checks if the loaded session's labels match the loaded labels. This is a good practice to ensure data consistency after loading.
sleap/io/dataset.py (7)
106-111: The function signature of
update
has been changed to accept a new parameternew_item
which can be of typeLabeledFrame
,RecordingSession
, or a tuple ofRecordingSession
andVideo
. Ensure that all calls to this function throughout the codebase have been updated to match the new signature.128-141: > Note: This review was outside of the patch, so it was mapped to the patch with the greatest overlap. Original lines [119-135]
A new dictionary
_session_by_video
is introduced to map videos to their respective sessions. This is a good approach for quick lookups, but it's important to ensure that this dictionary is always kept in sync with the actual data. The code seems to handle this well by updating the dictionary in theupdate
method whenever a new item is added.
248-249: Good job on ensuring that when a video is removed, it is also removed from the
_session_by_video
dictionary. This helps keep the data consistent.448-451: The attribute
sessions
has been made private (_sessions
) and a property getter and setter have been added for it. This is a good practice as it allows for better control over how this attribute is accessed and modified.1637-1642: The
add_session
method has been updated to also update the cache when a new session is added. This is a good practice as it ensures that the cache is always up-to-date with the actual data.1659-1668: The
get_session
method uses the_session_by_video
dictionary in the cache to quickly get the session associated with a video. This is an efficient way to retrieve this information.1670-1680: The
remove_session_video
method removes a video from a session and also updates the cache accordingly. This is a good practice as it ensures that the cache is always in sync with the actual data.
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.
Review Status
Actionable comments generated: 0
Files selected for processing (2)
- sleap/io/cameras.py (4 hunks)
- sleap/io/dataset.py (6 hunks)
Additional comments (Suppressed): 12
sleap/io/cameras.py (3)
414-418: The addition of the
labels
attribute to theRecordingSession
class is a significant change. This attribute links aRecordingSession
to aLabels
object, which represents a set of labels for a video dataset. The comment on line 414 suggests that an Observer pattern might be implemented in the future forcamera_cluster
andlabels
. This would allow changes in these objects to automatically update related objects, improving code maintainability and reducing potential errors.521-527: The
add_video
method now updates thelabels
cache when a video is added to theRecordingSession
. This ensures that thelabels
object is kept up-to-date with the current state of theRecordingSession
, improving data consistency. However, it's important to ensure that theupdate_session
method in theLabels
class correctly handles this update.if self.labels is not None: self.labels.update_session(self, video)
- 545-550: Similarly, the
remove_video
method now updates thelabels
cache when a video is removed from theRecordingSession
. This also helps maintain data consistency. Again, it's crucial to verify that theremove_session_video
method in theLabels
class correctly handles this update.if self.labels is not None and self.labels.get_session(video) is not None: self.labels.remove_session_video(self, video)sleap/io/dataset.py (9)
103-131: The
rebuild_cache
method has been updated to include a new dictionary_session_by_video
. This dictionary maps each video to its corresponding recording session. The logic seems correct and efficient as it loops through all sessions and videos only once. However, please ensure that thelabels.sessions
attribute is correctly populated before this method is called.146-155: The
add_recording_session
method has been added to update the_session_by_video
cache when a new recording session is added. It correctly updates the cache for each video in the new session.156-165: The
add_video_to_session
method has been added to update the_session_by_video
cache when a new video is added to a session. It correctly updates the cache with the new video-session pair.166-185: The
update
method has been refactored to handle different types of input and call the appropriate methods to update the cache. It correctly identifies the type of the new item and calls the corresponding method. However, it might be more maintainable to split this into separate methods for each type of input instead of usingisinstance
checks.def update_labeled_frame(self, new_frame: LabeledFrame): self.add_labeled_frame(new_frame) def update_recording_session(self, new_session: RecordingSession): self.add_recording_session(new_session) def update_video_to_session(self, session_video_pair: Tuple[RecordingSession, Video]): self.add_video_to_session(*session_video_pair)
270-279: The
remove_video
method has been updated to remove a video from the_session_by_video
cache if it exists. This is a necessary step to keep the cache consistent.477-480: The
_sessions
attribute has been renamed tosessions
and a new setter method has been added. This change makes the attribute private and prevents direct assignment, which is good for encapsulation.492-506: The
__attrs_post_init__
method has been updated to set thelabels
property of each session toself
. This is necessary to keep the back-reference from each session to its labels object up-to-date.652-658: A setter method has been added for the
sessions
attribute that raises aValueError
when an attempt is made to directly assign to it. This enforces the use of theadd_session
method to add sessions, which is good for maintaining consistency in the cache.1669-1715: New methods
update_session
,get_session
, andremove_session_video
have been added to update the session-video map in the cache, retrieve the associated session of a video, and remove a video from a session respectively. These methods correctly interact with the cache and the session objects.
…talmolab/sleap into liezl/ars-add-sessions-to-cache
CodeRabbit review skipped By default, CodeRabbit only reviews PRs on the default branch. If you wish to have PRs reviewed on additional branches, you can configure that under the repository settings in the UI. |
Description
Add a
Labels.get_session
method that uses theLabelsDataCache._session_by_video
dictionary to look-up aRecordingSession
using aVideo
.Types of changes
Does this address any currently open issues?
[list open issues here]
Outside contributors checklist
Thank you for contributing to SLEAP!
❤️
Summary by CodeRabbit
RecordingSession
objects in theLabels
class, including adding and removing sessions and videos.LabelsDataCache
class to improve data retrieval efficiency.update
method inLabelsDataCache
to handle different types of input and rebuild the cache accordingly.Labels
class.