def get_bat_stats_for_lineup_spot_by_player_for_team( cls, db_engine, bat_order_list, team_id_bbref, year): s = select([cls]).where( and_(cls.bat_order.in_(bat_order_list), cls.team_id_bbref == team_id_bbref, cls.year == year)) results = db_engine.execute(s).fetchall() return BatStatsMetrics.from_query_results(results) if results else []
def get_bat_stats_for_starters_for_team(cls, db_engine, team_id_bbref, year): s = select([cls]).where( and_(cls.team_id_bbref == team_id_bbref, cls.year == year)) results = db_engine.execute(s).fetchall() return BatStatsMetrics.from_query_results( results)[0] if results else None
def get_bat_stats_for_defpos_by_year_for_team(cls, db_engine, def_position_list, team_id_bbref): s = select([cls]).where( and_(cls.def_position.in_(def_position_list), cls.team_id_bbref == team_id_bbref)) results = db_engine.execute(s).fetchall() return BatStatsMetrics.from_query_results(results) if results else []
def convert_career_bat_stats(career_bat_stats: BatStatsMetrics, total_seasons: int): stats_dict = career_bat_stats.as_dict() stats_dict["age"] = 0 stats_dict["league"] = "MLB" stats_dict["changed_teams_midseason"] = False stats_dict["all_stats_for_season"] = False stats_dict["all_stats_for_stint"] = False stats_dict["career_stats_all_teams"] = True stats_dict["career_stats_for_team"] = False stats_dict["total_seasons"] = total_seasons assign_row_id(stats_dict) return stats_dict
def get_bat_stats_for_season_for_all_teams(cls, db_engine, year): s = select([cls]).where(cls.year == year) results = db_engine.execute(s).fetchall() return BatStatsMetrics.from_query_results(results) if results else []
def get_bat_stats_by_year_for_team(cls, db_engine, team_id_bbref): s = select([cls]).where(cls.team_id_bbref == team_id_bbref) results = db_engine.execute(s).fetchall() return BatStatsMetrics.from_query_results(results) if results else []
def get_bat_stats_for_defpos_for_season_for_all_teams( cls, db_engine, def_position_list, year): s = select([cls]).where( and_(cls.def_position.in_(def_position_list), cls.year == year)) results = db_engine.execute(s).fetchall() return BatStatsMetrics.from_query_results(results) if results else []
def get_bat_stats_for_lineup_spot_for_season_for_all_teams( cls, db_engine, bat_order_list, year): s = select([cls]).where( and_(cls.bat_order.in_(bat_order_list), cls.year == year)) results = db_engine.execute(s).fetchall() return BatStatsMetrics.from_query_results(results) if results else []
def get_bat_stats_for_career_for_player(cls, db_engine, mlb_id): s = select([cls]).where(cls.mlb_id == mlb_id) results = db_engine.execute(s).fetchall() return BatStatsMetrics.from_query_results( results)[0] if results else None