rsbag/examples/bag_info.rs

43 lines
1018 B
Rust
Raw Normal View History

2021-11-19 21:04:21 -08:00
use std::env::args;
2021-11-18 15:11:56 -08:00
2021-11-19 21:04:21 -08:00
use log::info;
use rsbag::{Bag, Result};
2021-11-19 15:19:35 -08:00
2021-11-19 14:15:15 -08:00
fn main() -> Result<()> {
color_eyre::install()?;
2021-11-18 15:11:56 -08:00
env_logger::init();
let args: Vec<_> = args().collect();
if args.len() != 2 {
eprintln!("Usage: {} <bag path>", args[0]);
2021-11-19 14:15:15 -08:00
return Ok(());
2021-11-18 15:11:56 -08:00
}
let bag_path = &args[1];
2021-11-19 21:04:21 -08:00
let mut bag = Bag::open(bag_path)?;
2022-06-08 20:18:55 -07:00
let chunk_positions = bag
.index()
.chunks
.iter()
.map(|chunk| chunk.pos)
.collect::<Vec<_>>();
let chunk_sizes = chunk_positions
.windows(2)
.map(|window| {
if let &[last, next] = window {
next - last
} else {
unreachable!();
}
})
.collect::<Vec<_>>();
let mean_chunk_size =
chunk_sizes.iter().map(|s| *s as f64).sum::<f64>() / (chunk_sizes.len() as f64);
info!("average chunk size: {}", mean_chunk_size);
2021-11-18 21:05:46 -08:00
2021-11-19 21:04:21 -08:00
let info = bag.compute_info()?;
2021-11-19 18:01:25 -08:00
info!("bag info: {:#?}", info);
2021-11-18 21:05:46 -08:00
2021-11-19 14:15:15 -08:00
Ok(())
2021-11-18 15:11:56 -08:00
}