From 08e686a5161d3baf1eb25014721147bb4e17a54d Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 17 Nov 2021 00:01:59 +0100 Subject: Better output for World vs. World logs --- src/main.rs | 5 ++++- src/output/formats.rs | 59 +++++++++++++++++++++++++++++++++------------------ 2 files changed, 42 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index b35f769..8bde143 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::{Encounter, EventKind, Log, Outcome}; +use evtclib::{Encounter, EventKind, GameMode, Log, Outcome}; mod fexpr; mod filters; @@ -180,6 +180,8 @@ pub struct LogResult { outcome: FightOutcome, /// Whether the fight had the Challenge Mote turned on. is_cm: bool, + /// The game mode of the fight. + game_mode: Option, } /// A player. @@ -578,6 +580,7 @@ fn extract_info(path: &Path, log: &Log) -> LogResult { players, outcome: get_fight_outcome(log), is_cm: log.is_cm(), + game_mode: log.game_mode(), } } diff --git a/src/output/formats.rs b/src/output/formats.rs index d22ab19..47da57e 100644 --- a/src/output/formats.rs +++ b/src/output/formats.rs @@ -5,6 +5,7 @@ use super::super::guilds; use super::{FightOutcome, LogResult}; use chrono::Local; +use evtclib::GameMode; /// An output format pub trait Format: Sync + Send { @@ -30,27 +31,43 @@ impl Format for HumanReadable { item.log_file.to_string_lossy() ) .expect("writing to String failed"); - let outcome = match item.outcome { - FightOutcome::Success => "SUCCESS".green(), - FightOutcome::Wipe => "WIPE".red(), - }; - writeln!( - result, - "{}: {} - {}: {}{} {} after {}", - "Date".green(), - item.time - .with_timezone(&Local) - .format("%Y-%m-%d %H:%M:%S %a"), - "Boss".green(), - item.encounter - .map(|x| x.to_string()) - .unwrap_or_else(|| "unknown".into()), - if item.is_cm { " CM" } else { "" }, - outcome, - humantime::Duration::from(item.duration.to_std().unwrap()), - ) - .expect("writing to String failed"); - for player in &item.players { + + if item.game_mode != Some(GameMode::WvW) { + let outcome = match item.outcome { + FightOutcome::Success => "SUCCESS".green(), + FightOutcome::Wipe => "WIPE".red(), + }; + writeln!( + result, + "{}: {} - {}: {}{} {} after {}", + "Date".green(), + item.time + .with_timezone(&Local) + .format("%Y-%m-%d %H:%M:%S %a"), + "Boss".green(), + item.encounter + .map(|x| x.to_string()) + .unwrap_or_else(|| "unknown".into()), + if item.is_cm { " CM" } else { "" }, + outcome, + humantime::Duration::from(item.duration.to_std().unwrap()), + ) + .expect("writing to String failed"); + } else { + writeln!( + result, + "{}: {} - {} ended after {}", + "Date".green(), + item.time + .with_timezone(&Local) + .format("%Y-%m-%d %H:%M:%S %a"), + "World vs. World".green(), + humantime::Duration::from(item.duration.to_std().unwrap()), + ) + .expect("writing to String failed"); + } + + for player in item.players.iter().filter(|p| !p.account_name.is_empty()) { write!( result, " {:2} {:20} {:19} {:12}", -- cgit v1.2.3 From 28d098e5ae326dd899b3a31ab05bfcd464a83554 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 17 Nov 2021 10:06:59 +0100 Subject: fix tests --- src/output/sorting.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/output/sorting.rs b/src/output/sorting.rs index 234d804..27ea1e1 100644 --- a/src/output/sorting.rs +++ b/src/output/sorting.rs @@ -135,7 +135,7 @@ mod tests { use super::*; use chrono::prelude::*; - use evtclib::Encounter as E; + use evtclib::{Encounter as E, GameMode}; #[test] fn test_parse_component() { @@ -179,6 +179,7 @@ mod tests { players: vec![], outcome: FightOutcome::Success, is_cm: false, + game_mode: Some(GameMode::Raid), }, &LogResult { log_file: "".into(), @@ -188,6 +189,7 @@ mod tests { players: vec![], outcome: FightOutcome::Success, is_cm: false, + game_mode: Some(GameMode::Raid), }, &LogResult { log_file: "".into(), @@ -197,6 +199,7 @@ mod tests { players: vec![], outcome: FightOutcome::Success, is_cm: false, + game_mode: Some(GameMode::Raid), }, &LogResult { log_file: "".into(), @@ -206,6 +209,7 @@ mod tests { players: vec![], outcome: FightOutcome::Success, is_cm: false, + game_mode: Some(GameMode::Raid), }, &LogResult { log_file: "".into(), @@ -215,6 +219,7 @@ mod tests { players: vec![], outcome: FightOutcome::Success, is_cm: false, + game_mode: Some(GameMode::Raid), }, ]; -- cgit v1.2.3 From 5d18c3e79638573fb7ccf03349b7a5ca0c9d97f9 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 17 Nov 2021 20:32:21 +0100 Subject: Add a game-mode filter --- src/fexpr/grammar.lalrpop | 7 ++++++- src/filters/log.rs | 29 ++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/fexpr/grammar.lalrpop b/src/fexpr/grammar.lalrpop index ce78396..580fa1b 100644 --- a/src/fexpr/grammar.lalrpop +++ b/src/fexpr/grammar.lalrpop @@ -9,7 +9,7 @@ use super::{ DurationProducer, CountProducer, }; -use evtclib::Encounter; +use evtclib::{Encounter, GameMode}; use std::collections::HashSet; use lalrpop_util::ParseError; @@ -64,6 +64,11 @@ LogPredicate: Box = { "-boss" > => filters::log::encounter(<>), "-cm" => filters::log::challenge_mote(), + "-raid" => filters::log::game_mode([GameMode::Raid].into()), + "-fractal" => filters::log::game_mode([GameMode::Fractal].into()), + "-strike" => filters::log::game_mode([GameMode::Strike].into()), + "-wvw" => filters::log::game_mode([GameMode::WvW].into()), + "-include" => filters::constant(true), "-exclude" => filters::constant(false), diff --git a/src/filters/log.rs b/src/filters/log.rs index ac166e1..c878b78 100644 --- a/src/filters/log.rs +++ b/src/filters/log.rs @@ -9,7 +9,7 @@ use super::{ use std::collections::HashSet; -use evtclib::Encounter; +use evtclib::{Encounter, GameMode}; use chrono::{DateTime, Datelike, Utc, Weekday}; @@ -36,6 +36,33 @@ pub fn encounter(bosses: HashSet) -> Box { Box::new(BossFilter(bosses)) } +#[derive(Debug, Clone)] +struct GameModeFilter(HashSet); + +impl Filter for GameModeFilter { + fn filter_early(&self, early_log: &EarlyLogResult) -> Inclusion { + let encounter_id = early_log.evtc.header.combat_id; + // Special WvW encounter + const GENERIC_ENCOUNTER_ID: u16 = 1; + let mode = if encounter_id == GENERIC_ENCOUNTER_ID { + Some(GameMode::WvW) + } else { + Encounter::from_header_id(encounter_id).map(Encounter::game_mode) + }; + mode.map(|m| self.0.contains(&m).into()) + .unwrap_or(Inclusion::Exclude) + } + + fn filter(&self, log: &LogResult) -> bool { + log.game_mode.map(|m| self.0.contains(&m)).unwrap_or(false) + } +} + +/// A [`LogFilter`] that only accepts logs with the given game mode. +pub fn game_mode(game_modes: HashSet) -> Box { + Box::new(GameModeFilter(game_modes)) +} + #[derive(Debug, Clone)] struct OutcomeFilter(HashSet); -- cgit v1.2.3 From dcc7cb9ccb7a8d133c96e939fce500eb97c866e6 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 17 Nov 2021 21:24:35 +0100 Subject: Implement -gamemode -gamemode is a more general version of -raid/-fractal/... --- src/fexpr/grammar.lalrpop | 10 ++++++++++ src/fexpr/mod.rs | 2 ++ 2 files changed, 12 insertions(+) (limited to 'src') diff --git a/src/fexpr/grammar.lalrpop b/src/fexpr/grammar.lalrpop index 580fa1b..bca7691 100644 --- a/src/fexpr/grammar.lalrpop +++ b/src/fexpr/grammar.lalrpop @@ -68,6 +68,7 @@ LogPredicate: Box = { "-fractal" => filters::log::game_mode([GameMode::Fractal].into()), "-strike" => filters::log::game_mode([GameMode::Strike].into()), "-wvw" => filters::log::game_mode([GameMode::WvW].into()), + "-gamemode" > => filters::log::game_mode(<>), "-include" => filters::constant(true), "-exclude" => filters::constant(false), @@ -155,6 +156,15 @@ Encounter: Encounter = { }), } +GameMode: GameMode = { + =>? w.parse().map_err(|_| ParseError::User { + error: FError { + location: l, + kind: FErrorKind::GameMode, + } + }), +} + PlayerClass: PlayerClass = { =>? w.parse().map_err(|_| ParseError::User { error: FError { diff --git a/src/fexpr/mod.rs b/src/fexpr/mod.rs index 0fe2acf..6eeb753 100644 --- a/src/fexpr/mod.rs +++ b/src/fexpr/mod.rs @@ -51,6 +51,8 @@ pub enum FErrorKind { Boss, #[error("invalid class name")] Class, + #[error("invalid game mode")] + GameMode, } /// Shortcut to create a new parser and parse the given input. -- cgit v1.2.3 From 4a9ca9f7a463cea8adf3c3a24ee541fd637d3202 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 19 Nov 2021 21:57:58 +0100 Subject: update manpage and help text --- src/main.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index 8bde143..365a400 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,16 +61,23 @@ const RETCODE_ERROR: i32 = 2; /// -after DATE Only include logs from after the given date. /// -boss BOSSES Only include logs from the given bosses. /// -cm Only include logs with challenge mote enabled. +/// -gamemode MODE Only include logs from the given game modes. +/// -raid Only include raid logs. +/// -fractal Only include fractal logs. +/// -strike Only include strike mission logs. +/// -golem Only include golem logs. +/// -wvw Only include WvW logs. /// -player REGEX Shorthand to check if any player in the log has the given name. /// -include Always evaluates to including the log. /// -exclude Always evaluates to excluding the log. /// /// BOSS NAMES: /// The following names can be used with the -boss filter: -/// vg, gorseval, sabetha, slothasor, matthias, kc, xera, cairn, -/// mo, samarog, deimos, desmina, dhuum, ca, largos, qadim, -/// adina, sabir, qadimp, ai, skorvald, artsariiv, arkk, mama, siax, -/// ensolyss, icebrood, fraenir, kodans, boneskinner, whisper. +/// vg, gorseval, sabetha, slothasor, trio, matthias, kc, xera, cairn, +/// mo, samarog, deimos, desmina, river, broken king, eater, eyes, +/// dhuum, ca, largos, qadim, adina, sabir, qadimp, ai, skorvald, +/// artsariiv, arkk, mama, siax, ensolyss, icebrood, fraenir, kodans, +/// boneskinner, whisper, standard golem, medium golem, large golem. /// Names can also be comma separated. #[derive(StructOpt, Debug)] #[structopt(verbatim_doc_comment)] -- cgit v1.2.3