Wider artist pool (artists credited on DR-played tracks, groups; weekly refresh, oldest first); Platt recalibration of the add model on recent closed windows; Bauer plays per artist on the site
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+38
-1
@@ -191,6 +191,34 @@ fn fold(e: &mut Value, target: &str, ch: &str, prob: Option<f64>, mean: Option<f
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Bauer plays (NOVA, Radio Soft, The Voice, Pop FM, Radio 100) in the 7 days up to the latest
|
||||
/// one, per artist name key (each credited artist) and station: (plays, songs).
|
||||
fn bauer_week(c: &Connection) -> Result<HashMap<String, HashMap<String, (i64, Vec<(String, i64)>)>>> {
|
||||
let mut out: HashMap<String, HashMap<String, (i64, Vec<(String, i64)>)>> = HashMap::new();
|
||||
let mut st = c.prepare(
|
||||
"SELECT station, artist, title, count(*) FROM plays WHERE source = 'bauer'
|
||||
AND played_at > (SELECT strftime('%Y-%m-%dT%H:%M:%SZ', max(played_at), '-7 days') FROM plays WHERE source = 'bauer')
|
||||
GROUP BY station, artist, title")?;
|
||||
let rows = st.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?, r.get::<_, String>(2)?, r.get::<_, i64>(3)?)))?;
|
||||
for r in rows {
|
||||
let (station, artist, title, n) = r?;
|
||||
let mut parts = vec![artist.to_lowercase()];
|
||||
for sep in [" feat. ", " feat ", " ft. ", " ft ", " featuring ", " & ", ", ", " x ", " og ", " vs "] {
|
||||
parts = parts.iter().flat_map(|p| p.split(sep).map(str::to_string).collect::<Vec<_>>()).collect();
|
||||
}
|
||||
let mut keys: Vec<String> = parts.iter().map(|p| crate::model::panel::key(p)).collect();
|
||||
keys.push(crate::model::panel::key(&artist));
|
||||
keys.sort(); keys.dedup();
|
||||
for k in keys.into_iter().filter(|k| !k.is_empty()) {
|
||||
let e = out.entry(k).or_default().entry(station.clone()).or_insert((0, Vec::new()));
|
||||
e.0 += n;
|
||||
e.1.push((title.clone(), n));
|
||||
}
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn rank(st: &State, h: usize) -> Result<Reply> {
|
||||
let c = ro(&st.db_path)?;
|
||||
let Some(made) = latest_run(&c)? else { return ok(json!({"rows": []})) };
|
||||
@@ -217,6 +245,11 @@ fn rank(st: &State, h: usize) -> Result<Reply> {
|
||||
if target == "add_any" && window.is_empty() { window = week; }
|
||||
fold(e, &target, ch, prob, mean, lo, hi);
|
||||
}
|
||||
let bauer = bauer_week(&c)?;
|
||||
for e in rows.values_mut() {
|
||||
let k = crate::model::panel::key(e["name"].as_str().unwrap_or(""));
|
||||
if let Some(b) = bauer.get(&k) { e["bauer"] = json!(b.iter().map(|(s, v)| (s.clone(), v.0)).collect::<HashMap<_, _>>()); }
|
||||
}
|
||||
let mut out: Vec<Value> = rows.into_values().collect();
|
||||
out.sort_by(|a, b| b["add_any"].as_f64().unwrap_or(0.0).total_cmp(&a["add_any"].as_f64().unwrap_or(0.0)));
|
||||
let body = Arc::new(json!({"made_at": made, "h": h, "window_start": window, "rows": out}).to_string());
|
||||
@@ -288,8 +321,12 @@ fn artist(st: &State, id: &str) -> Result<Reply> {
|
||||
}
|
||||
}
|
||||
|
||||
let bauer: Value = bauer_week(&c)?.remove(&key).map(|b| json!(b.into_iter().map(|(s, (n, mut songs))| {
|
||||
songs.sort_by(|x, y| y.1.cmp(&x.1));
|
||||
(s, json!({"plays": n, "songs": songs.into_iter().take(5).map(|(t, n)| json!({"title": t, "plays": n})).collect::<Vec<_>>()}))
|
||||
}).collect::<HashMap<_, _>>())).unwrap_or(Value::Null);
|
||||
ok(json!({
|
||||
"id": id, "name": name, "country": a["country"], "gender": a["gender"], "description": a["description"],
|
||||
"id": id, "name": name, "bauer": bauer, "country": a["country"], "gender": a["gender"], "description": a["description"],
|
||||
"debut": a["lifespan"]["beginYear"], "type": a["type"], "image": image, "top_tracks": top,
|
||||
"weeks": weeks, "plays": plays, "forecasts": fc, "now": now_out, "charts": charts,
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user