NMF Denmark in the add model (placed in the window, top 10, history), scenario type (release / NMF) for the ranking and the what-if; NMF Denmark export

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 11:43:52 +00:00
co-authored by Claude Opus 5.5
parent e6b080246b
commit e94601b997
6 changed files with 268 additions and 151 deletions
+39 -1
View File
@@ -79,6 +79,8 @@ pub struct Panel {
/// dates of DR's real rotation lists (2023–) that had the artist on any channel.
pub archive_rate: Vec<f64>,
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>)>>,
}
impl Panel {
@@ -144,7 +146,8 @@ impl Panel {
let list_tau = super::calibrate::stored(db)?;
let releases = load_releases(db, &id_of, artists.len())?;
let (archive_rate, listed_on) = load_long_history(db, &id_of, &names, artists.len())?;
Ok(Panel { weeks, artists, y, chart, list_tau, releases, archive_rate, listed_on })
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 })
}
}
@@ -272,3 +275,38 @@ fn load_long_history(db: &Db, id_of: &HashMap<String, usize>, names: &HashMap<St
for v in listed.iter_mut() { v.sort(); v.dedup(); }
Ok((rate, listed))
}
/// NMF Denmark placements per DR artist: the artist's SuperFridayChart placements, confirmed on the
/// track page (country Denmark, with position), or for Danish acts not yet read on the track page,
/// one playlist the size of NMF Denmark that Friday.
fn load_nmf_dk(db: &Db, id_of: &HashMap<String, usize>, artists: &[Artist]) -> Result<Vec<Vec<(NaiveDate, Option<i64>)>>> {
let mut out: Vec<Vec<(NaiveDate, Option<i64>)>> = vec![Vec::new(); artists.len()];
let has = |t: &str| -> Result<bool> { Ok(db.conn.query_row("SELECT count(*) FROM sqlite_master WHERE name = ?1", [t], |r| r.get::<_, i64>(0))? > 0) };
if !has("nmf_artist_tracks")? || !has("nmf_additions")? { return Ok(out); }
let mut confirmed: HashMap<(String, String), Option<i64>> = HashMap::new();
let mut read: std::collections::HashSet<(String, String)> = std::collections::HashSet::new();
let mut size: HashMap<String, f64> = HashMap::new();
for r in db.conn.prepare("SELECT isrc, friday, country, position, followers FROM nmf_additions")?
.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?, r.get::<_, String>(2)?, r.get::<_, Option<i64>>(3)?, r.get::<_, Option<f64>>(4)?)))? {
let (isrc, f, country, pos, fo) = r?;
read.insert((isrc.clone(), f.clone()));
if country.eq_ignore_ascii_case("denmark") {
if let Some(fo) = fo { let e = size.entry(f.clone()).or_insert(0.0); *e = e.max(fo); }
confirmed.insert((isrc, f), pos);
}
}
for r in db.conn.prepare(
"SELECT l.dr_artist_id, t.isrc, t.friday, coalesce(t.playlists, 0), coalesce(t.followers, 0)
FROM nmf_artist_tracks t JOIN nmf_artist_lookups l ON l.spotify_artist_id = t.spotify_artist_id")?
.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?, r.get::<_, String>(2)?, r.get::<_, i64>(3)?, r.get::<_, f64>(4)?)))? {
let (id, isrc, f, pl, fo) = r?;
let Some(&a) = id_of.get(&id) else { continue };
let Ok(d) = NaiveDate::parse_from_str(&f, "%Y-%m-%d") else { continue };
let key = (isrc, f.clone());
if let Some(pos) = confirmed.get(&key) { out[a].push((d, *pos)); continue; }
if read.contains(&key) { continue; } // read: not on NMF Denmark
if artists[a].danish && pl == 1 && size.get(&f).is_some_and(|n| (fo - n).abs() <= 0.02 * n) { out[a].push((d, None)); }
}
for v in out.iter_mut() { v.sort(); v.dedup_by_key(|x| x.0); }
Ok(out)
}