From 8e8ba1238607d2fbcbdf546340c2e4b76a4f0688 Mon Sep 17 00:00:00 2001 From: Olivia Brooks <109807080+Cutieguwu@users.noreply.github.com> Date: Thu, 15 May 2025 20:11:41 -0400 Subject: [PATCH] Play frequency tallies --- gamelog/src/file.rs | 15 +++++++++++++++ miller/src/main.rs | 3 +++ 2 files changed, 18 insertions(+) diff --git a/gamelog/src/file.rs b/gamelog/src/file.rs index 6dfaff4..0eaea52 100644 --- a/gamelog/src/file.rs +++ b/gamelog/src/file.rs @@ -50,6 +50,21 @@ impl LogFile { (least_freq_action, frequency) } + pub fn frequency_of_plays(&self, team: Team) -> Vec<(Action, usize)> { + let team_actions = self.team_actions(team.to_owned()).into_iter(); + let mut plays: Vec<(Action, usize)> = vec![]; + + Action::iter().for_each(|action| { + plays.push(( + action.to_owned(), + team_actions.clone().filter(|a| *a == action).count(), + )) + }); + + plays.sort_by(|a, b| a.1.cmp(&b.1)); + plays + } + pub fn most_effective_play(&self, team: Team) -> (Action, TerrainState) { let deltas = self .0 diff --git a/miller/src/main.rs b/miller/src/main.rs index d0cf00a..9715156 100644 --- a/miller/src/main.rs +++ b/miller/src/main.rs @@ -102,6 +102,7 @@ fn main() -> io::Result<()> { stats[team_idx].most_effective_play = Some(log.most_effective_play(team.to_owned())); */ + stats[team_idx].play_frequencies = Some(log.frequency_of_plays(team.to_owned())) } } @@ -147,6 +148,7 @@ struct TeamStats { most_common_key: Option, least_common_key: Option, most_effective_play: Option<(Action, TerrainState)>, + play_frequencies: Option>, // Traits // Typical number of downs to achieve 10 yards. time_to_first_down: Option, @@ -167,6 +169,7 @@ impl TeamStats { most_common_key: None, least_common_key: None, most_effective_play: None, + play_frequencies: None, time_to_first_down: None, } }