Skip to main content

stats

Macro stats 

Source
macro_rules! stats {
    ($($t:tt)*) => { ... };
}
Expand description

Generates stat data types to be used in requests.

These are commonly associated with person_hydrations to create a PersonRequest.

§Stat Types & Stat Groups for stats!

NameStat TypeStat GroupNotes
ProjectedWithPlayer<_>HP--likely ZIPS projections
YearByYearHashMap<SeasonId, WithSeason<_>>HPCF1.
YearByYearAdvancedHashMap<SeasonId, WithSeason<_>>HP--1.
SeasonWithSeason<_>HPCF
CareerCareer<_>HPCF
SeasonAdvancedWithSeason<_>HP--
CareerAdvancedCareer<_>HP--
GameLogVec<WithGame<_>>HPCF
PlayLogVec<SingleMatchup<Play<_>>>HPCFsame format as in games
PitchLogVec<SingleMatchup<PitchStat>>HPCFsame format as in games
ExpectedStatisticsno wrapperHP--xAVG, xwOBA`, etc.
Sabermetricsno wrapperHP--xFIP, fWAR`, etc.
VsPlayer5YAccumulatedVsPlayerMatchup<_>HP--opposing_player in builder
LastXGamesWithTeam<_>HPCFgames_back in builder
ByDateRangeWithTeam<_>HPCFdate_range in builder
ByDateRangeAdvancedWithTeam<_>HPCFdate_range in builder
ByMonthHashMap<Month, WithMonth<_>>HPCF
ByDayOfWeekHashMap<Weekday, WithWeekday<_>>HPCF
HomeAndAwayWithHomeAndAway<_>HPCF
WinLossWithWinLoss<_>HPCF
OpponentsFacedFieldedMatchupHPCF
StatSplitsWithSeason<_>HP--situations in builder
StatSplitsAdvancedWithSeason<_>HP--situations in builder

Note: HPCF stands for Hitting, Pitching, Catching, and Fielding. StatTypes will be marked as for what StatGroups they support in requests.

Table Footnotes

  1. Seasons will display the last entry sent via the API, which is typically a full season with multiple teams, as opposed to the split with one team (ex. if a player is traded at the deadline).

§Examples

 mlb_api::stats! {
     pub struct MyStats {
         [Season, Career] = [Hitting, Pitching]
     }
 }

 mlb_api::person_hydrations! {
     pub struct MyStatsHydrations {
         stats: MyStats,
     }
 }

 let response = mlb_api::person::PersonRequest::<MyStatsHydrations>::builder()
     .id(id)
     .hydrations(MyStatsHydrations::builder()
         .stats(MyStats::builder()))
     .build_and_get()
     .await?;

 // for simple requests which don't involve values supplied in the builder (see table above), this also works:
 let response = mlb_api::person::PersonRequest::<MyStatsHydrations>::for_id(id)
     .build_and_get()
     .await?;

 let stats: &MyStats = &response.people[0].extras.stats;