from vigorish.data.player_data import PlayerData
from vigorish.enums import DefensePosition

from .conftest import BBREF_GAME_ID


def test_bat_stats(vig_app):
    bat_stats_for_career_dict = {
        "all_player_stats_for_bat_order": False,
        "all_player_stats_for_def_pos": False,
        "all_stats_for_season": False,
        "all_stats_for_stint": False,
        "all_team_stats_for_bat_order": False,
        "all_team_stats_for_def_pos": False,
        "at_bats": 5,
        "avg": 0.8,
        "bases_on_balls": 0,
        "bat_order_list": [2],
        "bat_order_metrics": [{"bat_order": 2, "percent": 100.0, "total_games": 1}],
        "bb_rate": 0.0,
        "bbref_id": "troutmi01",
        "career_stats_all_teams": False,
        "career_stats_for_team": False,
        "caught_stealing": 1,
        "changed_teams_midseason": False,
        "contact_rate": 1.0,
        "def_position_list": [DefensePosition.CENTER_FIELD],
        "def_position_metrics": [
            {"def_pos": DefensePosition.CENTER_FIELD, "is_starter": True, "percent": 100.0, "total_games": 1}
        ],
        "doubles": 1,
        "gdp": 0,
        "hit_by_pitch": 0,
        "hits": 4,
        "homeruns": 1,
        "intentional_bb": 0,
        "is_starter": False,
        "iso": 0.8,
        "k_rate": 0.0,
        "mlb_id": 545361,
        "obp": 0.8,
        "opponent_team_id_bbref": None,
        "ops": 2.4,
        "percent_started": 1.0,
        "percent_subbed": 0.0,
        "plate_appearances": 5,
        "player_team_id_bbref": None,
        "rbis": 3,
        "re24_bat": 2.9,
        "runs_scored": 2,
        "sac_fly": 0,
        "sac_hit": 0,
        "separate_player_stats_for_bat_order": False,
        "separate_player_stats_for_def_pos": False,
        "slg": 1.6,
        "stint_number": None,
        "stolen_bases": 0,
        "strikeouts": 0,
        "team_id_bbref": None,
        "total_games": 1,
        "total_games_started": 1,
        "total_games_subbed": 0,
        "total_pitches": 19,
        "total_strikes": 11,
        "triples": 0,
        "wpa_bat": 0.14,
        "wpa_bat_neg": -0.02,
        "wpa_bat_pos": 0.17,
        "year": None,
        "bat_order": "2",
        "def_position": "CF",
    }

    bat_stats_by_year_dict = {
        "all_player_stats_for_bat_order": False,
        "all_player_stats_for_def_pos": False,
        "all_stats_for_season": False,
        "all_stats_for_stint": False,
        "all_team_stats_for_bat_order": False,
        "all_team_stats_for_def_pos": False,
        "at_bats": 5,
        "avg": 0.8,
        "bases_on_balls": 0,
        "bat_order_list": [2],
        "bat_order_metrics": [{"bat_order": 2, "percent": 100.0, "total_games": 1}],
        "bb_rate": 0.0,
        "bbref_id": "troutmi01",
        "career_stats_all_teams": False,
        "career_stats_for_team": False,
        "caught_stealing": 1,
        "changed_teams_midseason": False,
        "contact_rate": 1.0,
        "def_position_list": [DefensePosition.CENTER_FIELD],
        "def_position_metrics": [
            {"def_pos": DefensePosition.CENTER_FIELD, "is_starter": True, "percent": 100.0, "total_games": 1}
        ],
        "doubles": 1,
        "gdp": 0,
        "hit_by_pitch": 0,
        "hits": 4,
        "homeruns": 1,
        "intentional_bb": 0,
        "is_starter": False,
        "iso": 0.8,
        "k_rate": 0.0,
        "mlb_id": 545361,
        "obp": 0.8,
        "opponent_team_id_bbref": None,
        "ops": 2.4,
        "percent_started": 1.0,
        "percent_subbed": 0.0,
        "plate_appearances": 5,
        "player_team_id_bbref": None,
        "rbis": 3,
        "re24_bat": 2.9,
        "runs_scored": 2,
        "sac_fly": 0,
        "sac_hit": 0,
        "separate_player_stats_for_bat_order": False,
        "separate_player_stats_for_def_pos": False,
        "slg": 1.6,
        "stint_number": None,
        "stolen_bases": 0,
        "strikeouts": 0,
        "team_id_bbref": None,
        "total_games": 1,
        "total_games_started": 1,
        "total_games_subbed": 0,
        "total_pitches": 19,
        "total_strikes": 11,
        "triples": 0,
        "wpa_bat": 0.14,
        "wpa_bat_neg": -0.02,
        "wpa_bat_pos": 0.17,
        "year": 2019,
        "bat_order": "2",
        "def_position": "CF",
    }

    bat_stats_by_team_dict = {
        "all_player_stats_for_bat_order": False,
        "all_player_stats_for_def_pos": False,
        "all_stats_for_season": False,
        "all_stats_for_stint": False,
        "all_team_stats_for_bat_order": False,
        "all_team_stats_for_def_pos": False,
        "at_bats": 5,
        "avg": 0.8,
        "bases_on_balls": 0,
        "bat_order_list": [2],
        "bat_order_metrics": [{"bat_order": 2, "percent": 100.0, "total_games": 1}],
        "bb_rate": 0.0,
        "bbref_id": "troutmi01",
        "career_stats_all_teams": False,
        "career_stats_for_team": False,
        "caught_stealing": 1,
        "changed_teams_midseason": False,
        "contact_rate": 1.0,
        "def_position_list": [DefensePosition.CENTER_FIELD],
        "def_position_metrics": [
            {"def_pos": DefensePosition.CENTER_FIELD, "is_starter": True, "percent": 100.0, "total_games": 1}
        ],
        "doubles": 1,
        "gdp": 0,
        "hit_by_pitch": 0,
        "hits": 4,
        "homeruns": 1,
        "intentional_bb": 0,
        "is_starter": False,
        "iso": 0.8,
        "k_rate": 0.0,
        "mlb_id": 545361,
        "obp": 0.8,
        "opponent_team_id_bbref": None,
        "ops": 2.4,
        "percent_started": 1.0,
        "percent_subbed": 0.0,
        "plate_appearances": 5,
        "player_team_id_bbref": "LAA",
        "rbis": 3,
        "re24_bat": 2.9,
        "runs_scored": 2,
        "sac_fly": 0,
        "sac_hit": 0,
        "separate_player_stats_for_bat_order": False,
        "separate_player_stats_for_def_pos": False,
        "slg": 1.6,
        "stint_number": None,
        "stolen_bases": 0,
        "strikeouts": 0,
        "team_id_bbref": "LAA",
        "total_games": 1,
        "total_games_started": 1,
        "total_games_subbed": 0,
        "total_pitches": 19,
        "total_strikes": 11,
        "triples": 0,
        "wpa_bat": 0.14,
        "wpa_bat_neg": -0.02,
        "wpa_bat_pos": 0.17,
        "year": None,
        "bat_order": "2",
        "def_position": "CF",
    }

    bat_stats_by_team_by_year_dict = {
        "all_player_stats_for_bat_order": False,
        "all_player_stats_for_def_pos": False,
        "all_stats_for_season": False,
        "all_stats_for_stint": False,
        "all_team_stats_for_bat_order": False,
        "all_team_stats_for_def_pos": False,
        "at_bats": 5,
        "avg": 0.8,
        "bases_on_balls": 0,
        "bat_order_list": [2],
        "bat_order_metrics": [{"bat_order": 2, "percent": 100.0, "total_games": 1}],
        "bb_rate": 0.0,
        "bbref_id": "troutmi01",
        "career_stats_all_teams": False,
        "career_stats_for_team": False,
        "caught_stealing": 1,
        "changed_teams_midseason": False,
        "contact_rate": 1.0,
        "def_position_list": [DefensePosition.CENTER_FIELD],
        "def_position_metrics": [
            {"def_pos": DefensePosition.CENTER_FIELD, "is_starter": True, "percent": 100.0, "total_games": 1}
        ],
        "doubles": 1,
        "gdp": 0,
        "hit_by_pitch": 0,
        "hits": 4,
        "homeruns": 1,
        "intentional_bb": 0,
        "is_starter": False,
        "iso": 0.8,
        "k_rate": 0.0,
        "mlb_id": 545361,
        "obp": 0.8,
        "opponent_team_id_bbref": None,
        "ops": 2.4,
        "percent_started": 1.0,
        "percent_subbed": 0.0,
        "plate_appearances": 5,
        "player_team_id_bbref": "LAA",
        "rbis": 3,
        "re24_bat": 2.9,
        "runs_scored": 2,
        "sac_fly": 0,
        "sac_hit": 0,
        "separate_player_stats_for_bat_order": False,
        "separate_player_stats_for_def_pos": False,
        "slg": 1.6,
        "stint_number": 1,
        "stolen_bases": 0,
        "strikeouts": 0,
        "team_id_bbref": "LAA",
        "total_games": 1,
        "total_games_started": 1,
        "total_games_subbed": 0,
        "total_pitches": 19,
        "total_strikes": 11,
        "triples": 0,
        "wpa_bat": 0.14,
        "wpa_bat_neg": -0.02,
        "wpa_bat_pos": 0.17,
        "year": 2019,
        "bat_order": "2",
        "def_position": "CF",
    }

    bat_stats_by_opp_team_dict = {
        "all_player_stats_for_bat_order": False,
        "all_player_stats_for_def_pos": False,
        "all_stats_for_season": False,
        "all_stats_for_stint": False,
        "all_team_stats_for_bat_order": False,
        "all_team_stats_for_def_pos": False,
        "at_bats": 5,
        "avg": 0.8,
        "bases_on_balls": 0,
        "bat_order_list": [2],
        "bat_order_metrics": [{"bat_order": 2, "percent": 100.0, "total_games": 1}],
        "bb_rate": 0.0,
        "bbref_id": "troutmi01",
        "career_stats_all_teams": False,
        "career_stats_for_team": False,
        "caught_stealing": 1,
        "changed_teams_midseason": False,
        "contact_rate": 1.0,
        "def_position_list": [DefensePosition.CENTER_FIELD],
        "def_position_metrics": [
            {"def_pos": DefensePosition.CENTER_FIELD, "is_starter": True, "percent": 100.0, "total_games": 1}
        ],
        "doubles": 1,
        "gdp": 0,
        "hit_by_pitch": 0,
        "hits": 4,
        "homeruns": 1,
        "intentional_bb": 0,
        "is_starter": False,
        "iso": 0.8,
        "k_rate": 0.0,
        "mlb_id": 545361,
        "obp": 0.8,
        "opponent_team_id_bbref": "TOR",
        "ops": 2.4,
        "percent_started": 1.0,
        "percent_subbed": 0.0,
        "plate_appearances": 5,
        "player_team_id_bbref": None,
        "rbis": 3,
        "re24_bat": 2.9,
        "runs_scored": 2,
        "sac_fly": 0,
        "sac_hit": 0,
        "separate_player_stats_for_bat_order": False,
        "separate_player_stats_for_def_pos": False,
        "slg": 1.6,
        "stint_number": None,
        "stolen_bases": 0,
        "strikeouts": 0,
        "team_id_bbref": None,
        "total_games": 1,
        "total_games_started": 1,
        "total_games_subbed": 0,
        "total_pitches": 19,
        "total_strikes": 11,
        "triples": 0,
        "wpa_bat": 0.14,
        "wpa_bat_neg": -0.02,
        "wpa_bat_pos": 0.17,
        "year": None,
        "bat_order": "2",
        "def_position": "CF",
    }

    bat_stats_by_opp_team_by_year_dict = {
        "all_player_stats_for_bat_order": False,
        "all_player_stats_for_def_pos": False,
        "all_stats_for_season": False,
        "all_stats_for_stint": False,
        "all_team_stats_for_bat_order": False,
        "all_team_stats_for_def_pos": False,
        "at_bats": 5,
        "avg": 0.8,
        "bases_on_balls": 0,
        "bat_order_list": [2],
        "bat_order_metrics": [{"bat_order": 2, "percent": 100.0, "total_games": 1}],
        "bb_rate": 0.0,
        "bbref_id": "troutmi01",
        "career_stats_all_teams": False,
        "career_stats_for_team": False,
        "caught_stealing": 1,
        "changed_teams_midseason": False,
        "contact_rate": 1.0,
        "def_position_list": [DefensePosition.CENTER_FIELD],
        "def_position_metrics": [
            {"def_pos": DefensePosition.CENTER_FIELD, "is_starter": True, "percent": 100.0, "total_games": 1}
        ],
        "doubles": 1,
        "gdp": 0,
        "hit_by_pitch": 0,
        "hits": 4,
        "homeruns": 1,
        "intentional_bb": 0,
        "is_starter": False,
        "iso": 0.8,
        "k_rate": 0.0,
        "mlb_id": 545361,
        "obp": 0.8,
        "opponent_team_id_bbref": "TOR",
        "ops": 2.4,
        "percent_started": 1.0,
        "percent_subbed": 0.0,
        "plate_appearances": 5,
        "player_team_id_bbref": None,
        "rbis": 3,
        "re24_bat": 2.9,
        "runs_scored": 2,
        "sac_fly": 0,
        "sac_hit": 0,
        "separate_player_stats_for_bat_order": False,
        "separate_player_stats_for_def_pos": False,
        "slg": 1.6,
        "stint_number": None,
        "stolen_bases": 0,
        "strikeouts": 0,
        "team_id_bbref": None,
        "total_games": 1,
        "total_games_started": 1,
        "total_games_subbed": 0,
        "total_pitches": 19,
        "total_strikes": 11,
        "triples": 0,
        "wpa_bat": 0.14,
        "wpa_bat_neg": -0.02,
        "wpa_bat_pos": 0.17,
        "year": 2019,
        "bat_order": "2",
        "def_position": "CF",
    }

    player_data = PlayerData(vig_app, 545361)
    assert player_data.bat_stats_for_career.as_dict() == bat_stats_for_career_dict
    assert player_data.bat_stats_by_year[0].as_dict() == bat_stats_by_year_dict
    assert player_data.bat_stats_by_team[0].as_dict() == bat_stats_by_team_dict
    assert player_data.bat_stats_by_team_by_year[0].as_dict() == bat_stats_by_team_by_year_dict
    assert player_data.bat_stats_by_opp_team["TOR"].as_dict() == bat_stats_by_opp_team_dict
    assert player_data.bat_stats_by_opp_team_by_year[2019]["TOR"].as_dict() == bat_stats_by_opp_team_by_year_dict


def test_pitch_stats(vig_app):

    pitch_stats_as_rp_dict = {
        "bases_on_balls": 0,
        "batters_faced": 0,
        "bb_per_nine": 0.0,
        "bb_rate": 0.0,
        "bbref_id": "lawde01",
        "earned_runs": 0,
        "era": 0.0,
        "fly_balls": 0,
        "games_as_rp": 0,
        "games_as_sp": 0,
        "ground_balls": 0,
        "hits": 0,
        "homeruns": 0,
        "hr_per_fb": 0.0,
        "hr_per_nine": 0.0,
        "inherited_runners": 0,
        "inherited_scored": 0,
        "innings_pitched": 0.0,
        "k_minus_bb": 0.0,
        "k_per_bb": 0.0,
        "k_per_nine": 0.0,
        "k_rate": 0.0,
        "line_drives": 0,
        "losses": 0,
        "mlb_id": 571882,
        "opponent_team_id_bbref": None,
        "pitch_count": 0,
        "player_team_id_bbref": None,
        "re24_pitch": 0,
        "role": "RP",
        "runs": 0,
        "saves": 0,
        "stint_number": None,
        "strikeouts": 0,
        "strikes": 0,
        "strikes_contact": 0,
        "strikes_looking": 0,
        "strikes_swinging": 0,
        "team_id_bbref": None,
        "total_games": 0,
        "total_outs": 0,
        "unknown_type": 0,
        "whip": 0.0,
        "wins": 0,
        "wpa_pitch": 0,
        "year": None,
    }

    pitch_stats_as_sp_dict = {
        "bases_on_balls": 0,
        "batters_faced": 3,
        "bb_per_nine": 0.0,
        "bb_rate": 0.0,
        "bbref_id": "lawde01",
        "earned_runs": 0,
        "era": 0.0,
        "fly_balls": 1,
        "games_as_rp": 0,
        "games_as_sp": 1,
        "ground_balls": 0,
        "hits": 0,
        "homeruns": 0,
        "hr_per_fb": 0.0,
        "hr_per_nine": 0.0,
        "inherited_runners": 0,
        "inherited_scored": 0,
        "innings_pitched": 1.0,
        "k_minus_bb": 0.667,
        "k_per_bb": 0.0,
        "k_per_nine": 18.0,
        "k_rate": 0.667,
        "line_drives": 1,
        "losses": 0,
        "mlb_id": 571882,
        "opponent_team_id_bbref": None,
        "pitch_count": 17,
        "player_team_id_bbref": None,
        "re24_pitch": 0.5,
        "role": "SP",
        "runs": 0,
        "saves": 0,
        "stint_number": None,
        "strikeouts": 2,
        "strikes": 11,
        "strikes_contact": 4,
        "strikes_looking": 5,
        "strikes_swinging": 2,
        "team_id_bbref": None,
        "total_games": 1,
        "total_outs": 3,
        "unknown_type": 0,
        "whip": 0.0,
        "wins": 0,
        "wpa_pitch": 0.05,
        "year": None,
    }
    pitch_stats_by_opp_team_by_year_dict = {
        "bases_on_balls": 0,
        "batters_faced": 3,
        "bb_per_nine": 0.0,
        "bb_rate": 0.0,
        "bbref_id": "lawde01",
        "earned_runs": 0,
        "era": 0.0,
        "fly_balls": 1,
        "games_as_rp": 0,
        "games_as_sp": 1,
        "ground_balls": 0,
        "hits": 0,
        "homeruns": 0,
        "hr_per_fb": 0.0,
        "hr_per_nine": 0.0,
        "inherited_runners": 0,
        "inherited_scored": 0,
        "innings_pitched": 1.0,
        "k_minus_bb": 0.667,
        "k_per_bb": 0.0,
        "k_per_nine": 18.0,
        "k_rate": 0.667,
        "line_drives": 1,
        "losses": 0,
        "mlb_id": 571882,
        "opponent_team_id_bbref": "LAA",
        "pitch_count": 17,
        "player_team_id_bbref": None,
        "re24_pitch": 0.5,
        "role": None,
        "runs": 0,
        "saves": 0,
        "stint_number": None,
        "strikeouts": 2,
        "strikes": 11,
        "strikes_contact": 4,
        "strikes_looking": 5,
        "strikes_swinging": 2,
        "team_id_bbref": None,
        "total_games": 1,
        "total_outs": 3,
        "unknown_type": 0,
        "whip": 0.0,
        "wins": 0,
        "wpa_pitch": 0.05,
        "year": 2019,
    }
    pitch_stats_by_opp_team_dict = {
        "bases_on_balls": 0,
        "batters_faced": 3,
        "bb_per_nine": 0.0,
        "bb_rate": 0.0,
        "bbref_id": "lawde01",
        "earned_runs": 0,
        "era": 0.0,
        "fly_balls": 1,
        "games_as_rp": 0,
        "games_as_sp": 1,
        "ground_balls": 0,
        "hits": 0,
        "homeruns": 0,
        "hr_per_fb": 0.0,
        "hr_per_nine": 0.0,
        "inherited_runners": 0,
        "inherited_scored": 0,
        "innings_pitched": 1.0,
        "k_minus_bb": 0.667,
        "k_per_bb": 0.0,
        "k_per_nine": 18.0,
        "k_rate": 0.667,
        "line_drives": 1,
        "losses": 0,
        "mlb_id": 571882,
        "opponent_team_id_bbref": "LAA",
        "pitch_count": 17,
        "player_team_id_bbref": None,
        "re24_pitch": 0.5,
        "role": None,
        "runs": 0,
        "saves": 0,
        "stint_number": None,
        "strikeouts": 2,
        "strikes": 11,
        "strikes_contact": 4,
        "strikes_looking": 5,
        "strikes_swinging": 2,
        "team_id_bbref": None,
        "total_games": 1,
        "total_outs": 3,
        "unknown_type": 0,
        "whip": 0.0,
        "wins": 0,
        "wpa_pitch": 0.05,
        "year": None,
    }
    pitch_stats_by_team_by_year_dict = {
        "bases_on_balls": 0,
        "batters_faced": 3,
        "bb_per_nine": 0.0,
        "bb_rate": 0.0,
        "bbref_id": "lawde01",
        "earned_runs": 0,
        "era": 0.0,
        "fly_balls": 1,
        "games_as_rp": 0,
        "games_as_sp": 1,
        "ground_balls": 0,
        "hits": 0,
        "homeruns": 0,
        "hr_per_fb": 0.0,
        "hr_per_nine": 0.0,
        "inherited_runners": 0,
        "inherited_scored": 0,
        "innings_pitched": 1.0,
        "k_minus_bb": 0.667,
        "k_per_bb": 0.0,
        "k_per_nine": 18.0,
        "k_rate": 0.667,
        "line_drives": 1,
        "losses": 0,
        "mlb_id": 571882,
        "opponent_team_id_bbref": None,
        "pitch_count": 17,
        "player_team_id_bbref": "TOR",
        "re24_pitch": 0.5,
        "role": None,
        "runs": 0,
        "saves": 0,
        "stint_number": 1,
        "strikeouts": 2,
        "strikes": 11,
        "strikes_contact": 4,
        "strikes_looking": 5,
        "strikes_swinging": 2,
        "team_id_bbref": "TOR",
        "total_games": 1,
        "total_outs": 3,
        "unknown_type": 0,
        "whip": 0.0,
        "wins": 0,
        "wpa_pitch": 0.05,
        "year": 2019,
    }
    pitch_stats_by_team_dict = {
        "bases_on_balls": 0,
        "batters_faced": 3,
        "bb_per_nine": 0.0,
        "bb_rate": 0.0,
        "bbref_id": "lawde01",
        "earned_runs": 0,
        "era": 0.0,
        "fly_balls": 1,
        "games_as_rp": 0,
        "games_as_sp": 1,
        "ground_balls": 0,
        "hits": 0,
        "homeruns": 0,
        "hr_per_fb": 0.0,
        "hr_per_nine": 0.0,
        "inherited_runners": 0,
        "inherited_scored": 0,
        "innings_pitched": 1.0,
        "k_minus_bb": 0.667,
        "k_per_bb": 0.0,
        "k_per_nine": 18.0,
        "k_rate": 0.667,
        "line_drives": 1,
        "losses": 0,
        "mlb_id": 571882,
        "opponent_team_id_bbref": None,
        "pitch_count": 17,
        "player_team_id_bbref": "TOR",
        "re24_pitch": 0.5,
        "role": None,
        "runs": 0,
        "saves": 0,
        "stint_number": None,
        "strikeouts": 2,
        "strikes": 11,
        "strikes_contact": 4,
        "strikes_looking": 5,
        "strikes_swinging": 2,
        "team_id_bbref": "TOR",
        "total_games": 1,
        "total_outs": 3,
        "unknown_type": 0,
        "whip": 0.0,
        "wins": 0,
        "wpa_pitch": 0.05,
        "year": None,
    }
    pitch_stats_by_year_dict = {
        "bases_on_balls": 0,
        "batters_faced": 3,
        "bb_per_nine": 0.0,
        "bb_rate": 0.0,
        "bbref_id": "lawde01",
        "earned_runs": 0,
        "era": 0.0,
        "fly_balls": 1,
        "games_as_rp": 0,
        "games_as_sp": 1,
        "ground_balls": 0,
        "hits": 0,
        "homeruns": 0,
        "hr_per_fb": 0.0,
        "hr_per_nine": 0.0,
        "inherited_runners": 0,
        "inherited_scored": 0,
        "innings_pitched": 1.0,
        "k_minus_bb": 0.667,
        "k_per_bb": 0.0,
        "k_per_nine": 18.0,
        "k_rate": 0.667,
        "line_drives": 1,
        "losses": 0,
        "mlb_id": 571882,
        "opponent_team_id_bbref": None,
        "pitch_count": 17,
        "player_team_id_bbref": None,
        "re24_pitch": 0.5,
        "role": None,
        "runs": 0,
        "saves": 0,
        "stint_number": None,
        "strikeouts": 2,
        "strikes": 11,
        "strikes_contact": 4,
        "strikes_looking": 5,
        "strikes_swinging": 2,
        "team_id_bbref": None,
        "total_games": 1,
        "total_outs": 3,
        "unknown_type": 0,
        "whip": 0.0,
        "wins": 0,
        "wpa_pitch": 0.05,
        "year": 2019,
    }
    pitch_stats_for_career_dict = {
        "bases_on_balls": 0,
        "batters_faced": 3,
        "bb_per_nine": 0.0,
        "bb_rate": 0.0,
        "bbref_id": "lawde01",
        "earned_runs": 0,
        "era": 0.0,
        "fly_balls": 1,
        "games_as_rp": 0,
        "games_as_sp": 1,
        "ground_balls": 0,
        "hits": 0,
        "homeruns": 0,
        "hr_per_fb": 0.0,
        "hr_per_nine": 0.0,
        "inherited_runners": 0,
        "inherited_scored": 0,
        "innings_pitched": 1.0,
        "k_minus_bb": 0.667,
        "k_per_bb": 0.0,
        "k_per_nine": 18.0,
        "k_rate": 0.667,
        "line_drives": 1,
        "losses": 0,
        "mlb_id": 571882,
        "opponent_team_id_bbref": None,
        "pitch_count": 17,
        "player_team_id_bbref": None,
        "re24_pitch": 0.5,
        "role": None,
        "runs": 0,
        "saves": 0,
        "stint_number": None,
        "strikeouts": 2,
        "strikes": 11,
        "strikes_contact": 4,
        "strikes_looking": 5,
        "strikes_swinging": 2,
        "team_id_bbref": None,
        "total_games": 1,
        "total_outs": 3,
        "unknown_type": 0,
        "whip": 0.0,
        "wins": 0,
        "wpa_pitch": 0.05,
        "year": None,
    }

    player_data = PlayerData(vig_app, 571882)
    assert player_data.all_pitch_stats_for_career.as_dict() == pitch_stats_for_career_dict
    assert player_data.pitch_stats_as_sp.as_dict() == pitch_stats_as_sp_dict
    assert player_data.pitch_stats_as_rp.as_dict() == pitch_stats_as_rp_dict
    assert player_data.pitch_stats_by_year[0].as_dict() == pitch_stats_by_year_dict
    assert player_data.pitch_stats_by_team[0].as_dict() == pitch_stats_by_team_dict
    assert player_data.pitch_stats_by_team_by_year[0].as_dict() == pitch_stats_by_team_by_year_dict
    assert player_data.pitch_stats_by_opp_team["LAA"].as_dict() == pitch_stats_by_opp_team_dict
    assert player_data.pitch_stats_by_opp_team_by_year[2019]["LAA"].as_dict() == pitch_stats_by_opp_team_by_year_dict


def test_pitchfx_pitching_metrics_career(vig_app):
    # All PitchFX metrics used by this test are from a single pitching performance by Derek Law, who appeared
    # as the starting pitcher for the Toronto Blue Jays against the Los Angeles Angels on June 17, 2019.

    pfx_metrics_career_vsALL_combined_dict = {
        "avg": 0.0,
        "avg_break_angle": 9.2,
        "avg_break_length": 7.8,
        "avg_break_y": 24.0,
        "avg_extension": 6.29,
        "avg_hit_distance": 328.0,
        "avg_launch_angle": 27.0,
        "avg_launch_speed": 85.3,
        "avg_pfx_x": -0.31,
        "avg_pfx_z": 2.41,
        "avg_plate_time": 0.442,
        "avg_px": 0.13,
        "avg_pz": 2.27,
        "avg_speed": 86.0,
        "avg_spin_direction": 123.0,
        "avg_spin_rate": 2127.0,
        "bad_whiff_rate": 0.167,
        "barrel_rate": 0.0,
        "bat_stand": None,
        "bb_rate": 0.0,
        "called_strike_rate": 0.294,
        "contact_rate": 0.667,
        "csw_rate": 0.412,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 0.667,
        "line_drive_rate": 1.0,
        "max_launch_speed": 85.3,
        "medium_hit_rate": 1.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.667,
        "o_swing_rate": 0.3,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 1,
        "pitch_type_int": 32803,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.353,
        "swinging_strike_rate": 0.118,
        "total_at_bats": 3,
        "total_bad_whiffs": 1,
        "total_balls_in_play": 1,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 5,
        "total_contact_inside_zone": 2,
        "total_contact_outside_zone": 2,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 7,
        "total_k": 2,
        "total_line_drives": 1,
        "total_medium_hits": 1,
        "total_outs": 3,
        "total_outside_strike_zone": 10,
        "total_pa": 3,
        "total_pitches": 17,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 2,
        "total_swings": 6,
        "total_swings_inside_zone": 3,
        "total_swings_made_contact": 4,
        "total_swings_outside_zone": 3,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.333,
        "z_contact_rate": 0.667,
        "z_swing_rate": 0.429,
        "zone_rate": 0.412,
        "pitch_type": ["CH", "CU", "FF", "SL"],
    }

    pfx_metrics_career_vsRHB_combined_dict = {
        "avg": 0.0,
        "avg_break_angle": 9.1,
        "avg_break_length": 6.7,
        "avg_break_y": 24.0,
        "avg_extension": 6.25,
        "avg_hit_distance": 328.0,
        "avg_launch_angle": 27.0,
        "avg_launch_speed": 85.3,
        "avg_pfx_x": -0.26,
        "avg_pfx_z": 3.81,
        "avg_plate_time": 0.432,
        "avg_px": 0.29,
        "avg_pz": 2.9,
        "avg_speed": 88.3,
        "avg_spin_direction": 131.0,
        "avg_spin_rate": 2206.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": "R",
        "bb_rate": 0.0,
        "called_strike_rate": 0.2,
        "contact_rate": 1.0,
        "csw_rate": 0.2,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 0.0,
        "line_drive_rate": 1.0,
        "max_launch_speed": 85.3,
        "medium_hit_rate": 1.0,
        "mlb_id": 571882,
        "o_contact_rate": 1.0,
        "o_swing_rate": 0.333,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 1,
        "pitch_type_int": 32802,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.4,
        "swinging_strike_rate": 0.0,
        "total_at_bats": 1,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 1,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 1,
        "total_contact_inside_zone": 1,
        "total_contact_outside_zone": 1,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 2,
        "total_k": 0,
        "total_line_drives": 1,
        "total_medium_hits": 1,
        "total_outs": 1,
        "total_outside_strike_zone": 3,
        "total_pa": 1,
        "total_pitches": 5,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 0,
        "total_swings": 2,
        "total_swings_inside_zone": 1,
        "total_swings_made_contact": 2,
        "total_swings_outside_zone": 1,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.0,
        "z_contact_rate": 1.0,
        "z_swing_rate": 0.5,
        "zone_rate": 0.4,
        "pitch_type": ["CU", "FF", "SL"],
    }

    pfx_metrics_career_vsLHB_combined_dict = {
        "avg": 0.0,
        "avg_break_angle": 9.2,
        "avg_break_length": 8.2,
        "avg_break_y": 24.0,
        "avg_extension": 6.3,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": -0.34,
        "avg_pfx_z": 1.82,
        "avg_plate_time": 0.446,
        "avg_px": 0.07,
        "avg_pz": 2.01,
        "avg_speed": 85.0,
        "avg_spin_direction": 119.0,
        "avg_spin_rate": 2093.0,
        "bad_whiff_rate": 0.25,
        "barrel_rate": 0.0,
        "bat_stand": "L",
        "bb_rate": 0.0,
        "called_strike_rate": 0.333,
        "contact_rate": 0.5,
        "csw_rate": 0.5,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 1.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.5,
        "o_swing_rate": 0.286,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 1,
        "pitch_type_int": 32803,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.333,
        "swinging_strike_rate": 0.167,
        "total_at_bats": 2,
        "total_bad_whiffs": 1,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 4,
        "total_contact_inside_zone": 1,
        "total_contact_outside_zone": 1,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 5,
        "total_k": 2,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 2,
        "total_outside_strike_zone": 7,
        "total_pa": 2,
        "total_pitches": 12,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 2,
        "total_swings": 4,
        "total_swings_inside_zone": 2,
        "total_swings_made_contact": 2,
        "total_swings_outside_zone": 2,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.5,
        "z_contact_rate": 0.5,
        "z_swing_rate": 0.4,
        "zone_rate": 0.417,
        "pitch_type": ["CH", "CU", "FF", "SL"],
    }

    pfx_metrics_career_vsALL_CU_dict = {
        "avg": 0.0,
        "avg_break_angle": 5.4,
        "avg_break_length": 13.2,
        "avg_break_y": 24.0,
        "avg_extension": 5.82,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": 3.04,
        "avg_pfx_z": -5.96,
        "avg_plate_time": 0.502,
        "avg_px": 0.23,
        "avg_pz": 1.59,
        "avg_speed": 76.2,
        "avg_spin_direction": 27.0,
        "avg_spin_rate": 2056.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": None,
        "bb_rate": 0.0,
        "called_strike_rate": 0.5,
        "contact_rate": 0.0,
        "csw_rate": 0.5,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 0.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.0,
        "o_swing_rate": 0.0,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.23529411764705882,
        "pitch_type_int": 2,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.0,
        "swinging_strike_rate": 0.0,
        "total_at_bats": 0,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 2,
        "total_contact_inside_zone": 0,
        "total_contact_outside_zone": 0,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 2,
        "total_k": 0,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 0,
        "total_outside_strike_zone": 2,
        "total_pa": 0,
        "total_pitches": 4,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 0,
        "total_swings": 0,
        "total_swings_inside_zone": 0,
        "total_swings_made_contact": 0,
        "total_swings_outside_zone": 0,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.0,
        "z_contact_rate": 0.0,
        "z_swing_rate": 0.0,
        "zone_rate": 0.5,
        "pitch_type": ["CU"],
    }

    pfx_metrics_career_vsRHB_CU_dict = {
        "avg": 0.0,
        "avg_break_angle": 2.4,
        "avg_break_length": 13.2,
        "avg_break_y": 24.0,
        "avg_extension": 5.64,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": 1.2,
        "avg_pfx_z": -6.97,
        "avg_plate_time": 0.51,
        "avg_px": 0.73,
        "avg_pz": 1.44,
        "avg_speed": 75.6,
        "avg_spin_direction": 11.0,
        "avg_spin_rate": 2141.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": "R",
        "bb_rate": 0.0,
        "called_strike_rate": 0.0,
        "contact_rate": 0.0,
        "csw_rate": 0.0,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 0.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.0,
        "o_swing_rate": 0.0,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.2,
        "pitch_type_int": 2,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.0,
        "swinging_strike_rate": 0.0,
        "total_at_bats": 0,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 0,
        "total_contact_inside_zone": 0,
        "total_contact_outside_zone": 0,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 0,
        "total_k": 0,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 0,
        "total_outside_strike_zone": 1,
        "total_pa": 0,
        "total_pitches": 1,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 0,
        "total_swings": 0,
        "total_swings_inside_zone": 0,
        "total_swings_made_contact": 0,
        "total_swings_outside_zone": 0,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.0,
        "z_contact_rate": 0.0,
        "z_swing_rate": 0.0,
        "zone_rate": 0.0,
        "pitch_type": ["CU"],
    }

    pfx_metrics_career_vsLHB_CU_dict = {
        "avg": 0.0,
        "avg_break_angle": 6.4,
        "avg_break_length": 13.2,
        "avg_break_y": 24.0,
        "avg_extension": 5.88,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": 3.66,
        "avg_pfx_z": -5.63,
        "avg_plate_time": 0.5,
        "avg_px": 0.06,
        "avg_pz": 1.64,
        "avg_speed": 76.4,
        "avg_spin_direction": 32.0,
        "avg_spin_rate": 2028.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": "L",
        "bb_rate": 0.0,
        "called_strike_rate": 0.667,
        "contact_rate": 0.0,
        "csw_rate": 0.667,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 0.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.0,
        "o_swing_rate": 0.0,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.25,
        "pitch_type_int": 2,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.0,
        "swinging_strike_rate": 0.0,
        "total_at_bats": 0,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 2,
        "total_contact_inside_zone": 0,
        "total_contact_outside_zone": 0,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 2,
        "total_k": 0,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 0,
        "total_outside_strike_zone": 1,
        "total_pa": 0,
        "total_pitches": 3,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 0,
        "total_swings": 0,
        "total_swings_inside_zone": 0,
        "total_swings_made_contact": 0,
        "total_swings_outside_zone": 0,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.0,
        "z_contact_rate": 0.0,
        "z_swing_rate": 0.0,
        "zone_rate": 0.667,
        "pitch_type": ["CU"],
    }

    pfx_metrics_career_vsALL_FF_dict = {
        "avg": 0.0,
        "avg_break_angle": 7.0,
        "avg_break_length": 3.6,
        "avg_break_y": 24.0,
        "avg_extension": 6.61,
        "avg_hit_distance": 328.0,
        "avg_launch_angle": 27.0,
        "avg_launch_speed": 85.3,
        "avg_pfx_x": -1.25,
        "avg_pfx_z": 8.58,
        "avg_plate_time": 0.398,
        "avg_px": 0.05,
        "avg_pz": 3.3,
        "avg_speed": 94.0,
        "avg_spin_direction": 186.0,
        "avg_spin_rate": 2150.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": None,
        "bb_rate": 0.0,
        "called_strike_rate": 0.167,
        "contact_rate": 1.0,
        "csw_rate": 0.167,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 0.0,
        "line_drive_rate": 1.0,
        "max_launch_speed": 85.3,
        "medium_hit_rate": 1.0,
        "mlb_id": 571882,
        "o_contact_rate": 1.0,
        "o_swing_rate": 0.2,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.35294117647058826,
        "pitch_type_int": 32,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.333,
        "swinging_strike_rate": 0.0,
        "total_at_bats": 1,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 1,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 1,
        "total_contact_inside_zone": 1,
        "total_contact_outside_zone": 1,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 1,
        "total_k": 0,
        "total_line_drives": 1,
        "total_medium_hits": 1,
        "total_outs": 1,
        "total_outside_strike_zone": 5,
        "total_pa": 1,
        "total_pitches": 6,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 0,
        "total_swings": 2,
        "total_swings_inside_zone": 1,
        "total_swings_made_contact": 2,
        "total_swings_outside_zone": 1,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.0,
        "z_contact_rate": 1.0,
        "z_swing_rate": 1.0,
        "zone_rate": 0.167,
        "pitch_type": ["FF"],
    }

    pfx_metrics_career_vsRHB_FF_dict = {
        "avg": 0.0,
        "avg_break_angle": 11.6,
        "avg_break_length": 3.6,
        "avg_break_y": 24.0,
        "avg_extension": 6.58,
        "avg_hit_distance": 328.0,
        "avg_launch_angle": 27.0,
        "avg_launch_speed": 85.3,
        "avg_pfx_x": -1.92,
        "avg_pfx_z": 9.08,
        "avg_plate_time": 0.397,
        "avg_px": 0.05,
        "avg_pz": 3.45,
        "avg_speed": 94.6,
        "avg_spin_direction": 191.0,
        "avg_spin_rate": 2204.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": "R",
        "bb_rate": 0.0,
        "called_strike_rate": 0.0,
        "contact_rate": 1.0,
        "csw_rate": 0.0,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 0.0,
        "line_drive_rate": 1.0,
        "max_launch_speed": 85.3,
        "medium_hit_rate": 1.0,
        "mlb_id": 571882,
        "o_contact_rate": 1.0,
        "o_swing_rate": 0.5,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.6,
        "pitch_type_int": 32,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.667,
        "swinging_strike_rate": 0.0,
        "total_at_bats": 1,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 1,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 0,
        "total_contact_inside_zone": 1,
        "total_contact_outside_zone": 1,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 1,
        "total_k": 0,
        "total_line_drives": 1,
        "total_medium_hits": 1,
        "total_outs": 1,
        "total_outside_strike_zone": 2,
        "total_pa": 1,
        "total_pitches": 3,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 0,
        "total_swings": 2,
        "total_swings_inside_zone": 1,
        "total_swings_made_contact": 2,
        "total_swings_outside_zone": 1,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.0,
        "z_contact_rate": 1.0,
        "z_swing_rate": 1.0,
        "zone_rate": 0.333,
        "pitch_type": ["FF"],
    }

    pfx_metrics_career_vsLHB_FF_dict = {
        "avg": 0.0,
        "avg_break_angle": 2.4,
        "avg_break_length": 3.6,
        "avg_break_y": 24.0,
        "avg_extension": 6.64,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": -0.58,
        "avg_pfx_z": 8.07,
        "avg_plate_time": 0.4,
        "avg_px": 0.05,
        "avg_pz": 3.16,
        "avg_speed": 93.4,
        "avg_spin_direction": 182.0,
        "avg_spin_rate": 2096.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": "L",
        "bb_rate": 0.0,
        "called_strike_rate": 0.333,
        "contact_rate": 0.0,
        "csw_rate": 0.333,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 0.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.0,
        "o_swing_rate": 0.0,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.25,
        "pitch_type_int": 32,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.0,
        "swinging_strike_rate": 0.0,
        "total_at_bats": 0,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 1,
        "total_contact_inside_zone": 0,
        "total_contact_outside_zone": 0,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 0,
        "total_k": 0,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 0,
        "total_outside_strike_zone": 3,
        "total_pa": 0,
        "total_pitches": 3,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 0,
        "total_swings": 0,
        "total_swings_inside_zone": 0,
        "total_swings_made_contact": 0,
        "total_swings_outside_zone": 0,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.0,
        "z_contact_rate": 0.0,
        "z_swing_rate": 0.0,
        "zone_rate": 0.0,
        "pitch_type": ["FF"],
    }

    pfx_metrics_career_vsALL_CH_dict = {
        "avg": 0.0,
        "avg_break_angle": 22.8,
        "avg_break_length": 6.4,
        "avg_break_y": 24.0,
        "avg_extension": 6.55,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": -6.38,
        "avg_pfx_z": 6.99,
        "avg_plate_time": 0.437,
        "avg_px": -0.2,
        "avg_pz": 2.37,
        "avg_speed": 85.8,
        "avg_spin_direction": 222.0,
        "avg_spin_rate": 1967.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": None,
        "bb_rate": 0.0,
        "called_strike_rate": 0.333,
        "contact_rate": 0.5,
        "csw_rate": 0.667,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 1.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.0,
        "o_swing_rate": 0.0,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.17647058823529413,
        "pitch_type_int": 1,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.667,
        "swinging_strike_rate": 0.333,
        "total_at_bats": 1,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 1,
        "total_contact_inside_zone": 1,
        "total_contact_outside_zone": 0,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 3,
        "total_k": 1,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 1,
        "total_outside_strike_zone": 0,
        "total_pa": 1,
        "total_pitches": 3,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 1,
        "total_swings": 2,
        "total_swings_inside_zone": 2,
        "total_swings_made_contact": 1,
        "total_swings_outside_zone": 0,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.5,
        "z_contact_rate": 0.5,
        "z_swing_rate": 0.667,
        "zone_rate": 1.0,
        "pitch_type": ["CH"],
    }

    pfx_metrics_career_vsLHB_CH_dict = {
        "avg": 0.0,
        "avg_break_angle": 22.8,
        "avg_break_length": 6.4,
        "avg_break_y": 24.0,
        "avg_extension": 6.55,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": -6.38,
        "avg_pfx_z": 6.99,
        "avg_plate_time": 0.437,
        "avg_px": -0.2,
        "avg_pz": 2.37,
        "avg_speed": 85.8,
        "avg_spin_direction": 222.0,
        "avg_spin_rate": 1967.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": "L",
        "bb_rate": 0.0,
        "called_strike_rate": 0.333,
        "contact_rate": 0.5,
        "csw_rate": 0.667,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 1.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.0,
        "o_swing_rate": 0.0,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.25,
        "pitch_type_int": 1,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.667,
        "swinging_strike_rate": 0.333,
        "total_at_bats": 1,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 1,
        "total_contact_inside_zone": 1,
        "total_contact_outside_zone": 0,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 3,
        "total_k": 1,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 1,
        "total_outside_strike_zone": 0,
        "total_pa": 1,
        "total_pitches": 3,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 1,
        "total_swings": 2,
        "total_swings_inside_zone": 2,
        "total_swings_made_contact": 1,
        "total_swings_outside_zone": 0,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.5,
        "z_contact_rate": 0.5,
        "z_swing_rate": 0.667,
        "zone_rate": 1.0,
        "pitch_type": ["CH"],
    }

    pfx_metrics_career_vsALL_SL_dict = {
        "avg": 0.0,
        "avg_break_angle": 6.0,
        "avg_break_length": 9.6,
        "avg_break_y": 24.0,
        "avg_extension": 6.07,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": 2.29,
        "avg_pfx_z": -1.92,
        "avg_plate_time": 0.45,
        "avg_px": 0.41,
        "avg_pz": 1.35,
        "avg_speed": 83.7,
        "avg_spin_direction": 48.0,
        "avg_spin_rate": 2281.0,
        "bad_whiff_rate": 0.5,
        "barrel_rate": 0.0,
        "bat_stand": None,
        "bb_rate": 0.0,
        "called_strike_rate": 0.25,
        "contact_rate": 0.5,
        "csw_rate": 0.5,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 1.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.5,
        "o_swing_rate": 0.667,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.23529411764705882,
        "pitch_type_int": 32768,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.5,
        "swinging_strike_rate": 0.25,
        "total_at_bats": 1,
        "total_bad_whiffs": 1,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 1,
        "total_contact_inside_zone": 0,
        "total_contact_outside_zone": 1,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 1,
        "total_k": 1,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 1,
        "total_outside_strike_zone": 3,
        "total_pa": 1,
        "total_pitches": 4,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 1,
        "total_swings": 2,
        "total_swings_inside_zone": 0,
        "total_swings_made_contact": 1,
        "total_swings_outside_zone": 2,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.5,
        "z_contact_rate": 0.0,
        "z_swing_rate": 0.0,
        "zone_rate": 0.25,
        "pitch_type": ["SL"],
    }

    pfx_metrics_career_vsRHB_SL_dict = {
        "avg": 0.0,
        "avg_break_angle": 8.4,
        "avg_break_length": 9.6,
        "avg_break_y": 24.0,
        "avg_extension": 5.88,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": 3.27,
        "avg_pfx_z": -1.24,
        "avg_plate_time": 0.46,
        "avg_px": 0.55,
        "avg_pz": 2.72,
        "avg_speed": 81.9,
        "avg_spin_direction": 70.0,
        "avg_spin_rate": 2277.0,
        "bad_whiff_rate": 0.0,
        "barrel_rate": 0.0,
        "bat_stand": "R",
        "bb_rate": 0.0,
        "called_strike_rate": 1.0,
        "contact_rate": 0.0,
        "csw_rate": 1.0,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 0.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.0,
        "o_swing_rate": 0.0,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.2,
        "pitch_type_int": 32768,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.0,
        "swinging_strike_rate": 0.0,
        "total_at_bats": 0,
        "total_bad_whiffs": 0,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 1,
        "total_contact_inside_zone": 0,
        "total_contact_outside_zone": 0,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 1,
        "total_k": 0,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 0,
        "total_outside_strike_zone": 0,
        "total_pa": 0,
        "total_pitches": 1,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 0,
        "total_swings": 0,
        "total_swings_inside_zone": 0,
        "total_swings_made_contact": 0,
        "total_swings_outside_zone": 0,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.0,
        "z_contact_rate": 0.0,
        "z_swing_rate": 0.0,
        "zone_rate": 1.0,
        "pitch_type": ["SL"],
    }

    pfx_metrics_career_vsLHB_SL_dict = {
        "avg": 0.0,
        "avg_break_angle": 5.2,
        "avg_break_length": 9.6,
        "avg_break_y": 24.0,
        "avg_extension": 6.14,
        "avg_hit_distance": 0.0,
        "avg_launch_angle": 0.0,
        "avg_launch_speed": 0.0,
        "avg_pfx_x": 1.96,
        "avg_pfx_z": -2.15,
        "avg_plate_time": 0.447,
        "avg_px": 0.36,
        "avg_pz": 0.89,
        "avg_speed": 84.3,
        "avg_spin_direction": 41.0,
        "avg_spin_rate": 2282.0,
        "bad_whiff_rate": 0.5,
        "barrel_rate": 0.0,
        "bat_stand": "L",
        "bb_rate": 0.0,
        "called_strike_rate": 0.0,
        "contact_rate": 0.5,
        "csw_rate": 0.333,
        "fly_ball_rate": 0.0,
        "ground_ball_rate": 0.0,
        "hard_hit_rate": 0.0,
        "hr_per_fb": 0.0,
        "iso": 0.0,
        "k_rate": 1.0,
        "line_drive_rate": 0.0,
        "max_launch_speed": 0.0,
        "medium_hit_rate": 0.0,
        "mlb_id": 571882,
        "o_contact_rate": 0.5,
        "o_swing_rate": 0.667,
        "obp": 0.0,
        "ops": 0.0,
        "p_throws": "R",
        "percent": 0.25,
        "pitch_type_int": 32768,
        "popup_rate": 0.0,
        "slg": 0.0,
        "soft_hit_rate": 0.0,
        "swing_rate": 0.667,
        "swinging_strike_rate": 0.333,
        "total_at_bats": 1,
        "total_bad_whiffs": 1,
        "total_balls_in_play": 0,
        "total_barrels": 0,
        "total_bb": 0,
        "total_called_strikes": 0,
        "total_contact_inside_zone": 0,
        "total_contact_outside_zone": 1,
        "total_doubles": 0,
        "total_errors": 0,
        "total_fly_balls": 0,
        "total_ground_balls": 0,
        "total_hard_hits": 0,
        "total_hbp": 0,
        "total_hits": 0,
        "total_homeruns": 0,
        "total_ibb": 0,
        "total_inside_strike_zone": 0,
        "total_k": 1,
        "total_line_drives": 0,
        "total_medium_hits": 0,
        "total_outs": 1,
        "total_outside_strike_zone": 3,
        "total_pa": 1,
        "total_pitches": 3,
        "total_popups": 0,
        "total_sac_fly": 0,
        "total_sac_hit": 0,
        "total_singles": 0,
        "total_soft_hits": 0,
        "total_swinging_strikes": 1,
        "total_swings": 2,
        "total_swings_inside_zone": 0,
        "total_swings_made_contact": 1,
        "total_swings_outside_zone": 2,
        "total_triples": 0,
        "triple_slash": ".000/.000/.000 (.000)",
        "whiff_rate": 0.5,
        "z_contact_rate": 0.0,
        "z_swing_rate": 0.0,
        "zone_rate": 0.0,
        "pitch_type": ["SL"],
    }

    pitchfx_metrics_set_vsALL_for_year = {
        "pitch_type": ["CH", "CU", "FF", "SL"],
        "pitch_type_int": 32803,
        "total_pitches": 17,
        "total_pfx_removed": 0,
        "metrics_combined": pfx_metrics_career_vsALL_combined_dict,
        "metrics_by_pitch_type": {
            "FF": pfx_metrics_career_vsALL_FF_dict,
            "CU": pfx_metrics_career_vsALL_CU_dict,
            "SL": pfx_metrics_career_vsALL_SL_dict,
            "CH": pfx_metrics_career_vsALL_CH_dict,
        },
    }

    pitchfx_metrics_set_vsRHB_for_year = {
        "pitch_type": ["CU", "FF", "SL"],
        "pitch_type_int": 32802,
        "total_pitches": 5,
        "total_pfx_removed": 0,
        "metrics_combined": pfx_metrics_career_vsRHB_combined_dict,
        "metrics_by_pitch_type": {
            "FF": pfx_metrics_career_vsRHB_FF_dict,
            "CU": pfx_metrics_career_vsRHB_CU_dict,
            "SL": pfx_metrics_career_vsRHB_SL_dict,
        },
    }

    pitchfx_metrics_set_vsLHB_for_year = {
        "pitch_type": ["CH", "CU", "FF", "SL"],
        "pitch_type_int": 32803,
        "total_pitches": 12,
        "total_pfx_removed": 0,
        "metrics_combined": pfx_metrics_career_vsLHB_combined_dict,
        "metrics_by_pitch_type": {
            "FF": pfx_metrics_career_vsLHB_FF_dict,
            "CU": pfx_metrics_career_vsLHB_CU_dict,
            "SL": pfx_metrics_career_vsLHB_SL_dict,
            "CH": pfx_metrics_career_vsLHB_CH_dict,
        },
    }

    career_percentiles_vsALL_dict = [
        {
            "pitch_type": "FF",
            "avg_speed": (94.0, 54.0),
            "ops": (0.0, 100.0),
            "zone_rate": (0.167, 2.1),
            "o_swing_rate": (0.2, 15.4),
            "whiff_rate": (0.0, 1.3),
            "bad_whiff_rate": (0.0, 100.0),
            "contact_rate": (1.0, 1.4),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (85.3, 100.0),
        },
        {
            "pitch_type": "CU",
            "avg_speed": (76.2, 22.2),
            "ops": (0.0, 100.0),
            "zone_rate": (0.5, 99.4),
            "o_swing_rate": (0.0, 1.0),
            "whiff_rate": (0.0, 1.4),
            "bad_whiff_rate": (0.0, 100.0),
            "contact_rate": (0.0, 100.0),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (0.0, 100.0),
        },
        {
            "pitch_type": "SL",
            "avg_speed": (83.7, 31.1),
            "ops": (0.0, 100.0),
            "zone_rate": (0.25, 21.3),
            "o_swing_rate": (0.667, 100.0),
            "whiff_rate": (0.5, 93.1),
            "bad_whiff_rate": (0.5, 100.0),
            "contact_rate": (0.5, 93.3),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (0.0, 100.0),
        },
        {
            "pitch_type": "CH",
            "avg_speed": (85.8, 53.1),
            "ops": (0.0, 100.0),
            "zone_rate": (1.0, 100.0),
            "o_swing_rate": (0.0, 1.4),
            "whiff_rate": (0.5, 98.3),
            "bad_whiff_rate": (0.0, 100.0),
            "contact_rate": (0.5, 98.2),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (0.0, 100.0),
        },
    ]

    career_percentiles_vsRHB_dict = [
        {
            "pitch_type": "FF",
            "avg_speed": (94.6, 62.1),
            "ops": (0.0, 100.0),
            "zone_rate": (0.333, 23.2),
            "o_swing_rate": (0.5, 99.0),
            "whiff_rate": (0.0, 1.3),
            "bad_whiff_rate": (0.0, 100.0),
            "contact_rate": (1.0, 1.4),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (85.3, 100.0),
        },
        {
            "pitch_type": "CU",
            "avg_speed": (75.6, 16.2),
            "ops": (0.0, 100.0),
            "zone_rate": (0.0, 1.1),
            "o_swing_rate": (0.0, 1.0),
            "whiff_rate": (0.0, 1.4),
            "bad_whiff_rate": (0.0, 100.0),
            "contact_rate": (0.0, 100.0),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (0.0, 100.0),
        },
        {
            "pitch_type": "SL",
            "avg_speed": (81.9, 14.1),
            "ops": (0.0, 100.0),
            "zone_rate": (1.0, 100.0),
            "o_swing_rate": (0.0, 1.3),
            "whiff_rate": (0.0, 1.0),
            "bad_whiff_rate": (0.0, 100.0),
            "contact_rate": (0.0, 100.0),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (0.0, 100.0),
        },
    ]

    career_percentiles_vsLHB_dict = [
        {
            "pitch_type": "CH",
            "avg_speed": (85.8, 53.1),
            "ops": (0.0, 100.0),
            "zone_rate": (1.0, 100.0),
            "o_swing_rate": (0.0, 1.4),
            "whiff_rate": (0.5, 98.3),
            "bad_whiff_rate": (0.0, 100.0),
            "contact_rate": (0.5, 98.2),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (0.0, 100.0),
        },
        {
            "pitch_type": "CU",
            "avg_speed": (76.4, 23.2),
            "ops": (0.0, 100.0),
            "zone_rate": (0.667, 100.0),
            "o_swing_rate": (0.0, 1.0),
            "whiff_rate": (0.0, 1.4),
            "bad_whiff_rate": (0.0, 100.0),
            "contact_rate": (0.0, 100.0),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (0.0, 100.0),
        },
        {
            "pitch_type": "FF",
            "avg_speed": (93.4, 45.2),
            "ops": (0.0, 100.0),
            "zone_rate": (0.0, 1.3),
            "o_swing_rate": (0.0, 1.0),
            "whiff_rate": (0.0, 1.3),
            "bad_whiff_rate": (0.0, 100.0),
            "contact_rate": (0.0, 100.0),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (0.0, 100.0),
        },
        {
            "pitch_type": "SL",
            "avg_speed": (84.3, 38.0),
            "ops": (0.0, 100.0),
            "zone_rate": (0.0, 1.3),
            "o_swing_rate": (0.667, 100.0),
            "whiff_rate": (0.5, 93.1),
            "bad_whiff_rate": (0.5, 100.0),
            "contact_rate": (0.5, 93.3),
            "ground_ball_rate": (0.0, 100.0),
            "barrel_rate": (0.0, 100.0),
            "avg_exit_velocity": (0.0, 100.0),
        },
    ]

    player_data = PlayerData(vig_app, 571882)
    assert (
        player_data.pfx_pitching_metrics_vs_all_for_career.metrics_combined.as_dict()
        == pfx_metrics_career_vsALL_combined_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_all_for_career.metrics_by_pitch_type["CH"].as_dict()
        == pfx_metrics_career_vsALL_CH_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_all_for_career.metrics_by_pitch_type["CU"].as_dict()
        == pfx_metrics_career_vsALL_CU_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_all_for_career.metrics_by_pitch_type["FF"].as_dict()
        == pfx_metrics_career_vsALL_FF_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_all_for_career.metrics_by_pitch_type["SL"].as_dict()
        == pfx_metrics_career_vsALL_SL_dict
    )
    assert player_data.percentiles_for_pitch_types_for_career == career_percentiles_vsALL_dict

    assert (
        player_data.pfx_pitching_metrics_vs_rhb_for_career.metrics_combined.as_dict()
        == pfx_metrics_career_vsRHB_combined_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_rhb_for_career.metrics_by_pitch_type["CU"].as_dict()
        == pfx_metrics_career_vsRHB_CU_dict
    )

    assert (
        player_data.pfx_pitching_metrics_vs_rhb_for_career.metrics_by_pitch_type["FF"].as_dict()
        == pfx_metrics_career_vsRHB_FF_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_rhb_for_career.metrics_by_pitch_type["SL"].as_dict()
        == pfx_metrics_career_vsRHB_SL_dict
    )
    assert player_data.percentiles_for_pitch_types_vs_rhb_for_career == career_percentiles_vsRHB_dict

    assert (
        player_data.pfx_pitching_metrics_vs_lhb_for_career.metrics_combined.as_dict()
        == pfx_metrics_career_vsLHB_combined_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_lhb_for_career.metrics_by_pitch_type["CH"].as_dict()
        == pfx_metrics_career_vsLHB_CH_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_lhb_for_career.metrics_by_pitch_type["CU"].as_dict()
        == pfx_metrics_career_vsLHB_CU_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_lhb_for_career.metrics_by_pitch_type["FF"].as_dict()
        == pfx_metrics_career_vsLHB_FF_dict
    )
    assert (
        player_data.pfx_pitching_metrics_vs_lhb_for_career.metrics_by_pitch_type["SL"].as_dict()
        == pfx_metrics_career_vsLHB_SL_dict
    )
    assert player_data.percentiles_for_pitch_types_vs_lhb_for_career == career_percentiles_vsLHB_dict

    assert player_data.pfx_pitching_metrics_vs_all_by_year[2019].as_dict() == pitchfx_metrics_set_vsALL_for_year
    assert player_data.percentiles_for_pitch_types_by_year[2019] == career_percentiles_vsALL_dict
    assert player_data.pfx_pitching_metrics_vs_rhb_by_year[2019].as_dict() == pitchfx_metrics_set_vsRHB_for_year
    assert player_data.percentiles_for_pitch_types_vs_rhb_by_year[2019] == career_percentiles_vsRHB_dict
    assert player_data.pfx_pitching_metrics_vs_lhb_by_year[2019].as_dict() == pitchfx_metrics_set_vsLHB_for_year
    assert player_data.percentiles_for_pitch_types_vs_lhb_by_year[2019] == career_percentiles_vsLHB_dict

    assert player_data.get_pfx_pitching_metrics_vs_all_for_season(2019).as_dict() == pitchfx_metrics_set_vsALL_for_year
    assert player_data.get_pfx_pitching_metrics_vs_rhb_for_season(2019).as_dict() == pitchfx_metrics_set_vsRHB_for_year
    assert player_data.get_pfx_pitching_metrics_vs_lhb_for_season(2019).as_dict() == pitchfx_metrics_set_vsLHB_for_year

    assert (
        player_data.get_pfx_pitching_metrics_vs_all_for_game(BBREF_GAME_ID).as_dict()
        == pitchfx_metrics_set_vsALL_for_year
    )
    assert (
        player_data.get_pfx_pitching_metrics_vs_rhb_for_game(BBREF_GAME_ID).as_dict()
        == pitchfx_metrics_set_vsRHB_for_year
    )
    assert (
        player_data.get_pfx_pitching_metrics_vs_lhb_for_game(BBREF_GAME_ID).as_dict()
        == pitchfx_metrics_set_vsLHB_for_year
    )

    pfx_career_data = player_data.get_all_pfx_career_data()
    assert pfx_career_data["all"]["metrics"].as_dict() == pitchfx_metrics_set_vsALL_for_year
    assert pfx_career_data["all"]["percentiles"] == career_percentiles_vsALL_dict
    assert pfx_career_data["rhb"]["metrics"].as_dict() == pitchfx_metrics_set_vsRHB_for_year
    assert pfx_career_data["rhb"]["percentiles"] == career_percentiles_vsRHB_dict
    assert pfx_career_data["lhb"]["metrics"].as_dict() == pitchfx_metrics_set_vsLHB_for_year
    assert pfx_career_data["lhb"]["percentiles"] == career_percentiles_vsLHB_dict

    pfx_yearly_data = player_data.get_all_pfx_yearly_data()
    assert pfx_yearly_data["all"]["metrics"][2019].as_dict() == pitchfx_metrics_set_vsALL_for_year
    assert pfx_yearly_data["all"]["percentiles"][2019] == career_percentiles_vsALL_dict
    assert pfx_yearly_data["rhb"]["metrics"][2019].as_dict() == pitchfx_metrics_set_vsRHB_for_year
    assert pfx_yearly_data["rhb"]["percentiles"][2019] == career_percentiles_vsRHB_dict
    assert pfx_yearly_data["lhb"]["metrics"][2019].as_dict() == pitchfx_metrics_set_vsLHB_for_year
    assert pfx_yearly_data["lhb"]["percentiles"][2019] == career_percentiles_vsLHB_dict


def test_pitchfx_batting_metrics_career(vig_app):
    player_data = PlayerData(vig_app, 600303)
    assert player_data.pfx_batting_metrics_vs_all_for_career
    assert player_data.pfx_batting_metrics_vs_rhp_for_career
    assert player_data.pfx_batting_metrics_vs_lhp_for_career
    assert player_data.pfx_batting_metrics_vs_rhp_as_lhb_for_career
    assert player_data.pfx_batting_metrics_vs_lhp_as_lhb_for_career
    assert player_data.pfx_batting_metrics_by_year
    assert player_data.get_pfx_batting_metrics_vs_all_for_game(BBREF_GAME_ID)
    assert player_data.get_pfx_batting_metrics_vs_rhp_for_game(BBREF_GAME_ID)
    assert player_data.get_pfx_batting_metrics_vs_lhp_for_game(BBREF_GAME_ID)
    assert player_data.get_pfx_batting_metrics_vs_rhp_as_lhb_for_game(BBREF_GAME_ID)
    assert player_data.get_pfx_batting_metrics_vs_lhp_as_lhb_for_game(BBREF_GAME_ID)
    assert player_data.get_all_pfx_batting_career_data()
    assert player_data.get_all_pfx_batting_yearly_data()

    player_data = PlayerData(vig_app, 545361)
    assert player_data.pfx_batting_metrics_vs_rhp_as_rhb_for_career
    assert player_data.pfx_batting_metrics_vs_lhp_as_rhb_for_career
    assert player_data.get_pfx_batting_metrics_vs_rhp_as_rhb_for_game(BBREF_GAME_ID)
    assert player_data.get_pfx_batting_metrics_vs_lhp_as_rhb_for_game(BBREF_GAME_ID)
