0.99.4: weighted rotation on Orbit 1, Orbit 2, Gold, Paradox, Evidence, Heroes and Vortex
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m11s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m31s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 02:00:26 +00:00
co-authored by Claude Opus 5.5
parent 63d2505c61
commit e21c746a8e
10 changed files with 393 additions and 17 deletions
@@ -21,7 +21,9 @@ class WeightedRolloutReplayTest {
private val day = 24 * 60 * 60_000L
private val hour = 60 * 60_000L
private val channels = listOf(TOTS_NUMBER, 605, 202, 203, 603)
/** Channels weighted on the box as installed (0.99.3), for the other channels' plans that each one avoids. */
private val installedWeighted = setOf(103, 202, 203, 603, 605, 614)
private val channels = (System.getenv("ORBIT_ROLLOUT_CHANNELS") ?: "614,605,202,203,603").split(",").map { it.trim().toInt() }
private fun plan(file: File): ChannelPlan {
val root = JSONObject(file.readText()); val rows = root.getJSONArray("entries"); val t = root.getJSONObject("tail"); val marks = t.getJSONObject("marks")
@@ -57,7 +59,7 @@ class WeightedRolloutReplayTest {
while (now < end) {
if (restartEvery > 0 && ++step % restartEvery == 0) { ScheduleStore(folder).savePlan("user", programming.number, current); current = ScheduleStore(folder).loadPlan("user", programming.number)!! }
current = topUpPlan(current, current.tail, series, now, programming.filmRestMs, programming.finishTogether, programming.dayParts, zone, avoid,
shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = weightOf) ?: break
shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = weightOf, adaptiveRest = programming.adaptiveFilmRest) ?: break
current.entries.filter { e -> all.none { it.startMs == e.startMs } }.forEach { all += it }
now += 6 * hour
}
@@ -66,6 +68,7 @@ class WeightedRolloutReplayTest {
return if (keepCommitted) all.filter { it.startMs < end } else all.filter { it.startMs >= committed.endMs && it.startMs < end }
}
private fun local(ms: Long) = java.time.Instant.ofEpochMilli(ms).atZone(zone).toLocalDateTime().withNano(0)
private fun pct(x: Double) = "%.0f%%".format(100 * x)
private fun report(label: String, entries: List<ScheduleEntry>, series: List<PoolSeries>, programming: ChannelProgramming, weightOf: (PoolSeries) -> Double, others: ProgrammeClash, out: StringBuilder): Map<String, Int> {
@@ -94,7 +97,11 @@ class WeightedRolloutReplayTest {
val waits = inBlocks.associate { s -> s.title to (listOf(first) + entries.filter { it.seriesId == s.id }.map { it.startMs } + listOf(last)).zipWithNext().maxOf { (a, b) -> b - a } / day.toDouble() }
val never = inBlocks.filter { s -> entries.none { it.seriesId == s.id } }.map { it.title }
out.appendLine(" starvation: never aired ${never.ifEmpty { listOf("none") }.joinToString()}; longest waits " + waits.entries.sortedByDescending { it.value }.take(4).joinToString { "${it.key} ${"%.1f".format(it.value)} d" })
val twice = entries.zipWithNext().count { (a, b) -> a.seriesId == b.seriesId && weightedAt(b) }
// A show twice running is only allowed when every other show in its block is on another channel at that moment.
// A block of one show, such as Gold's Sunday Only Fools and Horses, plays it back to back by design.
fun choice(e: ScheduleEntry) = dayPartFor(series, programming.dayParts, e.startMs, zone).first.size > 1
val twice = entries.zipWithNext().count { (a, b) -> a.seriesId == b.seriesId && weightedAt(b) && choice(b) && "air elsewhere then" !in b.why && "airs elsewhere then" !in b.why }
val twiceForClash = entries.zipWithNext().count { (a, b) -> a.seriesId == b.seriesId && weightedAt(b) && choice(b) } - twice
val clashes = entries.count { others(byId.getValue(it.seriesId), it.startMs, it.endMs) }
val ordered = series.filter { !(programming.shuffleEpisodes || programming.mixes(it)) }.associateBy { it.id }
val back = entries.filter { it.seriesId in ordered }.groupBy { it.seriesId }.values.sumOf { es -> es.zipWithNext().count { (a, b) -> b.mark <= a.mark && b.mark != ordered.getValue(a.seriesId).episodes.first().mark } }
@@ -104,7 +111,7 @@ class WeightedRolloutReplayTest {
val outside = entries.count { e -> dayPartFor(series, programming.dayParts, e.startMs, zone).first.none { it.id == e.seriesId } }
val bursts = entries.indices.count { i -> val w = entries.drop(i).takeWhile { it.startMs < entries[i].startMs + 3 * hour }; w.size >= 4 && w.count { it.seriesId == entries[i].seriesId } * 2 > w.size }
out.appendLine(" on another channel at the same time: $clashes")
out.appendLine(" rules: same show twice running (weighted blocks) $twice; three-hour stretches over half one show $bursts; in-order stepping back $back; shuffled off its deck $offDeck; gaps $gaps; outside its block $outside")
out.appendLine(" rules: same show twice running (weighted blocks with a choice) $twice, plus $twiceForClash where every other show airs elsewhere; three-hour stretches over half one show $bursts; in-order stepping back $back; shuffled off its deck $offDeck; gaps $gaps; outside its block $outside")
return mapOf("sameDay" to sameDayWeighted, "twice" to twice, "back" to back, "offDeck" to offDeck, "gaps" to gaps, "outside" to outside, "never" to never.size, "clashes" to clashes)
}
@@ -114,7 +121,7 @@ class WeightedRolloutReplayTest {
"every other channel's programmes as the box does. Copies of the box's files from 3 November.\n\n")
// Every other channel's four weeks on today's rules, for clash avoidance.
val baseline = SmartChannels.filter { File(dir, "schedule-${it.number}.json").exists() && File(dir, "episodes-${it.number}.json").exists() }.associate { p ->
p.number to replay(plan(File(dir, "schedule-${p.number}.json")), pool(File(dir, "episodes-${p.number}.json")), p, p.tierWeights?.let { p::weightOf }.takeIf { p.number == 103 }, keepCommitted = true)
p.number to replay(plan(File(dir, "schedule-${p.number}.json")), pool(File(dir, "episodes-${p.number}.json")), p, p.tierWeights?.let { p::weightOf }.takeIf { p.number in installedWeighted }, keepCommitted = true)
}
for (number in channels) {
val programming = SmartChannels.first { it.number == number }
@@ -129,9 +136,10 @@ class WeightedRolloutReplayTest {
val weighted = replay(committed, series, programming, weightOf, others)
val restarted = replay(committed, series, programming, weightOf, others, restartEvery = 3)
report("Today", today, series, programming, weightOf, others, out)
val after = report("Weighted (0.98.0)", weighted, series, programming, weightOf, others, out)
val after = report("Weighted (as built)", weighted, series, programming, weightOf, others, out)
assertEquals("${programming.name}: a restart changes nothing", weighted, restarted)
out.appendLine(" a save and reload every 18 hours gives the identical four weeks: true")
File(dir, "weighted-rollout-replay.txt").writeText(out.toString())
for (key in listOf("sameDay", "twice", "back", "offDeck", "gaps", "outside", "never")) assertEquals("${programming.name}: $key", 0, after[key])
// Blocks left on equal turns keep today's rule. Their programmes start at slightly different times, as the day before
// them now ends at different moments, so the sequence shifts at block edges; the rule and the shares stay the same.
@@ -190,7 +190,13 @@ class WeightedRotationTest {
}
@Test fun theApprovedChannelsAreWeightedAndTotsBedtimeIsNot() {
assertEquals(listOf(103, 202, 203, 603, 605, 614), SmartChannels.filter { it.tierWeights != null }.map { it.number }.sorted())
assertEquals(listOf(101, 102, 103, 104, 106, 107, 202, 203, 601, 602, 603, 605, 614), SmartChannels.filter { it.tierWeights != null }.map { it.number }.sorted())
// Riot, Terra, Ring X and Junior keep equal turns; Rewind and Dark Files wait on their repeat investigation.
assertTrue(SmartChannels.filter { it.number in setOf(105, 201, 401, 611, 604, 204) }.all { it.tierWeights == null })
assertEquals(TIER_CORE, SmartChannels.first { it.number == 101 }.weightOf(show("The Wonder Years", 1)), 0.0)
assertEquals(TIER_SURPRISE, SmartChannels.first { it.number == 101 }.weightOf(show("Heartbeat", 1)), 0.0)
assertEquals(TIER_CORE, SmartChannels.first { it.number == 601 }.weightOf(show("Tenchi Muyo! Ryo-Ohki", 1)), 0.0)
assertEquals(TIER_CORE, SmartChannels.first { it.number == 106 }.weightOf(show("Doctor Who (2023)", 1)), 0.0)
val tots = SmartChannels.first { it.number == TOTS_NUMBER }
assertEquals(listOf(true, true, false, false), tots.dayParts.map { it.weighted })
val toonz = SmartChannels.first { it.number == 605 }
@@ -202,7 +208,7 @@ class WeightedRotationTest {
assertEquals(TIER_SURPRISE, SmartChannels.first { it.number == 203 }.weightOf(show("Dirty Jobs", 1)), 0.0)
assertEquals(TIER_CORE, SmartChannels.first { it.number == 603 }.weightOf(show("Mighty Morphin Power Rangers", 1)), 0.0)
assertEquals(TIER_CORE, SmartChannels.first { it.number == 202 }.weightOf(show("Cosmos", 1)), 0.0)
assertTrue(SmartChannels.filter { it.number !in setOf(103, 202, 203, 603, 605, 614) }.all { p -> p.dayParts.all { it.weighted && it.weights.isEmpty() } })
assertTrue(SmartChannels.filter { it.number != 614 && it.number != 605 }.all { p -> p.dayParts.all { it.weighted && it.weights.isEmpty() } })
}
@Test fun orbitThreesTiers() {