diff options
author | Daniel <kingdread@gmx.de> | 2020-06-12 12:31:48 +0200 |
---|---|---|
committer | Daniel <kingdread@gmx.de> | 2020-06-12 12:31:48 +0200 |
commit | dda777e70121324c4855b94ee2b985f9eda7a251 (patch) | |
tree | 46ea22055aff5cf9df59ce28ab4d96056f2ab3cb /src/main.rs | |
parent | 9c7df815d2b19929fe5ca5295c8a5526bcfcee73 (diff) | |
download | raidgrep-dda777e70121324c4855b94ee2b985f9eda7a251.tar.gz raidgrep-dda777e70121324c4855b94ee2b985f9eda7a251.tar.bz2 raidgrep-dda777e70121324c4855b94ee2b985f9eda7a251.zip |
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.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 9 insertions, 9 deletions
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::<Vec<Player>>(); 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) +} |