Repeat investigation for Rewind, Dark Files and Vortex (read-only); file rest is now a parameter, default unchanged
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 12m53s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m34s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 02:03:43 +00:00
co-authored by Claude Opus 5.5
parent e21c746a8e
commit 8eeeeeac49
4 changed files with 337 additions and 10 deletions
@@ -49,7 +49,7 @@ class WeightedRolloutReplayTest {
}
private fun replay(committed: ChannelPlan, series: List<PoolSeries>, programming: ChannelProgramming, weightOf: ((PoolSeries) -> Double)?,
avoid: ProgrammeClash = { _, _, _ -> false }, restartEvery: Int = 0, keepCommitted: Boolean = false): List<ScheduleEntry> {
avoid: ProgrammeClash = { _, _, _ -> false }, restartEvery: Int = 0, keepCommitted: Boolean = false, fileRestMs: Long = SAME_FILE_MS): List<ScheduleEntry> {
var current = committed
var now = committed.entries.first().startMs + SCHEDULE_KEEP_PAST_MS
val end = committed.endMs + 28 * day
@@ -59,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, adaptiveRest = programming.adaptiveFilmRest) ?: break
shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = weightOf, adaptiveRest = programming.adaptiveFilmRest, fileRestMs = fileRestMs) ?: break
current.entries.filter { e -> all.none { it.startMs == e.startMs } }.forEach { all += it }
now += 6 * hour
}
@@ -190,4 +190,45 @@ class WeightedRolloutReplayTest {
println(out)
}
/**
* Read-only: Rewind, Dark Files and Vortex, which repeat episodes more often under weighted rotation. Each is replayed
* on today's rule, weighted as proposed, weighted with a longer rest before a file may air again (4 and 7 days), and a
* hybrid where a show with a short catalogue has its weight scaled down by how many hours of episodes it holds, alone
* and with the 4-day rest. Tiers as proposed (proposed-tiers.json) or as built. Writes repeat-investigation.txt.
*/
@Test fun repeatInvestigation() {
val file = dir?.let { File(it, "proposed-tiers.json") }
assumeTrue(file != null && file.exists())
val proposed = JSONObject(file!!.readText())
val out = StringBuilder("Repeat investigation: four weeks of new bookings after each committed plan, avoiding every other channel as the box does. Read-only.\n\n")
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 in installedWeighted }, keepCommitted = true)
}
for (number in listOf(604, 204, 601)) {
val base = SmartChannels.first { it.number == number }
val tiers = base.tierWeights ?: proposed.getJSONObject(number.toString()).let { row -> row.keys().asSequence().associate { seriesKey(it) to row.getDouble(it) } }
val programming = base.copy(tierWeights = tiers)
val committed = plan(File(dir, "schedule-$number.json")); val series = pool(File(dir, "episodes-$number.json"))
val others = clashesWith(baseline.filterKeys { it != number }.values.map { ChannelPlan(it, ScheduleCursor()) })
val hours = series.associate { it.id to it.episodes.sumOf { e -> e.durationMs } / 3_600_000.0 }
fun hybrid(full: Double) = { s: PoolSeries -> programming.weightOf(s) * minOf(1.0, hours.getValue(s.id) / full) }
out.appendLine("== ${programming.name} ($number): catalogues from ${"%.0f".format(hours.values.min())} to ${"%.0f".format(hours.values.max())} hours; under 12 h: ${series.filter { hours.getValue(it.id) < 12 }.joinToString { it.title }}")
val day = 24 * 60 * 60_000L
for ((label, weightOf, rest) in listOf(
Triple("Today, equal turns", null, SAME_FILE_MS),
Triple("Weighted, 24 h file rest (as proposed)", programming::weightOf, SAME_FILE_MS),
Triple("Weighted, 4-day file rest", programming::weightOf, 4 * day),
Triple("Weighted, 7-day file rest", programming::weightOf, 7 * day),
Triple("Hybrid, weight scaled under 12 h of episodes", hybrid(12.0), SAME_FILE_MS),
Triple("Hybrid, weight scaled under 24 h of episodes", hybrid(24.0), SAME_FILE_MS),
Triple("Hybrid under 12 h, with 4-day file rest", hybrid(12.0), 4 * day))) {
report(label, replay(committed, series, programming, weightOf, others, fileRestMs = rest), series, programming, programming::weightOf, others, out)
}
out.appendLine()
}
File(dir, "repeat-investigation.txt").writeText(out.toString())
println(out)
}
}