Director's Chair: other channels in a drop-down, and learning from your decisions

The pop-up keeps its suggestion (or an ask's two channels) up front and puts
every other channel in an 'Other channels' drop-down: scored fits first,
then the rest of the title's kind with why each is outside its usual brief.
Never the wrong kind, a children's channel for an adult rating, animation
for live action, or Premiere.

Learning (ChairLearning.kt): the decisions the Chair keeps become lessons
when two or more go the same way: a redirect (you keep putting a genre on
another channel) or a hold-back (you keep dropping a genre for a channel),
each explained by its own decisions. Shown always; used only while your
Learning switch on the Chair is on (off by default). Off undoes every
effect at once. Nothing is booked, placed or approved by it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-05 15:34:49 +00:00
co-authored by Claude Opus 5.5
parent a8a84034fb
commit 16901c50ce
6 changed files with 190 additions and 22 deletions
@@ -0,0 +1,45 @@
package tv.orbit.classic
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assert.*
import org.junit.Test
import java.io.File
/** The Chair learning from your decisions: patterns of two or more, explained, used only while learning is on. */
class ChairLearningTest {
private fun ev(id: String, title: String, genres: List<String>) = TitleEvidence(id, "Movie", title, 2026, "A story.", genres, null, null, null, null)
private fun placed(id: String, title: String, channel: Int, suggested: Int) = ChairDecision(id, title, "Movie", true, channel, suggested, 1)
private fun dropped(id: String, title: String, suggested: Int) = ChairDecision(id, title, "Movie", false, null, suggested, 1)
@Test fun twoMatchingDecisionsMakeALessonOneDoesNot() {
val evidence = mapOf("1" to ev("1", "Gore Night", listOf("Horror")), "2" to ev("2", "Splatter Party", listOf("Horror")), "3" to ev("3", "Wedding", listOf("Romance")),
"4" to ev("4", "Big Day", listOf("Romance")), "5" to ev("5", "Lone Shark", listOf("Horror")))
val lessons = chairLessons(listOf(placed("1", "Gore Night", 305, 304), placed("2", "Splatter Party", 305, 304), dropped("3", "Wedding", 307), dropped("4", "Big Day", 307),
placed("5", "Lone Shark", 304, 304)), evidence)
assertEquals(5, lessons.decisions); assertEquals(1, lessons.agreed); assertEquals(2, lessons.changed); assertEquals(2, lessons.dropped)
assertEquals(305, lessons.redirectFor(304, setOf("Horror"))!!.to)
assertNotNull(lessons.holdBackFor(307, setOf("Romance")))
assertNull(lessons.redirectFor(304, setOf("Comedy")))
assertTrue(lessons.lessons.first { it.kind == ChairLesson.Kind.Redirect }.text().contains("Gore Night")) // explained by its own decisions
// One decision alone is no pattern.
assertTrue(chairLessons(listOf(placed("1", "Gore Night", 305, 304)), evidence).lessons.isEmpty())
}
@Test fun lessonsChangeSuggestionsOnlyWhileLearningIsOn() {
val horror = { id: String, name: String -> JSONObject().put("id", id).put("type", "Movie").put("name", name).put("year", 2026)
.put("overview", "A haunted house, a demon and a curse: terror for a family in the night.").put("genres", JSONArray(listOf("Horror"))).put("studios", JSONObject.NULL)
.put("rating", JSONObject.NULL).put("countries", JSONArray(listOf("United States"))).put("taglines", JSONObject.NULL) }
val evidence = File.createTempFile("evidence", ".jsonl").apply { deleteOnExit(); writeText(listOf(horror("1", "Gore Night"), horror("2", "Splatter Party"), horror("9", "The Haunting"), horror("10", "The Curse")).joinToString("") { "$it\n" }) }
val sets = File.createTempFile("collections", ".jsonl").apply { delete(); deleteOnExit() }
val history = listOf(placed("1", "Gore Night", 305, 304), placed("2", "Splatter Party", 305, 304))
fun report(learning: Boolean) = buildDeskReport(evidence, sets, emptyMap(), listOf(Arrival("9", "Movie", "The Haunting", 2026, "2026-10-30", "tmdb:9", 0)),
emptySet(), emptyMap(), 1, true, DirectorMode.Balanced, 1_793_800_000_000, decided = setOf("1", "2"), history = history, learning = learning)
val off = report(false); val on = report(true)
assertEquals(1, off.lessons.size); assertFalse(off.learningOn)
val offFirst = (off.picks.map { it.options } + off.asks.map { it.options }).single().first()
val onFirst = (on.picks.map { it.options } + on.asks.map { it.options }).single().first()
assertEquals(304, offFirst.number) // off: the brief's own suggestion
assertEquals(305, onFirst.number); assertTrue(onFirst.reason.startsWith("learned from you"))
}
}
@@ -105,7 +105,9 @@ class DirectorChairTest {
val pick = before.picks.first()
assertEquals(1, before.picks.size); assertEquals("Series", pick.type) // one pick per channel: both are Terra's
assertEquals(201, pick.options.first().number) // the suggested channel first
assertTrue(pick.options.size <= 3); assertTrue(pick.options.none { it.number == 107 }) // never a channel the scoring ruled out (Evidence takes no documentaries)
// The drop-down offers the other channels too: a channel the scoring ruled out says why, and the wrong kind never appears.
assertTrue(pick.options.first { it.number == 107 }.reason.startsWith("outside its usual brief"))
assertTrue(pick.options.none { it.number == 303 || it.number == PREMIERE_NUMBER }) // a film channel for a series, and Premiere, never
assertTrue(pick.options.first().reason.isNotBlank())
// Once decided, a title isn't shown again; the counts stay as they were.
val after = buildDeskReport(ev, sets, pools, released, emptySet(), emptyMap(), 2, true, DirectorMode.Balanced, 1_793_800_000_000, decided = setOf(pick.id))