Deezer discographies for every DR artist; release features in the add model (recency, releases in the window); rankings 'if they release in the window' and blended by release rate; site switch and what-if release toggle

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 03:21:59 +00:00
co-authored by Claude Opus 5.5
parent 7815ed417c
commit 5b7e544b1c
7 changed files with 189 additions and 34 deletions
+10 -4
View File
@@ -186,6 +186,9 @@ fn fold(e: &mut Value, target: &str, ch: &str, prob: Option<f64>, mean: Option<f
"rotation" => { e["p"][ch] = r3(prob); e["plays"][ch] = r1(mean); }
"add_any" => { e["add_any"] = r3(prob); }
"add" => { e["add"][ch] = r3(prob); }
"add_any_rel" => { e["add_any_rel"] = r3(prob); }
"add_rel" => { if !e["add_rel"].is_object() { e["add_rel"] = json!({}); } e["add_rel"][ch] = r3(prob); }
"p_release" => { e["p_release"] = r3(prob); }
"now" => { e["now"][ch] = json!({"on": prob.unwrap_or(0.0) > 0.5, "plays": mean}); }
_ => {}
}
@@ -231,7 +234,7 @@ fn rank(st: &State, h: usize) -> Result<Reply> {
}
let mut rows: HashMap<String, Value> = HashMap::new();
let mut st_ = c.prepare("SELECT key, target, prob, mean, lo, hi, target_week FROM forecasts WHERE made_at = ?1 AND model_version = ?2
AND ((target IN ('rotation', 'any') AND horizon = ?3) OR (target IN ('add', 'add_any') AND horizon = ?4) OR target = 'now')")?;
AND ((target IN ('rotation', 'any') AND horizon = ?3) OR (target IN ('add', 'add_any', 'add_rel', 'add_any_rel', 'p_release') AND horizon = ?4) OR target = 'now')")?;
let it = st_.query_map(params![made, VERSION, h.max(1) as i64, h as i64], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?, r.get::<_, Option<f64>>(2)?,
r.get::<_, Option<f64>>(3)?, r.get::<_, Option<f64>>(4)?, r.get::<_, Option<f64>>(5)?, r.get::<_, String>(6)?)))?;
let mut window = String::new();
@@ -296,7 +299,7 @@ fn artist(st: &State, id: &str) -> Result<Reply> {
let ch = key.split_once(':').map(|x| x.1).unwrap_or("");
if target == "now" { fold(&mut now, "now", ch, prob, mean, lo, hi); continue; }
let e = byh.entry(h).or_insert_with(|| json!({"h": h, "p": {}, "plays": {}, "add": {}}));
if target.starts_with("add") { e["window_start"] = json!(week); } else { e["week"] = json!(week); }
if target.starts_with("add") || target == "p_release" { e["window_start"] = json!(week); } else { e["week"] = json!(week); }
fold(e, &target, ch, prob, mean, lo, hi);
}
now_out = now["now"].clone();
@@ -352,11 +355,13 @@ fn whatif(st: &State, q: &HashMap<String, String>) -> Result<Reply> {
let num = |k: &str| q.get(k).filter(|v| !v.is_empty()).and_then(|v| v.parse::<f64>().ok());
let entry: Option<Option<f64>> = q.get("entry").filter(|v| !v.is_empty()).map(|v| if v == "none" { None } else { v.parse().ok() });
let (t40, air) = (num("t40"), num("air"));
// The scenario: a release in the window (default) or none.
let release = q.get("release").map(|v| v != "no").unwrap_or(true);
let over = move |x: &mut [f64], idx: [usize; 4]| set_chart(x, idx, entry, t40, air);
let run = |overrides: bool| -> Value {
let f: Option<&dyn Fn(&mut [f64], [usize; 4])> = if overrides { Some(&over) } else { None };
let (add_c, add_any) = am.predict(p, &m.rot, a, t0, f);
let (add_c, add_any) = am.predict(p, &m.rot, a, t0, Some(release), f);
let mut x = vec![0.0; P];
let mut mu = [0.0; C];
for c in 0..C {
@@ -378,7 +383,8 @@ fn whatif(st: &State, q: &HashMap<String, String>) -> Result<Reply> {
};
let now: serde_json::Map<String, Value> = (0..C).filter(|&c| m.rot.on(a, c, t0)).map(|c| (CHANNELS[c].to_string(), json!(p.y(a, c, t0)))).collect();
ok(json!({
"h": h, "window_start": (p.weeks[t0] + chrono::Duration::weeks(h as i64 + 1)).to_string(),
"h": h, "release": release, "p_release": crate::model::adds::p_release(p, a, t0),
"window_start": (p.weeks[t0] + chrono::Duration::weeks(h as i64 + 1)).to_string(),
"current": {"t40": chart.t40_rank, "air": chart.air_rank,
"entry": if chart.weeks_since_entry == u16::MAX { Value::Null } else { json!(chart.weeks_since_entry) },
"t40_hits": chart.t40_hits, "air_hits": chart.air_hits, "in_rotation": now},