0.99.4: weighted rotation on Orbit 1, Orbit 2, Gold, Paradox, Evidence, Heroes and Vortex
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m11s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m31s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 02:00:26 +00:00
co-authored by Claude Opus 5.5
parent 63d2505c61
commit e21c746a8e
10 changed files with 393 additions and 17 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic"
minSdk = 26
targetSdk = 36
versionCode = 133
versionName = "0.99.3-adaptive-film-rest"
versionCode = 134
versionName = "0.99.4-weighted-seven"
}
buildFeatures { compose = true }
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
@@ -373,3 +373,31 @@ internal val PpvSunday = listOf("WWE WrestleMania III", "WCW Capital Combat: The
"WWE WrestleMania X-Seven", "ECW Guilty as Charged 1999", "WWE In Your House 16: Canadian Stampede", "NJPW Dominion 6.9 in Osaka-jo Hall",
"IMPACT Wrestling: Bound for Glory 2019", "WCW Bash at the Beach 1996", "WWE WrestleMania XV", "NWA Chi-Town Rumble", "AEW Full Gear (2021)",
"WWE Survivor Series 1997", "ECW November To Remember 1998", "WCW Spring Stampede 1994", "WWE King of the Ring 1998")
// Weighted rotation for seven more channels (approved 4 November 2026). Rewind and Dark Files wait on a repeat investigation;
// Riot, Terra, Ring X and Junior keep equal turns.
/** Orbit 1's tiers, from docs/channels/orbit-1.md (approved 4 November 2026): core 3, surprises 1, everything else 2. */
internal val Orbit1Tiers: Map<String, Double> get() =
listOf("Boy Meets World", "Cheers", "Everybody Loves Raymond", "Family Matters", "Frasier", "Full House", "Miranda", "My Family", "Not Going Out", "Outnumbered", "Sabrina, The Teenage Witch", "Saved by the Bell", "The Big Bang Theory", "The Fresh Prince of Bel-Air", "The King of Queens", "The Wonder Years").associate { seriesKey(it) to TIER_CORE } +
listOf("Ballykissangel", "Doc Martin", "Heartbeat", "Little House on the Prairie", "The Waltons").associate { seriesKey(it) to TIER_SURPRISE }
/** Orbit 2's tiers, from docs/channels/orbit-2.md (approved 4 November 2026): core 3, surprises 1, everything else 2. */
internal val Orbit2Tiers: Map<String, Double> get() =
listOf("Airwolf", "Countdown", "Gladiators", "Have I Got News for You", "Knight Rider", "MacGyver", "Mastermind", "Pointless", "QI", "Robot Wars", "Takeshi's Castle", "The A-Team", "The Crystal Maze", "University Challenge", "Would I Lie to You?").associate { seriesKey(it) to TIER_CORE } +
listOf("Are You Afraid of the Dark?", "Eerie, Indiana", "Goosebumps", "Quantum Leap", "Tales from the Crypt").associate { seriesKey(it) to TIER_SURPRISE }
/** Gold's tiers, from docs/channels/orbit-gold.md (approved 4 November 2026): core 3, surprises 1, everything else 2. */
internal val GoldTiers: Map<String, Double> get() =
listOf("Blackadder", "Dad's Army", "Father Ted", "Fawlty Towers", "Keeping Up Appearances", "One Foot in the Grave", "Only Fools and Horses", "Open All Hours", "Porridge", "The Vicar of Dibley").associate { seriesKey(it) to TIER_CORE } +
listOf("Lovejoy", "Minder", "The Two Ronnies").associate { seriesKey(it) to TIER_SURPRISE }
/** Paradox's tiers, from docs/channels/paradox.md (approved 4 November 2026): core 3, surprises 1, everything else 2. */
internal val ParadoxTiers: Map<String, Double> get() =
listOf("Buffy the Vampire Slayer", "Doctor Who (2005)", "Doctor Who (2023)", "Star Trek: The Next Generation", "Supernatural", "The X-Files").associate { seriesKey(it) to TIER_CORE } +
listOf("Twin Peaks").associate { seriesKey(it) to TIER_SURPRISE }
/** Evidence's tiers, from docs/channels/evidence.md (approved 4 November 2026): core 3, surprises 1, everything else 2. */
internal val EvidenceTiers: Map<String, Double> get() =
listOf("A Touch of Frost", "Bones", "CSI: Crime Scene Investigation", "Columbo", "Criminal Minds", "Inspector Morse", "Law & Order", "Midsomer Murders", "NCIS", "Vera").associate { seriesKey(it) to TIER_CORE }
/** Heroes' tiers, from docs/channels/heroes.md (approved 4 November 2026): core 3, surprises 1, everything else 2. */
internal val HeroesTiers: Map<String, Double> get() =
listOf("Batman Beyond", "Batman: The Animated Series", "Justice League", "Spider-Man: The Animated Series", "Superman: The Animated Series", "Teen Titans", "The Batman", "X-Men: The Animated Series").associate { seriesKey(it) to TIER_CORE }
/** Vortex's tiers, from docs/channels/vortex.md (approved 4 November 2026): core 3, surprises 1, everything else 2. */
internal val VortexTiers: Map<String, Double> get() =
listOf("Batman Beyond", "Cardcaptor Sakura", "Dragon Ball", "Dragon Ball GT", "Dragon Ball Z", "Jonny Quest", "Gundam Wing", "Mobile Suit Gundam Wing", "Mortal Kombat: Defenders of the Realm", "Outlaw Star", "Pokémon", "Sailor Moon", "Samurai Jack", "Tenchi Muyo", "Tenchi Muyo! Ryo-Ohki", "Tenchi Universe", "Tenchi Muyo! Tenchi Universe", "The Big O", "ThunderCats", "Yu Yu Hakusho", "Yu-Gi-Oh! Duel Monsters").associate { seriesKey(it) to TIER_CORE }
@@ -88,7 +88,7 @@ internal val SmartChannels = listOf(
SuggestionRule("day", "Daytime", "Movie", listOf("Science Fiction", "Action"), 1975..2005, 6.5f, setOf("NC-17", "X"), 40, NotCultCinema + "Adventure", 70, 7.9f),
SuggestionRule("day", "Daytime", "Movie", listOf("Thriller", "Mystery"), 1975..2005, 6.5f, setOf("NC-17", "X"), 30, NotCultCinema + "Science Fiction", 70, 7.9f),
SuggestionRule("late", "Late night", "Movie", listOf("Horror"), 1970..2010, 6f, emptySet(), 90, NotCultCinema, 70))),
ChannelProgramming(VORTEX_NUMBER, "Vortex", VortexShows, seriesCount = 40, finishTogether = true, exactTitles = true, englishAudio = false,
ChannelProgramming(VORTEX_NUMBER, "Vortex", VortexShows, seriesCount = 40, finishTogether = true, exactTitles = true, englishAudio = false, tierWeights = VortexTiers,
dayParts = VortexDayParts,
suggestionRules = listOf(
SuggestionRule("movie", "Movie Night", "Movie", listOf("Animation"), 1985..2025, 5f, setOf("NC-17", "X"), 30, setOf("Documentary"), 30, titleContains = "Dragon Ball"),
@@ -99,7 +99,8 @@ internal val SmartChannels = listOf(
ChannelProgramming(201, "Terra", TerraShows, seriesCount = TerraShows.size, finishTogether = true, exactTitles = true, dayParts = TerraDayParts),
ChannelProgramming(TOTS_NUMBER, "Tots", TotsShows, seriesCount = 40, finishTogether = true, exactTitles = true, dayParts = TotsDayParts, shuffleEpisodes = true,
tierWeights = TotsTiers),
ChannelProgramming(106, "Paradox", ParadoxShows, seriesCount = 20, finishTogether = true, exactTitles = true, dayParts = ParadoxDayParts, shuffleTitles = ParadoxStandalones.toSet())) +
ChannelProgramming(106, "Paradox", ParadoxShows, seriesCount = 20, finishTogether = true, exactTitles = true, dayParts = ParadoxDayParts, shuffleTitles = ParadoxStandalones.toSet(),
tierWeights = ParadoxTiers)) +
ChannelPresets.filter { it.smartOnly }.map { ChannelProgramming(it.number, it.name, it.searches, seriesCount = if (it.films) it.searches.size else 60, finishTogether = !it.films, exactTitles = true,
filmRestMs = if (it.films) 7 * 24 * 60 * 60_000L else null,
suggestionRules = SmartChannelRules[it.number].orEmpty(), dayParts = SmartChannelParts[it.number].orEmpty(), shuffleTitles = SmartChannelMixed[it.number].orEmpty(),
@@ -108,8 +109,9 @@ internal val SmartChannels = listOf(
/** Film channels whose rest adapts to their pools: Premiere, whose pool runs well past a week (After Dark is set above). Proposed 4 November 2026. */
private val AdaptiveFilmRestChannels get() = setOf(301)
/** Editorially weighted rotation, per channel, once its tiers are approved: Orbit Three (0.97.0), then Odyssey, Wild, Orbit X and ToonZ (0.98.0). */
private val SmartChannelTiers: Map<Int, Map<String, Double>> get() = mapOf(103 to ThreeTiers, 202 to OdysseyTiers, 203 to WildTiers, 603 to OrbitXTiers, 605 to ToonZTiers)
/** Editorially weighted rotation, per channel, once its tiers are approved: Orbit Three (0.97.0), Odyssey, Wild, Orbit X and ToonZ (0.98.0), then Orbit 1, Orbit 2, Gold, Evidence and Heroes (0.99.4; Vortex and Paradox are set above). */
private val SmartChannelTiers: Map<Int, Map<String, Double>> get() = mapOf(103 to ThreeTiers, 202 to OdysseyTiers, 203 to WildTiers, 603 to OrbitXTiers, 605 to ToonZTiers,
101 to Orbit1Tiers, 102 to Orbit2Tiers, 104 to GoldTiers, 107 to EvidenceTiers, 602 to HeroesTiers)
/** Shows that play in a mixed order on channels whose identity is agreed. See ChannelIdentities.kt. */
private val SmartChannelMixed: Map<Int, Set<String>> get() = mapOf(101 to Orbit1Mixed, 102 to Orbit2Mixed, 103 to ThreeMixed, 104 to GoldMixed, 105 to RiotMixed,
@@ -404,7 +406,11 @@ internal fun extendWeighted(pool: List<PoolSeries>, cursor: ScheduleCursor, from
val series = eligible.minWith(compareBy<PoolSeries> { tally[it.id]!! }.thenBy { pool.indexOf(it) })
val episode = following(series)
val why = "$block; weighted: lowest tally for its tier (${"%.0f".format(tally[series.id])})" + (if (eligible.size < clear.size) ", others resting or just played" else "") +
if (unclashed.isEmpty()) "; fallback: every show here airs elsewhere then" else ""
when {
unclashed.isEmpty() -> "; fallback: every show here airs elsewhere then"
series.id == last && unclashed.size < available.size -> "; again, as the others here air elsewhere then"
else -> ""
}
val item = if (series.isFilm) SampleItem(series.title, "Movie", episode.durationMs / 60_000, "", episode.id, episode.durationMs) else scheduledItem(series.title, episode)
entries += ScheduleEntry(series.id, episode.mark, ScheduledMedia(item, episode.sourceId, episode.durationMs), start, why, if (series in available) part?.key.orEmpty() else "")
val weight = part?.takeIf { series in available }?.weights?.get(seriesKey(series.title)) ?: weightOf(series)
@@ -66,7 +66,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
connection.connectTimeout = 10_000
connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.99.3\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.99.4\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -33,7 +33,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
next.instanceFollowRedirects = false
next.connectTimeout = 10_000
next.readTimeout = 20_000
next.setRequestProperty("User-Agent", "OrbitTV/0.99.3")
next.setRequestProperty("User-Agent", "OrbitTV/0.99.4")
next.setRequestProperty("Accept-Encoding", "identity")
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {
@@ -21,7 +21,9 @@ class WeightedRolloutReplayTest {
private val day = 24 * 60 * 60_000L
private val hour = 60 * 60_000L
private val channels = listOf(TOTS_NUMBER, 605, 202, 203, 603)
/** Channels weighted on the box as installed (0.99.3), for the other channels' plans that each one avoids. */
private val installedWeighted = setOf(103, 202, 203, 603, 605, 614)
private val channels = (System.getenv("ORBIT_ROLLOUT_CHANNELS") ?: "614,605,202,203,603").split(",").map { it.trim().toInt() }
private fun plan(file: File): ChannelPlan {
val root = JSONObject(file.readText()); val rows = root.getJSONArray("entries"); val t = root.getJSONObject("tail"); val marks = t.getJSONObject("marks")
@@ -57,7 +59,7 @@ class WeightedRolloutReplayTest {
while (now < end) {
if (restartEvery > 0 && ++step % restartEvery == 0) { ScheduleStore(folder).savePlan("user", programming.number, current); current = ScheduleStore(folder).loadPlan("user", programming.number)!! }
current = topUpPlan(current, current.tail, series, now, programming.filmRestMs, programming.finishTogether, programming.dayParts, zone, avoid,
shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = weightOf) ?: break
shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = weightOf, adaptiveRest = programming.adaptiveFilmRest) ?: break
current.entries.filter { e -> all.none { it.startMs == e.startMs } }.forEach { all += it }
now += 6 * hour
}
@@ -66,6 +68,7 @@ class WeightedRolloutReplayTest {
return if (keepCommitted) all.filter { it.startMs < end } else all.filter { it.startMs >= committed.endMs && it.startMs < end }
}
private fun local(ms: Long) = java.time.Instant.ofEpochMilli(ms).atZone(zone).toLocalDateTime().withNano(0)
private fun pct(x: Double) = "%.0f%%".format(100 * x)
private fun report(label: String, entries: List<ScheduleEntry>, series: List<PoolSeries>, programming: ChannelProgramming, weightOf: (PoolSeries) -> Double, others: ProgrammeClash, out: StringBuilder): Map<String, Int> {
@@ -94,7 +97,11 @@ class WeightedRolloutReplayTest {
val waits = inBlocks.associate { s -> s.title to (listOf(first) + entries.filter { it.seriesId == s.id }.map { it.startMs } + listOf(last)).zipWithNext().maxOf { (a, b) -> b - a } / day.toDouble() }
val never = inBlocks.filter { s -> entries.none { it.seriesId == s.id } }.map { it.title }
out.appendLine(" starvation: never aired ${never.ifEmpty { listOf("none") }.joinToString()}; longest waits " + waits.entries.sortedByDescending { it.value }.take(4).joinToString { "${it.key} ${"%.1f".format(it.value)} d" })
val twice = entries.zipWithNext().count { (a, b) -> a.seriesId == b.seriesId && weightedAt(b) }
// A show twice running is only allowed when every other show in its block is on another channel at that moment.
// A block of one show, such as Gold's Sunday Only Fools and Horses, plays it back to back by design.
fun choice(e: ScheduleEntry) = dayPartFor(series, programming.dayParts, e.startMs, zone).first.size > 1
val twice = entries.zipWithNext().count { (a, b) -> a.seriesId == b.seriesId && weightedAt(b) && choice(b) && "air elsewhere then" !in b.why && "airs elsewhere then" !in b.why }
val twiceForClash = entries.zipWithNext().count { (a, b) -> a.seriesId == b.seriesId && weightedAt(b) && choice(b) } - twice
val clashes = entries.count { others(byId.getValue(it.seriesId), it.startMs, it.endMs) }
val ordered = series.filter { !(programming.shuffleEpisodes || programming.mixes(it)) }.associateBy { it.id }
val back = entries.filter { it.seriesId in ordered }.groupBy { it.seriesId }.values.sumOf { es -> es.zipWithNext().count { (a, b) -> b.mark <= a.mark && b.mark != ordered.getValue(a.seriesId).episodes.first().mark } }
@@ -104,7 +111,7 @@ class WeightedRolloutReplayTest {
val outside = entries.count { e -> dayPartFor(series, programming.dayParts, e.startMs, zone).first.none { it.id == e.seriesId } }
val bursts = entries.indices.count { i -> val w = entries.drop(i).takeWhile { it.startMs < entries[i].startMs + 3 * hour }; w.size >= 4 && w.count { it.seriesId == entries[i].seriesId } * 2 > w.size }
out.appendLine(" on another channel at the same time: $clashes")
out.appendLine(" rules: same show twice running (weighted blocks) $twice; three-hour stretches over half one show $bursts; in-order stepping back $back; shuffled off its deck $offDeck; gaps $gaps; outside its block $outside")
out.appendLine(" rules: same show twice running (weighted blocks with a choice) $twice, plus $twiceForClash where every other show airs elsewhere; three-hour stretches over half one show $bursts; in-order stepping back $back; shuffled off its deck $offDeck; gaps $gaps; outside its block $outside")
return mapOf("sameDay" to sameDayWeighted, "twice" to twice, "back" to back, "offDeck" to offDeck, "gaps" to gaps, "outside" to outside, "never" to never.size, "clashes" to clashes)
}
@@ -114,7 +121,7 @@ class WeightedRolloutReplayTest {
"every other channel's programmes as the box does. Copies of the box's files from 3 November.\n\n")
// Every other channel's four weeks on today's rules, for clash avoidance.
val baseline = SmartChannels.filter { File(dir, "schedule-${it.number}.json").exists() && File(dir, "episodes-${it.number}.json").exists() }.associate { p ->
p.number to replay(plan(File(dir, "schedule-${p.number}.json")), pool(File(dir, "episodes-${p.number}.json")), p, p.tierWeights?.let { p::weightOf }.takeIf { p.number == 103 }, keepCommitted = true)
p.number to replay(plan(File(dir, "schedule-${p.number}.json")), pool(File(dir, "episodes-${p.number}.json")), p, p.tierWeights?.let { p::weightOf }.takeIf { p.number in installedWeighted }, keepCommitted = true)
}
for (number in channels) {
val programming = SmartChannels.first { it.number == number }
@@ -129,9 +136,10 @@ class WeightedRolloutReplayTest {
val weighted = replay(committed, series, programming, weightOf, others)
val restarted = replay(committed, series, programming, weightOf, others, restartEvery = 3)
report("Today", today, series, programming, weightOf, others, out)
val after = report("Weighted (0.98.0)", weighted, series, programming, weightOf, others, out)
val after = report("Weighted (as built)", weighted, series, programming, weightOf, others, out)
assertEquals("${programming.name}: a restart changes nothing", weighted, restarted)
out.appendLine(" a save and reload every 18 hours gives the identical four weeks: true")
File(dir, "weighted-rollout-replay.txt").writeText(out.toString())
for (key in listOf("sameDay", "twice", "back", "offDeck", "gaps", "outside", "never")) assertEquals("${programming.name}: $key", 0, after[key])
// Blocks left on equal turns keep today's rule. Their programmes start at slightly different times, as the day before
// them now ends at different moments, so the sequence shifts at block edges; the rule and the shares stay the same.
@@ -190,7 +190,13 @@ class WeightedRotationTest {
}
@Test fun theApprovedChannelsAreWeightedAndTotsBedtimeIsNot() {
assertEquals(listOf(103, 202, 203, 603, 605, 614), SmartChannels.filter { it.tierWeights != null }.map { it.number }.sorted())
assertEquals(listOf(101, 102, 103, 104, 106, 107, 202, 203, 601, 602, 603, 605, 614), SmartChannels.filter { it.tierWeights != null }.map { it.number }.sorted())
// Riot, Terra, Ring X and Junior keep equal turns; Rewind and Dark Files wait on their repeat investigation.
assertTrue(SmartChannels.filter { it.number in setOf(105, 201, 401, 611, 604, 204) }.all { it.tierWeights == null })
assertEquals(TIER_CORE, SmartChannels.first { it.number == 101 }.weightOf(show("The Wonder Years", 1)), 0.0)
assertEquals(TIER_SURPRISE, SmartChannels.first { it.number == 101 }.weightOf(show("Heartbeat", 1)), 0.0)
assertEquals(TIER_CORE, SmartChannels.first { it.number == 601 }.weightOf(show("Tenchi Muyo! Ryo-Ohki", 1)), 0.0)
assertEquals(TIER_CORE, SmartChannels.first { it.number == 106 }.weightOf(show("Doctor Who (2023)", 1)), 0.0)
val tots = SmartChannels.first { it.number == TOTS_NUMBER }
assertEquals(listOf(true, true, false, false), tots.dayParts.map { it.weighted })
val toonz = SmartChannels.first { it.number == 605 }
@@ -202,7 +208,7 @@ class WeightedRotationTest {
assertEquals(TIER_SURPRISE, SmartChannels.first { it.number == 203 }.weightOf(show("Dirty Jobs", 1)), 0.0)
assertEquals(TIER_CORE, SmartChannels.first { it.number == 603 }.weightOf(show("Mighty Morphin Power Rangers", 1)), 0.0)
assertEquals(TIER_CORE, SmartChannels.first { it.number == 202 }.weightOf(show("Cosmos", 1)), 0.0)
assertTrue(SmartChannels.filter { it.number !in setOf(103, 202, 203, 603, 605, 614) }.all { p -> p.dayParts.all { it.weighted && it.weights.isEmpty() } })
assertTrue(SmartChannels.filter { it.number != 614 && it.number != 605 }.all { p -> p.dayParts.all { it.weighted && it.weights.isEmpty() } })
}
@Test fun orbitThreesTiers() {