Esempio n. 1
0
def getAll(start,end):
    df1 = bball.team_pitching(start, end)
    df2 = bball.team_batting(start_season=start, end_season=end, league='all', ind=1)

    dfAll = dc.mergeFramesHow(df1, df2, ["Team", "Season"],'inner')
    #print(dfAll.columns)
    return dfAll
Esempio n. 2
0
def get_stat():
    if request.method == "POST":
        stat = request.json["stat"]
        year = request.json["year"]
        if stat == "avg":
            data = team_batting(year)
            best_team = pd.DataFrame(data[data.AVG == data.AVG.max()])
            best_team_name = best_team.values[0][2]
            return jsonify({"success": True, "best_team": best_team_name})
        elif stat == "obp":
            data = team_batting(year)
            best_team = pd.DataFrame(data[data.OBP == data.OBP.max()])
            best_team_name = best_team.values[0][2]
            return jsonify({"success": True, "best_team": best_team_name})
        elif stat == "slg":
            data = team_batting(year)
            best_team = pd.DataFrame(data[data.SLG == data.SLG.max()])
            best_team_name = best_team.values[0][2]
            return jsonify({"success": True, "best_team": best_team_name})
        elif stat == "ops":
            data = team_batting(year)
            best_team = pd.DataFrame(data[data.OPS == data.OPS.max()])
            best_team_name = best_team.values[0][2]
            return jsonify({"success": True, "best_team": best_team_name})
        elif stat == "era":
            data = team_pitching(year)
            best_team = pd.DataFrame(data[data.ERA == data.ERA.min()])
            best_team_name = best_team.values[0][2]
            return jsonify({"success": True, "best_team": best_team_name})
        elif stat == "fip":
            data = team_pitching(year)
            best_team = pd.DataFrame(data[data.FIP == data.FIP.min()])
            best_team_name = best_team.values[0][2]
            return jsonify({"success": True, "best_team": best_team_name})
        elif stat == "whip":
            data = team_pitching(year)
            best_team = pd.DataFrame(data[data.WHIP == data.WHIP.min()])
            best_team_name = best_team.values[0][2]
            return jsonify({"success": True, "best_team": best_team_name})
def cmd_teampitching_upload(start_year, end_year, db_username, db_password,
                            db_hostname, db_name, db_tablename):

    click.echo('[[[ PULLING TEAMPITCHING DATAFRAME ]]]')

    engine = initdb_pitching(db_username, db_password, db_hostname, db_name,
                             db_tablename)

    click.echo(str('Pulling data...'))
    try:
        data = team_pitching(start_year, end_year)
        data.columns = data.columns.str.replace('%', '')
        upload_block(data, engine, db_tablename)
    except Exception as exc:
        click.echo("ERROR pulling down data - Error was = " + str(exc))
    else:
        click.echo(str('SUCCESS, pulled ' + str(data.shape[0]) + ' records'))
Esempio n. 4
0
def teamPitchingData(dateRange, stats, league, aggregate):
    if league is None or aggregate is None:
        # TODO
        raise Exception

    period = dc.convertDateStringToInt(dateRange)
    df = bball.team_pitching(period[0], period[1], league, aggregate)

    # ignore the parameters like player_id
    # drop all columns from the dataframe except the ones specified in stats
    dfHeaders = list(df.columns)
    neededCols = stats + ['Team', 'Season']
    dropCols = []
    for column in dfHeaders:
        if column not in neededCols:
            dropCols += [column]
    df = df.drop(dropCols, axis=1)
    return df
Esempio n. 5
0
def team_info():  #need to finish!!
    if request.method == "POST":
        team = request.json["team"]
        batting = team_batting(2021)
        batting_team = pd.DataFrame(batting[batting.Team == team])
        pitching = team_pitching(2021)
        pitching_team = pd.DataFrame(pitching[pitching.Team == team])
        wins = int(pitching_team.values[0][4])
        losses = int(pitching_team.values[0][5])
        home_runs = int(batting_team.iloc[0]['HR'])
        winp = wins / (wins + losses)
        ba = batting_team.iloc[0]["AVG"]
        era = pitching_team.iloc[0]["ERA"]

        return jsonify({
            "success": True,
            "wins": wins,
            "losses": losses,
            "winp": round(winp, 3),
            "home_runs": home_runs,
            "ba": ba,
            "era": era
        })
Esempio n. 6
0
def yearGrab(currentSeason):

    # Batting Stats
    from pybaseball import batting_stats

    BattingStats_Year = batting_stats(currentSeason, qual=1)
    # print(BattingStats_Year.head()) # Test
    BattingStats_Year.to_csv('data/YearlyData/temp/bstats.csv')

    import pybaseball

    #Team Batting Stats
    BattingStats_Team_Year = pybaseball.team_batting(currentSeason)
    BattingStats_Team_Year.to_csv('data/YearlyData/temp/team_bstats.csv')

    # Pitching Stats
    from pybaseball import pitching_stats

    PitchingStats_Year = pitching_stats(currentSeason)
    # print(PitchingStats_Year.head()) # Test
    PitchingStats_Year.to_csv('data/YearlyData/temp/pstats.csv')

    print(str(currentSeason) + " : Stats Grab: Successful")

    # Team Pitching Stats
    PitchingStats_Team_Year = pybaseball.team_pitching(currentSeason)
    PitchingStats_Team_Year.to_csv('data/YearlyData/temp/team_pstats.csv')
    """
    # Year Standings
    if currentSeason >=1969:
        from pybaseball import standings
        # get the end-of-season division standings for each season
        Standings = standings(currentSeason)
        Standings.insert(0, 'Season', currentSeason)
        Standings.to_csv('data/YearlyData/temp/team_standings.csv')
    """
    """
    # Amateur Draft Data
    if currentSeason >= 1965:

        from pybaseball import amateur_draft

        # Get amateur Draft Results
        Number_Rounds = 30
        RoundRange = list(range(1, Number_Rounds + 1))
        for i in RoundRange:
            #Pull season draft data 1 round at a time
            Amateur_Draft = amateur_draft(currentSeason, i)
            #Add Draft Year
            Amateur_Draft.insert(0, 'Draft_Year', currentSeason)

            # print(Amateur_Draft.head()) # Test

            # Read file with all draft files so far
            A_Draft = pd.read_csv('data/YearlyData/temp/amateur_draft.csv') 
            # Add New Round
            A_Draft = A_Draft.append(Amateur_Draft, ignore_index=True)
            #Save new round to File
            A_Draft.to_csv('data/YearlyData/temp/amateur_draft.csv', sep=',', index=False, encoding='utf-8')
        """

    # Exit Veolocity Data

    from pybaseball import statcast_batter_exitvelo_barrels

    Exit_Velocity = statcast_batter_exitvelo_barrels(currentSeason)
    Exit_Velocity.insert(0, 'Season', currentSeason)
    Exit_Velocity.to_csv('data/YearlyData/temp/statcast_exit_velocity.csv')

    # FanGraph Data
    import pybaseball

    # Individual Batting Stats
    fan_bat = pybaseball.batting_stats(currentSeason)
    fan_bat.to_csv('data/YearlyData/temp/fan_bat.csv')

    # Individual Pitching Stats
    fan_pit = pybaseball.pitching_stats(currentSeason)
    fan_pit.to_csv('data/YearlyData/temp/fan_pit.csv')

    # Team Batting Stats
    fan_team_bat = pybaseball.team_batting(currentSeason)
    fan_team_bat.to_csv('data/YearlyData/temp/fan_team_bat.csv')

    # Team Pitching Stats
    fan_team_pit = pybaseball.team_pitching(currentSeason)
    fan_team_pit.to_csv('data/YearlyData/temp/fan_team_pit.csv')

    from pybaseball import top_prospects

    # Get top overall prospects leaguewide
    topProspects = top_prospects()
    topProspects.to_csv('data/YearlyData/Top_Prospects.csv')
Esempio n. 7
0
def profile_team_pitching():
    team_pitching(2019)
Esempio n. 8
0
 def __init__(self, year: int):
     super().__init__(pybaseball.team_pitching(year))