Skip to content

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 dismissed imanjra’s stale review April 7, 2024 14:43

not ready to merge yet

@brimoor brimoor force-pushed the load-default-view branch from bc6675f to 273ac3c Compare April 13, 2024 14:55
@brimoor brimoor force-pushed the load-default-view branch from 273ac3c to ad9231d Compare August 22, 2024 16:07
@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
@brimoor brimoor force-pushed the load-default-view branch from 082f590 to 014b3ba Compare March 23, 2025 22:11
@brimoor brimoor changed the title Load default view [DRAFT] Load default view May 5, 2025
@brimoor brimoor changed the title [DRAFT] Load default view [HOLD] Load default view May 5, 2025
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