From a7f8cb04f7caaf9b7aca2fc3c9adff3a0f415386 Mon Sep 17 00:00:00 2001 From: Cutieguwu Date: Sun, 6 Apr 2025 12:19:42 -0400 Subject: [PATCH] Finish tasks to bring calculation capabilities in line with last interval. --- README.adoc | 8 ++++---- gamelog.ron | 9 +++++++-- gamelog/src/game.rs | 37 ++++++++++++++++++++++++++++--------- miller/src/main.rs | 31 ++++++++++++++++++++++++++----- 4 files changed, 65 insertions(+), 20 deletions(-) diff --git a/README.adoc b/README.adoc index 2338ac5..295222c 100644 --- a/README.adoc +++ b/README.adoc @@ -47,10 +47,10 @@ I figured, that since I already had to digitize every note, that I was required === Miller: * [ ] Mathematics -** [ ] Avg. Terrain Gain -** [ ] Avg. Terrain Loss -** [ ] Avg. Terrain Delta -** [ ] Avg. Offence Plays per quarter +** [*] Avg. Terrain Gain +** [*] Avg. Terrain Loss +** [*] Avg. Terrain Delta +** [*] Avg. Offence Plays per quarter ** [ ] Avg. Offence Plays per game ** [ ] Avg. Penalties per game * [ ] Play Trend Analysis diff --git a/gamelog.ron b/gamelog.ron index 9d8e492..517a1dd 100644 --- a/gamelog.ron +++ b/gamelog.ron @@ -9,7 +9,7 @@ periods: [ Period( start: First, - end: Third, + end: Second, events: [ Kickoff(ArizonaState), Play( @@ -83,6 +83,12 @@ down: First, terrain: Yards(10), ), + ] + ), + Period( + start: Third, + end: None, + events: [ Kickoff(TexasAnM), Play( action: Unknown, // PA Comebacks or Curls? Original note: Spike Centre @@ -619,7 +625,6 @@ down: First, terrain: GoalLine, ), - // Touchdown Score(Touchdown), Score(PatSafety), Kickoff(Iowa), diff --git a/gamelog/src/game.rs b/gamelog/src/game.rs index a1ef14f..efea30a 100644 --- a/gamelog/src/game.rs +++ b/gamelog/src/game.rs @@ -65,8 +65,7 @@ impl Game { } pub fn team_plays(&self, team: Team) -> usize { - let quarterly_plays: Vec = self - .periods + self.periods .iter() .filter_map(|period| { if !period.is_overtime() { @@ -76,13 +75,9 @@ impl Game { None } }) - .collect::>(); - - let mut summation = 0_usize; - - quarterly_plays.iter().for_each(|value| summation += value); - - summation + .collect::>() + .iter() + .sum::() } /// The average number of plays in a quarter. @@ -145,6 +140,30 @@ impl Game { deltas.iter().sum::() as f32 / deltas.len() as f32 } + + pub fn penalties(&self, team: Team) -> usize { + self.periods + .iter() + .filter_map(|period| { + Some( + period + .team_events(team.to_owned(), None) + .ok()? + .iter() + .filter_map(|event| { + if let Event::Penalty(_) = event { + Some(event.to_owned()) + } else { + None + } + }) + .collect::>(), + ) + }) + .collect::>>() + .concat() + .len() + } } #[derive(Debug, Deserialize, Clone, PartialEq)] diff --git a/miller/src/main.rs b/miller/src/main.rs index bc9515c..58667aa 100644 --- a/miller/src/main.rs +++ b/miller/src/main.rs @@ -1,9 +1,10 @@ -use clap::Parser; +use clap::{ArgAction, Parser}; use core::panic; -use gamelog::{Action, Flags, LogFile, Team}; +use gamelog::{Action, Flags, Key, LogFile, Team}; use std::path::PathBuf; #[derive(Debug, Parser)] +#[clap(author, version, about)] struct Args { /// Path to source file or block device #[arg( @@ -17,6 +18,12 @@ struct Args { .unwrap()) )] logfile_path: PathBuf, + + // Behaviour is backwards. + // ArgAction::SetFalse by default evaluates to true, + // ArgAction::SetTrue by default evaluates to false. + #[arg(short, long, action=ArgAction::SetFalse)] + display_results: bool, } fn main() { @@ -39,6 +46,7 @@ fn main() { TeamStats::new(Team::TexasAnM), ]; + // Work on knocking down the nesting here? for game in log.0.iter() { if let Ok(teams) = game.teams() { for team in teams { @@ -70,13 +78,22 @@ fn main() { stats[team_idx] .plays_per_quarter .push(game.avg_plays_per_quarter(team.to_owned())); + + stats[team_idx] + .plays_per_game + .push(game.team_plays(team.to_owned())); + + stats[team_idx] + .penalties_per_game + .push(game.penalties(team.to_owned())); } } } } - for team in stats { - dbg!(team); + if dbg!(config.display_results) { + // :#? for pretty-printing. + stats.iter().for_each(|team| println!("{:#?}", team)); } } @@ -91,13 +108,15 @@ struct TeamStats { plays_per_quarter: Vec, plays_per_game: Vec, // Penalties - penalties_per_game: Vec, + penalties_per_game: Vec, // Score points_per_quarter: Vec, points_per_game: Vec, // Biases most_common_play: Option, least_common_play: Option, + most_common_key: Option, + least_common_key: Option, } impl TeamStats { @@ -114,6 +133,8 @@ impl TeamStats { points_per_game: vec![], most_common_play: None, least_common_play: None, + most_common_key: None, + least_common_key: None, } } }