Spaces:
Running
Running
Commit
·
977ef2a
1
Parent(s):
a8e1700
Add batting leaderboard
Browse files- app.py +3 -1
- player_team_leaderboard.py +16 -1
app.py
CHANGED
|
@@ -4,7 +4,7 @@ import matplotlib as mpl
|
|
| 4 |
from data import data_df
|
| 5 |
from pitcher_overview import create_pitcher_overview
|
| 6 |
# from pitcher_leaderboard import create_pitcher_leaderboard
|
| 7 |
-
from player_team_leaderboard import create_pitcher_leaderboard, create_team_pitching_leaderboard
|
| 8 |
from pitch_leaderboard import create_pitch_leaderboard
|
| 9 |
from daily_weekly_leaderboard import create_daily_weekly_leaderboard_app
|
| 10 |
from css import css
|
|
@@ -33,6 +33,8 @@ if __name__ == '__main__':
|
|
| 33 |
create_pitch_leaderboard()
|
| 34 |
with gr.Tab('Team Pitching Leaderboard'):
|
| 35 |
create_team_pitching_leaderboard()
|
|
|
|
|
|
|
| 36 |
with gr.Tab('Daily/Weekly Leaderboard'):
|
| 37 |
create_daily_weekly_leaderboard_app(data_df)
|
| 38 |
with gr.Tab('Acknowledgements'):
|
|
|
|
| 4 |
from data import data_df
|
| 5 |
from pitcher_overview import create_pitcher_overview
|
| 6 |
# from pitcher_leaderboard import create_pitcher_leaderboard
|
| 7 |
+
from player_team_leaderboard import create_pitcher_leaderboard, create_team_pitching_leaderboard, create_batter_leaderboard
|
| 8 |
from pitch_leaderboard import create_pitch_leaderboard
|
| 9 |
from daily_weekly_leaderboard import create_daily_weekly_leaderboard_app
|
| 10 |
from css import css
|
|
|
|
| 33 |
create_pitch_leaderboard()
|
| 34 |
with gr.Tab('Team Pitching Leaderboard'):
|
| 35 |
create_team_pitching_leaderboard()
|
| 36 |
+
with gr.Tab('Batter Leaderboard'):
|
| 37 |
+
create_batter_leaderboard()
|
| 38 |
with gr.Tab('Daily/Weekly Leaderboard'):
|
| 39 |
create_daily_weekly_leaderboard_app(data_df)
|
| 40 |
with gr.Tab('Acknowledgements'):
|
player_team_leaderboard.py
CHANGED
|
@@ -4,6 +4,7 @@ import numpy as np
|
|
| 4 |
|
| 5 |
from datetime import datetime
|
| 6 |
from functools import partial
|
|
|
|
| 7 |
|
| 8 |
from data import data_df
|
| 9 |
from stats import compute_player_stats, filter_data_by_date_and_game_kind
|
|
@@ -73,7 +74,15 @@ def create_player_team_leaderboard_app(player_team_type):
|
|
| 73 |
id_col = f'{player_type[:3].lower()}Id' if not team else f'{player_type}_team_name_short'
|
| 74 |
qual_name = 'IP' if pitching else 'PA'
|
| 75 |
|
| 76 |
-
def gr_create_player_team_leaderboard(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
assert pitcher_lr in ['Both', 'Left', 'Right']
|
| 78 |
assert batter_lr in ['Both', 'Left', 'Right']
|
| 79 |
|
|
@@ -185,6 +194,7 @@ def create_player_team_leaderboard_app(player_team_type):
|
|
| 185 |
gr.Markdown(notes)
|
| 186 |
|
| 187 |
search.click(gr_create_player_team_leaderboard, inputs=[start_date, end_date, min_ip, qualified, pitcher_lr, batter_lr, include_teams], outputs=leaderboard)
|
|
|
|
| 188 |
all_teams.click(lambda _teams : [] if _teams == TEAMS else TEAMS, inputs=include_teams, outputs=include_teams)
|
| 189 |
qualified.change(lambda qualified: gr.Number(interactive=not qualified), inputs=qualified, outputs=min_ip)
|
| 190 |
pin_columns.input(
|
|
@@ -205,6 +215,11 @@ create_team_pitching_leaderboard = partial(
|
|
| 205 |
player_team_type='team pitching'
|
| 206 |
)
|
| 207 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
if __name__ == '__main__':
|
| 209 |
app = foo()
|
| 210 |
app.launch()
|
|
|
|
| 4 |
|
| 5 |
from datetime import datetime
|
| 6 |
from functools import partial
|
| 7 |
+
from typing import Optional
|
| 8 |
|
| 9 |
from data import data_df
|
| 10 |
from stats import compute_player_stats, filter_data_by_date_and_game_kind
|
|
|
|
| 74 |
id_col = f'{player_type[:3].lower()}Id' if not team else f'{player_type}_team_name_short'
|
| 75 |
qual_name = 'IP' if pitching else 'PA'
|
| 76 |
|
| 77 |
+
def gr_create_player_team_leaderboard(
|
| 78 |
+
start_date: datetime,
|
| 79 |
+
end_date: datetime,
|
| 80 |
+
min_qual: int,
|
| 81 |
+
qualified: bool,
|
| 82 |
+
pitcher_lr: str='Both',
|
| 83 |
+
batter_lr: str = 'Both',
|
| 84 |
+
include_teams: Optional[list[str]] = None
|
| 85 |
+
):
|
| 86 |
assert pitcher_lr in ['Both', 'Left', 'Right']
|
| 87 |
assert batter_lr in ['Both', 'Left', 'Right']
|
| 88 |
|
|
|
|
| 194 |
gr.Markdown(notes)
|
| 195 |
|
| 196 |
search.click(gr_create_player_team_leaderboard, inputs=[start_date, end_date, min_ip, qualified, pitcher_lr, batter_lr, include_teams], outputs=leaderboard)
|
| 197 |
+
# gr.api(gr_create_player_team_leaderboard, api_name=f'gr_create_{player_team_type.replace(" ", "_")}_leaderboard')
|
| 198 |
all_teams.click(lambda _teams : [] if _teams == TEAMS else TEAMS, inputs=include_teams, outputs=include_teams)
|
| 199 |
qualified.change(lambda qualified: gr.Number(interactive=not qualified), inputs=qualified, outputs=min_ip)
|
| 200 |
pin_columns.input(
|
|
|
|
| 215 |
player_team_type='team pitching'
|
| 216 |
)
|
| 217 |
|
| 218 |
+
create_batter_leaderboard = partial(
|
| 219 |
+
create_player_team_leaderboard_app,
|
| 220 |
+
player_team_type='batter'
|
| 221 |
+
)
|
| 222 |
+
|
| 223 |
if __name__ == '__main__':
|
| 224 |
app = foo()
|
| 225 |
app.launch()
|