After Dark daytime comparison (read-only)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m4s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m23s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 09:48:02 +00:00
co-authored by Claude Opus 5.5
parent a7f888bbc6
commit 623fb5a4e7
3 changed files with 175 additions and 0 deletions
@@ -0,0 +1,104 @@
package tv.orbit.classic
import org.json.JSONObject
import org.junit.Assume.assumeTrue
import org.junit.Test
import java.io.File
/**
* Read-only (4 November 2026): After Dark's daytime, today and with suitable late-night cult films allowed by day, from
* copies of the box's files. Four weeks of new bookings after the committed plan, avoiding every other channel's plan:
* ORBIT_REPLAY_DIR=<copies of the box's files> ./gradlew :app:testDebugUnitTest --tests '*AfterDarkDaytimeReplayTest*'
* Writes after-dark-daytime.txt. Nothing here changes the app.
*/
class AfterDarkDaytimeReplayTest {
private val dir = System.getenv("ORBIT_REPLAY_DIR")?.let(::File)
private val zone = java.time.ZoneId.of("Europe/London")
private val day = 24 * 60 * 60_000L
/** Lighter cult films for any hour: PG, PG-13, the 1950s monster films and the 1970s TV films. */
private val daytime = listOf("Attack of the Killer Tomatoes!", "Big Trouble in Little China", "Critters", "Harold and Maude", "It Came from Outer Space",
"Killer Klowns from Outer Space", "Mars Attacks!", "Night of the Comet", "Phantom of the Paradise", "Plan 9 from Outer Space",
"The Adventures of Buckaroo Banzai Across the 8th Dimension", "The Blob", "The Day of the Triffids", "Them!", "Count Dracula", "The Night Stalker",
"The Night Strangler", "Nosferatu the Vampyre", "Invasion of the Body Snatchers")
/** Cult comedy and British folk-horror television, from 18:00: grown-up but not graphic. */
private val earlyEvening = listOf("Barbarella", "Brazil", "Withnail & I", "The Big Lebowski", "Heathers", "The Rocky Horror Picture Show", "Army of Darkness",
"Death Race 2000", "Penda's Fen", "Robin Redbreast", "Beauty and the Beast", "The Outcasts")
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")
val entries = (0 until rows.length()).map { i ->
val o = rows.getJSONObject(i); val d = o.getLong("d"); val n = o.getJSONArray("n")
ScheduleEntry(o.getString("s"), EpisodeMark(n.getInt(0), n.getInt(1)), ScheduledMedia(SampleItem(o.getString("t"), o.optString("k", "Episode"), d / 60_000, "", o.getString("i"), d), o.getString("c"), d),
o.getLong("a"), o.optString("w"), o.optString("p"))
}
return ChannelPlan(entries, ScheduleCursor(if (t.isNull("last")) null else t.getString("last"),
marks.keys().asSequence().associateWith { id -> marks.getJSONArray(id).let { EpisodeMark(it.getInt(0), it.getInt(1)) } },
t.optJSONObject("shown")?.let { s -> s.keys().asSequence().associateWith { s.getLong(it) } }.orEmpty(),
t.optJSONObject("blocks")?.let { b -> b.keys().asSequence().associateWith { b.getString(it) } }.orEmpty()))
}
private fun pool(file: File): List<PoolSeries> {
val rows = JSONObject(file.readText()).getJSONArray("series")
return (0 until rows.length()).map { i ->
val o = rows.getJSONObject(i); val eps = o.getJSONArray("episodes")
PoolSeries(o.getString("id"), o.getString("title"), (0 until eps.length()).map { j ->
val e = eps.getJSONArray(j); PoolEpisode(e.getString(0), e.getString(1), EpisodeMark(e.getInt(2), e.getInt(3)), e.getString(4), e.getLong(5))
}, o.optString("group"))
}
}
@Test fun daytimeOptions() {
assumeTrue(dir != null && File(dir, "episodes-305.json").exists())
val base = SmartChannels.first { it.number == AFTER_DARK_NUMBER }
val committed = plan(File(dir, "schedule-305.json")); val series = pool(File(dir, "episodes-305.json"))
val others = clashesWith(SmartChannels.filter { it.number != AFTER_DARK_NUMBER }.mapNotNull { p -> File(dir, "schedule-${p.number}.json").takeIf { it.exists() }?.let(::plan) })
val dayPart = base.dayParts.single { it.group == "day" }
val missing = (daytime + earlyEvening).filter { t -> series.none { seriesKey(it.title) == seriesKey(t) } }
val out = StringBuilder("After Dark daytime options: four weeks of new bookings after the committed plan, from box copies. Read-only.\n" +
"Films named but not in the pool: ${missing.ifEmpty { listOf("none") }.joinToString()}\n\n")
val variants = listOf(
"A. Today: 05:00 to 21:00 from the day list and day suggestions" to base.dayParts,
"B. Selective crossover: ${daytime.size} lighter cult films also allowed 05:00 to 21:00" to base.dayParts.map { if (it == dayPart) it.copy(titles = it.titles + daytime) else it },
"C. Graded: B by day, then 18:00 to 21:00 also ${earlyEvening.size} cult comedies and British folk-horror television" to base.dayParts.flatMap {
if (it != dayPart) listOf(it) else listOf(it.copy(toHour = 18, titles = it.titles + daytime), it.copy(fromHour = 18, titles = it.titles + daytime + earlyEvening))
})
for ((label, parts) in variants) {
val p = base.copy(dayParts = parts)
var current = committed
var now = committed.entries.first().startMs + SCHEDULE_KEEP_PAST_MS
val end = committed.endMs + 28 * day
val all = committed.entries.toMutableList()
while (now < end) {
current = topUpPlan(current, current.tail, series, now, p.filmRestMs, p.finishTogether, p.dayParts, zone, others, adaptiveRest = p.adaptiveFilmRest) ?: break
current.entries.filter { e -> all.none { it.startMs == e.startMs } }.forEach { all += it }
now += 6 * 60 * 60_000L
}
check(all.take(committed.entries.size) == committed.entries)
val new = all.sortedBy { it.startMs }.filter { it.startMs >= committed.endMs && it.startMs < end }
fun hour(e: ScheduleEntry) = java.time.Instant.ofEpochMilli(e.startMs).atZone(zone).hour
val dayEntries = new.filter { hour(it) in 5..20 && "event" !in it.why }
val nightEntries = new.filter { (hour(it) >= 21 || hour(it) < 5) && "event" !in it.why }
fun gaps(es: List<ScheduleEntry>) = es.groupBy { it.media.item.id }.values.flatMap { x -> x.zipWithNext().map { (a, b) -> (b.startMs - a.startMs) / day.toDouble() } }.sorted()
val allGaps = gaps(new.filter { it.media.item.type == "Movie" })
fun line(name: String, es: List<ScheduleEntry>): String {
val g = gaps(es)
return " $name: ${es.size} screenings, ${es.map { it.media.item.id }.distinct().size} different films; repeat gap median ${"%.1f".format(g.getOrElse(g.size / 2) { 0.0 })} d, shortest ${"%.1f".format(g.firstOrNull() ?: 0.0)} d; fixed-order fallbacks ${es.count { "no film past its rest" in it.why }}"
}
val rests = parts.filter { it.days.isEmpty() }.map { part ->
val (available, _, _) = dayPartFor(series, listOf(part), java.time.LocalDate.of(2026, 11, 16).atTime(part.fromHour, 30).atZone(zone).toInstant().toEpochMilli(), zone)
"${part.fromHour}-${part.toHour} ${available.count { it.isFilm }} films, rest ${"%.1f".format(adaptiveRestMs(available.filter { it.isFilm }, part, base.filmRestMs!!) / day.toDouble())} d"
}
out.appendLine("== $label")
out.appendLine(" blocks: ${rests.joinToString("; ")}")
out.appendLine(line("Daytime 05:00 to 21:00", dayEntries))
out.appendLine(line("Late 21:00 to 05:00", nightEntries))
out.appendLine(" Whole channel: ${new.map { it.media.item.id }.distinct().size} different films; any film again within 3 days ${allGaps.count { it < 3 }}, within 7 days ${allGaps.count { it < 7 }}")
out.appendLine(" On another channel at the same time: ${new.count { e -> others(series.first { it.id == e.seriesId }, e.startMs, e.endMs) }}; gaps ${new.zipWithNext().count { (a, b) -> a.endMs != b.startMs }}")
out.appendLine(" Most-screened by day: " + dayEntries.groupBy { it.media.item.title }.entries.sortedByDescending { it.value.size }.take(5).joinToString { "${it.key} ${it.value.size}" })
out.appendLine()
}
File(dir, "after-dark-daytime.txt").writeText(out.toString())
println(out)
}
}