diff --git a/android/app/src/main/java/tv/orbit/classic/DirectorChair.kt b/android/app/src/main/java/tv/orbit/classic/DirectorChair.kt index f329f344..5d72b1b2 100644 --- a/android/app/src/main/java/tv/orbit/classic/DirectorChair.kt +++ b/android/app/src/main/java/tv/orbit/classic/DirectorChair.kt @@ -2,6 +2,7 @@ package tv.orbit.classic import androidx.compose.foundation.background import androidx.compose.foundation.border +import androidx.compose.foundation.clickable import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape @@ -37,12 +38,12 @@ internal class DeskPick(val title: String, val channel: String, val tag: String, internal class DeskAsk(val title: String, val first: String, val second: String) internal class DeskReport(val newlyReleased: Int, val newToLibrary: Int, val scanned: Int, val unread: Int, val strongByChannel: List>, val strong: Int, - val picks: List, val asks: List, val collections: Int, val catalogueComplete: Boolean, val computedMs: Long, val tookMs: Long) { + val picks: List, val asks: List, val collections: Int, val catalogueComplete: Boolean, val franchises: Int, val computedMs: Long, val tookMs: Long) { fun toJson(): JSONObject = JSONObject().put("newlyReleased", newlyReleased).put("newToLibrary", newToLibrary).put("scanned", scanned).put("unread", unread) .put("strong", strong).put("strongByChannel", JSONArray(strongByChannel.map { JSONObject().put("c", it.first).put("n", it.second) })) .put("picks", JSONArray(picks.map { JSONObject().put("t", it.title).put("c", it.channel).put("g", it.tag).put("l", it.line) })) .put("asks", JSONArray(asks.map { JSONObject().put("t", it.title).put("a", it.first).put("b", it.second) })) - .put("collections", collections).put("catalogueComplete", catalogueComplete).put("computedMs", computedMs).put("tookMs", tookMs) + .put("collections", collections).put("franchises", franchises).put("catalogueComplete", catalogueComplete).put("computedMs", computedMs).put("tookMs", tookMs) companion object { fun of(o: JSONObject): DeskReport { fun list(key: String) = o.optJSONArray(key)?.let { a -> (0 until a.length()).map { a.getJSONObject(it) } }.orEmpty() @@ -50,7 +51,7 @@ internal class DeskReport(val newlyReleased: Int, val newToLibrary: Int, val sca list("strongByChannel").map { it.optString("c") to it.optInt("n") }, o.optInt("strong"), list("picks").map { DeskPick(it.optString("t"), it.optString("c"), it.optString("g"), it.optString("l")) }, list("asks").map { DeskAsk(it.optString("t"), it.optString("a"), it.optString("b")) }, - o.optInt("collections"), o.optBoolean("catalogueComplete"), o.optLong("computedMs"), o.optLong("tookMs")) + o.optInt("collections"), o.optBoolean("catalogueComplete"), o.optInt("franchises"), o.optLong("computedMs"), o.optLong("tookMs")) } } } @@ -58,21 +59,29 @@ internal class DeskReport(val newlyReleased: Int, val newToLibrary: Int, val sca /** Paul's standing editorial calls so far, shown so the director's reasoning is visible. Decisions on the Chair itself come later. */ internal val DirectorRules = listOf("Made-for-TV romances: not for Orbit", "Tales from the Crypt: After Dark strand", "Black Mirror: Paradox from 21:00") -/** Emby collections as franchise links: each member's collection, and the channels its fellow members are on. */ -internal fun franchiseLinks(file: File, pools: Map>): Pair { - if (!file.exists()) return FranchiseLinks.Unknown to 0 +/** + * Emby collections as evidence: franchise links only from TMDB-style "... Collection" sets (each member's collection, and the + * channels its fellow members are on), and British origin from the broadcasters' lists. Curated lists link nothing. + * Returns the links, how many collections were read, and how many of them are franchises. + */ +internal fun franchiseLinks(file: File, pools: Map>): Triple { + if (!file.exists()) return Triple(FranchiseLinks.Unknown, 0, 0) val onChannel = HashMap>().apply { pools.forEach { (ch, ids) -> ids.forEach { getOrPut(it) { HashSet() } += ch } } } - val collectionOf = HashMap(); val channelsOf = HashMap>() - var count = 0 + val collectionOf = HashMap(); val channelsOf = HashMap>(); val british = HashMap() + var count = 0; var franchises = 0 file.forEachLine { line -> val o = runCatching { JSONObject(line) }.getOrNull() ?: return@forEachLine count++ val members = o.optJSONArray("members")?.let { a -> (0 until a.length()).map { a.getString(it) } }.orEmpty() val name = o.optString("name") - channelsOf[name] = members.flatMap { onChannel[it].orEmpty() }.toSet() - members.forEach { collectionOf[it] = name } + if (FranchiseCollection.containsMatchIn(name)) { + franchises++ + channelsOf[name] = members.flatMap { onChannel[it].orEmpty() }.toSet() + members.forEach { collectionOf[it] = name } + } + if (BritishLists.containsMatchIn(name)) members.forEach { british.putIfAbsent(it, name) } } - return FranchiseLinks(channelsOf, collectionOf) to count + return Triple(FranchiseLinks(channelsOf, collectionOf, british), count, franchises) } /** @@ -80,12 +89,17 @@ internal fun franchiseLinks(file: File, pools: Map>): Pair>, released: List, carriedWorks: Set, - originals: Map, newToLibrary: Int, catalogueComplete: Boolean, mode: DirectorMode, nowMs: Long, zone: ZoneId = ZoneId.systemDefault()): DeskReport { + originals: Map, newToLibrary: Int, catalogueComplete: Boolean, mode: DirectorMode, nowMs: Long, zone: ZoneId = ZoneId.systemDefault()): DeskReport = + buildDeskReports(evidenceFile, collectionsFile, pools, released, carriedWorks, originals, newToLibrary, catalogueComplete, nowMs, zone).getValue(mode) + +/** All three modes' reports from one scoring pass: the modes only differ in how many discoveries they show and how far they reach. */ +internal fun buildDeskReports(evidenceFile: File, collectionsFile: File, pools: Map>, released: List, carriedWorks: Set, + originals: Map, newToLibrary: Int, catalogueComplete: Boolean, nowMs: Long, zone: ZoneId = ZoneId.systemDefault()): Map { val started = System.nanoTime() val evidence = if (evidenceFile.exists()) evidenceFile.readLines().mapNotNull { runCatching { JSONObject(it) }.getOrNull() } .associate { it.optString("id") to TitleEvidence.of(it, originals[it.optString("id")]) } else emptyMap() val text = ChannelText(pools, evidence) - val (links, collections) = franchiseLinks(collectionsFile, pools) + val (links, collections, franchises) = franchiseLinks(collectionsFile, pools) val carriedIds = pools.values.flatten().toSet() val candidates = released.filter { it.id !in carriedIds && it.work !in carriedWorks }.distinctBy { it.work } val read = candidates.mapNotNull { evidence[it.id] } @@ -95,16 +109,45 @@ internal fun buildDeskReport(evidenceFile: File, collectionsFile: File, pools: M val today = Instant.ofEpochMilli(nowMs).atZone(zone).toLocalDate() val premiered = released.associate { it.id to it.premiere } fun recent(id: String) = premiered[id]?.takeIf { it.length == 10 }?.let { runCatching { LocalDate.parse(it) }.getOrNull() }?.let { !it.isBefore(today.minusDays(14)) } == true - // Discoveries: the strongest strong matches, one per channel; Surprise Me reaches into the possibles for channels the strong list missed. - val pool = strong.sortedByDescending { it.s1 }.distinctBy { it.top.number }.toMutableList() - if (mode == DirectorMode.Surprise) pool += placed.filter { it.tier == FitTier.Possible && pool.none { p -> p.top.number == it.top.number } }.sortedByDescending { it.s1 }.take(2) - val picks = pool.take(mode.picks).map { p -> - DeskPick(p.evidence.name, p.top.name, when { p.tier == FitTier.Possible -> "SOMETHING DIFFERENT"; recent(p.evidence.id) -> "JUST RELEASED"; else -> "STRONG MATCH" }, - p.evidence.overview?.let { sentence(it) } ?: "No description in the library yet") - } val asks = placed.filter { it.tier == FitTier.NeedsEye }.sortedByDescending { it.s1 }.take(3).map { DeskAsk(it.evidence.name, it.top.name, it.second.name) } - return DeskReport(candidates.size, newToLibrary, read.size, candidates.size - read.size, byChannel, strong.size, picks, asks, collections, catalogueComplete, nowMs, - (System.nanoTime() - started) / 1_000_000) + val tookMs = (System.nanoTime() - started) / 1_000_000 + return DirectorMode.values().associateWith { mode -> + // Discoveries: the strongest strong matches, one per channel; Surprise Me reaches into the possibles for channels the strong list missed. + val pool = strong.sortedByDescending { it.s1 }.distinctBy { it.top.number }.toMutableList() + if (mode == DirectorMode.Surprise) pool += placed.filter { it.tier == FitTier.Possible && pool.none { p -> p.top.number == it.top.number } }.sortedByDescending { it.s1 }.take(2) + val picks = pool.take(mode.picks).map { p -> + DeskPick(p.evidence.name, p.top.name, when { p.tier == FitTier.Possible -> "SOMETHING DIFFERENT"; recent(p.evidence.id) -> "JUST RELEASED"; else -> "STRONG MATCH" }, + p.evidence.overview?.let { sentence(it) } ?: "No description in the library yet") + } + DeskReport(candidates.size, newToLibrary, read.size, candidates.size - read.size, byChannel, strong.size, picks, asks, collections, catalogueComplete, franchises, nowMs, tookMs) + } +} + +private val DirectorLock = Any() + +/** + * The Chair's reports for all three modes, from the saved copy when nothing it reads has changed (the evidence, the + * collections, the channels' pools and the catalogue) and it's under a day old; otherwise worked out once and saved. One at + * a time: a second caller waits for the first and then reads its copy. Read only. + */ +internal fun directorReports(store: ScheduleStore, catalogue: CatalogueStore, userId: String, nowMs: Long = System.currentTimeMillis()): Map? = synchronized(DirectorLock) { + val evidence = store.evidenceFile(); val collections = store.collectionsFile(); val cache = store.directorFile() + val key = listOf(evidence.lastModified(), collections.lastModified(), store.poolsStamp(), catalogue.summary().total ?: 0L).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)) } + } + val today = Instant.ofEpochMilli(nowMs).atZone(ZoneId.systemDefault()).toLocalDate() + val released = catalogue.releasedBetween(today.minusDays(NEWLY_RELEASED_DAYS).toString(), today.toString(), 2_000) + val ids = SmartChannels.associate { p -> p.number to store.loadPool(userId, p.number)?.series.orEmpty().map { it.id } }.filterValues { it.isNotEmpty() } + val carriedWorks = catalogue.worksOf(ids.values.flatten()).values.toSet() + val (arrivals, _) = store.loadArrivals(userId) + val newToLibrary = arrivals.count { nowMs - it.firstSeenMs < NEW_TO_LIBRARY_DAYS * 24 * 60 * 60_000L } + val reports = buildDeskReports(evidence, collections, ids, released, carriedWorks, catalogue.originalTitles(released.map { it.id }), newToLibrary, catalogue.complete(), nowMs) + runCatching { cache.writeText(JSONObject().put("key", key).put("savedMs", nowMs).put("reports", JSONObject().apply { reports.forEach { (m, r) -> put(m.name, r.toJson()) } }).toString()) } + val b = reports.getValue(DirectorMode.Balanced) + android.util.Log.i("OrbitSchedule", "director newlyReleased=${b.newlyReleased} read=${b.scanned} strong=${b.strong} asks=${b.asks.size} collections=${b.collections} tookMs=${b.tookMs}") + reports } /** The first sentence of a description, kept short for a card. */ @@ -127,7 +170,8 @@ internal fun DirectorChair(load: (DirectorMode) -> DeskReport?, first: FocusRequ Spacer(Modifier.width(10.dp)) DirectorMode.values().forEachIndexed { i, m -> var focused by remember { mutableStateOf(false) } - Text(m.label, Modifier.then(if (i == 1) Modifier.focusRequester(first) else Modifier).onFocusChanged { focused = it.isFocused; if (it.isFocused) mode = m }.focusable() + Text(m.label, Modifier.then(if (i == 1) Modifier.focusRequester(first) else Modifier).onFocusChanged { focused = it.isFocused } + .clickable { mode = m } .background(if (m == mode) ChairGold else ChairPanel, RoundedCornerShape(12.dp)).border(if (focused) 2.dp else 0.dp, Color.White, RoundedCornerShape(12.dp)) .padding(horizontal = 10.dp, vertical = 3.dp), color = if (m == mode) ChairNavy else Color.White, fontSize = 11.sp, fontWeight = FontWeight.SemiBold) } @@ -135,7 +179,7 @@ internal fun DirectorChair(load: (DirectorMode) -> DeskReport?, first: FocusRequ Text("Auto-approval: OFF", color = ChairMint, fontSize = 11.sp, fontWeight = FontWeight.SemiBold) } val r = report - if (r == null) { Text("Reading the library's evidence…", color = Muted, fontSize = 12.sp); return@Column } + if (r == null) { Text("Working out this week's report. The first time takes a little while; after that the Chair opens straight away.", color = Muted, fontSize = 12.sp); return@Column } Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(10.dp)) { Column(Modifier.weight(.9f).background(ChairPanel, RoundedCornerShape(8.dp)).padding(10.dp), verticalArrangement = Arrangement.spacedBy(3.dp)) { Text("THIS WEEK", color = Color.White, fontFamily = Anton, fontSize = 14.sp) @@ -148,8 +192,9 @@ internal fun DirectorChair(load: (DirectorMode) -> DeskReport?, first: FocusRequ Text("Held as proposals. Nothing is booked.", color = Muted, fontSize = 10.sp) // Scan status, always visible: what hasn't been read yet is said, not hidden. val gaps = listOfNotNull("${r.unread} not read yet".takeIf { r.unread > 0 }, "no collections read, so franchises unknown".takeIf { r.collections == 0 }, + "franchises unknown: none of the library's ${r.collections} collections is a franchise".takeIf { r.collections > 0 && r.franchises == 0 }, "library list still importing".takeIf { !r.catalogueComplete }) - Text(if (gaps.isEmpty()) "Scan complete: ${r.scanned} read, ${r.collections} collections" else "Scan: " + gaps.joinToString("; "), color = if (gaps.isEmpty()) Muted else ChairGold, fontSize = 10.sp) + Text(if (gaps.isEmpty()) "Scan complete: ${r.scanned} read, ${r.franchises} franchise collections" else "Scan: " + gaps.joinToString("; "), color = if (gaps.isEmpty()) Muted else ChairGold, fontSize = 10.sp) } Column(Modifier.weight(1.3f), verticalArrangement = Arrangement.spacedBy(5.dp)) { Text("WORTH A LOOK", color = Color.White, fontFamily = Anton, fontSize = 14.sp) diff --git a/android/app/src/main/java/tv/orbit/classic/DirectorScoring.kt b/android/app/src/main/java/tv/orbit/classic/DirectorScoring.kt index 68dfec24..0a049773 100644 --- a/android/app/src/main/java/tv/orbit/classic/DirectorScoring.kt +++ b/android/app/src/main/java/tv/orbit/classic/DirectorScoring.kt @@ -131,17 +131,33 @@ internal class ChannelText(pools: Map>, evidence: Map = tokens(text).groupingBy { it }.eachCount().mapValues { (word, count) -> (1 + ln(count.toDouble())) * ln((n + 1.0) / ((df[word] ?: 0) + 1.0)) } private fun norm(v: Map): Map { val s = sqrt(v.values.sumOf { it * it }).takeIf { it > 0 } ?: 1.0; return v.mapValues { it.value / s } } - fun similarity(text: String, channel: Int): Double { val c = centroids[channel] ?: return 0.0; return norm(vec(text)).entries.sumOf { (k, x) -> x * (c[k] ?: 0.0) } } + /** A description's word weights, worked out once and reused for every channel (30 times fewer passes on the box). */ + private val normalised = HashMap>() + fun similarity(text: String, channel: Int): Double { + val c = centroids[channel] ?: return 0.0 + val v = synchronized(normalised) { normalised.getOrPut(text) { norm(vec(text)) } } + return v.entries.sumOf { (k, x) -> x * (c[k] ?: 0.0) } + } fun has(channel: Int) = channel in centroids } /** A franchise or series relationship from Emby's own collections: the channels its fellow members are on. Unknown when no collection says. */ -internal class FranchiseLinks(private val channelsOf: Map>, private val collectionOf: Map) { +internal class FranchiseLinks(private val channelsOf: Map>, private val collectionOf: Map, private val britishLists: Map = emptyMap()) { fun channels(id: String): Set? = collectionOf[id]?.let { channelsOf[it] } fun collection(id: String): String? = collectionOf[id] + /** The British broadcaster's list a title is on in the library (BBC, Channel 4, ITV, Sky, BritBox), as verified British origin. */ + fun britishList(id: String): String? = britishLists[id] companion object { val Unknown = FranchiseLinks(emptyMap(), emptyMap()) } } +/** + * Which of the library's collections are franchises: only TMDB-style "... Collection" sets. The library's other collections are + * curated lists (Trending, IMDB Top 250, Netflix, BBC - Shows...) and say nothing about franchises, so they never link titles. + */ +internal val FranchiseCollection = Regex("\\bCollection$", RegexOption.IGNORE_CASE) +/** The library's broadcaster lists that verify British origin. */ +internal val BritishLists = Regex("^(BBC\\b|Channel 4\\b|ITV\\b|Sky Originals|Britbox Originals)", RegexOption.IGNORE_CASE) + private fun foreign(e: TitleEvidence): String? { e.rating?.takeIf { ForeignBoard.containsMatchIn(it) }?.let { return "rated by a non-English-language board ($it)" } val original = e.originalTitle.orEmpty() @@ -188,10 +204,10 @@ internal fun channelScore(e: TitleEvidence, b: Brief, text: ChannelText, links: } if (ch == 101 && (g intersect setOf("Game Show", "Reality", "Talk")).isNotEmpty()) return 0.0 to listOf("a game, reality or talk show, not a sitcom") val countries = e.countries.orEmpty().joinToString(" "); val studios = e.studios.orEmpty().joinToString(" ") - val british = Uk.containsMatchIn(countries) || UkStudio.containsMatchIn(studios) - if (ch == 309 && !british) return 0.0 to listOf(if (e.countries.isNullOrEmpty() && e.studios.isNullOrEmpty()) "British origin not verified" else "not British by its countries or studios") + val british = Uk.containsMatchIn(countries) || UkStudio.containsMatchIn(studios) || links.britishList(e.id) != null + if (ch == 309 && !british) return 0.0 to listOf(if (e.countries.isNullOrEmpty() && e.studios.isNullOrEmpty()) "British origin not verified" else "not British by its countries, studios or lists") if (b.uk) { - if (british) { s += .1; ev += "British" } + if (british) { s += .1; ev += links.britishList(e.id)?.let { "British (on the library's $it list)" } ?: "British" } else if (!e.countries.isNullOrEmpty() || !e.studios.isNullOrEmpty()) { s *= .6; ev += "not British by its studios or countries" } } if (b.kids && rating.isNotEmpty() && rating !in KidsOk) { s *= .5; ev += "rated $rating" } diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt index 19e07d0f..f74e5bae 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -271,7 +271,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea catch (cancelled: CancellationException) { throw cancelled } catch (_: Exception) { /* Tried again next hour. */ } // Stage C's light daily library refresh, in the background. A failure changes nothing and is tried next hour. - try { withContext(Dispatchers.IO) { scheduler.readEvidence(active, active.accountId, catalogue) } } + try { withContext(Dispatchers.IO) { scheduler.readEvidence(active, active.accountId, catalogue); directorReports(scheduleStore, catalogue, active.accountId) } } catch (cancelled: CancellationException) { throw cancelled } catch (failure: Exception) { android.util.Log.w("OrbitSchedule", "evidence failed=${failure.javaClass.simpleName}") } try { withContext(Dispatchers.IO) { scheduler.refreshArrivals(active, active.accountId, catalogue) } } @@ -502,25 +502,10 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea val works = catalogue.worksOf(poolIds).entries.associate { (id, work) -> work to id } return arrivalsReport(arrivals, released, scheduleStore.loadNewEpisodes(active.accountId), works, scheduleStore.loadBooked(active.accountId), System.currentTimeMillis()) } - /** The Director's Chair's report: read back if nothing it reads has changed in the last six hours, else worked out afresh. Read only. */ + /** The Director's Chair's report, read back from the copy the background round keeps fresh; worked out here only if there's none. */ fun loadDirectorReport(mode: DirectorMode): DeskReport? { val active = session ?: return null - val now = System.currentTimeMillis() - val evidence = scheduleStore.evidenceFile(); val collections = scheduleStore.collectionsFile(); val cache = scheduleStore.directorFile() - runCatching { JSONObject(cache.readText()) }.getOrNull()?.takeIf { it.optString("mode") == mode.name }?.let { saved -> - val report = DeskReport.of(saved) - if (now - report.computedMs < 6 * 60 * 60_000L && report.computedMs > evidence.lastModified() && report.computedMs > collections.lastModified()) return report - } - val today = java.time.LocalDate.now() - val released = catalogue.releasedBetween(today.minusDays(NEWLY_RELEASED_DAYS).toString(), today.toString(), 2_000) - val pools = SmartChannels.associate { p -> p.number to scheduleStore.loadPool(active.accountId, p.number)?.series.orEmpty().map { it.id } }.filterValues { it.isNotEmpty() } - val carriedWorks = catalogue.worksOf(pools.values.flatten()).values.toSet() - val (arrivals, _) = scheduleStore.loadArrivals(active.accountId) - val newToLibrary = arrivals.count { now - it.firstSeenMs < NEW_TO_LIBRARY_DAYS * 24 * 60 * 60_000L } - val report = buildDeskReport(evidence, collections, pools, released, carriedWorks, catalogue.originalTitles(released.map { it.id }), newToLibrary, catalogue.complete(), mode, now) - runCatching { cache.writeText(report.toJson().put("mode", mode.name).toString()) } - android.util.Log.i("OrbitSchedule", "director mode=${mode.name} newlyReleased=${report.newlyReleased} read=${report.scanned} strong=${report.strong} picks=${report.picks.size} asks=${report.asks.size} tookMs=${report.tookMs}") - return report + return directorReports(scheduleStore, catalogue, active.accountId)?.get(mode) } SettingsScreen(settingsSection, { settingsSection = it }, modifier, busy, message, HttpsEmbyTransport.SERVER, sample?.total, arrivals = { detail, first -> NewArrivalsDetail(::loadArrivalsReport, first, detail) }, diff --git a/android/app/src/main/java/tv/orbit/classic/ScheduleStore.kt b/android/app/src/main/java/tv/orbit/classic/ScheduleStore.kt index 536d53db..2cd4c4e2 100644 --- a/android/app/src/main/java/tv/orbit/classic/ScheduleStore.kt +++ b/android/app/src/main/java/tv/orbit/classic/ScheduleStore.kt @@ -54,6 +54,8 @@ internal class ScheduleStore(private val directory: File) { fun collectionsFile() = File(directory, "collections-0.jsonl") /** The Director's Chair's last report, so the screen opens straight away. */ fun directorFile() = File(directory, "director-0.json") + /** When the channels' pools last changed, without reading them: their files' times together. */ + fun poolsStamp(): Long = directory.listFiles { f -> f.name.startsWith("episodes-") && f.name.endsWith(".json") }?.sumOf { it.lastModified() } ?: 0L /** Replaces in one step, keeping the last good copy. An interrupted write can't damage either. */ private fun write(target: File, root: JSONObject) { diff --git a/android/app/src/test/java/tv/orbit/classic/DirectorChairTest.kt b/android/app/src/test/java/tv/orbit/classic/DirectorChairTest.kt index 423bcbb3..766f3130 100644 --- a/android/app/src/test/java/tv/orbit/classic/DirectorChairTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/DirectorChairTest.kt @@ -52,8 +52,8 @@ class DirectorChairTest { 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) + val (links, count, franchises) = franchiseLinks(sets, pools) + assertEquals(1, count); assertEquals(1, franchises) 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) } @@ -79,8 +79,25 @@ class DirectorChairTest { assertTrue(channelScore(evidence.getValue("l"), Briefs.first { it.number == 107 }, text).first < .35) } + @Test fun curatedListsAreNotFranchisesButBroadcasterListsVerifyBritishOrigin() { + // The library's collections are mostly curated lists: being on IMDB Top 250 or Netflix together links nothing. + val a = line("c7", "Gangland", "Movie", listOf("Crime"), "A London gangster plans one last heist.") + val (ev, sets) = files(listOf(a), listOf( + JSONObject().put("id", "b2").put("name", "IMDB Top 250").put("members", JSONArray(listOf("e1", "c7"))), + JSONObject().put("id", "b3").put("name", "Netflix Movies").put("members", JSONArray(listOf("e1", "c7"))), + JSONObject().put("id", "b4").put("name", "BBC - Shows").put("members", JSONArray(listOf("c7"))))) + val (links, count, franchises) = franchiseLinks(sets, pools) + assertEquals(3, count); assertEquals(0, franchises) + assertNull(links.channels("c7")); assertNull(links.collection("c7")) + assertEquals("BBC - Shows", links.britishList("c7")) + val evidence = mapOf("c7" to TitleEvidence.of(a)) + val britx = channelScore(evidence.getValue("c7"), Briefs.first { it.number == 309 }, ChannelText(emptyMap(), evidence), links) + assertTrue(britx.first > 0); assertTrue(britx.second.any { "BBC - Shows" in it }) + assertTrue(ev.exists()) + } + @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 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, 0, 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."))