aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2020-06-26 17:00:58 +0200
committerDaniel Schadt <kingdread@gmx.de>2020-06-26 17:00:58 +0200
commite9c4f208a696cb6e6eaaf0c9595672b00d301e13 (patch)
treead6a5c4653646e05521493fc46d8e2b241b670ef /src
parent86e0f74bd7f0301886c1dda0f147b6c8ffbdd707 (diff)
downloadraidgrep-e9c4f208a696cb6e6eaaf0c9595672b00d301e13.tar.gz
raidgrep-e9c4f208a696cb6e6eaaf0c9595672b00d301e13.tar.bz2
raidgrep-e9c4f208a696cb6e6eaaf0c9595672b00d301e13.zip
implement sorting based on duration
Diffstat (limited to 'src')
-rw-r--r--src/output/sorting.rs9
1 files changed, 7 insertions, 2 deletions
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<Component>),
@@ -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::<Component>(), 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(),