Surge-based adds (onset, or plays jumping well above the artist's own baseline and staying up): finds 77% of DR's real song adds vs 64% for onset only; addcheck validation against the lists

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 13:04:22 +00:00
co-authored by Claude Opus 5.5
parent bc222d3cd0
commit cb5224fc4f
4 changed files with 142 additions and 47 deletions
+36 -3
View File
@@ -230,8 +230,16 @@ pub struct Rot {
pub tau: [u32; C],
rot: Vec<bool>, // [a][c][w]
any: Vec<bool>, // [a][w]
adds: Vec<bool>, // [a][c][w]
adds_any: Vec<bool>, // [a][w]
}
/// Which add definition: "onset" = entering rotation after GAP+ weeks out (the original); "surge" =
/// onset, or plays jumping well above the artist's own 8-week baseline and staying up the next
/// week (catches new songs of artists who never leave rotation). Default: surge.
pub static ADD_RULE: std::sync::OnceLock<String> = std::sync::OnceLock::new();
fn surge_rule() -> bool { ADD_RULE.get().is_none_or(|r| r != "onset") }
impl Rot {
pub fn new(p: &Panel, tau: &[u32; C]) -> Rot {
let nw = p.w();
@@ -242,12 +250,37 @@ impl Rot {
rot[(a * C + c) * nw + w] = r;
if r { any[a * nw + w] = true; }
} } }
Rot { nw, tau: *tau, rot, any }
let mut adds = vec![false; p.a() * C * nw];
let mut adds_any = vec![false; p.a() * nw];
let surge = surge_rule();
for a in 0..p.a() {
for c in 0..C {
let on = |w: usize| rot[(a * C + c) * nw + w];
let t = tau[c] as f64;
for w in GAP..nw {
let onset = on(w) && (1..=GAP).all(|k| !on(w - k));
let jump = surge && w >= 8 && w + 1 < nw && {
let mut b: Vec<f64> = (w - 8..w).map(|k| p.y(a, c, k)).collect();
b.sort_by(f64::total_cmp);
let base = b[4];
let (y0, y1) = (p.y(a, c, w), p.y(a, c, w + 1));
y0 >= (0.6 * t).max(base + (0.5 * t).max(0.5 * base)) && y1 >= (0.6 * t).max(base + (0.25 * t).max(0.25 * base))
};
if (onset || jump) && (1..=GAP).all(|k| !adds[(a * C + c) * nw + w - k]) { adds[(a * C + c) * nw + w] = true; }
}
}
for w in GAP..nw {
let classic = any[a * nw + w] && (1..=GAP).all(|k| !any[a * nw + w - k]);
let some = if surge { (0..C).any(|c| adds[(a * C + c) * nw + w]) } else { classic };
if some && (1..=GAP).all(|k| !adds_any[a * nw + w - k]) { adds_any[a * nw + w] = true; }
}
}
Rot { nw, tau: *tau, rot, any, adds, adds_any }
}
pub fn on(&self, a: usize, c: usize, w: usize) -> bool { self.rot[(a * C + c) * self.nw + w] }
pub fn any(&self, a: usize, w: usize) -> bool { self.any[a * self.nw + w] }
pub fn add(&self, a: usize, c: usize, w: usize) -> bool { w >= GAP && self.on(a, c, w) && (1..=GAP).all(|k| !self.on(a, c, w - k)) }
pub fn add_any(&self, a: usize, w: usize) -> bool { w >= GAP && self.any(a, w) && (1..=GAP).all(|k| !self.any(a, w - k)) }
pub fn add(&self, a: usize, c: usize, w: usize) -> bool { w < self.nw && self.adds[(a * C + c) * self.nw + w] }
pub fn add_any(&self, a: usize, w: usize) -> bool { w < self.nw && self.adds_any[a * self.nw + w] }
/// An add in weeks t+h+1 ..= t+h+W (all inside the panel).
pub fn add_in_window(&self, a: usize, c: usize, t: usize, h: usize) -> bool { self.add_in(a, c, t, h, W) }
pub fn add_any_in_window(&self, a: usize, t: usize, h: usize) -> bool { self.add_any_in(a, t, h, W) }