macro_rules! stats_hydrations {
($($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_hydrations!
| Name | Stat Type | Stat Group | Notes |
|---|---|---|---|
Projected | WithPlayer<_> | HP-- | likely ZIPS projections |
YearByYear | HashMap<SeasonId, WithSeason<_>> | HPCF | 1. |
YearByYearAdvanced | HashMap<SeasonId, WithSeason<_>> | HP-- | 1. |
Season | WithSeason<_> | HPCF | |
Career | Career<_> | HPCF | |
SeasonAdvanced | WithSeason<_> | HP-- | |
CareerAdvanced | Career<_> | HP-- | |
GameLog | Vec<WithGame<_>> | HPCF | |
PlayLog | Vec<SingleMatchup<Play<_>>> | HPCF | same format as in games |
PitchLog | Vec<SingleMatchup<PitchStat>> | HPCF | same format as in games |
ExpectedStatistics | no wrapper | HP-- | xAVG, xwOBA, etc. |
Sabermetrics | no wrapper | HP-- | xFIP, fWAR, etc. |
VsPlayer5Y | AccumulatedVsPlayerMatchup<_> | HP-- | opposing_player in builder |
LastXGames | WithTeam<_> | HPCF | games_back in builder |
ByDateRange | WithTeam<_> | HPCF | date_range in builder |
ByDateRangeAdvanced | WithTeam<_> | HPCF | date_range in builder |
ByMonth | HashMap<Month, WithMonth<_>> | HPCF | |
ByDayOfWeek | HashMap<Weekday, WithWeekday<_>> | HPCF | |
HomeAndAway | WithHomeAndAway<_> | HPCF | |
WinLoss | WithWinLoss<_> | HPCF | |
OpponentsFaced | FieldedMatchup | HPCF | |
StatSplits | WithSeason<_> | HP-- | situations in builder |
StatSplitsAdvanced | WithSeason<_> | 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
- 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_hydrations! {
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;