feat: selection mode filtering with av fallback
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user