Synthetic lists: top-N rule (N = typical DR list size), 4-week blocks (weekly samples are noise); long-history features (archive presence 2012-21, DR lists before t); NMF analysis on full artist histories
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+41
-8
@@ -150,6 +150,33 @@ pub fn run(db: &Db, p: &Panel) -> Result<String> {
|
||||
let false_pos: usize = hit[3][..3].iter().sum();
|
||||
writeln!(md, "\nIn-sample check (song-weeks): listed songs found {listed_found} of {listed_total}; songs wrongly put on the list {false_pos}. Thresholds are refitted as exact plays and lists for the same weeks accumulate.\n")?;
|
||||
|
||||
// Typical list size per channel (DR's real lists: A/B/C or one list), the era-robust rule:
|
||||
// on the list = among the channel's N most played songs that week.
|
||||
let mut list_size: HashMap<String, usize> = HashMap::new();
|
||||
for lc in ["p3", "p4", "p5", "p6beat", "p8jazz"] {
|
||||
let mut v: Vec<i64> = db.conn.prepare("SELECT count(*) FROM rotation_lists WHERE channel = ?1 AND category IN ('A', 'B', 'C', 'LIST') GROUP BY list_date")?
|
||||
.query_map([lc], |r| r.get(0))?.collect::<Result<_, _>>()?;
|
||||
v.sort();
|
||||
if !v.is_empty() { list_size.insert(lc.to_string(), v[v.len() / 2] as usize); }
|
||||
}
|
||||
// Check the rule where the real list is known: top N by plays vs the list.
|
||||
let (mut tp, mut fp, mut fnn) = (0usize, 0usize, 0usize);
|
||||
for (week, by_station) in &plays {
|
||||
let days = days_seen.get(week).map(|s| s.len()).unwrap_or(0);
|
||||
if days < 5 { continue; }
|
||||
for (station, songs) in by_station {
|
||||
let Some(lc) = list_channel(station) else { continue };
|
||||
let (Some((list, _)), Some(&n)) = (list_for(*week, lc), list_size.get(lc)) else { continue };
|
||||
let mut ranked: Vec<(&String, &f64)> = songs.iter().collect();
|
||||
ranked.sort_by(|a, b| b.1.total_cmp(a.1));
|
||||
let top: std::collections::HashSet<&String> = ranked.iter().take(n).map(|x| x.0).collect();
|
||||
for s in &top { if list.contains_key(*s) { tp += 1 } else { fp += 1 } }
|
||||
fnn += list.keys().filter(|s| !top.contains(s)).count();
|
||||
}
|
||||
}
|
||||
writeln!(md, "Era-robust rule used for the archive: on the list = among the channel's N most played songs that week, N = the median size of DR's lists ({}). Where the real list is known it finds {tp} of {} listed songs, with {fp} songs wrongly on (precision {:.0}%, recall {:.0}%).\n",
|
||||
list_size.iter().map(|(k, v)| format!("{k} {v}")).collect::<Vec<_>>().join(", "), tp + fnn, 100.0 * tp as f64 / (tp + fp).max(1) as f64, 100.0 * tp as f64 / (tp + fnn).max(1) as f64)?;
|
||||
|
||||
// ---- 2. apply to the archive
|
||||
let has_archive: i64 = db.conn.query_row("SELECT count(*) FROM sqlite_master WHERE name = 'archive_plays'", [], |r| r.get(0))?;
|
||||
writeln!(md, "## 2. Archived playlists → synthetic lists\n")?;
|
||||
@@ -163,7 +190,12 @@ pub fn run(db: &Db, p: &Panel) -> Result<String> {
|
||||
.query_map([], |r| Ok((r.get::<_, String>(0)?, r.get::<_, String>(1)?, r.get::<_, String>(2)?, r.get::<_, String>(3)?)))? {
|
||||
let (st, at, a, t) = r?;
|
||||
let Ok(d) = NaiveDate::parse_from_str(&at[..10], "%Y-%m-%d") else { continue };
|
||||
let w = weeks.entry((st, d.iso_week().year(), d.iso_week().week())).or_insert_with(|| Wk { hours: HashMap::new(), songs: HashMap::new() });
|
||||
// 4-week blocks (from Monday 3 Jan 2000): a few sampled days a week are too noisy for a
|
||||
// weekly list (two 36-hour samples of one week's P3 differ by ~9 of the top 32 songs),
|
||||
// pooled over 4 weeks the list holds; songs stay on the list ~7+ weeks anyway.
|
||||
let epoch = NaiveDate::from_ymd_opt(2000, 1, 3).unwrap();
|
||||
let block = epoch + Duration::weeks(((d - epoch).num_days() / 7 / 4) * 4);
|
||||
let w = weeks.entry((st, block.iso_week().year(), block.iso_week().week())).or_insert_with(|| Wk { hours: HashMap::new(), songs: HashMap::new() });
|
||||
w.hours.entry(at[..10].to_string()).or_default().insert(at[11..13].to_string());
|
||||
let e = w.songs.entry(song(&a, &t)).or_insert((0.0, a.clone(), t.clone()));
|
||||
e.0 += 1.0;
|
||||
@@ -173,17 +205,18 @@ pub fn run(db: &Db, p: &Panel) -> Result<String> {
|
||||
let mut summary: BTreeMap<(String, i32), (usize, usize)> = BTreeMap::new(); // (station, year) -> (weeks, songs listed)
|
||||
for ((st, y, w), wk) in &weeks {
|
||||
let Some(lc) = list_channel(st) else { continue };
|
||||
let Some(th) = thresholds.get(lc) else { continue };
|
||||
if !thresholds.contains_key(lc) { continue; }
|
||||
// Only daytime-complete days count fully; scale plays by covered hours / 24.
|
||||
let hours: usize = wk.hours.values().map(|h| h.len()).sum();
|
||||
let days = wk.hours.values().filter(|h| h.len() >= 12).count();
|
||||
if hours < 36 { continue; } // less than a day and a half: too thin to tell a C song from chance
|
||||
if hours < 96 { continue; } // under 4 days' worth in the block: too thin (two 72-hour samples of one week still differ by ~5 of 32)
|
||||
let day_equiv = hours as f64 / 24.0;
|
||||
let Some(&size) = list_size.get(lc) else { continue };
|
||||
let mut ranked: Vec<(&String, &(f64, String, String))> = wk.songs.iter().filter(|(_, v)| v.0 >= 3.0).collect();
|
||||
ranked.sort_by(|a, b| b.1 .0.total_cmp(&a.1 .0));
|
||||
let mut n = 0;
|
||||
for (s, (cnt, a, t)) in &wk.songs {
|
||||
if *cnt < 3.0 { continue; } // a song needs 3+ plays in the sample to count
|
||||
for (s, (cnt, a, t)) in ranked.into_iter().take(size) {
|
||||
let ppd = cnt / day_equiv;
|
||||
if ppd < th[2] { continue; }
|
||||
tx.execute("INSERT OR REPLACE INTO synthetic_rotation VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, 'wayback')",
|
||||
rusqlite::params![lc, y, w, s, a, t, ppd, "listed", days as i64, hours as i64])?;
|
||||
n += 1;
|
||||
@@ -192,9 +225,9 @@ pub fn run(db: &Db, p: &Panel) -> Result<String> {
|
||||
e.0 += 1; e.1 += n;
|
||||
}
|
||||
tx.commit()?;
|
||||
writeln!(md, "| Station | Year | Weeks with a synthetic list | Avg songs listed per week |\n|---|---|---|---|")?;
|
||||
writeln!(md, "| Station | Year | 4-week blocks with a synthetic list | Avg songs listed |\n|---|---|---|---|")?;
|
||||
for ((st, y), (wks, n)) in &summary { writeln!(md, "| {st} | {y} | {wks} | {:.0} |", *n as f64 / *wks as f64)?; }
|
||||
writeln!(md, "\nA week needs at least 36 archived hours and a song at least 3 plays in them; plays are scaled to a full day by the hours covered.\n")?;
|
||||
writeln!(md, "\nLists are per 4-week block (iso_year/iso_week = its first week): a block needs at least 96 archived hours; a song needs 3+ plays and is then ranked against the block's other songs (top N = on the list in that block). Weekly lists from a few sampled days are mostly sampling noise.\n")?;
|
||||
}
|
||||
|
||||
// ---- 3. IFPI Airplay Top-20 position vs DR plays
|
||||
|
||||
Reference in New Issue
Block a user