Skip to content
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 RecordingSessions table to SessionsDock #1654

Conversation

vaibhavtrip29
Copy link
Contributor

@vaibhavtrip29 vaibhavtrip29 commented Jan 10, 2024

Description

The overall goal here is to add a new table to the SessionsDock that displays all RecordingSessions in the SessionsDock.main_window.label.sessions: List[RecordingSession] list. The widget should be a table that displays the RecordingSessions hash (eventually name), number of RecordingSession.cameras: List[Camcorder], and number of RecordingSession.videos: List[Video] (see Figure 1). This SessionsTable will be used to dynamically populate our CamerasTable later on.

  • Subclass GenericTableModel to create a new model called SessionsTableModel with the class attribute properties = ("id", "videos", "cameras") (similar to VideosTableModel)
  • Implement the method SessionsTableModel.item_to_data(self, obj: List[RecordingSession], item: RecordingSession) which returns the following dictionary: {id: item.__hash__(), videos: len(item.videos), cameras: len(item.cameras)} (similar to VideosTableModel.item_to_data)
  • Add a sessions_model_type = SessionsTableModel attribute to SessionsDock (similar to SkeletonDock.nodes_model_type) and pass into the model_type list for super().__init__
  • Add a SessionsDock.create_models method (or append to it if it already exists) that sets a SessionsDock.sessions_model = SessionsDock.sessions_model_type(items=main_window.state["labels"].sessions, context=main_window.commands) and returns a list of all models created (see SkeletonDock.create_models)
  • Add a SessionsDock.create_tables method (or append to it if it already exists) that sets a SessionsDock.sessions_table = GenericTableView(state=..., row_name="session", ...) and returns a list of all tables created (see SkeletonDock.create_tables)
  • Add button to "Add Session" and link it to CommandContext.add_session(self)
  • Create a command class called RemoveSession (similar to AddSession with only a do_action method) that uses Labels.remove_recording_session(session: RecordingSession) (does not exist yet, but it will be named this) to remove the RecordingSession from the labels
  • Add a method to the command context CommandContext.remove_session(self, session: RecordingSession) which takes in a RecordingSession to remove and CommandContext.executes the RemoveSession class (similar to CommandContext.add_session but with an additional argument)

Note: CommandContext.execute(command: AppCommand, **kwargs) passes all keyword arguments into the command: AppCommand class as key-value pairs in the params: dict

sleap/sleap/gui/commands.py

Lines 242 to 244 in 7f74a8b

def execute(self, command: Type[AppCommand], **kwargs):
"""Execute command in this context, passing named arguments."""
command().execute(context=self, params=kwargs)

  • Add button to "Remove Session" and link it to CommandContext.remove_session (similar to you add sessions button).
  • Disable "Remove Session" button when no selected RecordingSession (see comment on CamerasTable PR)
  • In the SessionsDock.lay_everything_out method, add the SessionsDock.sessions_table to the SessionsDock.wgt_layout: QVBoxLayout (see the InstancesDock.lay_everything_out).
  • Add a sessions option to UpdateTopic: Enum
  • In MainWindow.on_data_update add (or append to) the if _has_topic(UpdateTopic.sessions) that updates the items to display in the SessionsTable (see video_dock.table update)

Test the SessionsTable

Tests for the SessionsTable will be added to tests/gui/test_dataviews.py.

  • Test that the expected RecordingSession is returned when we select a specific row of the table (see existing test for inspiration)
  • Test that when we update a RecordingSession in labels.sessions, the RecordingSession in the table is updated as well

Test the SessionsTable as part of the SessionsDock

Tests for the SessionsDock will be added to tests/gui/widgets/test_docks.py.

Figure 1: Depiction of SessionsTable layout.

Types of changes

  • Bugfix
  • New feature
  • Refactor / Code style update (no logical changes)
  • Build / CI changes
  • Documentation Update
  • Other (explain)

Does this address any currently open issues?

[list open issues here]

Outside contributors checklist

  • Review the guidelines for contributing to this repository
  • Read and sign the CLA and add yourself to the authors list
  • Make sure you are making a pull request against the develop branch (not main). Also you should start your branch off develop
  • Add tests that prove your fix is effective or that your feature works
  • Add necessary documentation (if appropriate)

Thank you for contributing to SLEAP!

❤️

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added a check for the presence of a selected session in the GUI state.
    • Enabled a button based on the presence of a selected session.
    • Introduced a new UpdateTopic enum value for sessions.
    • Added a removeSelectedSession method to AppCommand for session removal.
    • Updated the AddSession class to handle adding sessions and resetting the selected session state.
    • Updated the SessionsTableModel class with properties for id, videos, and cameras.
    • Added functionality to SessionsDock class for creating models and tables.
  • Bug Fixes
    • Updated logic in the find_path_using_paths function for improved file existence checks.
  • Tests
    • Added tests for session-related functionality within GUI widgets.

Copy link

coderabbitai bot commented Jan 10, 2024

Walkthrough

The recent code changes focused on enhancing the GUI functionality and data handling in the Sleap application. These updates include improvements such as session management, data presentation refinements, and adjustments to the camera handling logic, all aimed at enhancing the user experience and overall system robustness.

Changes

File Summary
sleap/gui/app.py, sleap/gui/commands.py Added session management features like session selection check, removal methods, and enum value updates.
sleap/gui/dataviews.py Introduced SessionsTableModel class for data representation and formatting changes in SuggestionsTableModel.
sleap/gui/widgets/docks.py Enhanced SessionsDock functionality with model and table creation methods.
sleap/io/cameras.py Updated camera handling logic for add_video method and added new methods.
sleap/io/dataset.py Added session removal method and updated logic for path searching.
tests/gui/test_dataviews.py, tests/gui/widgets/test_docks.py Tests and enhancements related to GUI functionality testing.

Poem

🐇
Code changes dance like leaves in spring,
GUI enhancements make the heart sing.
Cameras iterate, datasets refine,
Testing the limits, line by line.
🌿

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link

@coderabbitai coderabbitai bot left a 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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cc78c91 and e55d870.
Files selected for processing (1)
  • sleap/gui/dataviews.py (2 hunks)
Files skipped from review due to trivial changes (1)
  • sleap/gui/dataviews.py

@vaibhavtrip29 vaibhavtrip29 marked this pull request as draft January 10, 2024 19:58
@roomrys roomrys changed the title added todo comment Add RecordingSessions table to SessionsDock Jan 10, 2024
@roomrys roomrys added the MultiView Stack This PR is part of the MultView stacked PRs. label Jan 12, 2024
Copy link

codecov bot commented Jan 19, 2024

Codecov Report

Attention: Patch coverage is 78.57143% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 73.70%. Comparing base (cc78c91) to head (f4c68ac).

❗ Current head f4c68ac differs from pull request most recent head c9b5780. Consider uploading reports for the commit c9b5780 to get more accurate results

Files Patch % Lines
sleap/gui/dataviews.py 37.50% 5 Missing ⚠️
sleap/gui/widgets/docks.py 92.30% 2 Missing ⚠️
sleap/gui/commands.py 75.00% 1 Missing ⚠️
sleap/io/dataset.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@                           Coverage Diff                           @@
##           liezl/add-gui-elements-for-sessions    #1654      +/-   ##
=======================================================================
- Coverage                                73.70%   73.70%   -0.01%     
=======================================================================
  Files                                      135      135              
  Lines                                    24540    24578      +38     
=======================================================================
+ Hits                                     18086    18114      +28     
- Misses                                    6454     6464      +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@roomrys
Copy link
Collaborator

roomrys commented Jan 19, 2024

GUI status

image

  • Automatically Loads labels.sessions on project load
    image

  • Add Session button is working
    image

  • Remove Session button is working

@roomrys roomrys marked this pull request as ready for review March 15, 2024 23:36
@roomrys roomrys merged commit 90a2c0e into talmolab:liezl/add-gui-elements-for-sessions Mar 15, 2024
5 checks passed
Copy link

@coderabbitai coderabbitai bot left a 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: 7

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e55d870 and 9e3b977.
Files selected for processing (8)
  • sleap/gui/app.py (4 hunks)
  • sleap/gui/commands.py (5 hunks)
  • sleap/gui/dataviews.py (2 hunks)
  • sleap/gui/widgets/docks.py (5 hunks)
  • sleap/io/cameras.py (3 hunks)
  • sleap/io/dataset.py (2 hunks)
  • tests/gui/test_dataviews.py (2 hunks)
  • tests/gui/widgets/test_docks.py (2 hunks)
Additional comments: 13
tests/gui/test_dataviews.py (1)
  • 73-98: The test test_sessions_table is well-structured and covers the basic functionality of adding and removing videos from a session. However, it's important to ensure that the test also verifies the UI updates accordingly after these operations. Consider adding assertions or checks to confirm that the table view reflects the changes made to the session's videos.
tests/gui/widgets/test_docks.py (2)
  • 113-120: The test test_sessions_dock correctly initializes the SessionsDock and verifies its basic properties. This is a good practice for ensuring the dock is correctly set up. However, it would be beneficial to also test the interactions within the dock, such as button clicks and table selections, to ensure they trigger the expected actions.
  • 123-144: The test test_sessions_dock_session_table effectively checks if the sessions table loads correctly and attempts to test the removal of a session. However, since the "Remove Session" functionality is noted as not yet implemented, this test might fail or not behave as expected. It's important to either implement the removal functionality or mark this test as expected to fail or skip until the functionality is available.
sleap/gui/widgets/docks.py (3)
  • 577-579: The initialization of SessionsDock with SessionsTableModel as the model_type is correctly done. This ensures that the dock will use the appropriate model for displaying session data. Good use of inheritance to streamline the creation of specific dock types.
  • 612-622: The create_tables method properly sets up the sessions_table with the necessary state and model. This method ensures that the table is ready to display session data. It's well-implemented and follows the pattern established by other docks in the application. No changes are necessary here.
  • 637-647: The layout setup in lay_everything_out method is clear and well-organized, ensuring that the sessions table and edit buttons are added to the dock's layout. Including triangulation options is a thoughtful addition for user convenience. This method effectively organizes the dock's UI components.
sleap/io/cameras.py (2)
  • 585-587: The addition of the __bool__ method to always return True ensures that a RecordingSession instance is always considered truthy. This is a reasonable default, but ensure it aligns with the intended use cases of RecordingSession instances.
  • 587-587: Adding self.camera_cluster.add_session(self) in __attrs_post_init__ is a good practice to ensure the RecordingSession is registered with its CameraCluster upon creation. This change enhances the maintainability and consistency of session management.
sleap/gui/app.py (2)
  • 1095-1095: The implementation for checking the presence of a selected session and subsequently enabling the "remove session" button based on this condition seems logically sound. However, it's important to ensure that the self.state["selected_session"] is updated appropriately elsewhere in the code to reflect the current GUI state accurately.
  • 1180-1182: Updating the sessions_table model items directly with self.labels.sessions is a straightforward approach to reflect changes in the sessions data. However, consider emitting a signal or using a dedicated method for updating the model to encapsulate the update logic better and potentially handle additional tasks such as refreshing the view or handling data conversion if needed in the future.
sleap/gui/commands.py (3)
  • 85-85: The addition of the sessions enum value to UpdateTopic is a good practice for maintaining a clear and extendable way to signal updates related to session management in the GUI.
  • 448-450: Adding the removeSelectedSession method to CommandContext provides a clear and direct way to remove a session from the project. It's good to see encapsulation of functionality within the context.
  • 1974-1999: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1992-2010]

The updates to the AddSession class, including handling the addition of a session and resetting the selected session state, are well-implemented. It's good to see that the method properly loads the session from the provided camera calibration file and adds it to the project. The reset of the selected_session state ensures a clean state after adding a session.

Comment on lines +1717 to +1725
def remove_recording_session(self, session: RecordingSession):
"""Remove a session from self.sessions.

Args:
session: `RecordingSession` instance
"""
if session in self._sessions:
self._sessions.remove(session)

Copy link

@coderabbitai coderabbitai bot Mar 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method remove_recording_session is added to remove a session from self.sessions. This method is straightforward and correctly removes the specified session from the list of sessions. However, it's important to ensure that any references to the removed session in other parts of the Labels class or related classes are also handled appropriately to avoid dangling references.

Consider verifying if there are any additional steps needed when a session is removed, such as updating caches or handling references in other parts of the code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we need to also update the LabelsDataCache._session_by_video dictionary

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roomrys, you're absolutely right. I'll make sure to update the LabelsDataCache._session_by_video dictionary when a recording session is removed to maintain the integrity of the data structure and ensure correct behavior throughout the codebase. Thank you for pointing this out.


New Learnings Added
User: roomrys
PR: talmolab/sleap#1654
File: sleap/io/dataset.py:1717-1725
Timestamp: 2024-03-15T23:59:34.765Z
Learning: When removing a recording session using the `remove_recording_session` method in the `Labels` class, it's necessary to also update the `LabelsDataCache._session_by_video` dictionary to reflect the removal. This ensures that the mapping between videos and their corresponding recording sessions remains accurate.

Note: Learnings are effective only in the context of specific code segments. To apply general coding guidelines, please configure path-based instructions.

sleap/gui/commands.py Outdated Show resolved Hide resolved
sleap/gui/dataviews.py Outdated Show resolved Hide resolved
tests/gui/test_dataviews.py Outdated Show resolved Hide resolved
sleap/io/cameras.py Outdated Show resolved Hide resolved
sleap/gui/widgets/docks.py Outdated Show resolved Hide resolved
sleap/gui/widgets/docks.py Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a 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

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9e3b977 and c9b5780.
Files selected for processing (1)
  • sleap/io/cameras.py (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sleap/io/cameras.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MultiView Stack This PR is part of the MultView stacked PRs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants