Just-this-week changes¶
How one song of a generated week is changed for that week only, and stays changed when the week is generated again.
What a change is¶
A week_change row belongs to a week (playlist; deleting the week
deletes it) and names one song by its place: row and block (from 1,
as traces number them; a flat station's row is 1) and which of that
rule's songs it is (k, from 0). There are two kinds:
- swap: a song chosen by hand (
track_id, from any of the station's pools); - rule: the song a changed rule picks there (
rule, the whole block as changed; its size is always the original's).
Each keeps its rule's rule_strategy and rule_source as they were
when it was made. A change whose place now holds another kind of rule
isn't put on it.
Making one¶
POST /api/playlists/{id}/changes works out the song and appends a
version of the week at once, with only that song different and a
note saying so ("Just this week: song 7 swapped for …"). It's made
against the version the page shows (expected_version; 409 if the
week has changed since) and refused while the station's week is being
generated. DELETE …/changes/{change_id} undoes it the same way. The
changed song's trace slot keeps its rule's source, strategy and place,
and carries a change note: what kind, the rule's own song (was,
all of it, so undoing puts it back exactly) and, for a rule change, the
rule and what it picked.
A rule change's song is worked out by playing the week again with the
changed rule at that one place (generate(..., override_block=…); on a
row station the other rows keep the template's rule), with the same
seed and inputs, and stopping once it has played (stop_after).
Everything before it plays the same, so the song is picked in the same
context the rule's own was. Each replay costs part of a week (up to
about 4 s on Rebirth Radio's 2,196 songs, a few ms on Rebirth
Classics), so a week has at most 20 rule changes; swaps cost nothing.
A change can't be made on a week the station's rules have moved on
from (regenerate it first), past a rule's size now, or as a no-op (the
song its rule picks, or the rule as it is). Each change version stores
the whole week, compressed: about 0.5 MB on Rebirth Radio.
Generating again¶
Every way a week is generated (/generate, its job, the preview job,
generate_chain, the CLI) generates it as the rules play it, then makes
its changes (engine.week_change_store). The preview job makes the
changes it's sent, so the week page can preview its own, following its
queued edits. Changes that can't be made are reported
(week_changes_dropped, with the reason) and deleted.
Generating a week again with the same seed gives the same week: its mix exclusions are the mixes of the weeks before it, not its own earlier version's or later weeks'. So the song a rule change shows when it's made is the one regenerating keeps, and a preview matches its week.
The station's state follows what its rules picked
(GenerationResult.rule_picks): mix usage records the rule's song, and
cursors don't depend on picks, so a change doesn't shift later weeks.
The songs the week played, changes included, are what prev_ref repeats
next week.
On the week's page¶
- The ask. Changing a song's rule in the rule panel asks: Every
week (the rule itself, queued with the other changes, as before) or
Just this song, week N (saved now,
kind: "rule", the rule worked out as the station's own save would:changedRule,applyEditson the saved template). The choice made last time has focus, so Enter takes it. "Just this song" says why when it can't be: rule changes are queued (a song is changed on the week as saved), the week was made before the rules last changed, only the size changed, or the week has its 20 rule changes. Ticking the other identical rules too makes the change every week's, without asking. - Swap song. The rule panel's box for the picked song offers Swap
song, just this week: a search over the station's pools
(
GET /api/stations/{slug}/songs, the rule's own pool first), saying where songs already play in the week. The rule's own song isn't offered: Undo puts it back. - This week only. The week's changes are listed above the songs, each with an Undo, saved at once. Changed songs say just this week in the list and the table; a version's note shows in the picker.
- Previews. A queued rule change's preview makes the week's changes,
moved through the queue (
changesAfter, the twin offollow_rule_ops). When the queue would drop one (its rule changes kind or source), the edit bar says so before it's saved; once saved, regenerating says which changes it kept and which it dropped. The station editor's preview of a generated week makes that week's changes too, read only, with a link to its page. - A change made against a version that's no longer current (another tab regenerated the week) is refused, and the page reloads the week.
Following the rules¶
When the editor's batch save or the structure route moves, adds or
removes rules, every week's changes follow their rule
(follow_rule_ops, the twin of the editor's slotAfter, checked
against the shared cases in tests/fixtures/slot_after.json). A
change whose rule is removed, or whose song a smaller rule no longer
has, is deleted. The station's JSON page replaces the whole template,
so there the rule check at the next generation is what drops a change
on a place that now holds another kind of rule.
Rollback makes the week's changes those of the version rolled back to,
from its songs' change notes.