Finish tasks to bring calculation capabilities in line with last interval.

This commit is contained in:
Cutieguwu
2025-04-06 12:19:42 -04:00
parent 89f97101af
commit a7f8cb04f7
4 changed files with 65 additions and 20 deletions

View File

@@ -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

View File

@@ -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),

View File

@@ -65,8 +65,7 @@ impl Game {
}
pub fn team_plays(&self, team: Team) -> usize {
let quarterly_plays: Vec<usize> = self
.periods
self.periods
.iter()
.filter_map(|period| {
if !period.is_overtime() {
@@ -76,13 +75,9 @@ impl Game {
None
}
})
.collect::<Vec<usize>>();
let mut summation = 0_usize;
quarterly_plays.iter().for_each(|value| summation += value);
summation
.collect::<Vec<usize>>()
.iter()
.sum::<usize>()
}
/// The average number of plays in a quarter.
@@ -145,6 +140,30 @@ impl Game {
deltas.iter().sum::<i8>() 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::<Vec<Event>>(),
)
})
.collect::<Vec<Vec<Event>>>()
.concat()
.len()
}
}
#[derive(Debug, Deserialize, Clone, PartialEq)]

View File

@@ -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<f32>,
plays_per_game: Vec<usize>,
// Penalties
penalties_per_game: Vec<u8>,
penalties_per_game: Vec<usize>,
// Score
points_per_quarter: Vec<u8>,
points_per_game: Vec<u8>,
// Biases
most_common_play: Option<Action>,
least_common_play: Option<Action>,
most_common_key: Option<Key>,
least_common_key: Option<Key>,
}
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,
}
}
}