Stage 2: network-wide film rest, one copy per film in the Chair's ideas, catalogue-based fit, series short of episodes (build 70)

Film channels pass over a film another channel shows or has booked within five days,
Joe Bob's episodes counting as their film, whenever another rested film is available.
The Chair's rotation check judges films from catalogue genres and ratings where no
description has been read, and offers one copy of each film. Schedule health lists
series a channel can only play part of, with the missing episode numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-23 09:12:37 +00:00
co-authored by Claude Opus 5.5
parent 92784bb3d3
commit 40ec46e7b5
10 changed files with 273 additions and 24 deletions
@@ -88,6 +88,36 @@ class ChairRotationTest {
assertTrue(cards(blocks, evidence, poolIds = mapOf(305 to dayFilms.map { it.id }.toSet(), 306 to setOf("a2")), dismissed = setOf(card.proposals.single().key), briefs = listOf(brief)).isEmpty())
}
@Test fun copiesOfOneFilmAreOfferedOnceAndNotAtAllWhenAnotherChannelHasACopy() {
// 23 November 2026: Fraggle Rock offered three times, once for each copy in the library.
val dayFilms = (1..8).map { film("d$it", "Day $it") }
val evidence = dayFilms.associate { it.id to ev(it.id, it.title, listOf("Horror", "Comedy"), "R") } + mapOf(
"c1" to ev("c1", "Copied Film", listOf("Horror", "Comedy"), "R"),
"c2" to ev("c2", "Copied Film", listOf("Horror", "Comedy"), "R"),
"c3" to ev("c3", "Copied Film", listOf("Horror", "Comedy"), "R"),
"r1" to ev("r1", "Copied Film", listOf("Horror", "Comedy"), "R", year = 2004),
"o1" to ev("o1", "Shown Elsewhere", listOf("Horror", "Comedy"), "R"),
"o2" to ev("o2", "Shown Elsewhere", listOf("Horror", "Comedy"), "R"))
val brief = Brief(305, "After Dark", setOf("Movie"), setOf("Horror", "Comedy"), themes = Regex("comedy"), against = Regex("^$"), era = 1970 to 2010)
val blocks = rotationBlocks(darkLike(dayFilms.map { it.title }), dayFilms).filter { it.group == "day" }
val card = cards(blocks, evidence, poolIds = mapOf(305 to dayFilms.map { it.id }.toSet(), 306 to setOf("o1")), briefs = listOf(brief)).single()
// One copy of the 1988 film, the 2004 remake as its own film, and nothing another channel already has a copy of.
assertEquals(listOf("Copied Film|1988", "Copied Film|2004"), card.proposals.map { "${it.title}|${it.year}" }.sorted())
}
@Test fun catalogueGenresAndRatingsAreEnoughWhereNoDescriptionWasRead() {
// As rotationReport builds them from the box's catalogue: name, year, genres and rating, no description.
fun cat(id: String, name: String, genres: List<String>, rating: String) = TitleEvidence(id, "Movie", name, 1988, null, genres, null, rating, null, null)
val dayFilms = (1..8).map { film("d$it", "Day $it") }
val evidence = dayFilms.associate { it.id to cat(it.id, it.title, listOf("Horror", "Comedy"), "R") } + mapOf(
"k1" to cat("k1", "Catalogue Film", listOf("Horror", "Comedy"), "R"),
"k2" to cat("k2", "Catalogue Drama", listOf("Drama"), "R"))
val brief = Brief(305, "After Dark", setOf("Movie"), setOf("Horror", "Comedy"), themes = Regex("comedy"), against = Regex("^$"), era = 1970 to 2010)
val blocks = rotationBlocks(darkLike(dayFilms.map { it.title }), dayFilms).filter { it.group == "day" }
val card = cards(blocks, evidence, poolIds = mapOf(305 to dayFilms.map { it.id }.toSet()), briefs = listOf(brief)).single()
assertEquals(listOf("Catalogue Film"), card.proposals.map { it.title })
}
@Test fun yourOwnChannelWithTwentyFilmsIsCheckedToo() {
val films = (1..20).map { film("c$it", "Comedy $it", minutes = 95) }
val mine = ChannelProgramming(YOURS_FIRST, "My Comedy", emptyList())
@@ -0,0 +1,77 @@
package tv.orbit.classic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
/** Network-wide film rest (Paul, 23 November 2026: Sleepaway Camp on After Dark, the Drive-In and Horror in one week). */
class NetworkFilmRestTest {
private val hour = 60 * 60_000L
private val day = 24 * hour
private val start = java.time.LocalDate.of(2026, 11, 23).atStartOfDay(java.time.ZoneOffset.UTC).toInstant().toEpochMilli()
private fun film(n: Int, title: String = "Film $n", minutes: Int = 100) =
PoolSeries("f$n", title, listOf(PoolEpisode("f$n", "src", EpisodeMark(1, 1), title, minutes * 60_000L)))
private fun films(range: IntRange) = range.map { film(it) }
private fun entry(title: String, type: String, at: Long, minutes: Int = 100) =
ScheduleEntry("x", EpisodeMark(1, 1), ScheduledMedia(SampleItem(title, type, minutes.toLong(), "", "i-$title"), "src", minutes * 60_000L), at, "")
private fun otherChannel(vararg titles: String, at: Long = start) = ChannelPlan(titles.mapIndexed { i, t -> entry(t, "Movie", at + i * 2 * hour) }, ScheduleCursor())
@Test fun aFilmOnAnotherChannelThisWeekWaitsWhileOthersAreRested() {
val elsewhere = restingElsewhere(filmAiringsOf(otherChannel(*(1..10).map { "Film $it" }.toTypedArray())))
val plan = extendFilmSchedule(films(1..40), ScheduleCursor(), start, start + 2 * day, 7 * day, network = elsewhere)
assertTrue(plan.entries.size > 20)
assertTrue(plan.entries.none { it.seriesId in (1..10).map { n -> "f$n" } })
assertTrue(plan.entries.any { "on another channel this week" in it.why })
plan.entries.zipWithNext().forEach { (a, b) -> assertEquals(a.endMs, b.startMs) }
}
@Test fun aChannelNeverGoesWithoutBecauseOfIt() {
// Every film the channel has is on elsewhere: it plays them anyway, with no gap, and says why.
val elsewhere = restingElsewhere(filmAiringsOf(otherChannel(*(1..10).map { "Film $it" }.toTypedArray())))
val plan = extendFilmSchedule(films(1..10), ScheduleCursor(), start, start + day, 7 * day, network = elsewhere)
assertTrue(plan.endMs >= start + day)
assertTrue(plan.entries.first().why.contains("every rested film is on another channel this week"))
plan.entries.zipWithNext().forEach { (a, b) -> assertEquals(a.endMs, b.startMs) }
}
@Test fun withNothingElsewhereThePlanIsExactlyAsBefore() {
val pool = films(1..60)
val before = extendFilmSchedule(pool, ScheduleCursor(), start, start + 7 * day, 7 * day)
val after = extendFilmSchedule(pool, ScheduleCursor(), start, start + 7 * day, 7 * day, network = restingElsewhere(emptyList()))
val unrelated = extendFilmSchedule(pool, ScheduleCursor(), start, start + 7 * day, 7 * day, network = restingElsewhere(filmAiringsOf(otherChannel("Something Else"))))
assertEquals(before.entries.map { it.seriesId }, after.entries.map { it.seriesId })
assertEquals(before.entries.map { it.seriesId }, unrelated.entries.map { it.seriesId })
}
@Test fun joeBobsEpisodeCountsAsTheFilmItPresents() {
val joeBob = ChannelPlan(listOf(entry("$LAST_DRIVE_IN / S1 E2 / Sleepaway Camp", "Episode", start, 120)), ScheduleCursor())
val airings = filmAiringsOf(joeBob)
assertEquals(listOf("sleepaway camp"), airings.map { it.key })
val elsewhere = restingElsewhere(airings)
assertTrue(elsewhere(film(1, "Sleepaway Camp (1983)"), start + 5 * day))
assertFalse(elsewhere(film(2, "Sleepaway Camp 2"), start + day))
// Any other series' episode is not a film showing.
assertTrue(filmAiringsOf(ChannelPlan(listOf(entry("Phoenix Nights / S1 E1 / Pilot", "Episode", start)), ScheduleCursor())).isEmpty())
}
@Test fun theRestRunsBothWaysForFiveDays() {
val elsewhere = restingElsewhere(filmAiringsOf(otherChannel("Army of Darkness", at = start)))
val army = film(1, "Army of Darkness")
assertTrue(elsewhere(army, start - 4 * day))
assertTrue(elsewhere(army, start + 4 * day))
assertFalse(elsewhere(army, start - 6 * day))
assertFalse(elsewhere(army, start + 6 * day))
}
@Test fun channelsSharingAPoolStopShowingTheSameFilms() {
// Three film channels with the same 45 films, each planning a day after the one before it.
val pool = films(1..45)
fun showing(plans: List<ChannelPlan>) = plans.flatMapIndexed { i, p -> p.entries.map { it.seriesId to i } }.groupBy({ it.first }, { it.second }).values.count { it.toSet().size >= 2 }
val rested = mutableListOf<ChannelPlan>()
repeat(3) { rested += extendFilmSchedule(pool, ScheduleCursor(), start + it * hour, start + day, 7 * day, network = restingElsewhere(rested.flatMap(::filmAiringsOf))) }
val plain = (0 until 3).map { extendFilmSchedule(pool, ScheduleCursor(), start + it * hour, start + day, 7 * day) }
assertTrue(showing(plain) > 0)
assertEquals(0, showing(rested))
}
}
@@ -0,0 +1,34 @@
package tv.orbit.classic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
/** Missing instalments explained (23 November 2026: Phoenix Nights has 4 playable episodes of 12, so it seemed to jump back). */
class SeriesGapsTest {
private fun show(title: String, vararg marks: Pair<Int, Int>) =
PoolSeries(title, title, marks.map { (s, e) -> PoolEpisode("$title-$s-$e", "x", EpisodeMark(s, e), "Ep", 30 * 60_000L) })
private val three = ChannelProgramming(103, "Orbit Three", emptyList())
@Test fun theNumbersMissingBetweenWhatsPlayableAreListed() {
val phoenix = show("Phoenix Nights", 1 to 3, 1 to 5, 2 to 2, 2 to 5)
assertEquals(listOf(EpisodeMark(1, 1), EpisodeMark(1, 2), EpisodeMark(1, 4), EpisodeMark(2, 1), EpisodeMark(2, 3), EpisodeMark(2, 4)), missingEpisodes(phoenix))
val gap = seriesGaps(listOf(three to listOf(phoenix))).single()
assertEquals(4, gap.playable)
assertTrue(gap.line.startsWith("4 playable; missing S1 E1, S1 E2, S1 E4, S2 E1, S2 E3, S2 E4."))
}
@Test fun aWholeShowOrOneMissingEpisodeIsntFlaggedAndFilmsArentSeries() {
val whole = show("Whole", *(1..6).map { 1 to it }.toTypedArray())
val oneShort = show("One Short", *(1..12).filter { it != 7 }.map { 1 to it }.toTypedArray())
val film = PoolSeries("f1", "A Film", listOf(PoolEpisode("f1", "x", EpisodeMark(1, 9), "A Film", 90 * 60_000L)))
assertTrue(seriesGaps(listOf(three to listOf(whole, oneShort, film))).isEmpty())
}
@Test fun theWorstGapsComeFirstAndTheListIsShort() {
val shows = (1..20).map { n -> show("Show $n", 1 to n + 2) } + show("Nearly Empty", 1 to 40)
val gaps = seriesGaps(listOf(three to shows))
assertEquals(8, gaps.size)
assertEquals("Nearly Empty", gaps.first().title)
}
}