From dda777e70121324c4855b94ee2b985f9eda7a251 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 12 Jun 2020 12:31:48 +0200 Subject: compute fight duration from event times It seems a bit iffy to use the local timestamp to compute the fight duration: First of all, the event timestamps have higher precision, being counted in milliseconds rather than seconds. Second, it is more reliable, as we always have a first and a last event, whereas the LogStart and LogEnd may not exist. Third, we may want to change how this value is calculated in the future anyway, as some bosses have a bit of a pre-log before the fight actually starts (arcdps starts the log when you get into combat, which might be before the boss actually spawns, like on Ensolyss). In either case, this function is probably a strong contender for being implemented properly in evtclib. --- src/main.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 9ed67cf..133bd2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ use structopt::StructOpt; use walkdir::{DirEntry, WalkDir}; use evtclib::raw::parser::PartialEvtc; -use evtclib::{Boss, EventKind, Log}; +use evtclib::{Boss, Event, EventKind, Log}; mod fexpr; mod filters; @@ -552,17 +552,10 @@ fn extract_info(path: &Path, log: &Log) -> LogResult { .collect::>(); players.sort(); - let duration = log - .local_end_timestamp() - .and_then(|end| log.local_start_timestamp().map(|start| end - start)) - .map(|x| x as i64) - .map(Duration::seconds) - .unwrap_or_else(Duration::zero); - LogResult { log_file: path.to_path_buf(), time: Utc.timestamp(i64::from(log.local_end_timestamp().unwrap_or(0)), 0), - duration, + duration: get_fight_duration(log), boss, players, outcome: get_fight_outcome(log), @@ -599,3 +592,10 @@ fn get_fight_outcome(log: &Log) -> FightOutcome { FightOutcome::Wipe } } + +/// Get the duration of the fight. +fn get_fight_duration(log: &Log) -> Duration { + let start = log.events().first().map(Event::time).unwrap_or(0) as i64; + let end = log.events().last().map(Event::time).unwrap_or(0) as i64; + Duration::milliseconds(end - start) +} -- cgit v1.2.3