0.98.0: weighted rotation on Odyssey, Wild, Orbit X, ToonZ and Tots Morning and Playtime
Per-block switch keeps Tots' Wind Down and Night on equal turns; per-block weights put ToonZ's teatime trio level with the core in teatime only. Tiers from each channel's brief. Four-week real-pool replays with clash avoidance and restarts, and fingerprints against 0.97.0, in docs/replays. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@ import java.io.File
|
||||
* Four weeks of top-ups on every channel from copies of the box's committed plans and pools, run by hand:
|
||||
* ORBIT_REPLAY_DIR=<copies of the box's files> ./gradlew :app:testDebugUnitTest --tests '*ReplayFingerprintTest*'
|
||||
* Writes replay-fingerprints.txt there, one line per channel: a fingerprint of every programme booked and why. Run it
|
||||
* on two versions of the app to show which channels a change touches. Only uses what every version has.
|
||||
* on two versions of the app to show which channels a change touches. Needs 0.97.0 or later (weighted rotation).
|
||||
*/
|
||||
class ReplayFingerprintTest {
|
||||
private val dir = System.getenv("ORBIT_REPLAY_DIR")?.let(::File)
|
||||
@@ -51,7 +51,7 @@ class ReplayFingerprintTest {
|
||||
val all = committed.entries.toMutableList()
|
||||
while (now < end) {
|
||||
current = topUpPlan(current, current.tail, series, now, programming.filmRestMs, programming.finishTogether, programming.dayParts, zone,
|
||||
shuffle = programming.shuffleEpisodes, mixed = programming::mixes) ?: break
|
||||
shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = programming.tierWeights?.let { programming::weightOf }) ?: break
|
||||
current.entries.filter { e -> all.none { it.startMs == e.startMs } }.forEach { all += it }
|
||||
now += 6 * 60 * 60_000L
|
||||
}
|
||||
|
||||
+60
-52
@@ -2,45 +2,26 @@ package tv.orbit.classic
|
||||
|
||||
import org.json.JSONObject
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Assume.assumeTrue
|
||||
import org.junit.Test
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* The rollout proposal after Orbit Three (4 November 2026): read-only, nothing here is used by the app. For Tots, ToonZ,
|
||||
* Odyssey, Wild and Orbit X, four weeks of new bookings after each committed plan, from copies of the box's files, both
|
||||
* the rule each channel has today and weighted rotation with the tiers proposed from its own brief:
|
||||
* ORBIT_REPLAY_DIR=<copies of the box's files> ./gradlew :app:testDebugUnitTest --tests '*RolloutProposalReplayTest*'
|
||||
* Writes rollout-proposal-replay.txt there.
|
||||
* 0.98.0's check: weighted rotation on Odyssey, Wild, Orbit X, ToonZ and Tots (Morning and Playtime only), as configured in
|
||||
* the app. For each, four weeks of new bookings after its committed plan, from copies of the box's files, today's rule
|
||||
* against the app's, with other channels' programmes avoided as the box avoids them, and once more with a save and
|
||||
* reload every 18 hours. Run by hand:
|
||||
* ORBIT_REPLAY_DIR=<copies of the box's files> ./gradlew :app:testDebugUnitTest --tests '*WeightedRolloutReplayTest*'
|
||||
* Writes weighted-rollout-replay.txt there, and fails on any broken rule.
|
||||
*/
|
||||
class RolloutProposalReplayTest {
|
||||
class WeightedRolloutReplayTest {
|
||||
private val dir = System.getenv("ORBIT_REPLAY_DIR")?.let(::File)
|
||||
private val zone = java.time.ZoneId.of("Europe/London")
|
||||
private val day = 24 * 60 * 60_000L
|
||||
private val hour = 60 * 60_000L
|
||||
|
||||
private class Proposal(val number: Int, val name: String, val tiers: Map<String, Double>, val note: String, val alternatives: List<Pair<String, Map<String, Double>>> = emptyList())
|
||||
private fun tiers(core: List<String>, surprise: List<String> = emptyList(), other: Map<String, Double> = emptyMap()) =
|
||||
core.associate { seriesKey(it) to TIER_CORE } + surprise.associate { seriesKey(it) to TIER_SURPRISE } + other.mapKeys { seriesKey(it.key) }
|
||||
|
||||
// Each channel's tiers, from its own brief in docs/channels. Anything not named is supporting (2).
|
||||
private val proposals = listOf(
|
||||
Proposal(614, "Tots", emptyMap(), "No tiers in the brief: every show equal (2), so airtime is shared by minutes, not by episode count.",
|
||||
listOf("Night Garden anchors bedtime (3), Clangers and BeddyByes light (1)" to tiers(listOf("In The Night Garden"), surprise = listOf("Clangers", "BeddyByes")))),
|
||||
Proposal(605, "ToonZ", tiers(listOf("Looney Tunes", "Tom and Jerry", "Scooby-Doo, Where Are You!", "The Flintstones", "The Jetsons", "The Yogi Bear Show", "Popeye the Sailor", "Popeye")),
|
||||
"Core 3 and supporting 2 from the brief. The British teatime trio counts as supporting (2), not surprise: teatime is their block.",
|
||||
listOf("teatime trio at 3, level with the core" to tiers(listOf("Looney Tunes", "Tom and Jerry", "Scooby-Doo, Where Are You!", "The Flintstones", "The Jetsons", "The Yogi Bear Show",
|
||||
"Popeye the Sailor", "Popeye", "Danger Mouse", "Count Duckula", "Bananaman")))),
|
||||
Proposal(202, "Odyssey", tiers(listOf("The Universe", "How the Universe Works", "Cosmos", "Cosmos: A Spacetime Odyssey", "Wonders of the Universe", "Wonders of the Solar System",
|
||||
"Horizon", "Through the Wormhole", "The Sky at Night", "The Planets (2019)", "Wonders of Life", "Human Universe", "Forces of Nature with Brian Cox",
|
||||
"Brian Cox's Adventures in Space and Time", "When We Left Earth: The NASA Missions", "Impossible Engineering", "Extreme Engineering", "Megastructures")),
|
||||
"Core 3 and supporting 2 from the brief. The Journeys titles are equal (2) within their weekend block."),
|
||||
Proposal(203, "Wild", tiers(listOf("Man vs. Wild", "Running Wild with Bear Grylls", "Survivorman", "Dual Survival", "Naked and Afraid", "Alone", "Survival with Ray Mears",
|
||||
"Bear Grylls: Mission Survive", "The Crocodile Hunter", "River Monsters"), surprise = listOf("Dirty Jobs")),
|
||||
"Core 3, supporting 2 and Dirty Jobs as the surprise (1), all from the brief."),
|
||||
Proposal(603, "Orbit X", tiers(listOf("Biker Mice from Mars", "Digimon: Digital Monsters", "Teenage Mutant Ninja Turtles", "The Transformers", "He-Man and the Masters of the Universe",
|
||||
"ThunderCats", "Gargoyles", "The Real Ghostbusters", "Power Rangers", "G.I. Joe", "Digimon Adventure", "Mighty Morphin Power Rangers", "G.I. Joe: A Real American Hero")),
|
||||
"Core 3 (with the earlier names of the same shows) and supporting 2 from the brief, X-Men and Spider-Man included as the brief lists them."))
|
||||
private val channels = listOf(TOTS_NUMBER, 605, 202, 203, 603)
|
||||
|
||||
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")
|
||||
@@ -65,25 +46,29 @@ class RolloutProposalReplayTest {
|
||||
}
|
||||
}
|
||||
|
||||
private fun replay(committed: ChannelPlan, series: List<PoolSeries>, programming: ChannelProgramming, weightOf: ((PoolSeries) -> Double)?): List<ScheduleEntry> {
|
||||
private fun replay(committed: ChannelPlan, series: List<PoolSeries>, programming: ChannelProgramming, weightOf: ((PoolSeries) -> Double)?,
|
||||
avoid: ProgrammeClash = { _, _, _ -> false }, restartEvery: Int = 0, keepCommitted: Boolean = false): List<ScheduleEntry> {
|
||||
var current = committed
|
||||
var now = committed.entries.first().startMs + SCHEDULE_KEEP_PAST_MS
|
||||
val end = committed.endMs + 28 * day
|
||||
val all = committed.entries.toMutableList()
|
||||
val folder = java.nio.file.Files.createTempDirectory("rollout").toFile()
|
||||
var step = 0
|
||||
while (now < end) {
|
||||
current = topUpPlan(current, current.tail, series, now, programming.filmRestMs, programming.finishTogether, programming.dayParts, zone,
|
||||
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
|
||||
current.entries.filter { e -> all.none { it.startMs == e.startMs } }.forEach { all += it }
|
||||
now += 6 * hour
|
||||
}
|
||||
all.sortBy { it.startMs }
|
||||
assertEquals("${programming.name}: committed programmes kept", committed.entries, all.take(committed.entries.size))
|
||||
return all.filter { it.startMs >= committed.endMs && it.startMs < end }
|
||||
return if (keepCommitted) all.filter { it.startMs < end } else all.filter { it.startMs >= committed.endMs && it.startMs < end }
|
||||
}
|
||||
|
||||
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, out: StringBuilder) {
|
||||
private fun report(label: String, entries: List<ScheduleEntry>, series: List<PoolSeries>, programming: ChannelProgramming, weightOf: (PoolSeries) -> Double, others: ProgrammeClash, out: StringBuilder): Map<String, Int> {
|
||||
val byId = series.associateBy { it.id }
|
||||
fun tier(id: String) = when (weightOf(byId.getValue(id))) { TIER_CORE -> "core"; TIER_SURPRISE -> "surprise"; else -> "supporting" }
|
||||
fun minutes(es: List<ScheduleEntry>) = es.groupBy { it.seriesId }.mapValues { (_, x) -> x.sumOf { it.media.durationMs } / 60_000.0 }
|
||||
@@ -100,13 +85,17 @@ class RolloutProposalReplayTest {
|
||||
// Repeats: the same file again, within a day and within a week.
|
||||
val gapsByFile = entries.groupBy { it.media.item.id }.values.flatMap { es -> es.zipWithNext().map { (a, b) -> b.startMs - a.startMs } }
|
||||
val sameDay = gapsByFile.count { it < day }; val sameWeek = gapsByFile.count { it < 7 * day }
|
||||
fun weightedAt(e: ScheduleEntry) = dayPartFor(series, programming.dayParts, e.startMs, zone).third?.weighted != false
|
||||
val sameDayWeighted = entries.groupBy { it.media.item.id }.values.sumOf { es -> es.zipWithNext().count { (a, b) -> b.startMs - a.startMs < day && weightedAt(b) } }
|
||||
out.appendLine(" repeats: ${entries.map { it.media.item.id }.distinct().size} different episodes; same file again within 24 h $sameDay, within 7 days $sameWeek" +
|
||||
(if (gapsByFile.isNotEmpty()) ", median ${"%.1f".format(gapsByFile.sorted()[gapsByFile.size / 2] / day.toDouble())} days between repeats" else ""))
|
||||
(if (gapsByFile.isNotEmpty()) ", median ${"%.1f".format(gapsByFile.sorted()[gapsByFile.size / 2] / day.toDouble())} days between repeats" else "") +
|
||||
(if (programming.dayParts.any { !it.weighted }) " (within 24 h in weighted blocks: $sameDayWeighted)" else ""))
|
||||
val first = entries.first().startMs; val last = entries.last().endMs
|
||||
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 }
|
||||
val twice = entries.zipWithNext().count { (a, b) -> a.seriesId == b.seriesId && weightedAt(b) }
|
||||
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 } }
|
||||
val decks = series.filter { programming.shuffleEpisodes || programming.mixes(it) }.associate { s -> s.id to shuffledEpisodes(s).map { it.mark } }
|
||||
@@ -114,31 +103,50 @@ class RolloutProposalReplayTest {
|
||||
val gaps = entries.zipWithNext().count { (a, b) -> a.endMs != b.startMs }
|
||||
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(" rules: same show twice running $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(" 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")
|
||||
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)
|
||||
}
|
||||
|
||||
@Test fun rolloutChannels() {
|
||||
assumeTrue(dir != null && dir.isDirectory)
|
||||
val out = StringBuilder("Rollout proposal replays: four weeks of new bookings after each committed plan, today's rule against weighted rotation with the proposed tiers.\n" +
|
||||
"Read-only: the tiers below are proposals, defined only in this test.\n\n")
|
||||
for (p in proposals) {
|
||||
val programming = SmartChannels.first { it.number == p.number }
|
||||
val committedFile = File(dir, "schedule-${p.number}.json"); val poolFile = File(dir, "episodes-${p.number}.json")
|
||||
if (!committedFile.exists() || !poolFile.exists()) { out.appendLine("== ${p.name}: no files"); continue }
|
||||
val committed = plan(committedFile); val series = pool(poolFile)
|
||||
val weightOf = { s: PoolSeries -> p.tiers[seriesKey(s.title)] ?: TIER_SUPPORTING }
|
||||
out.appendLine("== ${p.name} (${p.number}), committed plan ends ${java.time.Instant.ofEpochMilli(committed.endMs).atZone(zone).toLocalDateTime().withNano(0)}")
|
||||
out.appendLine(" ${p.note}")
|
||||
if (p.tiers.isNotEmpty()) out.appendLine(" in the pool: ${series.size} shows; core ${series.count { weightOf(it) == TIER_CORE }}, supporting ${series.count { weightOf(it) == TIER_SUPPORTING }}, surprise ${series.count { weightOf(it) == TIER_SURPRISE }}")
|
||||
report("Today", replay(committed, series, programming, null), series, programming, weightOf, out)
|
||||
report("Weighted", replay(committed, series, programming, weightOf), series, programming, weightOf, out)
|
||||
for ((label, alt) in p.alternatives) {
|
||||
val altWeight = { s: PoolSeries -> alt[seriesKey(s.title)] ?: TIER_SUPPORTING }
|
||||
report("Alternative, $label", replay(committed, series, programming, altWeight), series, programming, altWeight, out)
|
||||
val out = StringBuilder("0.98.0: four weeks of new bookings after each committed plan, today's rule against the app's weighted rotation, avoiding\n" +
|
||||
"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)
|
||||
}
|
||||
for (number in channels) {
|
||||
val programming = SmartChannels.first { it.number == number }
|
||||
val committed = plan(File(dir, "schedule-$number.json")); val series = pool(File(dir, "episodes-$number.json"))
|
||||
val weightOf = programming::weightOf
|
||||
val others = clashesWith(baseline.filterKeys { it != number }.values.map { ChannelPlan(it, ScheduleCursor()) })
|
||||
out.appendLine("== ${programming.name} ($number), committed plan ends ${java.time.Instant.ofEpochMilli(committed.endMs).atZone(zone).toLocalDateTime().withNano(0)}")
|
||||
out.appendLine(" in the pool: ${series.size} shows; core ${series.count { weightOf(it) == TIER_CORE }}, supporting ${series.count { weightOf(it) == TIER_SUPPORTING }}, surprise ${series.count { weightOf(it) == TIER_SURPRISE }}" +
|
||||
programming.dayParts.filter { !it.weighted }.joinToString("") { "; ${it.fromHour}-${it.toHour} stays on equal turns" } +
|
||||
programming.dayParts.filter { it.weights.isNotEmpty() }.joinToString("") { p -> "; ${p.fromHour}-${p.toHour} weights ${p.weights.size} shows ${p.weights.values.first()}" })
|
||||
val today = replay(committed, series, programming, null, others)
|
||||
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)
|
||||
assertEquals("${programming.name}: a restart changes nothing", weighted, restarted)
|
||||
out.appendLine(" a save and reload every 18 hours gives the identical four weeks: true")
|
||||
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.
|
||||
programming.dayParts.filter { !it.weighted }.forEach { part ->
|
||||
fun inPart(e: ScheduleEntry) = dayPartFor(series, programming.dayParts, e.startMs, zone).third == part
|
||||
val a = today.filter(::inPart); val b = weighted.filter(::inPart)
|
||||
assertTrue("${programming.name}: ${part.fromHour}-${part.toHour} stays on equal turns", b.isNotEmpty() && b.none { "weighted" in it.why })
|
||||
fun shares(es: List<ScheduleEntry>) = es.groupBy { it.seriesId }.mapValues { (_, x) -> x.sumOf { it.media.durationMs }.toDouble() / es.sumOf { it.media.durationMs } }
|
||||
val sa = shares(a); val sb = shares(b)
|
||||
out.appendLine(" ${part.fromHour}-${part.toHour} on equal turns, share today -> 0.98.0: " + sa.keys.joinToString { id -> "${series.first { it.id == id }.title} ${pct(sa.getValue(id))} -> ${pct(sb[id] ?: 0.0)}" })
|
||||
sa.keys.forEach { id -> assertEquals("${programming.name}: ${part.fromHour}-${part.toHour} share", sa.getValue(id), sb[id] ?: 0.0, 0.05) }
|
||||
}
|
||||
out.appendLine()
|
||||
}
|
||||
File(dir, "rollout-proposal-replay.txt").writeText(out.toString())
|
||||
File(dir, "weighted-rollout-replay.txt").writeText(out.toString())
|
||||
println(out)
|
||||
}
|
||||
}
|
||||
@@ -151,8 +151,61 @@ class WeightedRotationTest {
|
||||
sketch.forEachIndexed { i, mark -> assertEquals(deck[(at + i) % deck.size], mark) }
|
||||
}
|
||||
|
||||
@Test fun onlyOrbitThreeIsWeighted() {
|
||||
assertEquals(listOf(103), SmartChannels.filter { it.tierWeights != null }.map { it.number })
|
||||
@Test fun blocksLeftOnEqualTurnsPlanExactlyAsTheyDidAndWeightedOnesCarryOn() {
|
||||
// Tots' shape: a weighted day, and a night on equal turns with finish-together, sharing no shows.
|
||||
val day = listOf(show("A", 40, 10), show("B", 60, 12))
|
||||
val night = listOf(show("Big", 145, 26), show("Small", 26, 10), show("Mid", 52, 11))
|
||||
val pool = day + night
|
||||
val parts = listOf(DayPart(6, 17, listOf("A", "B")), DayPart(17, 6, night.map { it.title }, weighted = false))
|
||||
val mixed = { _: PoolSeries -> true }
|
||||
val plan = extendByBlock(pool, ScheduleCursor(), start, start + 14 * this.day, weights(), parts, zone, { _, _, _ -> false }, true, mixed, true)
|
||||
// The night, programme by programme, is what equal turns book there today, with the day on equal turns too.
|
||||
val nights = plan.entries.filter { it.seriesId in night.map { s -> s.id } }
|
||||
val alone = extendSchedule(pool, ScheduleCursor(), start, start + 30 * this.day, null, true, parts, zone, shuffle = true, mixed = mixed).entries.filter { it.seriesId in night.map { s -> s.id } }
|
||||
assertEquals(alone.take(nights.size).map { it.seriesId to it.mark }, nights.map { it.seriesId to it.mark })
|
||||
assertTrue(nights.none { "weighted" in it.why }); assertTrue(plan.entries.filter { it.seriesId in listOf("A", "B") }.all { "weighted" in it.why })
|
||||
plan.entries.zipWithNext().forEach { (a, b) -> assertEquals(a.endMs, b.startMs) }
|
||||
// And a top-up in the middle changes nothing.
|
||||
val first = extendByBlock(pool, ScheduleCursor(), start, start + 5 * this.day + 3 * 3_600_000L, weights(), parts, zone, { _, _, _ -> false }, true, mixed, true)
|
||||
val rest = topUpPlan(first, first.tail, pool, first.endMs - SCHEDULE_AHEAD_MS + 1, finishTogether = true, dayParts = parts, zone = zone, shuffle = true, mixed = mixed, weightOf = weights())!!
|
||||
assertEquals(plan.entries.map { it.seriesId to it.mark }.take(rest.entries.size), rest.entries.map { it.seriesId to it.mark })
|
||||
}
|
||||
|
||||
@Test fun aBlocksOwnWeightsApplyOnlyThere() {
|
||||
val core = (1..4).map { show("Core $it", 300) }; val trio = (1..3).map { show("Trio $it", 300) }
|
||||
val parts = listOf(DayPart(16, 18, (trio + core).map { it.title }, weights = trio.associate { seriesKey(it.title) to TIER_CORE }), DayPart(18, 16, (trio + core).map { it.title }))
|
||||
val plan = run(core + trio, weights(*core.map { it.title to TIER_CORE }.toTypedArray()), parts = parts)
|
||||
fun share(teatime: Boolean) = plan.entries.filter { (java.time.Instant.ofEpochMilli(it.startMs).atZone(zone).hour in 16..17) == teatime }
|
||||
.let { es -> es.count { it.seriesId.startsWith("Trio") }.toDouble() / es.size }
|
||||
assertEquals(3.0 / 7, share(true), 0.05)
|
||||
assertEquals(6.0 / 18, share(false), 0.05)
|
||||
}
|
||||
|
||||
@Test fun aShowAiringElsewhereIsSkipped() {
|
||||
val pool = listOf(show("Shared", 100), show("B", 100), show("C", 100))
|
||||
val busy = { show: PoolSeries, from: Long, _: Long -> show.title == "Shared" && java.time.Instant.ofEpochMilli(from).atZone(zone).hour in 18..21 }
|
||||
val plan = extendWeighted(pool, ScheduleCursor(), start, start + 7 * day, weights(), emptyList(), zone, busy, false, { false })
|
||||
assertTrue(plan.entries.none { busy(pool[0], it.startMs, it.endMs) && it.seriesId == "Shared" })
|
||||
assertTrue(plan.entries.any { it.seriesId == "Shared" })
|
||||
}
|
||||
|
||||
@Test fun theApprovedChannelsAreWeightedAndTotsBedtimeIsNot() {
|
||||
assertEquals(listOf(103, 202, 203, 603, 605, 614), SmartChannels.filter { it.tierWeights != null }.map { it.number }.sorted())
|
||||
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 }
|
||||
val teatime = toonz.dayParts.single { it.weights.isNotEmpty() }
|
||||
assertEquals(16 to 18, teatime.fromHour to teatime.toHour)
|
||||
assertEquals(setOf("Danger Mouse", "Count Duckula", "Bananaman").map(::seriesKey).toSet(), teatime.weights.keys)
|
||||
assertEquals(TIER_SUPPORTING, toonz.weightOf(show("Danger Mouse", 1)), 0.0)
|
||||
assertEquals(TIER_CORE, toonz.weightOf(show("Looney Tunes", 1)), 0.0)
|
||||
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() } })
|
||||
}
|
||||
|
||||
@Test fun orbitThreesTiers() {
|
||||
val three = SmartChannels.first { it.number == 103 }
|
||||
assertTrue(three.searches.none { seriesKey(it) == seriesKey("Family Guy") })
|
||||
assertEquals(TIER_CORE, three.weightOf(show("Gavin & Stacey", 1)), 0.0)
|
||||
|
||||
Reference in New Issue
Block a user