From e9c4f208a696cb6e6eaaf0c9595672b00d301e13 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Fri, 26 Jun 2020 17:00:58 +0200 Subject: implement sorting based on duration --- src/output/sorting.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/output') diff --git a/src/output/sorting.rs b/src/output/sorting.rs index 78f3538..2a0821c 100644 --- a/src/output/sorting.rs +++ b/src/output/sorting.rs @@ -29,6 +29,8 @@ pub enum Component { Outcome, /// Sort based on whether the Challenge Mote was active or not. ChallengeMote, + /// Sort based on the fight duration. + Duration, /// Sort by the given component but in reverse direction. Reverse(Box), @@ -46,6 +48,7 @@ impl FromStr for Component { "boss" => Ok(Component::Boss), "outcome" => Ok(Component::Outcome), "cm" => Ok(Component::ChallengeMote), + "duration" => Ok(Component::Duration), _ => Err(InvalidComponent), } } @@ -58,6 +61,7 @@ impl Display for Component { Component::Boss => write!(f, "boss"), Component::Outcome => write!(f, "outcome"), Component::ChallengeMote => write!(f, "cm"), + Component::Duration => write!(f, "duration"), Component::Reverse(ref inner) => write!(f, "~{}", inner), } } @@ -74,6 +78,7 @@ impl Component { Component::Boss => boss_id(lhs).cmp(&boss_id(rhs)), Component::Outcome => lhs.outcome.cmp(&rhs.outcome), Component::ChallengeMote => lhs.is_cm.cmp(&rhs.is_cm), + Component::Duration => lhs.duration.cmp(&rhs.duration), Component::Reverse(ref inner) => inner.cmp(lhs, rhs).reverse(), } } @@ -130,7 +135,6 @@ mod tests { use super::*; use chrono::prelude::*; - use chrono::Duration; use evtclib::Boss as B; #[test] @@ -139,6 +143,7 @@ mod tests { assert_eq!("boss".parse(), Ok(Component::Boss)); assert_eq!("outcome".parse(), Ok(Component::Outcome)); assert_eq!("cm".parse(), Ok(Component::ChallengeMote)); + assert_eq!("duration".parse(), Ok(Component::Duration)); assert_eq!("foobar".parse::(), Err(InvalidComponent)); @@ -164,7 +169,7 @@ mod tests { fn test_sorting_cmp() { use Component::*; - let duration = Duration::zero(); + let duration = chrono::Duration::zero(); let logs: &[&LogResult] = &[ &LogResult { log_file: "".into(), -- cgit v1.2.3