Wave features (time since the last DR add / Airplay Top-20 wave, peak band 13-25 weeks, 0.5-1.25x the artist's usual gap); ablation switch (model adds --without rel,wave); fix the per-channel row slice

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 03:56:10 +00:00
co-authored by Claude Opus 5.5
parent 7d656834fb
commit 992cc2b157
6 changed files with 209 additions and 15 deletions
+16 -1
View File
@@ -41,6 +41,10 @@ pub struct Chart {
/// Distinct songs on the Track Top-40 / Airplay Top-20 so far.
pub t40_hits: u16,
pub air_hits: u16,
/// Airplay Top-20 "waves": weeks since the artist's latest new song on the Airplay Top-20
/// (u16::MAX = never), and the median gap between their earlier new songs (0 = fewer than 2 gaps).
pub air_since: u16,
pub air_gap: u16,
}
pub struct Panel {
@@ -170,10 +174,12 @@ fn chart_states(db: &Db, weeks: &[NaiveDate], names: &HashMap<String, Vec<usize>
for entries in &by_artist {
for w in 0..nw {
let cutoff = cutoffs[w];
let mut s = Chart { t40_rank: 0, air_rank: 0, weeks_since_entry: u16::MAX, t40_hits: 0, air_hits: 0 };
let mut s = Chart { t40_rank: 0, air_rank: 0, weeks_since_entry: u16::MAX, t40_hits: 0, air_hits: 0, air_since: u16::MAX, air_gap: 0 };
let mut air_firsts: BTreeSet<NaiveDate> = BTreeSet::new();
let (mut t40_songs, mut air_songs) = (BTreeSet::new(), BTreeSet::new());
for e in entries.iter().filter(|e| e.monday <= cutoff) {
if e.t40 { t40_songs.insert(&e.song); } else { air_songs.insert(&e.song); }
if !e.t40 && e.new { air_firsts.insert(e.monday); }
let best = |cur: u8| if cur == 0 { e.rank } else { cur.min(e.rank) };
if e.t40 && Some(e.monday) == latest_t40[w] { s.t40_rank = best(s.t40_rank); }
if !e.t40 && Some(e.monday) == latest_air[w] { s.air_rank = best(s.air_rank); }
@@ -184,6 +190,15 @@ fn chart_states(db: &Db, weeks: &[NaiveDate], names: &HashMap<String, Vec<usize>
}
s.t40_hits = t40_songs.len() as u16;
s.air_hits = air_songs.len() as u16;
// Waves: new songs at least 2 weeks apart.
let mut waves: Vec<NaiveDate> = Vec::new();
for d in &air_firsts { if waves.last().is_none_or(|l| (*d - *l).num_days() >= 14) { waves.push(*d); } }
if let Some(last) = waves.last() { s.air_since = ((cutoff - *last).num_days() / 7).clamp(0, u16::MAX as i64 - 1) as u16; }
if waves.len() >= 3 {
let mut gaps: Vec<i64> = waves.windows(2).map(|w| (w[1] - w[0]).num_days() / 7).collect();
gaps.sort();
s.air_gap = gaps[gaps.len() / 2].clamp(1, 2000) as u16;
}
out.push(s);
}
}