Synthetic rotation lists: on the list or not (one threshold per channel)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 04:24:22 +00:00
co-authored by Claude Opus 5.5
parent 73366acd07
commit c114da9a63
+8 -9
View File
@@ -43,7 +43,7 @@ pub fn create_tables(db: &Db) -> Result<()> {
"CREATE TABLE IF NOT EXISTS synthetic_rotation ( "CREATE TABLE IF NOT EXISTS synthetic_rotation (
channel TEXT NOT NULL, iso_year INTEGER NOT NULL, iso_week INTEGER NOT NULL, channel TEXT NOT NULL, iso_year INTEGER NOT NULL, iso_week INTEGER NOT NULL,
song TEXT NOT NULL, artist TEXT, title TEXT, song TEXT NOT NULL, artist TEXT, title TEXT,
plays_per_day REAL NOT NULL, category TEXT NOT NULL, -- A | B | C (estimated) plays_per_day REAL NOT NULL, category TEXT NOT NULL, -- 'listed' (on the list or not; formats changed over the years)
days INTEGER NOT NULL, hours_covered INTEGER NOT NULL, source TEXT NOT NULL, days INTEGER NOT NULL, hours_covered INTEGER NOT NULL, source TEXT NOT NULL,
PRIMARY KEY (channel, iso_year, iso_week, song) PRIMARY KEY (channel, iso_year, iso_week, song)
); );
@@ -106,7 +106,8 @@ pub fn run(db: &Db, p: &Panel) -> Result<String> {
} }
writeln!(md, "## 1. Plays per day by category (exact plays vs DR's lists)\n")?; writeln!(md, "## 1. Plays per day by category (exact plays vs DR's lists)\n")?;
writeln!(md, "Weeks used: {}.\n", if used.is_empty() { "none yet".to_string() } else { used.iter().take(6).cloned().collect::<Vec<_>>().join(", ") + if used.len() > 6 { " …" } else { "" } })?; writeln!(md, "Weeks used: {}.\n", if used.is_empty() { "none yet".to_string() } else { used.iter().take(6).cloned().collect::<Vec<_>>().join(", ") + if used.len() > 6 { " …" } else { "" } })?;
writeln!(md, "| Channel | A median | B median | C median | Not listed, 90th pct | Threshold A | B | C |\n|---|---|---|---|---|---|---|---|")?; writeln!(md, "Synthetic lists only say \"on the list or not\": DR's list formats have changed over the years, and A/B can't be told apart from plays on every channel. The category medians are for reference.\n")?;
writeln!(md, "| Channel | A median | B median | C median | Not listed, 90th pct | On-list threshold (plays/day) |\n|---|---|---|---|---|---|")?;
let med = |v: &mut Vec<f64>| { if v.is_empty() { return f64::NAN; } v.sort_by(f64::total_cmp); v[v.len() / 2] }; let med = |v: &mut Vec<f64>| { if v.is_empty() { return f64::NAN; } v.sort_by(f64::total_cmp); v[v.len() / 2] };
let pct = |v: &mut Vec<f64>, q: f64| { if v.is_empty() { return f64::NAN; } v.sort_by(f64::total_cmp); v[((v.len() - 1) as f64 * q) as usize] }; let pct = |v: &mut Vec<f64>, q: f64| { if v.is_empty() { return f64::NAN; } v.sort_by(f64::total_cmp); v[((v.len() - 1) as f64 * q) as usize] };
let mut thresholds: HashMap<String, [f64; 3]> = HashMap::new(); let mut thresholds: HashMap<String, [f64; 3]> = HashMap::new();
@@ -137,7 +138,7 @@ pub fn run(db: &Db, p: &Panel) -> Result<String> {
} }
} }
writeln!(md, "| {lc} | {:.1} | {:.1} | {:.1} | {:.1} | {} |", m[0], m[1], m[2], nl, writeln!(md, "| {lc} | {:.1} | {:.1} | {:.1} | {:.1} | {} |", m[0], m[1], m[2], nl,
thresholds.get(lc).map(|t| format!("{:.1} | {:.1} | {:.1}", t[0], t[1], t[2])).unwrap_or("— | — | —".into()))?; thresholds.get(lc).map(|t| format!("{:.1}", t[2])).unwrap_or("—".into()))?;
} }
// In-sample check: how well the thresholds reproduce the list in the weeks used. // In-sample check: how well the thresholds reproduce the list in the weeks used.
let mut hit = [[0usize; 4]; 4]; let mut hit = [[0usize; 4]; 4];
@@ -147,8 +148,7 @@ pub fn run(db: &Db, p: &Panel) -> Result<String> {
let listed_total: usize = (0..3).map(|t| hit[t].iter().sum::<usize>()).sum(); let listed_total: usize = (0..3).map(|t| hit[t].iter().sum::<usize>()).sum();
let listed_found: usize = (0..3).map(|t| hit[t][..3].iter().sum::<usize>()).sum(); let listed_found: usize = (0..3).map(|t| hit[t][..3].iter().sum::<usize>()).sum();
let false_pos: usize = hit[3][..3].iter().sum(); 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}; exact category {} of {listed_total}. Thresholds are refitted as exact plays and lists for the same weeks accumulate.\n", 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")?;
(0..3).map(|t| hit[t][t]).sum::<usize>())?;
// ---- 2. apply to the archive // ---- 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))?; let has_archive: i64 = db.conn.query_row("SELECT count(*) FROM sqlite_master WHERE name = 'archive_plays'", [], |r| r.get(0))?;
@@ -183,10 +183,9 @@ pub fn run(db: &Db, p: &Panel) -> Result<String> {
for (s, (cnt, a, t)) in &wk.songs { for (s, (cnt, a, t)) in &wk.songs {
if *cnt < 3.0 { continue; } // a song needs 3+ plays in the sample to count if *cnt < 3.0 { continue; } // a song needs 3+ plays in the sample to count
let ppd = cnt / day_equiv; let ppd = cnt / day_equiv;
let k = cat_of(th, ppd); if ppd < th[2] { continue; }
if k == 3 { continue; }
tx.execute("INSERT OR REPLACE INTO synthetic_rotation VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, 'wayback')", 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, CATS[k], days as i64, hours as i64])?; rusqlite::params![lc, y, w, s, a, t, ppd, "listed", days as i64, hours as i64])?;
n += 1; n += 1;
} }
let e = summary.entry((st.clone(), *y)).or_insert((0, 0)); let e = summary.entry((st.clone(), *y)).or_insert((0, 0));
@@ -195,7 +194,7 @@ pub fn run(db: &Db, p: &Panel) -> Result<String> {
tx.commit()?; tx.commit()?;
writeln!(md, "| Station | Year | Weeks with a synthetic list | Avg songs listed per week |\n|---|---|---|---|")?; writeln!(md, "| Station | Year | Weeks with a synthetic list | Avg songs listed per week |\n|---|---|---|---|")?;
for ((st, y), (wks, n)) in &summary { writeln!(md, "| {st} | {y} | {wks} | {:.0} |", *n as f64 / *wks as f64)?; } 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. A/B is uncertain from a few sampled days (P3: A ≈ 4.7, B ≈ 3.3 plays a day); on P4, A and B get the same plays, so P4 synthetic lists only mean \"on the list\".\n")?; 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")?;
} }
// ---- 3. IFPI Airplay Top-20 position vs DR plays // ---- 3. IFPI Airplay Top-20 position vs DR plays