find settings events after run has started

This commit is contained in:
2025-12-14 14:52:46 -08:00
parent 63eb0fc374
commit 84a1b72aed

View File

@@ -32,14 +32,16 @@ async fn main()->Result<(),Error>{
};
const ONE_SECOND:u64=1<<32;
#[derive(Default)]
struct FoldState{
count:usize,
jumps:u64,
duration:u64,
settings:u64,
}
impl std::fmt::Display for FoldState{
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
write!(f,"count={} jumps={} duration={}",self.count,self.jumps,self.duration as f64/(ONE_SECOND as f64))
write!(f,"count={} jumps={} duration={} settings={}",self.count,self.jumps,self.duration as f64/(ONE_SECOND as f64),self.settings)
}
}
@@ -61,7 +63,7 @@ async fn main()->Result<(),Error>{
}
})
.buffer_unordered(available_parallelism)
.try_fold(FoldState{count:0,jumps:0,duration:0},async|mut state,(path,block)|{
.try_fold(FoldState::default(),async|mut state,(path,block)|{
state.count+=1;
state.jumps+=block.sound_events.iter()
.filter(|event|event.event.sound_type==v0::SoundType::JumpGround)
@@ -71,6 +73,12 @@ async fn main()->Result<(),Error>{
let first=first.time*(ONE_SECOND as f64);
state.duration+=last as u64-first as u64;
}
// find settings events after run has started
if let Some(run_start)=block.run_events.iter().find(|event|matches!(event.event,v0::RunEvent::Start(_))){
state.settings+=block.setting_events.iter()
.filter(|event|run_start.time<event.time)
.count() as u64;
}
println!("{:?} {}",path.file_name(),state);
Ok(state)
}).await?;