// The Speakers lane's "space" order (AutoQueueOrder): which video to capture // next so the disk frees fastest. // // Two keys, in this order: // 1. a channel whose media is on the CORPUS disk (no `mediaDir`) before one // whose media lives on another drive — the operator's ruling: internal // disk first, because that is the disk that fills; // 2. bytes of held audio per audio-hour, descending — the space one hour of // diarization CPU frees (the CPU cost is ~proportional to duration, the // space to the file's size). // A video whose rate is unknown (no duration on disk) sorts after every known // one within its disk class. Equal keys compare 0, so the sort is stable and // keeps the listed order between them. // // Pure: the runner (controller/autoRunner.ts recencyOrdering) supplies the two // lookups; nothing here touches the disk. export function audioBytesPerHour(bytes: number, seconds: number | null): number | null { if (!(bytes > 0) || seconds === null || !(seconds > 0)) return null; return bytes / (seconds / 3600); } export function spaceComparator(look: { external: (id: string) => boolean; bytesPerHour: (id: string) => number | null; }): (a: string, b: string) => number { return (a, b) => { const ea = look.external(a) ? 1 : 0; const eb = look.external(b) ? 1 : 0; if (ea !== eb) return ea - eb; const ra = look.bytesPerHour(a); const rb = look.bytesPerHour(b); if (ra === rb) return 0; if (ra === null) return 1; if (rb === null) return -1; return rb - ra; }; }