Catalogue discovery: score unassigned titles with the Chair (env-gated, read-only)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 08:53:54 +00:00
co-authored by Claude Opus 5.5
parent f426de2e14
commit da4b7b8a78
@@ -0,0 +1,35 @@
package tv.orbit.classic
import org.json.JSONObject
import org.junit.Assume.assumeTrue
import org.junit.Test
import java.io.File
/**
* The Director's Chair's catalogue discovery (Paul, 30 November 2026): library titles no channel uses yet, each scored against
* every channel's brief by the Chair's own scoring ([channelScore]), with each channel's description centroid built from what
* it shows now (a TV snapshot's pools and evidence). Read-only. Env: SIM_SNAP (snapshot schedule dir), DISCOVERY (the audit
* folder with evidence-discovery.jsonl); writes DISCOVERY/scores.tsv.
*/
class CatalogueDiscoveryTest {
@Test fun scoreTheUnassignedTitles() {
val snap = System.getenv("SIM_SNAP")?.let(::File); val dir = System.getenv("DISCOVERY")?.let(::File)
assumeTrue(snap != null && snap.isDirectory && dir != null && dir.isDirectory)
val user = snap!!.listFiles()!!.first { it.name.startsWith("episodes-") && it.name.endsWith(".json") }.let { JSONObject(it.readText()).getString("user") }
val store = ScheduleStore(snap)
val onAir = File(snap, "evidence-0.jsonl").readLines().mapNotNull { runCatching { TitleEvidence.of(JSONObject(it)) }.getOrNull() }.associateBy { it.id }
val candidates = File(dir, "evidence-discovery.jsonl").readLines().mapNotNull { runCatching { TitleEvidence.of(JSONObject(it)) }.getOrNull() }
val pools = Briefs.associate { b -> b.number to store.loadPool(user, b.number)?.series.orEmpty().map { it.id } }
val text = ChannelText(pools, onAir + candidates.associateBy { it.id })
val out = StringBuilder("id\ttype\ttitle\tyear\trating\tbest\tbestScore\tsecond\tsecondScore\twhy\n")
for (e in candidates) {
val scored = Briefs.map { b -> b to channelScore(e, b, text) }.sortedByDescending { it.second.first }
val best = scored[0]; val second = scored.getOrNull(1)
fun clean(s: String) = s.replace('\t', ' ').replace('\n', ' ')
out.append("${e.id}\t${e.type}\t${clean(e.name)}\t${e.year ?: ""}\t${e.rating ?: ""}\t${best.first.number} ${best.first.name}\t${"%.2f".format(best.second.first)}\t" +
"${second?.let { "${it.first.number} ${it.first.name}" } ?: ""}\t${second?.let { "%.2f".format(it.second.first) } ?: ""}\t${clean(best.second.second.take(4).joinToString("; "))}\n")
}
File(dir, "scores.tsv").writeText(out.toString())
println("scored ${candidates.size} against ${Briefs.size} briefs")
}
}