Exemple #1
0
def get_career_percentiles_vs_rhb_for_pitch_types(
    request: Request,
    response: Response,
    mlb_id: str,
    app: Vigorish = Depends(get_vig_app)):
    player_data = crud.get_player_data(mlb_id, app)
    return player_data.percentiles_for_pitch_types_vs_rhb_for_career
Exemple #2
0
def search_player_name(query: str, app: Vigorish = Depends(get_vig_app)):
    results = app.scraped_data.player_name_search(query)
    for player_match in results:
        player_data = crud.get_player_data(player_match["result"], app)
        if player_data:
            player_match["details"] = player_data.player_details
    return results
Exemple #3
0
def get_pfx_metrics_vs_lhp_as_lhb_for_career_for_batter(
    request: Request, response: Response, mlb_id: str, app: Vigorish = Depends(get_vig_app)
):
    player_data = crud.get_player_data(mlb_id, app)
    pfx_stats = player_data.pfx_batting_metrics_vs_lhp_as_lhb_for_career
    if not pfx_stats:
        raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND), detail="No results found")
    return pfx_stats.as_dict()
Exemple #4
0
def get_all_pfx_career_data(request: Request,
                            response: Response,
                            mlb_id: str,
                            app: Vigorish = Depends(get_vig_app)):
    player_data = crud.get_player_data(mlb_id, app)
    career_pfx = player_data.get_all_pfx_career_data()
    yearly_pfx = player_data.get_all_pfx_yearly_data()
    return combine_career_and_yearly_pfx_pitching_metrics_sets(
        career_pfx, yearly_pfx)
Exemple #5
0
def get_career_pfx_metrics_for_pitcher(request: Request,
                                       response: Response,
                                       mlb_id: str,
                                       app: Vigorish = Depends(get_vig_app)):
    player_data = crud.get_player_data(mlb_id, app)
    pfx_stats = player_data.pfx_pitching_metrics_vs_all_by_year
    if not pfx_stats or not pfx_stats.total_pitches:
        raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND),
                            detail="No results found")
    return pfx_stats.as_dict()
Exemple #6
0
def get_pfx_metrics_for_year_for_batter(
    request: Request,
    response: Response,
    mlb_id: str,
    season: MLBSeason = Depends(),
    app: Vigorish = Depends(get_vig_app),
):
    player_data = crud.get_player_data(mlb_id, app)
    pfx_stats = player_data.get_pfx_pitching_metrics_vs_all_for_season(season.year)
    if not pfx_stats:
        raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND), detail="No results found")
    return pfx_stats.as_dict()
Exemple #7
0
def get_pfx_metrics_for_game_vs_lhb_for_pitcher(
        request: Request,
        response: Response,
        pitch_app_params: Tuple = Depends(get_pitch_app_params),
        app: Vigorish = Depends(get_vig_app),
):
    mlb_id, game_id = pitch_app_params
    player_data = crud.get_player_data(mlb_id, app)
    pfx_stats = player_data.get_pfx_pitching_metrics_vs_lhb_for_game(game_id)
    if not pfx_stats or not pfx_stats.total_pitches:
        raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND),
                            detail="No results found")
    return pfx_stats.as_dict()
Exemple #8
0
def get_all_pfx_within_date_range_for_player(
        request: Request,
        response: Response,
        mlb_id: int,
        date_range: tuple = Depends(get_date_range),
        app: Vigorish = Depends(get_vig_app),
):
    start_date, end_date = date_range
    player_data = crud.get_player_data(mlb_id, app)
    all_pfx = [
        p.pitchfx for p in player_data.pitch_app_map.values()
        if p.game_date >= start_date and p.game_date <= end_date
    ]
    return flatten_list2d(all_pfx)
Exemple #9
0
def get_all_pfx_within_date_range_for_player(
    request: Request,
    response: Response,
    mlb_id: int,
    date_range: tuple = Depends(get_date_range),
    app: Vigorish = Depends(get_vig_app),
):
    start_date, end_date = date_range
    player_data = crud.get_player_data(mlb_id, app)
    return (
        app.db_session.query(PitchFx)
        .filter(PitchFx.batter_id == player_data.player.id)
        .filter(PitchFx.game_date >= start_date)
        .filter(PitchFx.game_date <= end_date)
        .all()
    )
Exemple #10
0
def get_player_details(request: Request,
                       response: Response,
                       mlb_id: str,
                       app: Vigorish = Depends(get_vig_app)):
    player_data = crud.get_player_data(mlb_id, app)
    return player_data.player_details