diff --git a/docs/channels.md b/docs/channels.md index e19b036b1..0207c7d59 100644 --- a/docs/channels.md +++ b/docs/channels.md @@ -75,6 +75,52 @@ Filler modes: Duration, Count, Pad (to nearest minute), RandomCount. `ProgramScheduleAlternate` overrides the main schedule for specific days of week, days of month, months of year, or date ranges. Useful for seasonal programming or weekend variations. +The date predicate itself is `IAlternateScheduleItem` (`ErsatzTV.Core/Domain/Scheduling/`), implemented by +`ProgramScheduleAlternate` (classic playouts) and `PlayoutTemplate` (block playouts). Both are evaluated by +`AlternateScheduleSelector.GetScheduleForDate`: rows are tested in `Index` order, **first match wins**, and +the broadest/unconditional row placed **last** acts as the catch-all default. `DaysOfWeek`, `DaysOfMonth` +and `MonthsOfYear` are ANDed with the date range, so a row only matches when *every* condition holds. + +### Recipe: seasonal / holiday programming + +Date-conditional scheduling is fully supported — there is no need to hand-build it seasonally. The +mechanism is named "Alternate Schedules" (classic) / "Playout Templates" (block), which is why it isn't +obvious if you go looking for "seasonal". + +**Classic playout — a December holiday channel:** + +1. Build the seasonal schedule at `/app/schedules` (clone your normal one, swap in the holiday content). +2. Go to `/app/playouts/{id}/alternate-schedules`. +3. Add a row pointing at the seasonal schedule; tick **Limit to date range**; set start `12/1`, end `12/31`. +4. **Leave the start/end year fields empty** — see the gotcha below; this is what makes it recur. +5. Add (or keep) a row for your normal schedule with no conditions, ordered **last** — the catch-all for the + other eleven months. + +**Block playout — same idea, plus holiday branding:** + +1. Build the seasonal `Template` at `/app/templates` (a day-grid of `Block`s). +2. Go to `/app/playouts/{id}/templates`, add a date-limited `PlayoutTemplate` row for it (same + date-range fields, same empty-years rule, same catch-all-last ordering). +3. Optionally set that row's **DecoTemplate** for seasonal watermarks/filler — one `PlayoutTemplate` row + carries both a `Template` and an optional `DecoTemplate`, so branding is date-gated along with content. + +**Gotchas** (all enforced in `AlternateScheduleSelector.cs:32-40`): + +- **Empty years = repeats every year.** Years default to the *queried date's* year, so `12/1 → 12/31` with + blank years fires every December, forever. Set explicit years only for a genuine one-off window. +- **It's both years or neither.** The explicit-year branch requires `StartYear` **and** `EndYear` to be set. + Filling in only one silently falls back to the yearly-repeat behaviour. +- **Wrap-around ranges work — but only with blank years.** `11/1 → 2/1` correctly spans the new year. Setting + explicit years disables wrap detection (`reverse = false`), turning the range into a plain start→end window. +- **Invalid dates are clamped, not rejected.** A start of `2/31` rolls to the 1st of the next month; an end of + `2/31` reduces to the last day of February (leap-year aware). +- **Decos have no dates of their own.** `DecoTemplateItem.StartTime`/`EndTime` are *time-of-day*. Date-gate a + deco via the `PlayoutTemplate` row that carries its `DecoTemplateId`; a playout's default `Playout.DecoId` + is deliberately never date-gated (it's the fallback). + +Not supported: *soft* prioritization ("prefer collection X in December" without swapping the schedule). +Selection is binary first-match-wins — see `decisions.md` 2026-07-17 (#73) and the weighting work in #70. + ## Playout Pipeline ``` diff --git a/docs/decisions.md b/docs/decisions.md index 8f91f2283..434017e5b 100644 --- a/docs/decisions.md +++ b/docs/decisions.md @@ -85,6 +85,7 @@ in-file entries. - [2026-07-16 — Per-playout reshuffle = scoped Reset build; seed surfaced (#71)](#2026-07-16--per-playout-reshuffle--scoped-reset-build-seed-surfaced-71) - [2026-07-17 — Clock-boundary schedule padding already exists (FillerMode.Pad); #77 verified, convenience toggle deferred](#2026-07-17--clock-boundary-schedule-padding-already-exists-fillermodepad-77-verified-convenience-toggle-deferred) - [2026-07-17 — Shuffle-source construction extracted to `ShuffleSourceBuilder`; per-family seam, not a god-factory (#380)](#2026-07-17--shuffle-source-construction-extracted-to-shufflesourcebuilder-per-family-seam-not-a-god-factory-380) +- [2026-07-17 — Seasonal / date-conditional scheduling already exists (alternate schedules / playout templates); #73 closed as implemented](#2026-07-17--seasonal--date-conditional-scheduling-already-exists-alternate-schedules--playout-templates-73-closed-as-implemented) --- @@ -1135,3 +1136,65 @@ one engine reaching into another engine's class. `PlaylistEnumerator.Create` reach-in characterization (Shuffle + ShuffleInOrder items) **before** the move, plus direct `ShuffleSourceBuilder` unit tests for the branches goldens don't reach (multi-collection vs fake-multi-collection lookup; multi-part grouping on/off). + +## 2026-07-17 — Seasonal / date-conditional scheduling already exists (alternate schedules / playout templates); #73 closed as implemented + +#73 asked for "seasonal / date-conditional channels & schedule rules" — a PseudoTV holiday-channel analogue +— on the stated premise that *"ErsatzTV has no native date-conditional scheduling today; you'd hand-build it +seasonally."* **That premise is false.** The feature is first-class, shipped, SPA-reachable, unit-tested and +already documented (upstream machinery carried into the fork). #73 is closed as already-implemented; the only +deliverable was the docs recipe below. + +- **The predicate**: `IAlternateScheduleItem` (`DaysOfWeek`, `DaysOfMonth`, `MonthsOfYear`, + `LimitToDateRange`, `StartMonth/StartDay/StartYear?`, `EndMonth/EndDay/EndYear?`), implemented by + `ProgramScheduleAlternate` (Classic — picks the `ProgramSchedule` for a date) and + `Scheduling/PlayoutTemplate` (Block — picks the `Template` + optional `DecoTemplate` for a date). +- **The evaluator**: `AlternateScheduleSelector.GetScheduleForDate` — first match in `Index` order, + broadest/unconditional row last = catch-all. Wired into `PlayoutBuilder` (:572, :956), `EffectiveBlock`, + `BlockPlayoutFillerBuilder`, and `DecoSelector`. Wrap-around (Nov→Feb) and invalid/leap dates (Feb 31 + clamped) are already handled; `AlternateScheduleSelectorTests` + `playoutTemplateCalendar.test.ts` pin it. +- **SPA**: `PlayoutScheduleEditors.tsx` ships the "Limit to date range" control for both editors, with a + per-date calendar preview (`playoutTemplateCalendar.ts`). +- **Nullable years are the seasonal switch** (`AlternateScheduleSelector.cs:32-40`): years default to the + *queried date's* year, so blank years = repeats every year. The override branch requires **both** + `StartYear` and `EndYear` (only one → silently still yearly), and explicit years force `reverse = false`, + disabling wrap-around. This was the single most load-bearing undocumented behaviour and is now in the docs. +- **Correcting the issue's Deco hypothesis**: the issue proposed "a Deco-like modifier". Decos carry **no** + dates — `DecoTemplateItem.StartTime/EndTime` are time-of-day. The date dimension lives *exclusively* on the + `PlayoutTemplate` / `ProgramScheduleAlternate` join row. Composition is **PlayoutTemplate (date range) → + Template (time-of-day grid) → Block (content)**. + +**Why closed rather than #77-style "re-scope to verify + document":** #77 had two real gaps (undocumented AND +untested). #73 has neither — tests and docs both already existed on main — so even the #77 re-scope target was +already met. Under the close-don't-park convention (same date), holding #73 open for a hypothetical future +build is precisely the parking that convention forbids. + +**Rejected asks, and why:** + +- **Per-schedule-item date predicate** (the issue's literal ask; shipped design swaps the *whole* schedule per + date instead). Rejected as-designed: functionally equivalent for every seasonal use case — clone a schedule, + date-gate it, order it above the catch-all — at a cost of "clone a schedule". Moving the predicate onto + `ProgramScheduleItem` rows would touch the classic playout builder's core loop for **zero new expressible + behaviour**, carrying regression risk in the exact engine #163/#380 just built golden nets around. +- **"Prioritize collection X during a date range"** — routed to **#70**, not built here. The ask decomposes as + *date scoping* (shipped) × *soft prioritization* (the weighting primitive #70 is actively building across the + `PlaybackOrder` switch sites). Once #70 lands, this is pure composition with no date-aware code in the + weighting path. Building a second weighting primitive under #73 while #70 was mid-flight would have been a + direct collision in the same milestone. +- **Date-gating a playout's default `Playout.DecoId`** — rejected: the gated path already exists + (`PlayoutTemplate.DecoTemplateId`), and a date-conditional *fallback* is a contradiction in terms. +- **UI rename** of "Alternate Schedules" / "Playout Templates" to something that reads as "seasonal" — rejected: + inherited upstream vocabulary baked into routes, API paths and parity docs; churn for marginal gain. The + discoverability gap is addressed with docs instead. + +**Known non-goal:** the issue's "optionally, auto-surface a seasonal channel in the lineup during its window" +is genuinely absent — M3U/XMLTV lineup visibility is not date-conditional. It was speculative, has no concrete +use case (the practical equivalent: air a date-gated schedule year-round, or toggle `ShowInEpg`), and per +close-don't-park no placeholder issue was filed. Refile if a real need appears. + +**The real gap was discoverability, and it was a docs gap.** The mechanism was documented as a *mechanism* +("Alternate Schedules… useful for seasonal programming") but never as a *task* — a user thinking "holiday +channel" has no reason to look under "Alternate Schedules", and on finding that line gets no worked steps. +Fixed with a task-shaped **"Recipe: seasonal / holiday programming"** section in `channels.md` (both engines, +plus the gotchas above) and a `domain-model.md` glossary row. No production code changed, so no live-E2E +(same reasoning as #77). diff --git a/docs/domain-model.md b/docs/domain-model.md index 4bc1ee9b5..2df09aa38 100644 --- a/docs/domain-model.md +++ b/docs/domain-model.md @@ -65,6 +65,7 @@ Channel (1) ──< Playout (0..N per channel; ChannelPlayoutSource distinguishe | **Default deco vs deco templates** | `Playout.DecoId` = one static deco for the whole playout; `PlayoutTemplate.DecoTemplateId` = a time-varying deco schedule. Both are optional and independent. | `Playout`, `PlayoutTemplate` | `/app/playouts/{id}/templates` | | **FillerPreset** | A reusable filler definition: `FillerKind` (PreRoll/MidRoll/PostRoll/Tail/Fallback; also `GuideMode=99`, `DecoDefault=100`) × `FillerMode` (None/Duration/Count/Pad/RandomCount) over a collection/media-item/multi-collection/smart-collection/playlist source, with an optional `Expression` (NCalc). Referenced from `ProgramScheduleItem` (Pre/Mid/Post/Tail/FallbackFillerId) and `Channel.FallbackFillerId`. | `FillerPreset`, `FillerKind`, `FillerMode` | `/app/filler-presets` | | **Clock-boundary padding** (#77) | Snapping a schedule to clean `:00/:15/:30`-style guide times is **not a separate feature** — it is `FillerMode.Pad` + `PadToNearestMinute` on a `FillerPreset` (Classic), or the `pad_to_next`/`pad_until` YAML instructions (Sequential). Block playouts are inherently clock-anchored via `TemplateItem.StartTime`. The EPG reflects the padded boundary automatically (`ChannelGuideProjector` coalesces trailing filler into the programme window). No one-click per-channel toggle yet — deferred to a UI follow-up blocked on #388. See `decisions.md` 2026-07-17. | `FillerPreset` (`Pad`) | `/app/filler-presets` | +| **Seasonal / date-conditional scheduling** (#73) | Holiday/seasonal channels are **not a separate feature** — they are the existing date predicate on `IAlternateScheduleItem`, implemented by `ProgramScheduleAlternate` (Classic) and `PlayoutTemplate` (Block), evaluated by `AlternateScheduleSelector.GetScheduleForDate` (first match by `Index`, catch-all last). **Leaving `StartYear`/`EndYear` empty makes the range repeat every year** — the "set once, works every December" switch; explicit years (required in pairs) mean a one-off window and disable wrap-around detection. Wrap-around (Nov→Feb) and invalid/leap dates (Feb 31) are handled. No *soft* prioritization primitive exists (binary first-match-wins); that ask belongs to #70's weighting work. See `channels.md` → "Recipe: seasonal / holiday programming" and `decisions.md` 2026-07-17. | `IAlternateScheduleItem`, `ProgramScheduleAlternate`, `PlayoutTemplate` | `/app/playouts/{id}/alternate-schedules`, `/app/playouts/{id}/templates` | | **Watermark** | `ChannelWatermark` image overlay; attached at channel, schedule-item, block-item, deco, or playout-item level with position/size/opacity. | `ChannelWatermark`, `DecoWatermark`, `BlockItemWatermark`, `ProgramScheduleItemWatermark` | `/app/watermarks` | | **Collection** | Manual list of media items (`CollectionItem`). | `Collection` | `/app/collections` | | **SmartCollection** | Saved search — a `Query` string, no static item list. | `SmartCollection` | `/app/collections` |