Release-week calendar: adjustable window (2-12 weeks, one release-event model each), time-since features moved to the release week, 'too soon' instead of special cases, season index (IFPI 2002-24) in the window; site: Best week tab, live ranking for any release week and window, single new-song view

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 12:24:01 +00:00
co-authored by Claude Opus 5.5
parent 347680bc9e
commit 3699944692
6 changed files with 369 additions and 154 deletions
+104 -32
View File
@@ -78,6 +78,21 @@ svg text { fill: var(--muted); font-size: 11px; }
.tracks { columns: 2; font-size: 14px; } .tracks div { break-inside: avoid; padding: 2px 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--bg); border-radius: 999px; padding: 3px 10px; font-size: 13px; }
/* best week calendar */
.cal { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; margin-top: 16px; }
.day { border-radius: 10px; padding: 10px; border: 1px solid var(--line); background: var(--panel); position: relative; min-height: 78px; }
.day .d { font-size: 12px; color: var(--muted); }
.day .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.day.soon { opacity: .55; background: repeating-linear-gradient(45deg, var(--bg), var(--bg) 6px, var(--panel) 6px, var(--panel) 12px); }
.day.soon .v { font-size: 13px; font-weight: 500; color: var(--muted); }
.day.best { outline: 3px solid var(--good); outline-offset: -1px; }
.day .tag { position: absolute; top: 8px; right: 8px; font-size: 11px; color: var(--muted); }
.bw-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: baseline; margin-top: 18px; }
.bw-head h2 { margin: 0; }
.lvl0 { background: color-mix(in srgb, var(--good) 28%, var(--panel)); }
.lvl1 { background: color-mix(in srgb, var(--good) 14%, var(--panel)); }
.lvl2 { background: var(--panel); }
.lvl3 { background: color-mix(in srgb, var(--bad) 10%, var(--panel)); }
/* model tab */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); }
@@ -101,13 +116,17 @@ svg text { fill: var(--muted); font-size: 11px; }
<div class="sub" id="sub">Loading…</div>
<nav>
<button class="on" data-tab="rank">Ranking</button>
<button data-tab="best">Best week</button>
<button data-tab="model">How good is it?</button>
</nav>
</header>
<main>
<section id="tab-rank">
<div class="controls">
<div class="ctl">8-week window starting <b id="hlabel">—</b><input type="range" id="h" min="0" max="12" value="0"></div>
<div class="ctl">Release week <b id="hlabel">—</b><input type="range" id="h" min="0" max="25" value="0"></div>
<div class="ctl">Added within
<select id="w"><option value="2">2 weeks</option><option value="4">4 weeks</option><option value="6">6 weeks</option><option value="8" selected>8 weeks</option><option value="10">10 weeks</option><option value="12">12 weeks</option></select>
</div>
<div class="ctl">Station
<select id="ch">
<option value="any">Any DR station</option>
@@ -118,12 +137,6 @@ svg text { fill: var(--muted); font-size: 11px; }
<option value="p8jazz">P8 Jazz</option>
</select>
</div>
<div class="ctl">Assume
<select id="mode">
<option value="rel">They release a new song</option>
<option value="mix">Any add (current songs included)</option>
</select>
</div>
<div class="ctl">Sort by
<select id="sort">
<option value="p">Chance of a new add</option>
@@ -132,8 +145,7 @@ svg text { fill: var(--muted); font-size: 11px; }
</select>
</div>
<div class="ctl">Artist <input type="search" id="q" placeholder="Search…"></div>
<div class="ctl"><label class="chk"><input type="checkbox" id="dk"> Danish acts only</label>
<label class="chk" title="Artists with a release in the last 6 weeks: their current song is still running, so a new-song estimate doesn't apply yet"><input type="checkbox" id="recent"> Include artists who just released</label></div>
<div class="ctl"><label class="chk"><input type="checkbox" id="dk"> Danish acts only</label></div>
</div>
<div class="tablewrap">
<table>
@@ -146,7 +158,23 @@ svg text { fill: var(--muted); font-size: 11px; }
</table>
</div>
<button class="more" id="more" hidden>Show more</button>
<p class="note">"In rotation now" lists DR stations where the artist is on the list, then Bauer stations (grey) with 14+ plays in the last 7 days. "They release a new song" = the chance DR adds a new song within 8 weeks of its release, learned from past releases with no other release in the 6 weeks before (so a current song's success isn't counted as the new one's); the new song's NMF Denmark placement is weighed by how often the artist's releases were placed. "Any add" = any new add in the window, current songs included. <b>New add</b> = the chance that the artist gets a song into rotation within the 8-week window: entering rotation (at or above the station's weekly play threshold) after at least 4 weeks out of rotation. For "any DR station", out of rotation everywhere first. An artist with a song in rotation now usually has to drop out before a new add, which is why current hits rank lower here. "In rotation now" shows where the artist is in rotation in the latest week; plays per week are for the window's first week. Click an artist for history and a what-if.</p>
<p class="note"><b>New add</b> = if the artist releases a new song in the chosen week, the chance DR puts it into rotation (at or above the station's weekly play threshold, after at least 4 weeks out) within the chosen number of weeks. Learned from past releases with no other release in the 6 weeks before, so a current song's success isn't counted as a new one's; a release less than 6 weeks after the artist's last one gets no estimate ("too soon"). The new song's NMF Denmark placement is weighed by how often the artist's releases were placed. "In rotation now" lists DR stations where the artist is on the list now, then Bauer stations (grey) with 14+ plays in the last 7 days. Click an artist for history and a what-if, or open <b>Best week</b> for their release calendar.</p>
</section>
<section id="tab-best" hidden>
<div class="controls">
<div class="ctl">Artist <input type="search" id="bw-q" list="bw-list" placeholder="Type an artist…" autocomplete="off"><datalist id="bw-list"></datalist></div>
<div class="ctl">Station
<select id="bw-ch"><option value="any">Any DR station</option><option value="P3">P3</option><option value="P4">P4 (best region)</option><option value="P5">P5</option><option value="P6">P6 Beat</option><option value="P8">P8 Jazz</option></select>
</div>
<div class="ctl">Added within
<select id="bw-w"><option value="2">2 weeks</option><option value="4">4 weeks</option><option value="6">6 weeks</option><option value="8" selected>8 weeks</option><option value="10">10 weeks</option><option value="12">12 weeks</option></select>
</div>
<div class="ctl">New Music Friday Denmark
<select id="bw-nmf"><option value="auto">As often as their releases were placed</option><option value="yes">Placed</option><option value="no">Not placed</option></select>
</div>
</div>
<div id="bw-out"><p class="empty">Pick an artist to see the best week to release a new song.</p></div>
</section>
<section id="tab-model" hidden>
@@ -192,10 +220,10 @@ const fmtDate = s => new Date(s + 'T00:00:00Z').toLocaleDateString('en-GB', { da
// Chance of a new add in the window (station group g, or any DR station).
function chanP(r, g) {
// "They release in the window" uses the conditional forecast where a discography is known.
const rel = document.getElementById('mode')?.value === 'rel' && r.add_rel;
const any = rel ? r.add_any_rel : r.add_any, per = rel ? r.add_rel : r.add;
// The new-song chance (null when the release week is too soon after the artist's last release).
const any = r.add_any_rel, per = r.add_rel;
if (g === 'any') return any;
if (any == null) return null;
if (g === 'p4') return Math.max(...P4S.map(c => per?.[c] ?? 0));
return per?.[g];
}
@@ -240,16 +268,20 @@ function windowStart(h) {
return d.toISOString().slice(0, 10);
}
async function loadRank() {
const h = +$('h').value;
const h = +$('h').value, w = $('w').value, k = h + '|' + w;
$('hlabel').textContent = `${fmtDate(windowStart(h))}${h ? ` (+${h} wk)` : ' (next week)'}`;
if (!data[h]) data[h] = (await API('rank?h=' + h)).rows;
if (!data[k]) {
const res = await API(`rank?h=${h}&w=${w}`);
data[k] = res.rows;
if (!res.live) setTimeout(() => { delete data[k]; loadRank(); }, 60000); // models still loading on the server
fillArtistList(res.rows);
}
render();
}
function render() {
const h = +$('h').value, g = $('ch').value, sort = $('sort').value, q = $('q').value.trim().toLowerCase(), dk = $('dk').checked;
const newSong = $('mode').value === 'rel';
let rows = data[h].filter(r => (!q || r.name.toLowerCase().includes(q)) && (!dk || r.danish) && (!newSong || !r.recent_release || $('recent').checked));
let rows = data[h + '|' + $('w').value].filter(r => (!q || r.name.toLowerCase().includes(q)) && (!dk || r.danish));
const key = sort === 'p' ? r => [chanP(r, g) ?? 0, chanPlays(r, g) ?? 0]
: sort === 'plays' ? r => [chanPlays(r, g) ?? 0, 0]
: r => [(chanPlays(r, g) ?? 0) - nowPlays(r, g), 0];
@@ -260,7 +292,7 @@ function render() {
const range = g === 'any' ? ` <small class="note">(${Math.round(r.lo)}–${Math.round(r.hi)})</small>` : '';
return `<tr data-id="${esc(r.id)}">
<td class="l">${i + 1}</td>
<td class="l name">${esc(r.name)}${r.danish ? '<small>DK</small>' : ''}${r.recent_release && $('mode').value === 'rel' ? '<small title="Released in the last 6 weeks: a new song now would compete with it">just released</small>' : ''}</td>
<td class="l name">${esc(r.name)}${r.danish ? '<small>DK</small>' : ''}${r.too_soon ? '<small title="Less than 6 weeks after their last release: no new-song estimate for this week">too soon</small>' : ''}</td>
<td><span class="bar"><i style="width:${Math.round((p ?? 0) * 70)}px"></i>${pct(p)}</span></td>
${GROUPS.map(([c]) => `<td class="hide-sm"><span class="cell" style="${heat(chanP(r, c))}">${pct(chanP(r, c))}</span></td>`).join('')}
<td class="l hide-sm">${nowChips(r.now, r.bauer)}</td>
@@ -318,9 +350,9 @@ async function showArtist(id) {
openDrawer('<div class="sec">Loading…</div>');
const a = await API('artist?id=' + encodeURIComponent(id));
if (a.error) { openDrawer(`<div class="sec">${esc(a.error)}</div>`); return; }
const h = +$('h').value;
const fc = a.forecasts.find(x => x.h === h) || a.forecasts[0] || {};
const fp = a.forecasts.find(x => x.h === Math.max(h, 1)) || {};
const h = +$('h').value, w = $('w').value;
const fc = (data[h + '|' + w] || []).find(r => r.id === id) || {};
const fp = a.forecasts.find(x => x.h === Math.max(Math.min(h, 12), 1)) || {};
const facts = [a.country, a.description, a.debut ? `active since ${a.debut}` : null].filter(Boolean).map(esc).join(' · ');
const runs = {};
a.charts.forEach(c => { const k = c.chart + '|' + c.title; (runs[k] ??= { ...c, weeks: 0, best: 99, first: c }); runs[k].weeks++; runs[k].best = Math.min(runs[k].best, c.position); runs[k].first = c; });
@@ -332,13 +364,13 @@ async function showArtist(id) {
<button class="x" aria-label="Close" onclick="closeDrawer()">×</button>
</div>
<div class="sec">
<h3>${$('mode').value === 'rel' && fc.add_rel ? 'If they release a new song: chance DR adds it within 8 weeks' : `Chance of any new add in the 8 weeks from ${fc.window_start ? fmtDate(fc.window_start) : '—'} (current songs included)`}</h3>
<div class="kpis">
<div class="kpi"><div>Any DR station</div><b>${pct(fc.add_any)}</b></div>
<h3>If they release a new song in the week of ${fmtDate(windowStart(h))}: chance DR adds it within ${w} weeks</h3>
${fc.too_soon ? '<p class="note"><b>Too soon:</b> less than 6 weeks after their last release, so there\'s no new-song estimate for this week. Pick a later week, or see their calendar.</p>' : `<div class="kpis">
<div class="kpi"><div>Any DR station</div><b>${pct(fc.add_any_rel)}</b></div>
${GROUPS.map(([g, l]) => `<div class="kpi"><div>${l}</div><b>${pct(chanP(fc, g))}</b></div>`).join('')}
</div>
${fc.recent_release ? '<p class="note"><b>Just released</b> (in the last 6 weeks). DR counts plays per artist, so the model can\'t tell a new song\'s chances from the current song\'s; the new-song estimate below doesn\'t really apply until the current song has run its course, and these artists are left out of the new-song ranking by default.</p>' : ''}
${fc.p_release != null ? `<p class="note">If they release a new song: <b>${pct(fc.add_any_rel)}</b>; if it's placed on New Music Friday Denmark: <b>${pct(fc.add_any_nmf)}</b> (their releases were placed about ${pct(fc.p_nmf)} of the time). Any add in the window, current songs included: ${pct(fc.add_any)} (chance they release in the window: ${pct(fc.p_release)}).</p>` : '<p class="note">No discography found on Deezer for this artist, so release timing isn\'t in the forecast.</p>'}
${fc.add_any_nmf != null ? `<p class="note">If it's placed on New Music Friday Denmark: <b>${pct(fc.add_any_nmf)}</b> (their releases were placed about ${pct(fc.p_nmf)} of the time).</p>` : ''}`}
<p><button class="more" style="margin:8px 0" onclick="closeDrawer(); openBest('${esc(id)}', '${esc(a.name).replace(/'/g, "\\'")}')">See the best week to release →</button></p>
<p class="note">In rotation now: ${nowChips(a.now, Object.fromEntries(Object.entries(a.bauer || {}).map(([s, v]) => [s, v.plays])))} · plays in the week of ${fp.week ? fmtDate(fp.week) : '—'}: <b>${Math.round(fp.mean ?? 0)}</b> (${Math.round(fp.lo ?? 0)}–${Math.round(fp.hi ?? 0)})</p>
</div>
<div class="sec"><h3>Weekly plays, last 51 weeks and next 12</h3>${historyChart(a)}</div>
@@ -353,14 +385,14 @@ async function showArtist(id) {
function whatIfUI(a, h) {
const box = $('wi');
box.innerHTML = `<div class="wi">
<div class="row"><label for="wi-h">Window starts in (weeks)</label><input type="range" id="wi-h" min="0" max="${meta.horizons.length}" value="${h}"><b id="wi-hv"></b></div>
<div class="row"><label for="wi-r">Releases a song in the window</label><input type="checkbox" id="wi-r" checked><b></b></div>
<div class="row"><label for="wi-h">Release week (weeks from now)</label><input type="range" id="wi-h" min="0" max="12" value="${Math.min(h, 12)}"><b id="wi-hv"></b></div>
<div class="row"><label for="wi-r">Releases a new song that week</label><input type="checkbox" id="wi-r" checked><b></b></div>
<div class="row"><label for="wi-n">…placed on New Music Friday Denmark</label><input type="checkbox" id="wi-n"><b></b></div>
<div class="row"><label for="wi-e">New chart entry, weeks ago</label><input type="range" id="wi-e" min="-1" max="26" value="-1"><b id="wi-ev"></b></div>
<div class="row"><label for="wi-t">Track Top-40 position now</label><input type="range" id="wi-t" min="0" max="40" value="0"><b id="wi-tv"></b></div>
<div class="row"><label for="wi-a">Airplay Top-20 position now</label><input type="range" id="wi-a" min="0" max="20" value="0"><b id="wi-av"></b></div>
<div id="wi-out"></div>
<p class="note">Switch the release on or off and change the artist's chart situation (as if it were true this week) to see how the forecast moves.</p>
<p class="note">Move the release week, switch the release or NMF placement, and change the artist's chart situation (as if it were true this week) to see how the forecast moves.</p>
</div>`;
let init = false, timer = null;
const label = () => {
@@ -387,7 +419,7 @@ function whatIfUI(a, h) {
const d = (x, y, f) => { const v = y - x; if (Math.abs(v) < 0.005 * (f === 'p' ? 1 : 100)) return ''; return `<span class="d ${v > 0 ? 'up' : 'down'}">${v > 0 ? '+' : ''}${f === 'p' ? Math.round(v * 100) + ' pts' : Math.round(v)}</span>`; };
const rows = [['Any DR station', w.base.add_any, w.scenario.add_any]].concat(GROUPS.map(([g, l]) => [l, chanP(w.base, g), chanP(w.scenario, g)]));
const onNow = Object.keys(w.current.in_rotation || {});
$('wi-out').innerHTML = `<p class="note">Chance of a new add in the 8 weeks from ${fmtDate(w.window_start)}. In rotation now on ${onNow.length ? onNow.length + ' station(s)' : 'no station'}. Now: ${w.current.t40 ? 'Track Top-40 #' + w.current.t40 : 'not on the Track Top-40'}, ${w.current.air ? 'Airplay Top-20 #' + w.current.air : 'not on the Airplay Top-20'}, ${w.current.entry == null ? 'no chart entry on record' : 'latest new chart entry ' + w.current.entry + ' weeks ago'}.</p>
$('wi-out').innerHTML = `<p class="note">${w.release ? (w.too_soon ? 'Too soon after their last release for a new-song estimate this week; the numbers below are the model\'s extrapolation.' : `A new song released the week of ${fmtDate(w.window_start)}: chance DR adds it within 8 weeks.`) : `No new release: chance of a new add from current songs in the 8 weeks from ${fmtDate(w.window_start)}.`} In rotation now on ${onNow.length ? onNow.length + ' station(s)' : 'no station'}. Now: ${w.current.t40 ? 'Track Top-40 #' + w.current.t40 : 'not on the Track Top-40'}, ${w.current.air ? 'Airplay Top-20 #' + w.current.air : 'not on the Airplay Top-20'}, ${w.current.entry == null ? 'no chart entry on record' : 'latest new chart entry ' + w.current.entry + ' weeks ago'}.</p>
<div class="kpis">${rows.map(([l, b, s]) => `<div class="kpi"><div>${l}</div><b>${pct(s)}</b>${d(b, s, 'p')}<div>was ${pct(b)}</div></div>`).join('')}
<div class="kpi"><div>Plays, first week</div><b>${Math.round(w.scenario.mean)}</b>${d(w.base.mean, w.scenario.mean, 'n')}<div>was ${Math.round(w.base.mean)}</div></div></div>`;
};
@@ -415,10 +447,50 @@ function renderModel() {
// ---------- wiring ----------
document.querySelectorAll('nav button').forEach(b => b.addEventListener('click', () => {
document.querySelectorAll('nav button').forEach(x => x.classList.toggle('on', x === b));
$('tab-rank').hidden = b.dataset.tab !== 'rank'; $('tab-model').hidden = b.dataset.tab !== 'model';
showTab(b.dataset.tab);
}));
function showTab(t) {
document.querySelectorAll('nav button').forEach(x => x.classList.toggle('on', x.dataset.tab === t));
['rank', 'best', 'model'].forEach(k => $('tab-' + k).hidden = k !== t);
}
$('h').addEventListener('input', () => { shown = 100; loadRank(); });
['ch', 'sort', 'dk', 'mode', 'recent'].forEach(id => $(id).addEventListener('change', () => { shown = 100; render(); }));
$('w').addEventListener('change', () => { shown = 100; loadRank(); });
['ch', 'sort', 'dk'].forEach(id => $(id).addEventListener('change', () => { shown = 100; render(); }));
// ---------- best week ----------
const artistByName = new Map();
let bestId = null;
function fillArtistList(rows) {
if (artistByName.size) return;
const opts = [];
rows.slice().sort((a, b) => a.name.localeCompare(b.name)).forEach(r => { if (!artistByName.has(r.name)) { artistByName.set(r.name, r.id); opts.push(`<option value="${esc(r.name)}">`); } });
$('bw-list').innerHTML = opts.join('');
}
function openBest(id, name) { bestId = id; $('bw-q').value = name; showTab('best'); loadBest(); }
async function loadBest() {
if (!bestId) return;
const w = $('bw-w').value, nmf = $('bw-nmf').value, ch = $('bw-ch').value;
$('bw-out').innerHTML = '<p class="empty">Loading…</p>';
const r = await fetch(`${BASE}/api/bestweek?id=${encodeURIComponent(bestId)}&w=${w}&nmf=${nmf}`);
if (r.status === 503) { $('bw-out').innerHTML = '<p class="empty">The model is still loading on the server; try again in a minute.</p>'; return; }
const b = await r.json();
if (b.error) { $('bw-out').innerHTML = `<p class="empty">${esc(b.error)}</p>`; return; }
const val = x => x.too_soon ? null : (ch === 'any' ? x.p : x.groups[ch]);
const vals = b.weeks.map(val).filter(v => v != null);
const max = Math.max(...vals), min = Math.min(...vals), avg = vals.reduce((s, v) => s + v, 0) / (vals.length || 1);
const best = b.weeks.find(x => val(x) === max);
// like a fare calendar: green = among the best weeks for this artist, red = among the worst
const level = v => { if (v == null || max === min) return 2; const z = (v - min) / (max - min); return z >= 0.85 ? 0 : z >= 0.5 ? 1 : z >= 0.2 ? 2 : 3; };
$('bw-out').innerHTML = vals.length ? `
<div class="bw-head"><h2>${esc(b.name)}</h2>
<span>Best week: <b>${fmtDate(best.week)}</b> · <b>${pct(max)}</b> chance DR adds a new song within ${w} weeks${ch === 'any' ? '' : ' on ' + ch} (average over the calendar ${pct(avg)}).</span></div>
<div class="cal">${b.weeks.map(x => { const v = val(x); return `<div class="day ${x.too_soon ? 'soon' : 'lvl' + level(v)} ${x === best ? 'best' : ''}" title="Release the week of ${fmtDate(x.week)}">
<div class="d">Week of ${fmtDate(x.week)}</div><div class="v">${x.too_soon ? 'too soon' : pct(v)}</div>${x.christmas ? '<span class="tag" title="Christmas weeks">🎄</span>' : ''}</div>`; }).join('')}</div>
<p class="note">Each tile: if ${esc(b.name)} releases a new song that week, the chance DR puts it into rotation within ${w} weeks. ${b.last_release ? `Their last release: ${fmtDate(b.last_release)}; weeks less than 6 weeks after it are "too soon" (the model only learned from releases with a clear gap).` : ''} The new song's NMF Denmark placement: ${nmf === 'auto' ? `as often as their releases were placed (${pct(b.p_nmf)})` : nmf === 'yes' ? 'placed' : 'not placed'}. What moves the numbers from week to week: time since their last release and last DR add, Christmas, and their NMF history; their current airplay is taken as it is now.</p>`
: `<h2>${esc(b.name)}</h2><p class="empty">No week in the next 26 has an estimate.</p>`;
}
$('bw-q').addEventListener('change', () => { const id = artistByName.get($('bw-q').value); if (id) { bestId = id; loadBest(); } });
['bw-w', 'bw-nmf', 'bw-ch'].forEach(id => $(id).addEventListener('change', loadBest));
$('q').addEventListener('input', () => { shown = 100; render(); });
$('more').addEventListener('click', () => { shown += 100; render(); });
$('rows').addEventListener('click', e => { const tr = e.target.closest('tr[data-id]'); if (tr) showArtist(tr.dataset.id); });