Stage D proposal: Beerus Afterburn premiere (prototype replay on box data) and automatic English subtitles
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m57s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m27s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 15:23:36 +00:00
co-authored by Claude Opus 5.5
parent 0ff6ec533c
commit 387ba43240
3 changed files with 236 additions and 0 deletions
@@ -0,0 +1,99 @@
package tv.orbit.classic
import org.json.JSONObject
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Assume.assumeTrue
import org.junit.Test
import java.io.File
/**
* Stage D proposal, read-only: Vortex with a prototype Afterburn premiere of Dragon Ball Super: Beerus on Saturdays at 21:00
* and a shortened, Dragon Ball-themed Movie Night before it, from copies of the box's files. Nothing in the app changes:
* the prototype blocks exist only here. Each double bill is modelled as one 46-minute programme, which is how it would fill
* the evening; Beerus joins the pool only after Saturday 14 November's evening, as a booking release installed by then
* would make it. Run by hand:
* ORBIT_REPLAY_DIR=<copies of the box's files> ./gradlew :app:testDebugUnitTest --tests '*BeerusPremiereReplayTest*'
* Writes beerus-premiere-replay.txt there.
*/
class BeerusPremiereReplayTest {
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
private val hour = 60 * 60_000L
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"))
}
}
private fun pct(x: Double) = "%.0f%%".format(100 * x)
@Test fun premiere() {
assumeTrue(dir != null && File(dir, "schedule-601.json").exists())
val vortex = SmartChannels.first { it.number == VORTEX_NUMBER }
val committed = plan(File(dir, "schedule-601.json")); val series = pool(File(dir, "episodes-601.json"))
fun at(date: String, h: Int, m: Int = 0) = java.time.LocalDate.parse(date).atTime(h, m).atZone(zone).toInstant().toEpochMilli()
fun t(ms: Long) = java.time.Instant.ofEpochMilli(ms).atZone(zone).toLocalDateTime().withNano(0)
val minute = 60_000L
val beerus = PoolSeries("8016753", "Dragon Ball Super: Beerus", listOf(
PoolEpisode("8016755", "mediasource_8016755", EpisodeMark(1, 1), "Episodes 1 and 2", 46 * minute),
PoolEpisode("8062564", "mediasource_8062564", EpisodeMark(1, 3), "Episodes 3 and 4", 46 * minute)))
// Dragon Ball films up to an hour, leaving out the two that tell the Beerus story.
val dbFilms = series.filter { it.isFilm && it.title.startsWith("Dragon Ball") && it.episodes[0].durationMs <= 61 * minute && "Battle of Gods" !in it.title && "Resurrection" !in it.title }
val movie = VortexDayParts.first()
val parts = listOf(
DayPart(21, 22, listOf(beerus.title), days = setOf(java.time.DayOfWeek.SATURDAY), onTime = true, once = true, key = "vortex.afterburn.premiere"),
DayPart(20, 21, dbFilms.map { it.title }, days = setOf(java.time.DayOfWeek.SATURDAY), key = movie.key),
movie.copy(days = setOf(java.time.DayOfWeek.FRIDAY))) + VortexDayParts.drop(1)
val joins = at("2026-11-14", 22)
var current = committed; var now = committed.entries.first().startMs + SCHEDULE_KEEP_PAST_MS
val all = committed.entries.toMutableList()
val out = StringBuilder("Stage D prototype replay: Vortex from the box's files (${t(committed.entries.first().startMs)} to ${t(committed.endMs)} committed), four weeks of top-ups every six hours.\n")
out.appendLine("Dragon Ball films that fit an hour (Battle of Gods and Resurrection 'F' left out): ${dbFilms.size}")
val bookedAt = mutableMapOf<Long, Pair<Long, Long>>()
while (now < committed.endMs + 28 * day) {
val pool = if (now >= joins) series + beerus else series
val before = current.endMs
current = topUpPlan(current, current.tail, pool, now, vortex.filmRestMs, vortex.finishTogether, parts, zone, shuffle = vortex.shuffleEpisodes, mixed = vortex::mixes,
weightOf = vortex.tierWeights?.let { vortex::weightOf }, adaptiveRest = vortex.adaptiveFilmRest, stories = vortex.storyGrouping) ?: break
current.entries.filter { e -> all.none { it.startMs == e.startMs } }.forEach { e -> all += e; if (e.seriesId == beerus.id) bookedAt[e.startMs] = now to before }
now += 6 * hour
}
all.sortBy { it.startMs }
assertEquals("committed kept", committed.entries, all.take(committed.entries.size))
bookedAt.forEach { (start, info) -> out.appendLine("premiere booked for ${t(start)} at the top-up of ${t(info.first)}; the plan then ended ${t(info.second)}, so the slot was uncommitted: ${info.second <= start}") }
val dbs = all.filter { it.media.item.title.startsWith("Dragon Ball Super / ") }
out.appendLine("Dragon Ball Super (2015) Beerus saga (season 1, 14 episodes): last episode booked ${dbs.lastOrNull { it.mark.season == 1 }?.let { "S${it.mark.season}E${it.mark.episode} at ${t(it.startMs)}" }}; first after it ${dbs.firstOrNull { it.mark.season > 1 }?.let { "S${it.mark.season}E${it.mark.episode} at ${t(it.startMs)}" }}" +
"; committed plan holds up to ${dbs.filter { it.startMs < committed.endMs }.lastOrNull()?.mark}")
for (date in listOf("2026-11-14", "2026-11-21", "2026-11-28", "2026-12-05")) {
out.appendLine("== Saturday $date, 19:00 to 23:00")
all.filter { it.startMs >= at(date, 19) && it.startMs < at(date, 23) }.forEach {
out.appendLine(" ${t(it.startMs).toLocalTime()}-${t(it.endMs).toLocalTime()} ${it.media.item.title.substringBefore(" / ")} [${it.presentation.ifEmpty { "-" }}] ${it.why.substringBefore(";")}")
}
}
val gaps = all.zipWithNext().count { (a, b) -> a.endMs != b.startMs }
out.appendLine("gaps or overlaps across the four weeks: $gaps")
File(dir, "beerus-premiere-replay.txt").writeText(out.toString())
println(out)
}
}