New-add model (add = entering rotation after 4+ weeks out; per channel and any DR channel, 8-week window), site ranks by it; DR rotation-list PDF parser (glyph positions, channel by play profile) and Wayback Machine backfill: 29 weekly lists 2023-2026

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 02:50:13 +00:00
co-authored by Claude Opus 5.5
parent 387502ebfa
commit c698925814
9 changed files with 1122 additions and 89 deletions
+61 -39
View File
@@ -107,7 +107,7 @@ svg text { fill: var(--muted); font-size: 11px; }
<main>
<section id="tab-rank">
<div class="controls">
<div class="ctl">Week <b id="hlabel">—</b><input type="range" id="h" min="1" max="12" value="4"></div>
<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">Station
<select id="ch">
<option value="any">Any DR station</option>
@@ -120,7 +120,7 @@ svg text { fill: var(--muted); font-size: 11px; }
</div>
<div class="ctl">Sort by
<select id="sort">
<option value="p">Chance of rotation</option>
<option value="p">Chance of a new add</option>
<option value="plays">Expected plays</option>
<option value="up">Biggest climbers</option>
</select>
@@ -131,24 +131,25 @@ svg text { fill: var(--muted); font-size: 11px; }
<div class="tablewrap">
<table>
<thead><tr>
<th class="l">#</th><th class="l">Artist</th><th>Chance</th>
<th class="l">#</th><th class="l">Artist</th><th>New add</th>
<th class="hide-sm">P3</th><th class="hide-sm">P4</th><th class="hide-sm">P5</th><th class="hide-sm">P6</th><th class="hide-sm">P8</th>
<th>Plays / wk (80%)</th>
<th class="l hide-sm">In rotation now</th><th>Plays / wk (80%)</th>
</tr></thead>
<tbody id="rows"><tr><td colspan="9" class="empty">Loading…</td></tr></tbody>
<tbody id="rows"><tr><td colspan="10" class="empty">Loading…</td></tr></tbody>
</table>
</div>
<button class="more" id="more" hidden>Show more</button>
<p class="note">Chance = probability the artist is in rotation (plays at or above the station's weekly threshold) in the chosen week. "Biggest climbers" ranks by expected plays in that week versus the latest week. Click an artist for history and a what-if.</p>
<p class="note"><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>
</section>
<section id="tab-model" hidden>
<div class="prose">
<h2>What the model does</h2>
<p>For every artist DR has played, it forecasts each DR music station's weekly plays 1–12 weeks ahead, and the chance that the artist is "in rotation" (at or above the station's weekly play threshold). It learns from 51 weeks of DR's per-artist weekly play counts plus the artist's IFPI chart history (Track Top-40, Airplay Top-20).</p>
<p>For every artist DR has played, it estimates the chance of a <b>new add</b>: the artist entering rotation on a station (at or above its weekly play threshold) after at least 4 weeks out of rotation, within an 8-week window starting 0–12 weeks from now. It also forecasts weekly plays. It learns from 51 weeks of DR's per-artist weekly play counts plus the artist's IFPI chart history (Track Top-40, Airplay Top-20).</p>
<p>DR publishes plays per artist, not per song, so "new add" can't yet tell a new song from an old one coming back. In the one week of song-level plays we have, only 3–12% of artists in rotation on a station had two songs in rotation at once, so "drops out first, then gets added" is the usual pattern. The weekly rotation lists (song level) will sharpen this.</p>
<p id="taus" class="note"></p>
</div>
<h2>Backtest</h2>
<h2>Backtest: new adds</h2>
<p class="note prose">Walk-forward: for each week from week 27, the models are fitted only on what was known at the time and forecast 1, 4 and 8 weeks ahead. "Adds" are rows where the artist was not in rotation at the time of the forecast, which is the hard and interesting part. Skill above 0 means better than the baseline.</p>
<div class="cards" id="cards"></div>
<div class="prose">
@@ -178,10 +179,23 @@ const esc = s => String(s ?? '').replace(/[&<>"']/g, c => ({ '&': '&amp;', '<':
const pct = p => p == null ? '—' : (p >= 0.995 ? '>99' : p < 0.005 ? '<1' : Math.round(p * 100)) + '%';
const fmtDate = s => new Date(s + 'T00:00:00Z').toLocaleDateString('en-GB', { day: 'numeric', month: 'short', timeZone: 'UTC' });
// Chance of a new add in the window (station group g, or any DR station).
function chanP(r, g) {
if (g === 'any') return r.p_any;
if (g === 'p4') return Math.max(...P4S.map(c => r.p[c] ?? 0));
return r.p[g];
if (g === 'any') return r.add_any;
if (g === 'p4') return Math.max(...P4S.map(c => r.add?.[c] ?? 0));
return r.add?.[g];
}
function nowPlays(r, g) {
const now = r.now || {};
const v = c => now[c]?.plays ?? 0;
if (g === 'any') return Object.keys(now).reduce((s, c) => s + v(c), 0);
if (g === 'p4') return P4S.reduce((s, c) => s + v(c), 0) / P4S.length;
return v(g);
}
function nowChips(now) {
now = now || {};
const on = GROUPS.filter(([g]) => g === 'p4' ? P4S.some(c => now[c]?.on) : now[g]?.on).map(([, l]) => l);
return on.length ? on.join(' · ') : '<span class="note">—</span>';
}
function chanPlays(r, g) {
if (g === 'any') return r.mean;
@@ -190,7 +204,7 @@ function chanPlays(r, g) {
}
function heat(p) {
if (p == null) return '';
const a = Math.min(1, Math.max(0, p));
const a = Math.min(1, Math.max(0, p / 0.5));
return `background: color-mix(in srgb, var(--accent) ${Math.round(a * 85)}%, transparent); color: ${a > .55 ? '#fff' : 'inherit'}`;
}
@@ -203,22 +217,24 @@ async function loadMeta() {
renderModel();
}
function windowStart(h) {
const d = new Date(meta.origin_week + 'T00:00:00Z');
d.setUTCDate(d.getUTCDate() + 7 * (h + 1));
return d.toISOString().slice(0, 10);
}
async function loadRank() {
const h = +$('h').value;
const hz = meta.horizons.find(x => x.h === h);
$('hlabel').textContent = hz ? `${fmtDate(hz.week)} (+${h} wk)` : `+${h} wk`;
$('hlabel').textContent = `${fmtDate(windowStart(h))}${h ? ` (+${h} wk)` : ' (next week)'}`;
if (!data[h]) data[h] = (await API('rank?h=' + h)).rows;
if (!data[1]) data[1] = (await API('rank?h=1')).rows;
render();
}
function render() {
const h = +$('h').value, g = $('ch').value, sort = $('sort').value, q = $('q').value.trim().toLowerCase(), dk = $('dk').checked;
const now = Object.fromEntries((data[1] || []).map(r => [r.id, r]));
let rows = data[h].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) - (chanPlays(now[r.id] || r, g) ?? 0), 0];
: r => [(chanPlays(r, g) ?? 0) - nowPlays(r, g), 0];
rows = rows.map(r => [key(r), r]).sort((a, b) => b[0][0] - a[0][0] || b[0][1] - a[0][1]).map(x => x[1]);
current = rows;
const body = rows.slice(0, shown).map((r, i) => {
@@ -229,10 +245,11 @@ function render() {
<td class="l name">${esc(r.name)}${r.danish ? '<small>DK</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)}</td>
<td>${pl == null ? '—' : pl.toFixed(pl < 10 ? 1 : 0)}${range}</td>
</tr>`;
}).join('');
$('rows').innerHTML = body || '<tr><td colspan="9" class="empty">No artists match.</td></tr>';
$('rows').innerHTML = body || '<tr><td colspan="10" class="empty">No artists match.</td></tr>';
$('more').hidden = rows.length <= shown;
}
@@ -243,12 +260,13 @@ function closeDrawer() { $('drawer').classList.remove('on'); $('shade').classLis
function historyChart(a) {
// Weekly plays: P3, P4 (mean of regions), P5, P6, P8 as lines, then the forecast of total plays as a band.
const W = 700, H = 220, L = 34, R = 10, T = 10, B = 26;
const n = a.weeks.length, f = a.forecasts.length;
const fcs = a.forecasts.filter(x => x.mean != null);
const n = a.weeks.length, f = fcs.length;
const series = GROUPS.map(([g]) => g === 'p4'
? a.weeks.map((_, i) => P4S.reduce((s, c) => s + (a.plays[c]?.[i] ?? 0), 0) / P4S.length)
: (a.plays[g] || []).slice());
const total = a.weeks.map((_, i) => Object.values(a.plays).reduce((s, v) => s + (v[i] ?? 0), 0));
const maxY = Math.max(5, ...series.flat(), ...a.forecasts.map(x => (x.hi ?? 0) / 4), ...total.map(t => t / 4));
const maxY = Math.max(5, ...series.flat(), ...fcs.map(x => (x.hi ?? 0) / 4), ...total.map(t => t / 4));
const X = i => L + (W - L - R) * i / (n + f - 1);
const Y = v => T + (H - T - B) * (1 - v / maxY);
let s = `<svg viewBox="0 0 ${W} ${H}" width="100%" role="img" aria-label="Weekly plays per station">`;
@@ -260,10 +278,10 @@ function historyChart(a) {
s += `<text x="${X(n - 0.3)}" y="${T + 12}">forecast</text>`;
// forecast band of total plays scaled to "per station" (÷ 4 so it shares the axis), labelled
if (f) {
const up = a.forecasts.map((x, i) => `${X(n + i)},${Y((x.hi ?? 0) / 4)}`).join(' ');
const dn = a.forecasts.map((x, i) => `${X(n + i)},${Y((x.lo ?? 0) / 4)}`).reverse().join(' ');
const up = fcs.map((x, i) => `${X(n + i)},${Y((x.hi ?? 0) / 4)}`).join(' ');
const dn = fcs.map((x, i) => `${X(n + i)},${Y((x.lo ?? 0) / 4)}`).reverse().join(' ');
s += `<polygon points="${up} ${dn}" fill="var(--muted)" opacity=".18"/>`;
s += `<polyline points="${X(n - 1)},${Y(total[n - 1] / 4)} ${a.forecasts.map((x, i) => `${X(n + i)},${Y((x.mean ?? 0) / 4)}`).join(' ')}" fill="none" stroke="var(--muted)" stroke-width="2" stroke-dasharray="4 3"/>`;
s += `<polyline points="${X(n - 1)},${Y(total[n - 1] / 4)} ${fcs.map((x, i) => `${X(n + i)},${Y((x.mean ?? 0) / 4)}`).join(' ')}" fill="none" stroke="var(--muted)" stroke-width="2" stroke-dasharray="4 3"/>`;
s += `<polyline points="${total.map((t, i) => `${X(i)},${Y(t / 4)}`).join(' ')}" fill="none" stroke="var(--muted)" stroke-width="1.5" opacity=".6"/>`;
}
GROUPS.forEach(([g], k) => {
@@ -272,7 +290,7 @@ function historyChart(a) {
s += `<polyline points="${v.map((y, i) => `${X(i)},${Y(y)}`).join(' ')}" fill="none" stroke="${COLORS[g]}" stroke-width="2"/>`;
});
[0, Math.floor(n / 2), n - 1].forEach(i => s += `<text x="${X(i)}" y="${H - 8}" text-anchor="middle">${fmtDate(a.weeks[i])}</text>`);
if (f) s += `<text x="${X(n + f - 1)}" y="${H - 8}" text-anchor="end">${fmtDate(a.forecasts[f - 1].week)}</text>`;
if (f) s += `<text x="${X(n + f - 1)}" y="${H - 8}" text-anchor="end">${fmtDate(fcs[f - 1].week)}</text>`;
s += '</svg>';
s += `<div class="legend">${GROUPS.map(([g, l]) => `<span><i style="background:${COLORS[g]}"></i>${l}${g === 'p4' ? ' (avg region)' : ''}</span>`).join('')}<span><i style="background:var(--muted)"></i>All DR ÷ 4, forecast with 80% band</span></div>`;
return s;
@@ -284,6 +302,7 @@ async function showArtist(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 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; });
@@ -295,12 +314,12 @@ async function showArtist(id) {
<button class="x" aria-label="Close" onclick="closeDrawer()">×</button>
</div>
<div class="sec">
<h3>Week of ${fc.week ? fmtDate(fc.week) : '—'} (+${fc.h ?? h} weeks)</h3>
<h3>Chance of a new add in the 8 weeks from ${fc.window_start ? fmtDate(fc.window_start) : '—'}</h3>
<div class="kpis">
<div class="kpi"><div>Any DR station</div><b>${pct(fc.p_any)}</b></div>
<div class="kpi"><div>Any DR station</div><b>${pct(fc.add_any)}</b></div>
${GROUPS.map(([g, l]) => `<div class="kpi"><div>${l}</div><b>${pct(chanP(fc, g))}</b></div>`).join('')}
<div class="kpi"><div>Plays that week</div><b>${Math.round(fc.mean ?? 0)}</b> <span class="note">${Math.round(fc.lo ?? 0)}–${Math.round(fc.hi ?? 0)}</span></div>
</div>
<p class="note">In rotation now: ${nowChips(a.now)} · 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>
<div class="sec"><h3>What if…</h3><div id="wi" class="note">Loading the model…</div></div>
@@ -313,7 +332,7 @@ async function showArtist(id) {
function whatIfUI(a, h) {
const box = $('wi');
box.innerHTML = `<div class="wi">
<div class="row"><label for="wi-h">Weeks ahead</label><input type="range" id="wi-h" min="1" max="${meta.horizons.length}" value="${h}"><b id="wi-hv"></b></div>
<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-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>
@@ -342,10 +361,11 @@ function whatIfUI(a, h) {
label();
}
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.p_any, w.scenario.p_any]].concat(GROUPS.map(([g, l]) => [l, chanP(w.base, g), chanP(w.scenario, g)]));
$('wi-out').innerHTML = `<p class="note">Week of ${fmtDate(w.week)}. 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>
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>
<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 that 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>`;
<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>`;
};
['wi-h', 'wi-e', 'wi-t', 'wi-a'].forEach(id => $(id).addEventListener('input', () => { label(); clearTimeout(timer); timer = setTimeout(run, 120); }));
run();
@@ -355,15 +375,17 @@ function whatIfUI(a, h) {
function renderModel() {
const sc = meta.backtest || [];
const get = (m, h, k) => sc.find(x => x.model === m && x.h === h && x.metric === k)?.value;
const hs = [...new Set(sc.map(x => x.h))].sort((a, b) => a - b);
const names = { persistence: 'Same as now', popularity: 'Last 12 weeks', kalman: 'Kalman form', nb: 'Play-count model', logit: 'Rotation model' };
const hs = [...new Set(sc.filter(x => x.metric.startsWith('add')).map(x => x.h))].sort((a, b) => a - b);
const ms = [['rate by in-rotation-now', 'Rate by "in rotation now"'], ['rate by last-12-weeks level', 'Rate by last-12-weeks level'], ['logit', 'Model']];
const f = (v, d) => v == null || isNaN(v) ? '—' : v.toFixed(d);
$('cards').innerHTML = hs.map(h => {
const ms = ['persistence', 'popularity', 'kalman', 'nb', 'logit'];
return `<div class="card"><h3>${h} week${h > 1 ? 's' : ''} ahead</h3>
<table class="wtable"><thead><tr><th class="l">Model</th><th>Skill on adds<br>vs last 12 wks</th><th>Ranking<br>NDCG@50</th></tr></thead><tbody>
${ms.map(m => { const s = get(m, h, 'skill_add_vs_popularity'); return `<tr><td class="l">${names[m]}</td><td class="${s > 0 ? 'up' : s < 0 ? 'down' : ''}">${s == null ? 'baseline' : (s > 0 ? '+' : '') + s.toFixed(3)}</td><td>${(get(m, h, 'ndcg50') ?? 0).toFixed(3)}</td></tr>`; }).join('')}
</tbody></table></div>`;
}).join('') || '<p class="note">No backtest stored yet (`airplay model backtest`).</p>';
const sk = get('logit', h, 'addany_skill_vs_level'), skc = get('logit', h, 'add_skill_vs_level');
return `<div class="card"><h3>Window starting ${h ? h + ' weeks ahead' : 'now'}</h3>
<table class="wtable"><thead><tr><th class="l"></th><th>Any station<br>log-loss</th><th>Any station<br>PR-AUC</th><th>Per station<br>PR-AUC</th></tr></thead><tbody>
${ms.map(([m, l]) => `<tr><td class="l">${l}</td><td>${f(get(m, h, 'addany_logloss'), 3)}</td><td>${f(get(m, h, 'addany_prauc'), 3)}</td><td>${f(get(m, h, 'add_prauc'), 3)}</td></tr>`).join('')}
</tbody></table>
<p>Skill vs the last-12-weeks baseline: <b class="${sk > 0 ? 'up' : 'down'}">${sk > 0 ? '+' : ''}${f(sk, 3)}</b> any station, <b class="${skc > 0 ? 'up' : 'down'}">${skc > 0 ? '+' : ''}${f(skc, 3)}</b> per station. Lower log-loss and higher PR-AUC are better.</p></div>`;
}).join('') || '<p class="note">No add backtest stored yet (`airplay model adds`).</p>';
}
// ---------- wiring ----------