Director's Chair: your channels get its picks too

Each channel you make joins the Chair with its own shows as its identity: the
kinds it carries, the genres most of them share, their era, and whether it's all
for children. Its few weekly picks can now land on your channels, matched to
them, from the same short list.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-07 08:35:26 +00:00
co-authored by Claude Opus 5.5
parent 2f41a76cc5
commit ee856bd6cf
5 changed files with 44 additions and 4 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ android {
minSdk = 26
targetSdk = 36
versionCode = 244
versionName = "0.108.84-smart-setup"
versionName = "0.108.84-your-chair"
}
buildFeatures { compose = true }
// The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so
@@ -316,8 +316,10 @@ private val DirectorLock = Any()
*/
internal fun directorReports(store: ScheduleStore, catalogue: CatalogueStore, userId: String, nowMs: Long = System.currentTimeMillis()): Map<DirectorMode, DeskReport>? = synchronized(DirectorLock) {
val evidence = store.evidenceFile(); val collections = store.collectionsFile(); val cache = store.directorFile(); val decisions = store.decisionsFile()
// Your channels join the Chair with their own shows as their identity.
YourBriefs = CustomChannels.list.mapNotNull { c -> runCatching { yourBrief(c.number, c.name, catalogue.shapeRows(store.loadChoices(userId, c.number).accepted.map { it.id })) }.getOrNull() }
val key = listOf(evidence.lastModified(), collections.lastModified(), store.poolsStamp(), catalogue.summary().total ?: 0L, decisions.lastModified(),
store.learningFile().lastModified(), store.eventIdeasFile().lastModified()).joinToString(":")
store.learningFile().lastModified(), store.eventIdeasFile().lastModified(), YourBriefs.joinToString("|") { "${it.number}${it.genresAny.sorted()}${it.era}" }.hashCode()).joinToString(":")
runCatching { JSONObject(cache.readText()) }.getOrNull()?.takeIf { it.optString("key") == key && nowMs - it.optLong("savedMs") < 24 * 60 * 60_000L }?.let { saved ->
val reports = saved.optJSONObject("reports")
if (reports != null) return@synchronized DirectorMode.values().associateWith { DeskReport.of(reports.getJSONObject(it.name)) }
@@ -18,8 +18,16 @@ internal class Brief(val number: Int, val name: String, val kinds: Set<String>,
private fun w(vararg words: String) = Regex("\\b(" + words.joinToString("|") + ")", RegexOption.IGNORE_CASE)
/** Every channel the Chair places titles on: Orbit's own, then the channels you've made ([YourBriefs]). */
internal val Briefs: List<Brief> get() = BaseBriefs + YourBriefs
/**
* Channels of your own as the Chair sees them (Paul, 7 November 2026: the same few strong picks for your channels, matched
* to each one's identity). Worked out from each channel's own shows when the Chair's report is made; see [yourBrief].
*/
@Volatile internal var YourBriefs: List<Brief> = emptyList()
/** The briefs, in the reference's order (ties keep this order). */
internal val Briefs: List<Brief> = listOf(
internal val BaseBriefs: List<Brief> = listOf(
Brief(101, "Orbit 1", setOf("Series"), setOf("Comedy"), themes = w("sitcom", "family", "household", "neighbou?r", "roommate", "parents", "dad", "mum", "mom", "sisters", "brothers", "college", "workplace"),
against = w("murder", "killer", "documentary", "wedding of", "engagement"), era = 1970 to 2026, needTheme = true),
Brief(102, "Orbit 2", setOf("Series"), setOf("Game Show", "Reality", "Comedy", "Talk"), themes = w("quiz", "game show", "contestants", "panel", "challenge", "teams compete"),
@@ -202,7 +210,7 @@ internal fun channelScore(e: TitleEvidence, b: Brief, text: ChannelText, links:
if (b.kids && rating in Adult) return 0.0 to listOf("rated $rating")
var s = 0.0
val animated = "Animation" in g; val doc = "Documentary" in g
if (animated && ch !in AnimatedChannels) return 0.0 to listOf("animation, not for this channel")
if (animated && ch !in AnimatedChannels && ch !in YOURS_FIRST..YOURS_LAST) return 0.0 to listOf("animation, not for this channel")
if (!animated && ch in AnimatedChannels && g.isNotEmpty() && ch != 611 && ch != 601) return 0.0 to listOf("live action, not for this channel")
if (doc && ch in FictionChannels) return 0.0 to listOf("a documentary, not fiction")
if (g.isNotEmpty() && !doc && ch in FactualChannels && ch != 401 && !("Reality" in g && (ch == 203 || ch == 204))) return 0.0 to listOf("fiction, not factual")
@@ -107,3 +107,19 @@ internal fun titlesCarriedBy(picks: Map<String, String>, channels: Collection<Sc
}
return out
}
/**
* A channel of your own as the Director's Chair sees it: the kinds it carries, the genres most of its shows share (and one
* every show has, as a must), their era, and whether it's all for children, so nothing grown-up is offered for it. Null for a
* channel too new to have shows yet.
*/
internal fun yourBrief(number: Int, name: String, rows: List<ShapeRow>): Brief? {
if (rows.isEmpty()) return null
val counts = rows.flatMap { it.genres }.groupingBy { it }.eachCount()
val common = counts.filter { it.value >= rows.size * .3 }.entries.sortedByDescending { it.value }.take(4).map { it.key }.toSet()
val must = counts.filter { it.value >= rows.size * .8 }.keys.take(1).toSet()
val years = rows.mapNotNull { it.year }
val never = Regex("(?!)")
return Brief(number, name, rows.map { it.type }.toSet(), common.ifEmpty { counts.keys.take(4).toSet() }, must, never, never,
(years.minOrNull() ?: 1900) - 5 to (years.maxOrNull() ?: 2030) + 5, kids = rows.all { it.rating in KidsOk })
}
@@ -69,4 +69,18 @@ class SmartSetupTest {
assertTrue(weekLine(200 * hour).contains("more than a week"))
assertTrue(weekLine(42 * hour, hoursPerDay = 6).contains("more than a week")) // an evenings-only channel goes further
}
@Test fun yourChannelsJoinTheChairWithTheirOwnShowsAsTheirIdentity() {
val rows = listOf(row("X-Files", "Series", "TV-14", "Science Fiction", "Mystery", "Drama", year = 1993), row("Millennium", "Series", "TV-14", "Mystery", "Crime", "Drama", year = 1996),
row("Twin Peaks", "Series", "TV-14", "Mystery", "Drama", year = 1990), row("Poltergeist", "Movie", "PG", "Horror", year = 1982))
val brief = yourBrief(701, "The Unknown", rows)!!
assertEquals(setOf("Series", "Movie"), brief.kinds)
assertTrue("Mystery" in brief.genresAny); assertTrue("Drama" in brief.genresAny)
assertTrue(brief.needAny.isEmpty()) // no genre on every one of them
assertEquals(1977 to 2001, brief.era); assertFalse(brief.kids)
assertTrue(yourBrief(702, "Little Ones", listOf(row("Bluey", "Series", "TV-Y", "Animation")))!!.kids)
assertNull(yourBrief(703, "Empty", emptyList()))
val before = YourBriefs
try { YourBriefs = listOf(brief); assertTrue(Briefs.any { it.number == 701 }); assertTrue(Briefs.any { it.number == 101 }) } finally { YourBriefs = before }
}
}