Simulations: Heroes Live switch-on check; Horror TV revised schedule with rotation and weekend events

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 19:53:34 +00:00
co-authored by Claude Opus 5.5
parent 1e500e7432
commit 0fd345fc68
2 changed files with 27 additions and 3 deletions
@@ -95,6 +95,20 @@ class HeroesLiveSimulationTest {
report.append(" nights without a 21:00 feature $nightsWithoutFeature\n")
checks += listOf(matureEarly == 0, clashes == 0, restBroken == 0, keptAll, order == 0)
}
// Switching the channel on (Paul, 30 November 2026): the first plan made at any time of day, and what its first two
// evenings get at 21:00. A feature missing, or two features in one evening, would show here.
for (hour in listOf(6, 12, 18, 20, 21, 22, 23, 2)) {
val on = LocalDateTime.of(2026, 12, 1, hour, 17).atZone(zone).toInstant().toEpochMilli()
val first = topUpPlan(null, ScheduleCursor(), pool, on, null, true, parts, zone, avoid = avoid, shuffle = false,
fileRestMs = NETWORK_FILM_REST_MS, stories = true, network = NoNetworkRest)!!
fun local(ms: Long) = Instant.ofEpochMilli(ms).atZone(zone)
val features = first.entries.filter { e -> pool.first { it.id == e.seriesId }.title in featureFilms }
val byEvening = (0..1).map { d -> val day = local(on).toLocalDate().plusDays(d.toLong())
features.count { local(it.startMs).toLocalDate() == day && local(it.startMs).hour in 21..22 } }
val early = features.filter { local(it.startMs).hour !in 21..22 }.map { "${local(it.startMs).toLocalTime()} ${it.media.item.title}" }
report.append("switched on ${"%02d".format(hour)}:17: features at 21:00 tonight ${byEvening[0]}, tomorrow ${byEvening[1]}; features outside 21:00-23:00 $early\n")
checks += listOf(byEvening.all { it <= 1 }, byEvening[1] == 1, early.isEmpty(), hour >= 21 || byEvening[0] == 1)
}
File(out, "summary.txt").writeText(report.toString()); println(report)
assertTrue(report.toString(), checks.all { it })
}
@@ -34,8 +34,17 @@ class HorrorTvSimulationTest {
PoolSeries(id, t, eps.map { e -> val s = e.getInt(0); val n = e.getInt(1)
PoolEpisode("$id$s${"%03d".format(n)}", "9$id$s$n", EpisodeMark(s, n), "$t / S$s E$n", min * 60_000L) })
}
val parts = doc.getJSONArray("parts").let { a -> (0 until a.length()).map { a.getJSONArray(it) } }.map { p ->
DayPart(p.getInt(0), p.getInt(1), list(p.getString(2)), key = "horrortv.${p.getString(2)}") }
// Parts as [from, to, list], or objects (revised schedule, Paul 30 November 2026): a weekly rotation cap ("only a handful of
// serials progressing at once") and weekend-only events, listed before the everyday blocks.
val parts = doc.getJSONArray("parts").let { a -> (0 until a.length()).map { a.get(it) } }.map { p ->
if (p is org.json.JSONArray) DayPart(p.getInt(0), p.getInt(1), list(p.getString(2)), key = "horrortv.${p.getString(2)}")
else (p as JSONObject).let { o ->
val titles = list(o.getString("list")); val cap = o.optInt("rotateCap", 0)
val days = o.optJSONArray("days")?.let { d -> (0 until d.length()).map { java.time.DayOfWeek.valueOf(d.getString(it)) }.toSet() }.orEmpty()
DayPart(o.getInt("from"), o.getInt("to"), if (cap > 0) emptyList() else titles, key = "horrortv.${o.optString("key", o.getString("list"))}", days = days,
rotating = if (cap > 0) titles else null, rotateCap = cap, rotateWeekHours = if (cap > 0) ((o.getInt("to") - o.getInt("from") + 24) % 24) * 7 else 0)
}
}
val others = (SmartChannels.map { it.number } + DRIVE_IN_NUMBER).mapNotNull { n -> store.loadPlan(user, n)?.let { n to it } }.toMap()
val clash = clashesWithAirings(others.values.flatMap { airingsOf(it) })
val mature = strings("matureKeys").map(::seriesKey).toSet()
@@ -43,6 +52,7 @@ class HorrorTvSimulationTest {
val report = StringBuilder("pool: ${pool.size} series (${pool.sumOf { it.episodes.size }} episodes)\n")
val checks = mutableListOf<Boolean>()
for ((label, start) in listOf("december" to LocalDateTime.of(2026, 12, 1, 6, 0), "october" to LocalDateTime.of(2027, 10, 1, 6, 0))) {
val prefix = System.getenv("SIM_LABEL").orEmpty()
val now = start.atZone(zone).toInstant().toEpochMilli()
val all = LinkedHashMap<String, ScheduleEntry>(); var plan: ChannelPlan? = null; var aired = ScheduleCursor(); var keptAll = true
for (d in 0 until 35) {
@@ -55,7 +65,7 @@ class HorrorTvSimulationTest {
fun show(e: ScheduleEntry) = pool.first { it.id == e.seriesId }
val tsv = StringBuilder("start\tminutes\ttitle\tblock\n")
entries.forEach { e -> tsv.append("${local(e.startMs).toLocalDateTime()}\t${(e.endMs - e.startMs) / 60_000}\t${e.media.item.title}\t${presentationOf(e, parts, zone)}\n") }
File(out, "plan-116-$label.tsv").writeText(tsv.toString())
File(out, "plan-116-$prefix$label.tsv").writeText(tsv.toString())
val matureEarly = entries.count { e -> seriesKey(show(e).title) in mature && local(e.startMs).hour in 3..22 && !(local(e.startMs).hour in 3..5) }
val intenseEarly = entries.count { e -> seriesKey(show(e).title) !in mature && seriesKey(show(e).title) !in day && local(e.startMs).hour in 6..20 }
val clashes = entries.count { e -> clash(show(e), e.startMs, e.endMs) }