}
// Calculate the progression time for a log, taking into account the presence of multi-day logs.
fn prog_time_for(fights: &Vec<Fight>) -> i32 {
// no fights, no prog
if fights.len() < 2 {
return 0;
}
let basic = fights.last().expect("there to be a fight").end_time - fights[0].start_time;
if Duration::milliseconds(basic as i64) <= Duration::hours(8) {
// fast path. regular-ass single-day log
basic
} else {
debug!(
"encountered a log that is {}ms log. assuming multi-day",
basic
);
let mut time = Duration::zero();
let mut prev = &fights[0];
for fight in &fights[1..] {
let start_delta = Duration::milliseconds((fight.start_time - prev.start_time) as i64);
if start_delta >= Duration::hours(8) {
// split here. ignore gap between current start time and previous
debug!(
"splitting log after fight {} (gap: {})",
prev.id, start_delta
);
time = time + Duration::milliseconds((prev.end_time - prev.start_time) as i64);
} else {
// not splitting. use the gap
time = time + start_delta;
}
prev = fight;
}
time = time + Duration::milliseconds((prev.end_time - prev.start_time) as i64);
time.num_milliseconds() as i32
}