Smart setup: at least three running series in a part of the day that has any (Sakura's late nights leaned on two)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -73,6 +73,11 @@ internal fun slotFor(row: ShapeRow, shared: Set<String> = emptySet()): Slot {
|
||||
}
|
||||
}
|
||||
|
||||
/** At least this many series in a part of the day that has any, where another part can spare them. */
|
||||
internal const val MIN_SERIES_PER_PART = 3
|
||||
/** A series with at least this many hours counts towards a part of the day's variety. */
|
||||
internal const val SUBSTANTIAL_SERIES_HOURS = 10.0
|
||||
|
||||
/** Hours a week each slot fills, all day every day. */
|
||||
private val WeekHours = mapOf(Slot.Daytime to 11 * 7.0, Slot.Evening to 5 * 7.0, Slot.Late to 8 * 7.0)
|
||||
|
||||
@@ -130,6 +135,21 @@ internal fun shapeChannel(rows: List<ShapeRow>): Shape {
|
||||
}
|
||||
}
|
||||
}
|
||||
// Variety at night (Paul, 7 November 2026: Sakura's late nights leaned on two series): a part of the day with series in it
|
||||
// should have at least three, where the evening can spare them without running short.
|
||||
for (to in listOf(Slot.Late, Slot.Daytime)) {
|
||||
// Counted by series with a run of their own: a six-episode show is gone in two nights.
|
||||
val seriesThere = rows.count { slots[it.id] == to && it.type == "Series" && hours(it) >= SUBSTANTIAL_SERIES_HOURS }
|
||||
if (seriesThere == 0 || seriesThere >= MIN_SERIES_PER_PART) continue
|
||||
val spare = rows.filter { slots[it.id] == Slot.Evening && it.type == "Series" && mayMove(it, Slot.Evening, to) }
|
||||
// The longest-running first, so the night isn't handed a show that runs out in a couple of evenings.
|
||||
.sortedWith(compareByDescending<ShapeRow> { hours(it) }.thenBy { listOf(RatingBand.Teen, RatingBand.Unknown, RatingBand.Family, RatingBand.Kids).indexOf(ratingBand(it.rating)) })
|
||||
for (c in spare.take(MIN_SERIES_PER_PART - seriesThere)) {
|
||||
if (rows.count { slots[it.id] == Slot.Evening && it.type == "Series" } <= MIN_SERIES_PER_PART) break
|
||||
if (content(Slot.Evening) - hours(c) < target(Slot.Evening)) continue
|
||||
slots[c.id] = to; notes += "${c.title} moves to ${to.label} for more variety."
|
||||
}
|
||||
}
|
||||
// Core shows are series where there are any: a film plays once a week whatever its star.
|
||||
val evening = rows.filter { slots[it.id] == Slot.Evening }.ifEmpty { rows }.let { e -> e.filter { it.type == "Series" }.ifEmpty { e } }
|
||||
val pick = evening.sortedByDescending { it.year ?: 0 }.take(3).map { it.id }.toSet()
|
||||
|
||||
@@ -60,6 +60,11 @@ class SmartSetupRegressionTest {
|
||||
assertTrue(repeats(r.plan) <= 15)
|
||||
val firstRepeat = r.plan.entries.filter { it.startMs < now + week }.groupBy { it.media.item.id }.values.filter { it.size > 1 }.minOfOrNull { it[1].startMs }
|
||||
assertTrue(firstRepeat == null || firstRepeat - now >= 5 * 24 * 3_600_000L)
|
||||
// Late nights have at least three series (it leaned on two), and no one series takes more than 15 late slots a week.
|
||||
assertTrue(r.rows.count { r.shape.slots[it.id] == Slot.Late && it.type == "Series" && (it.runMs ?: 0) >= SUBSTANTIAL_SERIES_HOURS * 3_600_000 } >= MIN_SERIES_PER_PART)
|
||||
val lateBySeries = r.plan.entries.filter { it.startMs < now + week && java.time.Instant.ofEpochMilli(it.startMs).atZone(zone).hour.let { h -> h >= 22 || h < 6 } }
|
||||
.filter { e -> r.rows.first { it.id == e.seriesId }.type == "Series" }.groupingBy { it.seriesId }.eachCount()
|
||||
assertTrue(lateBySeries.toString(), lateBySeries.values.max() <= 15)
|
||||
// Every title gets airtime in the week.
|
||||
assertEquals(r.rows.size, r.plan.entries.filter { it.startMs < now + week }.map { it.seriesId }.toSet().size)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user