Skip to main content

mlbt_api/
stats.rs

1use crate::schedule::IdNameLink;
2use serde::{Deserialize, Serialize};
3
4#[derive(Default, Debug, Serialize, Deserialize)]
5pub struct StatsResponse {
6    pub stats: Vec<Stat>,
7}
8
9#[derive(Debug, Serialize, Deserialize)]
10#[serde(rename_all = "camelCase")]
11pub struct Stat {
12    #[serde(rename = "type")]
13    pub stat_type: DisplayName,
14    pub group: DisplayName,
15    pub total_splits: u16,
16    pub splits: Vec<Split>,
17}
18
19#[derive(Debug, Serialize, Deserialize)]
20#[serde(rename_all = "camelCase")]
21pub struct DisplayName {
22    pub display_name: String,
23}
24
25#[derive(Debug, Serialize, Deserialize)]
26#[serde(rename_all = "camelCase")]
27pub struct Split {
28    season: Option<String>,
29    pub stat: StatSplit,
30    pub team: IdNameLink,
31    pub player: Option<Player>,
32}
33
34#[derive(Debug, Serialize, Deserialize)]
35#[serde(rename_all = "camelCase")]
36pub struct Player {
37    pub id: u64,
38    pub full_name: String,
39    pub first_name: String,
40    pub last_name: String,
41}
42
43/// StatSplit stores the two options for deserializing a Split.
44/// It uses the `untagged` enum representation to determine which one.
45/// https://serde.rs/enum-representations.html#untagged
46#[derive(Debug, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum StatSplit {
49    Pitching(Box<PitchingStat>),
50    Hitting(Box<HittingStat>),
51}
52
53#[derive(Debug, Serialize, Deserialize)]
54#[serde(rename_all = "camelCase")]
55pub struct PitchingStat {
56    pub wins: u16,
57    pub losses: u16,
58    pub era: String,
59    pub games_played: u16,
60    pub games_started: u16,
61    pub complete_games: u16,
62    pub shutouts: u16,
63    pub saves: u16,
64    pub save_opportunities: u16,
65    ground_outs: u16,
66    air_outs: u16,
67    pub innings_pitched: String,
68    pub hits: u16,
69    pub runs: u16,
70    pub earned_runs: u16,
71    doubles: i64,
72    triples: i64,
73    pub home_runs: u16,
74    pub hit_batsmen: u16,
75    pub base_on_balls: u16,
76    pub strike_outs: u16,
77    intentional_walks: u16,
78    hit_by_pitch: u16,
79    pub whip: String,
80    pub avg: String,
81    at_bats: u16,
82    obp: String,
83    slg: String,
84    ops: String,
85    caught_stealing: u16,
86    stolen_bases: u16,
87    stolen_base_percentage: String,
88    ground_into_double_play: u16,
89    number_of_pitches: u16,
90    holds: u16,
91    blown_saves: u16,
92    batters_faced: u16,
93    outs: u16,
94    games_pitched: u16,
95    strikes: u32,
96    strike_percentage: String,
97    balks: u16,
98    wild_pitches: u16,
99    pickoffs: Option<u16>,
100    total_bases: u16,
101    ground_outs_to_airouts: String,
102    win_percentage: String,
103    pitches_per_inning: String,
104    games_finished: u16,
105    strikeout_walk_ratio: String,
106    strikeouts_per9_inn: String,
107    walks_per9_inn: String,
108    hits_per9_inn: String,
109    runs_scored_per9: String,
110    home_runs_per9: String,
111    catchers_interference: Option<u16>,
112    sac_bunts: u16,
113    sac_flies: u16,
114}
115
116#[derive(Default, Debug, Serialize, Deserialize)]
117#[serde(rename_all = "camelCase")]
118pub struct HittingStat {
119    pub games_played: u16,
120    pub ground_outs: u16,
121    pub air_outs: u16,
122    pub runs: u16,
123    pub doubles: u16,
124    pub triples: u16,
125    pub home_runs: u16,
126    pub strike_outs: u16,
127    pub base_on_balls: u16,
128    pub intentional_walks: u16,
129    pub hits: u16,
130    pub hit_by_pitch: u16,
131    pub avg: String,
132    pub at_bats: u16,
133    pub obp: String,
134    pub slg: String,
135    pub ops: String,
136    pub caught_stealing: u16,
137    pub stolen_bases: u16,
138    pub stolen_base_percentage: String,
139    pub ground_into_double_play: u16,
140    pub number_of_pitches: u16,
141    pub plate_appearances: u16,
142    pub total_bases: u16,
143    pub rbi: u16,
144    pub left_on_base: u16,
145    pub sac_bunts: u16,
146    pub sac_flies: u16,
147    pub babip: String,
148    pub ground_outs_to_airouts: String,
149    pub catchers_interference: Option<u16>,
150    pub at_bats_per_home_run: String,
151}