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

Load default view #115

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Load default view #115

wants to merge 4 commits into from

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Feb 19, 2024

Adds a @voxel51/utils/load_default_view operator that will load a default saved view, if one is registered, whenever datasets are opened in the App.

TODO BEFORE MERGING

  • not sure we actually want this operator in @voxel51/utils as we should be sensitive to avoid too many things happening on_dataset_open in core plugins...

Example usage

from datetime import datetime, timedelta
from random import random

import fiftyone as fo
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset("quickstart")

# Add some dates
now = datetime.now()
collected_on = [now - timedelta(days=365 * random()) for _ in range(len(dataset))]
dataset.set_values("collected_on", collected_on)
dataset.create_index("collected_on")

# Configure a default view
view = dataset.sort_by("collected_on", reverse=True)
dataset.save_view("collected_on", view)
dataset.info["default_view"] = "collected_on"
dataset.save()

# Should automatically load `collected_on` view
session = fo.launch_app(dataset)

session.dataset = None

# Should automatically load `collected_on` view
session.dataset = dataset

imanjra
imanjra previously approved these changes Mar 22, 2024
Copy link
Contributor

@imanjra imanjra left a comment

Choose a reason for hiding this comment

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

Tested locally. LGTM

def execute(self, ctx):
default_view = ctx.dataset.info.get("default_view", None)
if default_view and ctx.dataset.has_saved_view(default_view):
if Version(fo.__version__) >= Version("0.23.7"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool!

@brimoor brimoor changed the title Load default view WIP: load default view Sep 27, 2024
@brimoor brimoor marked this pull request as draft September 27, 2024 00:53
@brimoor brimoor changed the title WIP: load default view Load default view Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants