From e4bcc51d10919a6b68d1f6d115a231ce059b4b46 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 24 Jul 2020 16:22:31 +0200 Subject: use Analyzer/span from evtclib This is better than re-implementing these functions, especially for the fight outcome as it is more accurate. --- src/main.rs | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 674d128..0915f42 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, Event, EventKind, Log}; +use evtclib::{Boss, EventKind, Log, Outcome}; mod fexpr; mod filters; @@ -212,15 +212,13 @@ pub enum FightOutcome { Wipe, } -/// A stripped version of [`LogResult`][LogResult] that is available early in the parsing process. -/// -/// This can be used by filters to filter out logs early, before they will be fully parsed. -#[derive(Debug, Clone)] -pub struct EarlyLogResult { - /// The path to the log file. - log_file: PathBuf, - /// The partially parsed evtc. - evtc: PartialEvtc, +impl From for FightOutcome { + fn from(outcome: Outcome) -> Self { + match outcome { + Outcome::Success => FightOutcome::Success, + Outcome::Failure => FightOutcome::Wipe, + } + } } impl FromStr for FightOutcome { @@ -235,6 +233,17 @@ impl FromStr for FightOutcome { } } +/// A stripped version of [`LogResult`][LogResult] that is available early in the parsing process. +/// +/// This can be used by filters to filter out logs early, before they will be fully parsed. +#[derive(Debug, Clone)] +pub struct EarlyLogResult { + /// The path to the log file. + log_file: PathBuf, + /// The partially parsed evtc. + evtc: PartialEvtc, +} + enum ZipWrapper { Raw(Option), Zipped(zip::ZipArchive), @@ -592,16 +601,13 @@ fn get_guild_mapping(log: &Log) -> HashMap { /// Get the outcome of the fight. fn get_fight_outcome(log: &Log) -> FightOutcome { - if log.was_rewarded() { - FightOutcome::Success - } else { - FightOutcome::Wipe - } + log.analyzer() + .and_then(|a| a.outcome()) + .map(Into::into) + .unwrap_or(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) + Duration::milliseconds(log.span() as i64) } -- cgit v1.2.3