use evtclib::{Agent, AgentName}; use evtclib::raw::parser::PartialEvtc; use evtclib::statistics::gamedata::Boss; use num_traits::FromPrimitive; use super::{SearchField, LogResult, Opt}; use chrono::Datelike; /// Do filtering based on the character or account name. pub fn filter_name(evtc: &PartialEvtc, opt: &Opt) -> bool { for player in &evtc.agents { let fancy = Agent::from_raw(player); if fancy.is_err() { continue; } match fancy.unwrap().name() { AgentName::Player { ref account_name, ref character_name, .. } => { if (opt.field.contains(&SearchField::Account) && opt.expression.is_match(account_name)) || (opt.field.contains(&SearchField::Character) && opt.expression.is_match(character_name)) { return true; } } _ => (), } } false } /// Do filtering based on the boss ID. pub fn filter_boss(evtc: &PartialEvtc, opt: &Opt) -> bool { let boss = Boss::from_u16(evtc.header.combat_id); boss .map(|b| opt.bosses.contains(&b)) .unwrap_or(true) } /// Do filtering based on the fight outcome. pub fn filter_outcome(result: &LogResult, opt: &Opt) -> bool { opt.outcome.contains(&result.outcome) } /// Do filtering based on the weekday of the fight. pub fn filter_weekday(result: &LogResult, opt: &Opt) -> bool { opt.weekdays.contains(&result.time.weekday()) } /// Do filtering based on encounter time. pub fn filter_time(result: &LogResult, opt: &Opt) -> bool { let after_ok = match opt.after { Some(time) => time <= result.time, None => true, }; let before_ok = match opt.before { Some(time) => time >= result.time, None => true, }; after_ok && before_ok }