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