0.108.5: Stage D scoring in Kotlin (parity with Python), Emby collections read, Settings > Director's Chair read only; built, not installed

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-05 08:14:42 +00:00
committed by Claude
co-authored by Claude Opus 5.5
parent 00153e25bd
commit a17834aa66
15 changed files with 685 additions and 1 deletions
@@ -0,0 +1,88 @@
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 Director's Chair: read only, counts and a few picks, franchise links only from Emby's collections, and scan gaps shown. */
class DirectorChairTest {
private fun line(id: String, name: String, type: String, genres: List<String>?, overview: String?, rating: String? = null, countries: List<String>? = null, studios: List<String>? = null) =
JSONObject().put("id", id).put("type", type).put("name", name).put("year", 2026).put("overview", overview ?: JSONObject.NULL)
.put("genres", genres?.let(::JSONArray) ?: JSONObject.NULL).put("studios", studios?.let(::JSONArray) ?: JSONObject.NULL)
.put("rating", rating ?: JSONObject.NULL).put("countries", countries?.let(::JSONArray) ?: JSONObject.NULL).put("taglines", JSONObject.NULL)
private val channelTitles = listOf(
line("e1", "Inspector Show", "Series", listOf("Crime", "Drama"), "A detective inspector and his sergeant investigate murders in a quiet town, with police procedure and forensic work."),
line("d1", "True Crime Show", "Series", listOf("Documentary", "Crime"), "A true crime documentary series about unsolved murders and missing people, with interviews and archive footage."),
line("t1", "Nature Show", "Series", listOf("Documentary"), "Wildlife and nature across the planet: oceans, reefs, forests and the animals and species that live there."))
private val pools = mapOf(107 to listOf("e1"), 204 to listOf("d1"), 201 to listOf("t1"))
private fun files(candidates: List<JSONObject>, collections: List<JSONObject> = emptyList()): Pair<File, File> {
val evidence = File.createTempFile("evidence", ".jsonl").apply { deleteOnExit(); writeText((channelTitles + candidates).joinToString("") { "$it\n" }) }
val sets = File.createTempFile("collections", ".jsonl").apply { delete(); deleteOnExit(); if (collections.isNotEmpty()) writeText(collections.joinToString("") { "$it\n" }) }
return evidence to sets
}
private fun arrival(id: String, name: String) = Arrival(id, "Series", name, 2026, "2026-10-30", "tmdb:$id", 0)
@Test fun countsAFewPicksAndNoDecisions() {
val cands = listOf(line("c1", "Ocean Life", "Series", listOf("Documentary"), "Wildlife of the ocean: reefs, sharks and the species of the deep sea."),
line("c2", "Missing in Maine", "Series", listOf("Documentary", "Crime"), "A true crime documentary about a disappearance and an unsolved murder case."),
line("c3", "Stand-up Night", "Movie", listOf("Comedy"), "A comedian takes aim at modern life in his debut special."))
val (ev, sets) = files(cands)
val report = buildDeskReport(ev, sets, pools, listOf(arrival("c1", "Ocean Life"), arrival("c2", "Missing in Maine"), arrival("c3", "Stand-up Night"), arrival("c4", "Not read yet")),
emptySet(), emptyMap(), 2, true, DirectorMode.Balanced, 1_793_800_000_000)
assertEquals(4, report.newlyReleased)
assertEquals(3, report.scanned)
assertEquals(1, report.unread) // shown, never hidden
assertTrue(report.picks.size <= DirectorMode.Balanced.picks)
assertEquals(report.picks.map { it.channel }.distinct().size, report.picks.size) // one per channel
assertTrue(report.picks.none { it.title == "Stand-up Night" })
assertEquals(0, report.collections)
}
@Test fun titlesAlreadyOnAChannelAreLeftOut() {
val (ev, sets) = files(listOf(line("c1", "Ocean Life", "Series", listOf("Documentary"), "Wildlife of the ocean.")))
val report = buildDeskReport(ev, sets, pools + (201 to listOf("t1", "c1")), listOf(arrival("c1", "Ocean Life"), Arrival("x2", "Series", "Other copy", 2026, "2026-10-30", "tmdb:c1", 0)),
setOf("tmdb:c1"), emptyMap(), 0, true, DirectorMode.Balanced, 1_793_800_000_000)
assertEquals(0, report.newlyReleased)
}
@Test fun franchiseLinksComeOnlyFromCollectionsAndNeverBreakTheLimits() {
val spinoff = line("c5", "Inspector Show: New York", "Series", listOf("Crime", "Drama"), "A new team.")
val docOfIt = line("c6", "Inside Inspector Show", "Series", listOf("Documentary"), "The making of the show.")
val (ev, sets) = files(listOf(spinoff, docOfIt), listOf(JSONObject().put("id", "b1").put("name", "Inspector Show Collection").put("members", JSONArray(listOf("e1", "c5", "c6")))))
val (links, count) = franchiseLinks(sets, pools)
assertEquals(1, count)
assertEquals(setOf(107), links.channels("c5"))
assertNull(links.channels("unlisted")) // unknown, never guessed from the title
val evidence = (channelTitles + listOf(spinoff, docOfIt)).associate { it.getString("id") to TitleEvidence.of(it) }
val text = ChannelText(pools, evidence)
val with = channelScore(evidence.getValue("c5"), Briefs.first { it.number == 107 }, text, links)
val without = channelScore(evidence.getValue("c5"), Briefs.first { it.number == 107 }, text)
assertTrue(with.first > without.first)
assertTrue(with.second.any { "collection" in it })
// The documentary is in the same collection, but Evidence is scripted only: the link can't put it there.
assertEquals(0.0, channelScore(evidence.getValue("c6"), Briefs.first { it.number == 107 }, text, links).first, 0.0)
assertTrue(ev.exists())
}
@Test fun britxNeedsVerifiedBritishOriginAndEvidenceIsNotLegalDrama() {
val evidence = mapOf("b" to TitleEvidence.of(line("b", "Gangland", "Movie", listOf("Crime"), "A London gangster plans one last heist.")),
"u" to TitleEvidence.of(line("u", "Gangland UK", "Movie", listOf("Crime"), "A London gangster plans one last heist.", countries = listOf("United Kingdom"))),
"l" to TitleEvidence.of(line("l", "The Firm", "Series", listOf("Drama", "Crime"), "Divorce lawyers at a top law firm fight a courtroom battle.")))
val text = ChannelText(emptyMap(), evidence)
val britx = Briefs.first { it.number == 309 }
assertEquals(0.0, channelScore(evidence.getValue("b"), britx, text).first, 0.0)
assertTrue(channelScore(evidence.getValue("b"), britx, text).second.single().contains("not verified"))
assertTrue(channelScore(evidence.getValue("u"), britx, text).first > 0)
assertTrue(channelScore(evidence.getValue("l"), Briefs.first { it.number == 107 }, text).first < .35)
}
@Test fun aReportReadsBackAsItWasSaved() {
val r = DeskReport(10, 2, 9, 1, listOf("Terra" to 1), 1, listOf(DeskPick("A", "Terra", "STRONG MATCH", "Line")), listOf(DeskAsk("B", "Sci-Fi", "Horror")), 0, false, 5, 6)
val back = DeskReport.of(r.toJson())
assertEquals(r.picks.single().title, back.picks.single().title); assertEquals("Horror", back.asks.single().second); assertFalse(back.catalogueComplete); assertEquals(1, back.unread)
assertEquals("A detective returns home.", sentence("A detective returns home. Then more happens."))
}
}
@@ -0,0 +1,35 @@
package tv.orbit.classic
import org.json.JSONArray
import org.json.JSONObject
import org.junit.Assume.assumeTrue
import org.junit.Test
import java.io.File
/**
* The Kotlin scoring against the Python reference on the same saved inputs, run by hand:
* ORBIT_DIRECTOR_FIXTURE=<folder with evidence-0.jsonl, episodes-*.json, candidates.json> ./gradlew :app:testDebugUnitTest --tests '*DirectorParityTest*'
* Writes kotlin-placements.json there, to compare with python-reference.json (docs/replays/stage-d-parity.py), and the time taken.
*/
class DirectorParityTest {
private val dir = System.getenv("ORBIT_DIRECTOR_FIXTURE")?.let(::File)
@Test fun sameInputsSamePlacements() {
assumeTrue(dir != null && File(dir, "candidates.json").exists())
val started = System.nanoTime()
val evidence = File(dir, "evidence-0.jsonl").readLines().map { JSONObject(it) }
val input = JSONObject(File(dir, "candidates.json").readText())
val originals = input.getJSONObject("originals")
val byId = evidence.associate { it.getString("id") to TitleEvidence.of(it, originals.optString(it.getString("id")).takeIf { o -> o.isNotEmpty() }) }
val pools = Briefs.mapNotNull { b -> File(dir, "episodes-${b.number}.json").takeIf { it.exists() }?.let { f ->
val rows = JSONObject(f.readText()).getJSONArray("series"); b.number to (0 until rows.length()).map { rows.getJSONObject(it).getString("id") } } }.toMap()
val text = ChannelText(pools, byId)
val built = (System.nanoTime() - started) / 1_000_000
val ids = input.getJSONArray("candidates").let { a -> (0 until a.length()).map { a.getString(it) } }
val out = JSONArray()
ids.forEach { id -> val p = placeTitle(byId.getValue(id), text); out.put(JSONObject().put("id", id).put("top", p.top.name).put("s1", p.s1).put("second", p.second.name).put("s2", p.s2).put("tier", p.tier.name)) }
val total = (System.nanoTime() - started) / 1_000_000
File(dir, "kotlin-placements.json").writeText(out.toString())
File(dir, "kotlin-timing.txt").writeText("profiles ${built}ms, all ${ids.size} titles ${total}ms, evidence ${evidence.size}\n")
}
}