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
+27 -1
View File
@@ -81,6 +81,9 @@ pub struct Panel {
pub listed_on: Vec<Vec<NaiveDate>>,
/// New Music Friday Denmark placements per artist: (Friday, position if known), sorted.
pub nmf_dk: Vec<Vec<(NaiveDate, Option<i64>)>>,
/// Season index per ISO week (1..=53): new songs reaching the Airplay Top-20 that week of the
/// year, relative to an average week, 2002–2024 (before the DR panel), smoothed over 5 weeks.
pub season: [f64; 54],
}
impl Panel {
@@ -147,7 +150,8 @@ impl Panel {
let releases = load_releases(db, &id_of, artists.len())?;
let (archive_rate, listed_on) = load_long_history(db, &id_of, &names, artists.len())?;
let nmf_dk = load_nmf_dk(db, &id_of, &artists)?;
Ok(Panel { weeks, artists, y, chart, list_tau, releases, archive_rate, listed_on, nmf_dk })
let season = load_season(db)?;
Ok(Panel { weeks, artists, y, chart, list_tau, releases, archive_rate, listed_on, nmf_dk, season })
}
}
@@ -310,3 +314,25 @@ fn load_nmf_dk(db: &Db, id_of: &HashMap<String, usize>, artists: &[Artist]) -> R
for v in out.iter_mut() { v.sort(); v.dedup_by_key(|x| x.0); }
Ok(out)
}
fn load_season(db: &Db) -> Result<[f64; 54]> {
let mut first: HashMap<String, (i32, u32)> = HashMap::new();
for r in db.conn.prepare("SELECT year, week, artist, title FROM hitlisten_charts WHERE chart = 'airplay' AND year BETWEEN 2002 AND 2024")?
.query_map([], |r| Ok((r.get::<_, i32>(0)?, r.get::<_, u32>(1)?, r.get::<_, String>(2)?, r.get::<_, String>(3)?)))? {
let (y, w, a, t) = r?;
let k = format!("{}|{}", key(&a), key(t.split(" (").next().unwrap_or(&t)));
let e = first.entry(k).or_insert((y, w));
if (y, w) < *e { *e = (y, w); }
}
let mut n = [0.0f64; 54];
for (_, w) in first.values() { if (1..=53).contains(w) { n[*w as usize] += 1.0; } }
n[53] = n[52]; // week 53 is rare; treat like 52
let mut out = [1.0f64; 54];
let mean = n[1..=52].iter().sum::<f64>() / 52.0;
if mean == 0.0 { return Ok(out); }
for w in 1..=53usize {
let s: f64 = (-2i32..=2).map(|d| { let k = ((w as i32 - 1 + d).rem_euclid(52) + 1) as usize; n[k] }).sum::<f64>() / 5.0;
out[w] = (s / mean).max(0.2);
}
Ok(out)
}