diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 14 | ||||
| -rw-r--r-- | src/main.rs | 6 | ||||
| -rw-r--r-- | src/statistics/gamedata.rs | 17 | ||||
| -rw-r--r-- | src/statistics/mechanics.rs | 22 | 
4 files changed, 55 insertions, 4 deletions
| @@ -37,6 +37,8 @@ pub mod statistics;  use statistics::gamedata::{self, Boss}; +use std::fmt; +  /// A macro that returns `true` when the given expression matches the pattern.  ///  /// ```rust @@ -92,6 +94,18 @@ pub enum AgentName {      },  } +impl fmt::Display for AgentName { +    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { +        let name = match *self { +            AgentName::Single(ref name) => name, +            AgentName::Player { +                ref character_name, .. +            } => character_name, +        }; +        f.write_str(name) +    } +} +  /// An agent.  #[derive(Debug, Clone, Getters)]  pub struct Agent { diff --git a/src/main.rs b/src/main.rs index 81ab36c..5480765 100644 --- a/src/main.rs +++ b/src/main.rs @@ -163,11 +163,11 @@ pub fn main() -> Result<(), evtclib::raw::parser::ParseError> {      }      for agent in processed.players() { -        println!("{:?}", agent.name()); +        println!("{}", agent.name());          for mechanic in evtclib::statistics::gamedata::get_mechanics(processed.boss_id()) {              println!( -                "{}: {}", -                mechanic.2, +                "  {}: {}", +                mechanic.name(),                  stats                      .mechanic_log                      .count(|m, a| m == mechanic && a == *agent.addr()) diff --git a/src/statistics/gamedata.rs b/src/statistics/gamedata.rs index 3bd895e..80f269e 100644 --- a/src/statistics/gamedata.rs +++ b/src/statistics/gamedata.rs @@ -113,6 +113,23 @@ pub enum Trigger {  #[derive(Debug, Clone, PartialEq, Eq, Hash)]  pub struct Mechanic(pub u16, pub Trigger, pub &'static str); +impl Mechanic { +    #[inline] +    pub fn boss_id(&self) -> u16 { +        self.0 +    } + +    #[inline] +    pub fn trigger(&self) -> &Trigger { +        &self.1 +    } + +    #[inline] +    pub fn name(&self) -> &'static str { +        self.2 +    } +} +  macro_rules! mechanics {      ( $( $boss_id:expr => [ $($name:expr => $trigger:expr,)* ], )* ) => {          &[ diff --git a/src/statistics/mechanics.rs b/src/statistics/mechanics.rs index 5a16204..0cf6f24 100644 --- a/src/statistics/mechanics.rs +++ b/src/statistics/mechanics.rs @@ -3,8 +3,9 @@ use super::math::{Monoid, RecordFunc, Semigroup};  use std::fmt; +/// A simple wrapper for integers.  #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct Counter(u32); +struct Counter(u32);  impl Semigroup for Counter {      #[inline] @@ -20,19 +21,38 @@ impl Monoid for Counter {      }  } +/// Provides access to the mechanic log.  #[derive(Clone, Default)]  pub struct MechanicLog {      inner: RecordFunc<u64, (&'static Mechanic, u64), Counter>,  }  impl MechanicLog { +    /// Increase the mechanic counter for the given mechanic and agent by one.      pub fn increase(&mut self, time: u64, mechanic: &'static Mechanic, agent: u64) {          self.inner.insert(time, (mechanic, agent), Counter(1));      } +    /// Return the count of mechanics. +    /// +    /// A function can be provided to filter entries by mechanic type and agent.      pub fn count<F: FnMut(&'static Mechanic, u64) -> bool>(&self, mut filter: F) -> u32 {          self.inner.tally_only(|(a, b)| filter(a, *b)).0      } + +    /// Return the count of mechanics between the two given times. +    /// +    /// A function can be provided to filter entries by mechanic type and agent. +    pub fn count_between<F: FnMut(&'static Mechanic, u64) -> bool>( +        &self, +        start: u64, +        stop: u64, +        mut filter: F, +    ) -> u32 { +        self.inner +            .between_only(&start, &stop, |(a, b)| filter(a, *b)) +            .0 +    }  }  impl fmt::Debug for MechanicLog { | 
