0.99.3: adaptive film rest for After Dark and Premiere (events keep 7 days)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package tv.orbit.classic
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
|
||||
class AdaptiveFilmRestTest {
|
||||
private val day = 24 * 60 * 60_000L
|
||||
private val zone = java.time.ZoneOffset.UTC
|
||||
private val start = java.time.LocalDate.of(2026, 11, 10).atStartOfDay(zone).toInstant().toEpochMilli()
|
||||
private fun films(n: Int, minutes: Int = 100) = (1..n).map { PoolSeries("f$it", "Film $it", listOf(PoolEpisode("f$it", "src", EpisodeMark(1, 1), "Film $it", minutes * 60_000L))) }
|
||||
|
||||
@Test fun theRestFollowsHowLongTheBlocksFilmsLast() {
|
||||
// 72 films of 100 minutes over 24 hours: 5 days back to back, too short for 7 days, so 90% of it.
|
||||
assertEquals((5 * day * 0.9).toLong(), adaptiveRestMs(films(72), null, 7 * day))
|
||||
// The same films in an 8-hour block last three times as long in days: 80% of 15, never under 7.
|
||||
assertEquals((15 * day * 0.8).toLong(), adaptiveRestMs(films(72), DayPart(21, 5), 7 * day))
|
||||
// Just past a week: kept at the channel's own 7 days.
|
||||
assertEquals(7 * day, adaptiveRestMs(films(125), null, 7 * day))
|
||||
// Floor and ceiling.
|
||||
assertEquals(ADAPTIVE_REST_FLOOR_MS, adaptiveRestMs(films(10), null, 7 * day))
|
||||
assertEquals(ADAPTIVE_REST_CEILING_MS, adaptiveRestMs(films(500), null, 7 * day))
|
||||
}
|
||||
|
||||
@Test fun aSmallPoolPicksFromARestedShortlistInsteadOfAFixedLoop() {
|
||||
val pool = films(72)
|
||||
val flat = extendFilmSchedule(pool, ScheduleCursor(), start, start + 28 * day, 7 * day)
|
||||
val adaptive = extendFilmSchedule(pool, ScheduleCursor(), start, start + 28 * day, 7 * day, adaptiveRest = true)
|
||||
assertTrue(flat.entries.count { "no film past its rest" in it.why } > 200)
|
||||
assertEquals(0, adaptive.entries.count { "no film past its rest" in it.why })
|
||||
// Every film still rests at least the adaptive time.
|
||||
adaptive.entries.groupBy { it.seriesId }.values.forEach { es -> es.zipWithNext().forEach { (a, b) -> assertTrue(b.startMs - a.startMs >= adaptiveRestMs(pool, null, 7 * day)) } }
|
||||
adaptive.entries.zipWithNext().forEach { (a, b) -> assertEquals(a.endMs, b.startMs) }
|
||||
}
|
||||
|
||||
@Test fun eventsKeepTheChannelsRestAndOnlyTheChosenChannelsAdapt() {
|
||||
val pool = films(72)
|
||||
val event = DayPart(20, 23, pool.take(6).map { it.title }, days = setOf(java.time.DayOfWeek.FRIDAY))
|
||||
val plan = extendFilmSchedule(pool, ScheduleCursor(), start, start + 28 * day, 7 * day, listOf(event, DayPart(0, 24)), zone, adaptiveRest = true)
|
||||
plan.entries.filter { "event" in it.why && "picked from" in it.why }.groupBy { it.seriesId }.values.forEach { es -> es.zipWithNext().forEach { (a, b) -> assertTrue(b.startMs - a.startMs >= 7 * day) } }
|
||||
assertEquals(setOf(301, 305), SmartChannels.filter { it.adaptiveFilmRest }.map { it.number }.toSet())
|
||||
}
|
||||
}
|
||||
@@ -56,7 +56,7 @@ class EditorialCorrectionsAuditTest {
|
||||
val plan = current[p.number] ?: continue
|
||||
val others = clashesWith(current.filterKeys { it != p.number }.values.toList())
|
||||
current[p.number] = topUpPlan(plan, plan.tail, pools.getValue(p.number), now, p.filmRestMs, p.finishTogether, p.dayParts, zone, others,
|
||||
shuffle = p.shuffleEpisodes, mixed = p::mixes, weightOf = p.tierWeights?.let { p::weightOf }) ?: plan
|
||||
shuffle = p.shuffleEpisodes, mixed = p::mixes, weightOf = p.tierWeights?.let { p::weightOf }, adaptiveRest = p.adaptiveFilmRest) ?: plan
|
||||
current.getValue(p.number).entries.filter { e -> all.getValue(p.number).none { it.startMs == e.startMs } }.forEach { all.getValue(p.number) += it }
|
||||
}
|
||||
now += 6 * hour
|
||||
@@ -135,6 +135,29 @@ class EditorialCorrectionsAuditTest {
|
||||
"${es.size} screenings, ${es.map { it.media.item.id }.distinct().size} different; early returns (rest not kept) $fallbacks; " +
|
||||
(if (gaps.isNotEmpty()) "repeat gap median ${"%.1f".format(gaps[gaps.size / 2])} d, shortest ${"%.1f".format(gaps.first())} d" else "no repeats"))
|
||||
}
|
||||
// 5b. The same four weeks with adaptive rest on every film channel's everyday blocks, everything else as it is.
|
||||
out.appendLine()
|
||||
out.appendLine("== 5b. Adaptive rest (90% of a short block's play-through time, or up to 80% of a long one but never under 7 days), flat 7 days -> adaptive")
|
||||
val adaptive = network(channels.map { if (it.filmRestMs != null) it.copy(adaptiveFilmRest = true) else it }, pools, plans, from)
|
||||
for (p in filmPools.sortedBy { it.number }) {
|
||||
fun stats(r: Map<Int, List<ScheduleEntry>>): String {
|
||||
val es = r.getValue(p.number).filter { it.startMs >= plans.getValue(p.number).endMs && it.media.item.type == "Movie" }
|
||||
val gaps = es.groupBy { it.media.item.id }.values.flatMap { x -> x.zipWithNext().map { (a, b) -> (b.startMs - a.startMs) / day.toDouble() } }.sorted()
|
||||
val shortlist = es.mapNotNull { Regex("picked from (\\d+) rested").find(it.why)?.groupValues?.get(1)?.toInt() }.sorted()
|
||||
return "${es.map { it.media.item.id }.distinct().size} different, fixed-order fallbacks ${es.count { "no film past its rest" in it.why }}, " +
|
||||
"shortlist median ${shortlist.getOrNull(shortlist.size / 2) ?: 0}, repeat gap median ${"%.1f".format(gaps.getOrElse(gaps.size / 2) { 0.0 })} d, shortest ${"%.1f".format(gaps.firstOrNull() ?: 0.0)} d"
|
||||
}
|
||||
val rests = p.dayParts.filter { it.days.isEmpty() }.ifEmpty { listOf(null) }.map { part ->
|
||||
val (available, _, _) = if (part == null) Triple(pools.getValue(p.number), "", null) else dayPartFor(pools.getValue(p.number), listOf(part), java.time.LocalDate.of(2026, 11, 16).atTime(part.fromHour, 30).atZone(zone).toInstant().toEpochMilli(), zone)
|
||||
val films = available.filter { it.isFilm }.ifEmpty { pools.getValue(p.number).filter { it.isFilm } }
|
||||
(part?.let { "${it.fromHour}-${it.toHour} " } ?: "") + "%.1f d".format(adaptiveRestMs(films, part, p.filmRestMs!!) / day.toDouble())
|
||||
}
|
||||
out.appendLine(" ${p.number} ${p.name}: rest ${rests.joinToString()}")
|
||||
out.appendLine(" flat: ${stats(run)}")
|
||||
out.appendLine(" adaptive: ${stats(adaptive)}")
|
||||
}
|
||||
val adaptiveClashes = adaptive.flatMap { (n, es) -> es.map { n to it } }.groupBy { title(it.second) }.values.sumOf { list -> list.indices.sumOf { i -> list.drop(i + 1).count { b -> b.first != list[i].first && list[i].second.startMs < b.second.endMs && b.second.startMs < list[i].second.endMs } } }
|
||||
out.appendLine(" overlaps with adaptive rest, all channels: $adaptiveClashes (the committed Shaun of the Dead included)")
|
||||
File(dir, "editorial-corrections.txt").writeText(out.toString())
|
||||
println(out)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class ReplayFingerprintTest {
|
||||
val all = committed.entries.toMutableList()
|
||||
while (now < end) {
|
||||
current = topUpPlan(current, current.tail, series, now, programming.filmRestMs, programming.finishTogether, programming.dayParts, zone,
|
||||
shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = programming.tierWeights?.let { programming::weightOf }) ?: break
|
||||
shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = programming.tierWeights?.let { programming::weightOf }, adaptiveRest = programming.adaptiveFilmRest) ?: break
|
||||
current.entries.filter { e -> all.none { it.startMs == e.startMs } }.forEach { all += it }
|
||||
now += 6 * 60 * 60_000L
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user