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 option to group cameras from sessions #2125

Draft
wants to merge 31 commits into
base: liezl/add-gui-elements-for-sessions
Choose a base branch
from

Conversation

justinvshen
Copy link
Collaborator

Description

This new feature allows users to group different camera angles into distinct groups, where upon exporting a training set, the user cab export all frames from a specific group.

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!

❤️

Copy link

coderabbitai bot commented Feb 27, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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>, please review it.
    • Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Feb 27, 2025

Codecov Report

Attention: Patch coverage is 36.55462% with 151 lines in your changes missing coverage. Please review.

Project coverage is 73.84%. Comparing base (d898a84) to head (9e6a698).

Files with missing lines Patch % Lines
sleap/gui/commands.py 31.49% 87 Missing ⚠️
sleap/gui/widgets/docks.py 34.66% 49 Missing ⚠️
sleap/gui/dataviews.py 57.89% 8 Missing ⚠️
sleap/io/cameras.py 41.66% 7 Missing ⚠️

❌ Your patch check has failed because the patch coverage (50.00%) is below the target coverage (100.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@                           Coverage Diff                           @@
##           liezl/add-gui-elements-for-sessions    #2125      +/-   ##
=======================================================================
- Coverage                                74.18%   73.84%   -0.35%     
=======================================================================
  Files                                      135      135              
  Lines                                    25450    25688     +238     
=======================================================================
+ Hits                                     18881    18969      +88     
- Misses                                    6569     6719     +150     

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

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@roomrys roomrys added the MultiView Stack This PR is part of the MultView stacked PRs. label Feb 28, 2025
Copy link
Collaborator

@roomrys roomrys left a comment

Choose a reason for hiding this comment

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

A few things:

  1. If a method does not exist, instead of calling the method that doesn't exist, raise a NotImplementedError and add a TODO(JS).
  2. Also, can we see some screenshots of the GUI elements in the PR.
  3. I would also like to see tests that hits each one of the methods you've created.

Comment on lines 718 to 719
# Mark project as changed
self.context.changestack_push("rename camera group")
Copy link
Collaborator

Choose a reason for hiding this comment

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

While we want to call a self.context method here, this is not the one (we haven't created the method we want to call yet).

Suggested change
# Mark project as changed
self.context.changestack_push("rename camera group")
# TODO(JS): Add `CommandContext` method that updates the camera group name
raise NotImplementedError

Comment on lines 693 to 701
# Register for updates
if context and hasattr(context, 'state'):
context.state.connect("camera_groups", self.update_items)

def update_items(self, camera_groups):
"""Update the model when camera groups change."""
self.items = camera_groups
self.beginResetModel()
self.endResetModel()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh man, yeah I do kinda like this better than what we currently do:

sleap/sleap/gui/app.py

Lines 1216 to 1220 in 6531447

if _has_topic([UpdateTopic.project, UpdateTopic.on_frame]):
self.instances_dock.table.model().items = self.state["labeled_frame"]
if _has_topic([UpdateTopic.suggestions]):
self.suggestions_dock.table.model().items = self.labels.suggestions

. Let's leave it for now (and possibly open a new PR to refactor all the other table updates).

Comment on lines 642 to 648
if not camera:
QMessageBox.information(
self.main_window,
"No Camera Selected",
"Please select a camera to add to a group."
)
return
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of raising an error message, maybe we can just disable the button so no one can click on it if there is no camera selected. See this example for the "Link Video" button:

sleap/sleap/gui/app.py

Lines 1191 to 1195 in d898a84

self._buttons["link video"].setEnabled(
has_selected_unlinked_video
and has_selected_camcorder
and has_selected_session
)

.

Suggested change
if not camera:
QMessageBox.information(
self.main_window,
"No Camera Selected",
"Please select a camera to add to a group."
)
return

Comment on lines 691 to 692
def __init__(self, items=None, context=None):
super().__init__(items=items, context=context)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Expose the property kwarg:

Suggested change
def __init__(self, items=None, context=None):
super().__init__(items=items, context=context)
def __init__(self, items=None, properties=None, context=None):
super().__init__(items=items, properties=properties, context=context)

self.main_window, "New Camera Group", "Enter name for camera group:"
)
if ok and name:
self.main_window.commands.addCameraGroup(name)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
self.main_window.commands.addCameraGroup(name)
# TODO(JS): self.main_window.commands.addCameraGroup(name)
raise NotImplementedError

return

# Get available groups
if not self.main_window.state.get("camera_groups") or len(self.main_window.state["camera_groups"]) == 0:
Copy link
Collaborator

Choose a reason for hiding this comment

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

GuiState has a __getitem__ method, so we at least won't run into an error if the key doesn't exist.

sleap/sleap/gui/state.py

Lines 52 to 54 in 6531447

def __getitem__(self, key: GSVarType) -> Any:
"""Gets value for key, or None if no value."""
return self.get(key, default=None)

How about we use get, but with a default of an empty list:

Suggested change
if not self.main_window.state.get("camera_groups") or len(self.main_window.state["camera_groups"]) == 0:
if len(self.main_window.state.get("camera_groups", []) == 0:

Copy link
Collaborator

Choose a reason for hiding this comment

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

ex:

In [20]: from sleap.gui.state import GuiState

In [21]: state = GuiState()

In [22]: state[3]

In [23]: state.get(3, [])
Out[23]: []

Comment on lines 881 to 919
def _add_camera_to_group(self):
"""Add the selected camera to a group."""
camera = self.main_window.state.get("camera")
if not camera:
QMessageBox.information(
self.main_window,
"No Camera Selected",
"Please select a camera to add to a group."
)
return

# Get available groups
if not self.main_window.state.get("camera_groups") or len(self.main_window.state["camera_groups"]) == 0:
reply = QMessageBox.question(
self.main_window,
"No Groups",
"No camera groups exist. Would you like to create one?",
QMessageBox.Yes | QMessageBox.No,
QMessageBox.Yes
)
if reply == QMessageBox.Yes:
self._create_camera_group()
return

# Show group selection dialog
group_names = [group.name for group in self.main_window.state["camera_groups"]]
selected_name, ok = QInputDialog.getItem(
self.main_window,
"Select Group",
"Choose a group to add the camera to:",
group_names,
0,
False
)

if ok and selected_name:
selected_idx = group_names.index(selected_name)
selected_group = self.main_window.state["camera_groups"][selected_idx]
self.main_window.commands.addCameraToGroup(camera, selected_group)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This entire method is a duplicate

Suggested change
def _add_camera_to_group(self):
"""Add the selected camera to a group."""
camera = self.main_window.state.get("camera")
if not camera:
QMessageBox.information(
self.main_window,
"No Camera Selected",
"Please select a camera to add to a group."
)
return
# Get available groups
if not self.main_window.state.get("camera_groups") or len(self.main_window.state["camera_groups"]) == 0:
reply = QMessageBox.question(
self.main_window,
"No Groups",
"No camera groups exist. Would you like to create one?",
QMessageBox.Yes | QMessageBox.No,
QMessageBox.Yes
)
if reply == QMessageBox.Yes:
self._create_camera_group()
return
# Show group selection dialog
group_names = [group.name for group in self.main_window.state["camera_groups"]]
selected_name, ok = QInputDialog.getItem(
self.main_window,
"Select Group",
"Choose a group to add the camera to:",
group_names,
0,
False
)
if ok and selected_name:
selected_idx = group_names.index(selected_name)
selected_group = self.main_window.state["camera_groups"][selected_idx]
self.main_window.commands.addCameraToGroup(camera, selected_group)

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.

3 participants