annie.dataset.filtering

Browse filtering (service): pure predicates over the manifest.

The Browse tab’s always-visible filter bar narrows the per-video manifest by annotation coverage, review verdict, notes, annotator selection, label values, and an explicit id list loaded from a CSV column. The logic lives here — independent of NiceGUI and SQLite — so it is unit-tested directly: the UI supplies a ReviewState per row (read from the store) and a FilterSpec built from the controls.

Facets combine with AND; within a single label column the selected values combine with OR (e.g. Sentiment in {negative, neutral}).

Attributes

PresenceFilter

Tri-state presence facet (vdet, video frames, audio stream).

VdetFilter

Backwards-compatible alias for the vdet facet.

TrackFilter

any / none (0) / exactly one / multiple (2+).

ReviewFilter

any / liked (good, the default) / disliked (bad).

FramesFilter

any / less-than-threshold / greater-than-threshold.

SOURCE_FACETS

Facets that only make sense when a vdet or track folder is a source.

Classes

ReviewState

The per-video review state a filter needs, defaulted to "liked".

FilterSpec

A snapshot of the Browse filter bar.

Functions

source_facets(→ set[str])

The source-dependent facets that fit the configured sources.

drop_facets(→ None)

Turn off every source-dependent facet not in keep, so a hidden box never filters.

matches(→ bool)

Return whether a single video passes every active facet.

apply_filters(→ list)

Filter a manifest, keeping the entries that pass spec.

Module Contents

annie.dataset.filtering.PresenceFilter

Tri-state presence facet (vdet, video frames, audio stream).

annie.dataset.filtering.VdetFilter

Backwards-compatible alias for the vdet facet.

annie.dataset.filtering.TrackFilter

any / none (0) / exactly one / multiple (2+).

Type:

Track-count facet

annie.dataset.filtering.ReviewFilter

any / liked (good, the default) / disliked (bad).

Type:

Review facet

annie.dataset.filtering.FramesFilter

any / less-than-threshold / greater-than-threshold.

Type:

Frame-count facet

class annie.dataset.filtering.ReviewState[source]

The per-video review state a filter needs, defaulted to “liked”.

Every video is liked (good) by default; a record only exists once the user interacts. Attributes mirror the persisted columns.

verdict

"good" (liked, default) or "bad" (disliked).

note

Free-text note (empty when none).

in_annotator

Whether the video is queued for the Annotator tab.

class annie.dataset.filtering.FilterSpec[source]

A snapshot of the Browse filter bar.

name_prefix

keep only videos whose id starts with this (case-insensitive).

video

video-file presence facet (rows from vdet/track files may have none).

audio

audio-stream presence facet (ffprobe, cached as rows are viewed; see audio_of). Rows not yet probed fail has and missing.

vdet

vdet-presence facet.

tracks

track-count facet.

frames

frame-count facet (uses the probed cache; see frames_of).

frames_threshold

the threshold for the frames facet.

review

review-verdict facet.

has_note

keep only videos with a non-empty note.

in_annotator

keep only videos queued for the Annotator.

labels

per-column allowed value sets (OR within a column, AND across).

id_list

keep only videos whose id is in this set — the ids read from a CSV column (see distinct_column_values()). None means the facet is off; an empty set is never set by the UI.

id_source

the name of the CSV the id_list came from (for display).

id_column

the CSV column the ids were read from (for display).

property is_active: bool

Whether any facet is set (so the UI can show a “clear” affordance).

annie.dataset.filtering.SOURCE_FACETS: tuple[str, ...] = ('video', 'vdet', 'tracks')

Facets that only make sense when a vdet or track folder is a source.

annie.dataset.filtering.source_facets(*, has_vdet: bool, has_track: bool) → set[str][source]

The source-dependent facets that fit the configured sources.

vdet needs a vdet folder and tracks a track folder. video (does the video file exist) needs either: only vdet/track files can produce a row without a video.

Parameters:
  • has_vdet – Whether a vdet folder is configured.

  • has_track – Whether a track folder is configured.

Returns:

The names (from SOURCE_FACETS) to offer in the filter bar.

annie.dataset.filtering.drop_facets(spec: FilterSpec, keep: set[str]) → None[source]

Turn off every source-dependent facet not in keep, so a hidden box never filters.

Parameters:
  • spec – The filter spec to update in place.

  • keep – The source-dependent facets still offered (see source_facets()).

annie.dataset.filtering.matches(entry, review: ReviewState, spec: FilterSpec, *, has_audio: bool | None = None, num_frames: int | None = None, label_of: collections.abc.Callable[[annie.core.models.VideoEntry, str], str | None] | None = None) → bool[source]

Return whether a single video passes every active facet.

Parameters:
  • entry – The VideoEntry under test.

  • review – Its ReviewState.

  • spec – The current filter snapshot.

  • has_audio – The probed audio-presence flag (None if not yet known).

  • num_frames – The decoded frame count (None if not yet known).

  • label_of – Maps (entry, column) to the (possibly transformed) label value; defaults to the entry’s raw label.

Returns:

True if the video matches the filter, False otherwise.

annie.dataset.filtering.apply_filters(entries: list, spec: FilterSpec, review_of: collections.abc.Callable[[str], ReviewState], audio_of: collections.abc.Callable[[str], bool | None] | None = None, frames_of: collections.abc.Callable[[str], int | None] | None = None, label_of: collections.abc.Callable[[annie.core.models.VideoEntry, str], str | None] | None = None) → list[source]

Filter a manifest, keeping the entries that pass spec.

Parameters:
  • entries – The per-video manifest.

  • spec – The current filter snapshot.

  • review_of – Maps a video key to its ReviewState.

  • audio_of – Maps a video key to its probed audio-presence flag (or None).

  • frames_of – Maps a video key to its decoded frame count (or None).

  • label_of – Maps (entry, column) to its (possibly transformed) label value.

Returns:

The entries that match, in their original order.