patrickramos commited on
Commit
b6144a8
·
1 Parent(s): 7e1973f

Correct velocity unit in leaderboard, add MPH

Browse files
Files changed (1) hide show
  1. daily_weekly_leaderboard.py +9 -7
daily_weekly_leaderboard.py CHANGED
@@ -18,7 +18,7 @@ df = (
18
  # .with_columns(pl.col('game_date').str.to_datetime())
19
  .rename({
20
  'name': 'Name',
21
- 'release_speed': 'Velocity',
22
  'team': 'Team'
23
  })
24
  )
@@ -84,12 +84,13 @@ def compute_pitcher_leaderboards(df, top_players, strict, ignore_zero_whiffs, sh
84
 
85
  velos = (
86
  _df
87
- .select(*other_cols, 'Velocity')
 
88
  .drop_nulls()
89
- .sort(['Velocity', 'Name'], descending=[True, False])
90
  )
91
  if len(velos) > top_players:
92
- velos = velos.filter(pl.col('Velocity') >= velos['Velocity'][top_players])
93
  if strict:
94
  velos = velos[:top_players]
95
  if show_rank:
@@ -153,7 +154,8 @@ def plot_tables(whiffs, velos, time_type, subheader):
153
  ColumnDefinition(name="Rank", title="Rank", width=0.25),
154
  ColumnDefinition(name='Team', title='Team', width=0.25, plot_fn=circled_image, textprops={'ha': 'center'}),
155
  ColumnDefinition(name="Name", title="Player", textprops={'ha': 'left'}),
156
- ColumnDefinition(name="Velocity", title="MPH", width=0.25)
 
157
  ],
158
  ax=velo_ax
159
  )
@@ -213,12 +215,12 @@ def create_daily_pitcher_leaderboard():
213
  daily_header = gr.HTML('<center><h1>Daily Leaderboard<h1><h2 style="display: none;"></h2><h3 style="display: none;"></h3></center>')
214
  with gr.Row():
215
  daily_whiffs = gr.Dataframe(pl.DataFrame({'Name': [], 'Whiffs': []}), label='Whiffs', interactive=False, height=1000)
216
- daily_velos = gr.Dataframe(pl.DataFrame({'Name': [], 'Velocity': []}), label='Velocity', interactive=False, height=1000)
217
 
218
  weekly_header = gr.HTML('<center><h1>Weekly Leaderboard<h1><h2 style="display: none;"></h2><h3 style="display: none;"></h3></center>')
219
  with gr.Row():
220
  weekly_whiffs = gr.Dataframe(pl.DataFrame({'Name': [], 'Whiffs': []}), label='Whiffs', interactive=False, height=1000)
221
- weekly_velos = gr.Dataframe(pl.DataFrame({'Name': [], 'Velocity': []}), label='Velocity', interactive=False, height=1000)
222
 
223
  with gr.Tab('Tables for sharing'):
224
  gr.Markdown('''# Plotted leaderboards
 
18
  # .with_columns(pl.col('game_date').str.to_datetime())
19
  .rename({
20
  'name': 'Name',
21
+ 'release_speed': 'KPH',
22
  'team': 'Team'
23
  })
24
  )
 
84
 
85
  velos = (
86
  _df
87
+ .select(*other_cols, 'KPH')
88
+ .with_columns((pl.col('KPH') / 1.609).round().cast(pl.Int16).alias('MPH'))
89
  .drop_nulls()
90
+ .sort(['KPH', 'Name'], descending=[True, False])
91
  )
92
  if len(velos) > top_players:
93
+ velos = velos.filter(pl.col('KPH') >= velos['KPH'][top_players])
94
  if strict:
95
  velos = velos[:top_players]
96
  if show_rank:
 
154
  ColumnDefinition(name="Rank", title="Rank", width=0.25),
155
  ColumnDefinition(name='Team', title='Team', width=0.25, plot_fn=circled_image, textprops={'ha': 'center'}),
156
  ColumnDefinition(name="Name", title="Player", textprops={'ha': 'left'}),
157
+ ColumnDefinition(name="KPH", title="KPH", width=0.25),
158
+ ColumnDefinition(name='MPH', title='MPH', width=0.25)
159
  ],
160
  ax=velo_ax
161
  )
 
215
  daily_header = gr.HTML('<center><h1>Daily Leaderboard<h1><h2 style="display: none;"></h2><h3 style="display: none;"></h3></center>')
216
  with gr.Row():
217
  daily_whiffs = gr.Dataframe(pl.DataFrame({'Name': [], 'Whiffs': []}), label='Whiffs', interactive=False, height=1000)
218
+ daily_velos = gr.Dataframe(pl.DataFrame({'Name': [], 'KPH': [], 'MPH': []}), label='Velocity', interactive=False, height=1000)
219
 
220
  weekly_header = gr.HTML('<center><h1>Weekly Leaderboard<h1><h2 style="display: none;"></h2><h3 style="display: none;"></h3></center>')
221
  with gr.Row():
222
  weekly_whiffs = gr.Dataframe(pl.DataFrame({'Name': [], 'Whiffs': []}), label='Whiffs', interactive=False, height=1000)
223
+ weekly_velos = gr.Dataframe(pl.DataFrame({'Name': [], 'KPH': [], 'MPH': []}), label='Velocity', interactive=False, height=1000)
224
 
225
  with gr.Tab('Tables for sharing'):
226
  gr.Markdown('''# Plotted leaderboards