From d4a24eef7fd410c147de201d776089e0601317d5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 12 Jun 2020 00:48:18 +0200 Subject: initial work on comparison based filters This enables filters such as -time > 2020-01-01 -time < 2020-02-03 ... for time and duration, and later possibly also for more things (such as a COUNT(...) construct). This work tries to integrate them into the existing filter system as seamless as possible, by providing a Comparator which implements LogFilter. The "type checking" is done at parse time, so nonsensical comparisons like -time > 12s flat out give a parse error. This however might be changed to a more dynamic system with run-time type checking, in which case we could do away with the type parameter on Producer and simply work with a generic Value. The comparator would then return an error if two non-identical types would be compared. Note that the system does not support arithmetic expressions, only simple comparisons to constant values. --- src/main.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index ba834ce..9ed67cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use std::str::FromStr; use std::sync::atomic::{AtomicBool, Ordering}; use anyhow::{anyhow, Context, Error, Result}; -use chrono::{DateTime, TimeZone, Utc}; +use chrono::{DateTime, Duration, TimeZone, Utc}; use colored::Colorize; use log::debug; use regex::Regex; @@ -156,6 +156,8 @@ pub struct LogResult { log_file: PathBuf, /// The time of the recording. time: DateTime, + /// The duration of the fight. + duration: Duration, /// The boss. boss: Option, /// A vector of all participating players. @@ -550,9 +552,17 @@ 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, boss, players, outcome: get_fight_outcome(log), -- cgit v1.2.3 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/main.rs') 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 From 3d4ac61f9d8506ef82301772fe41c75d0f19e5a4 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 12 Jun 2020 14:25:17 +0200 Subject: report invalid filters that are valid regexes --- src/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 133bd2d..674d128 100644 --- a/src/main.rs +++ b/src/main.rs @@ -129,10 +129,16 @@ impl Opt { fn build_filter(&self) -> Result> { // As a shortcut, we allow only the regular expression to be given, to retain the behaviour // before the filter changes. + + // Special characters that when present will prevent the filter to be interpreted as a + // regex. This is to ensure that errors are properly reported on invalid filterlines + // instead of being swallowed because the filter was taken as a (valid) regex: + const SPECIAL_CHARS: &[char] = &['-', '(', ')', ':', '<', '>', '=']; + if self.expression.len() == 1 { let line = &self.expression[0]; let maybe_filter = build_filter(line); - if maybe_filter.is_err() && !line.starts_with('-') { + if maybe_filter.is_err() && !line.contains(SPECIAL_CHARS) { let maybe_regex = Regex::new(line); if let Ok(rgx) = maybe_regex { let filter = filters::player::any( -- cgit v1.2.3