count jumps

This commit is contained in:
2025-12-14 14:22:03 -08:00
parent 8fe5e19dbe
commit f115b9104a

View File

@@ -30,22 +30,38 @@ async fn main()->Result<(),Error>{
let Some(dir)=std::env::args().skip(1).next()else{
return Err(Error::InvalidArgs);
};
struct FoldState{
count:usize,
jumps:u64,
}
let available_parallelism=std::thread::available_parallelism()?.get();
let read_dir=tokio::fs::read_dir(dir).await?;
tokio_stream::wrappers::ReadDirStream::new(read_dir).enumerate().map(|(count,dir_entry)|async move{
let tally=tokio_stream::wrappers::ReadDirStream::new(read_dir).map(|dir_entry|async move{
let entry=dir_entry?;
let path=entry.path();
let file=tokio::fs::read(path.as_path()).await?;
Ok((path,file,count))
Ok((path,file))
})
.buffer_unordered(PREFETCH_QUEUE)
.try_for_each_concurrent(available_parallelism,|(path,file,count)|async move{
.map(|result:Result<_,Error>|async move{
let (path,file)=result?;
let result=tokio::task::spawn_blocking(||v0::read_all_to_block(std::io::Cursor::new(file))).await?;
println!("{count} {:?}",path.file_name());
if let Err(err)=result{
return Err(Error::BotFile{path,err});
match result{
Err(err)=>Err(Error::BotFile{path,err}),
Ok(block)=>Ok((path,block)),
}
Ok(())
})
.buffer_unordered(available_parallelism)
.try_fold(FoldState{count:0,jumps:0},async|mut state,(path,block)|{
state.count+=1;
state.jumps+=block.sound_events.iter()
.filter(|event|event.event.sound_type==v0::SoundType::JumpGround)
.count() as u64;
println!("{} {:?} tally={}",state.count,path.file_name(),state.jumps);
Ok(state)
}).await?;
println!("total jump count = {}",tally.jumps);
Ok(())
}