Old DR artist pages from the Wayback Machine (53 weeks of plays per capture, 2019-2024) into dr_artist_history; leak fixes (weeks since last add counts only adds up to t-1; training windows close a week before the origin) and a leak test (model leakcheck) that rebuilds every feature from data cut at the origin; backtests split pre-release (NMF from history) and post-release (NMF known); site shows the new-song backtest

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 00:22:55 +00:00
co-authored by Claude Opus 5.5
parent 7a16eb45ef
commit 94abfa0255
9 changed files with 512 additions and 223 deletions
+22
View File
@@ -38,6 +38,7 @@ impl Panel {
}
}
#[derive(Clone)]
pub struct Artist {
pub id: String,
pub name: String,
@@ -65,6 +66,7 @@ pub struct Chart {
pub air_gap: u16,
}
#[derive(Clone)]
pub struct Panel {
/// Monday of each complete week, oldest first.
pub weeks: Vec<NaiveDate>,
@@ -100,6 +102,26 @@ impl Panel {
#[inline]
pub fn chart(&self, a: usize, w: usize) -> Chart { self.chart[a * self.weeks.len() + w] }
/// The panel as it was known at the end of week t: plays after t removed (and taken out of the
/// all-time counts), releases, NMF placements and lists after t dropped. For the leak test.
pub fn truncated(&self, t: usize) -> Panel {
let mut q = self.clone();
let nw = self.w();
let end_t = self.weeks[t] + Duration::days(6);
for a in 0..self.a() {
for g in 0..GROUPS {
let cs: Vec<usize> = (0..C).filter(|&c| group(c) == g).collect();
let after: f64 = (t + 1..nw).map(|w| cs.iter().map(|&c| self.y(a, c, w)).sum::<f64>() / cs.len() as f64).sum();
q.alltime[a][g] = (self.alltime[a][g] - after).max(0.0);
}
for c in 0..C { for w in t + 1..nw { q.y[(a * C + c) * nw + w] = 0.0; } }
if let Some(r) = q.releases[a].as_mut() { r.retain(|d| *d <= end_t); }
q.nmf_dk[a].retain(|(d, _)| *d <= end_t);
q.listed_on[a].retain(|d| *d <= end_t);
}
q
}
pub fn load(db: &Db) -> Result<Panel> {
// Weeks: every Monday in the artist pages whose week had ended before the earliest page was read.
let first_read: String = db.conn.query_row("SELECT min(fetched_at) FROM dr_artists", [], |r| r.get(0))?;