//! What share of bundles have a NARROW settle window -- and of WHICH bundles? //! //! `screen render --settle`'s help says "a narrow one means the bundle never //! settles (42 % of them, mostly `loop*` fragments)". The 42 % is correct and is //! stated precisely in ui-settle-time.md: 731 of **1 758 composable bundles //! carrying two or more keyframe times**. But inside `screen render`, "them" //! reads as the bundles you would render -- the SCREEN BUILDS -- which is a //! different and much smaller population. This computes both. //! //! cargo run -p sylpheed-formats --example settle_narrow_rate use std::path::PathBuf; use sylpheed_formats::{pak::PakArchive, ui_layout}; fn main() { let root = PathBuf::from(std::env::var("SYLPHEED_DISC").expect("SYLPHEED_DISC")); let mut paks: Vec = std::fs::read_dir(root.join("dat")) .expect("dat/") .filter_map(|e| e.ok().map(|e| e.path())) .filter(|p| p.extension().is_some_and(|x| x == "pak")) .collect(); paks.sort(); // (with >=2 keyframe times, narrow) for each population let (mut b2, mut bn) = (0usize, 0usize); // screen builds (is_build) let (mut c2, mut cn) = (0usize, 0usize); // composable (is_composable) for pak in &paks { let Ok(ar) = PakArchive::open(pak) else { continue; }; for e in ar.entries() { let Ok(by) = ar.read(e) else { continue }; let is_b = ui_layout::is_build(&by); let is_c = ui_layout::is_composable(&by); if !is_b && !is_c { continue; } let Some(b) = ui_layout::parse_build(&by) else { continue; }; let mut ts: Vec = b .elements .iter() .flat_map(|el| el.keyframes.iter().filter_map(|k| k.time)) .collect(); ts.sort_unstable(); ts.dedup(); if ts.len() < 2 { continue; } let narrow = match b.settle_window() { Some((lo, hi)) => hi - lo < 10, None => true, }; if is_b { b2 += 1; if narrow { bn += 1 } } if is_c { c2 += 1; if narrow { cn += 1 } } } } println!("population n narrow (<10 u) share"); println!("SCREEN BUILDS (is_build, what `screen render` renders by default)"); println!( " {b2:5} {bn:9} {:.0} %", 100.0 * bn as f64 / b2.max(1) as f64 ); println!("COMPOSABLE bundles (is_composable, what --all admits)"); println!( " {c2:5} {cn:9} {:.0} %", 100.0 * cn as f64 / c2.max(1) as f64 ); println!("\nui-settle-time.md quotes 731 / 1758 = 42 % over composable bundles."); println!("--- END ---"); }