feat: selection mode filtering with av fallback

This commit is contained in:
Ben Stull
2026-06-04 01:35:38 -07:00
parent d1c5190bbb
commit d28fb0a0a7
2 changed files with 49 additions and 0 deletions
+18
View File
@@ -35,3 +35,21 @@ def distance(a: Coordinate, b: Coordinate, weights: Weights = Weights()) -> floa
def record_coordinate(record: Record) -> Coordinate:
"""The (left, right, dark, light) coordinate of a catalog record."""
return Coordinate(record.left, record.right, record.dark, record.light)
def candidates_for_mode(records, mode: str, pool_size: int) -> list[Record]:
"""Records eligible for a content mode.
For 'av', if fewer than pool_size native 'av' records exist, fall back to
including 'audio' and 'video' records so the pool is never starved.
"""
if mode not in CONTENT_MODES:
raise ValueError(
f"candidates_for_mode expects a content mode {sorted(CONTENT_MODES)}, "
f"got {mode!r}"
)
primary = [r for r in records if r.mode == mode]
if mode == "av" and len(primary) < pool_size:
extra = [r for r in records if r.mode in {"audio", "video"}]
return primary + extra
return primary