Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -39,7 +39,7 @@ column_list = ['woba_percent',
|
|
39 |
'zone_contact_percent',
|
40 |
'chase_percent',
|
41 |
'chase_contact']
|
42 |
-
column_list_pitch = ['pitches','bip','
|
43 |
|
44 |
import joblib
|
45 |
|
@@ -50,6 +50,7 @@ in_zone_model = joblib.load('joblib_model/in_zone_model_knn_20240410.joblib')
|
|
50 |
stat_plot_dict = {'woba_percent':{'name':'wOBA','format':'.3f','flip':False},
|
51 |
'xwoba_percent':{'name':'xwOBA','format':'.3f','flip':False},
|
52 |
'woba_percent_contact':{'name':'wOBACON','format':'.3f','flip':False},
|
|
|
53 |
'barrel_percent':{'name':'Barrel%','format':'.1%','flip':False},
|
54 |
'max_launch_speed':{'name':'Max EV','format':'.1f','flip':False},
|
55 |
'launch_speed_90':{'name':'90th% EV','format':'.1f','flip':False},
|
@@ -320,11 +321,18 @@ def server(input, output, session):
|
|
320 |
df_summ_player['barrel_percent'] = np.nan
|
321 |
df_summ_player['hard_hit_percent'] = np.nan
|
322 |
df_summ_player['xwoba_percent'] = np.nan
|
323 |
-
|
|
|
324 |
df_summ_player_pct['sweet_spot_percent'] = np.nan
|
325 |
df_summ_player_pct['barrel_percent'] = np.nan
|
326 |
df_summ_player_pct['hard_hit_percent'] = np.nan
|
327 |
-
df_summ_player_pct['xwoba_percent'] = np.nan
|
|
|
|
|
|
|
|
|
|
|
|
|
328 |
# x = 0.1
|
329 |
# y = 0.9
|
330 |
for cat in range(len(column_list)):
|
@@ -507,7 +515,7 @@ def server(input, output, session):
|
|
507 |
ha='center',
|
508 |
va='center')
|
509 |
|
510 |
-
df_plot = df_summ_batter_pitch[column_list_pitch].xs([batter_select,df_summ_update.xs(batter_select,level=0).index[0]]).sort_values('pitches',ascending=False)
|
511 |
df_plot = df_plot[df_plot['pitches'] > 0]
|
512 |
|
513 |
df_plot_pct = df_summ_batter_pitch_pct[column_list_pitch].xs([batter_select,df_summ_update.xs(batter_select,level=0).index[0]]).sort_values('pitches',ascending=False)#.dropna()
|
@@ -539,7 +547,11 @@ def server(input, output, session):
|
|
539 |
w, h = table[0,1].get_width(), table[0,1].get_height()
|
540 |
cell_i = table.add_cell(0, -1, w,h, text='Pitch Type')
|
541 |
cell_i.get_text().set_horizontalalignment('left')
|
|
|
542 |
min_font_size = 12
|
|
|
|
|
|
|
543 |
# Set table properties
|
544 |
|
545 |
table.auto_set_font_size(False)
|
@@ -566,7 +578,7 @@ def server(input, output, session):
|
|
566 |
|
567 |
|
568 |
|
569 |
-
float_3_list = ['
|
570 |
for fl in float_3_list:
|
571 |
# Subset of column names
|
572 |
subset_columns = [fl]
|
|
|
39 |
'zone_contact_percent',
|
40 |
'chase_percent',
|
41 |
'chase_contact']
|
42 |
+
column_list_pitch = ['pitches','bip','xwoba_percent_contact','whiff_rate','chase_percent']
|
43 |
|
44 |
import joblib
|
45 |
|
|
|
50 |
stat_plot_dict = {'woba_percent':{'name':'wOBA','format':'.3f','flip':False},
|
51 |
'xwoba_percent':{'name':'xwOBA','format':'.3f','flip':False},
|
52 |
'woba_percent_contact':{'name':'wOBACON','format':'.3f','flip':False},
|
53 |
+
'xwoba_percent_contact':{'name':'xwOBACON','format':'.3f','flip':False},
|
54 |
'barrel_percent':{'name':'Barrel%','format':'.1%','flip':False},
|
55 |
'max_launch_speed':{'name':'Max EV','format':'.1f','flip':False},
|
56 |
'launch_speed_90':{'name':'90th% EV','format':'.1f','flip':False},
|
|
|
321 |
df_summ_player['barrel_percent'] = np.nan
|
322 |
df_summ_player['hard_hit_percent'] = np.nan
|
323 |
df_summ_player['xwoba_percent'] = np.nan
|
324 |
+
df_summ_player['xwoba_percent_contact'] = np.nan
|
325 |
+
if df_summ_player_pct['launch_speed'].isna().values[0]:
|
326 |
df_summ_player_pct['sweet_spot_percent'] = np.nan
|
327 |
df_summ_player_pct['barrel_percent'] = np.nan
|
328 |
df_summ_player_pct['hard_hit_percent'] = np.nan
|
329 |
+
df_summ_player_pct['xwoba_percent'] = np.nan
|
330 |
+
df_summ_player['xwoba_percent_contact'] = np.nan
|
331 |
+
if df_summ_batter_pitch['launch_speed'].isna().values[0]:
|
332 |
+
df_summ_batter_pitch['xwoba_percent_contact'] = np.nan
|
333 |
+
|
334 |
+
|
335 |
+
|
336 |
# x = 0.1
|
337 |
# y = 0.9
|
338 |
for cat in range(len(column_list)):
|
|
|
515 |
ha='center',
|
516 |
va='center')
|
517 |
|
518 |
+
df_plot = df_summ_batter_pitch[column_list_pitch].xs([batter_select,df_summ_update.xs(batter_select,level=0).index[0]]).sort_values('pitches',ascending=False).fillna('—')
|
519 |
df_plot = df_plot[df_plot['pitches'] > 0]
|
520 |
|
521 |
df_plot_pct = df_summ_batter_pitch_pct[column_list_pitch].xs([batter_select,df_summ_update.xs(batter_select,level=0).index[0]]).sort_values('pitches',ascending=False)#.dropna()
|
|
|
547 |
w, h = table[0,1].get_width(), table[0,1].get_height()
|
548 |
cell_i = table.add_cell(0, -1, w,h, text='Pitch Type')
|
549 |
cell_i.get_text().set_horizontalalignment('left')
|
550 |
+
|
551 |
min_font_size = 12
|
552 |
+
|
553 |
+
if len(df_plot) >3:
|
554 |
+
min_font_size = 10
|
555 |
# Set table properties
|
556 |
|
557 |
table.auto_set_font_size(False)
|
|
|
578 |
|
579 |
|
580 |
|
581 |
+
float_3_list = ['xwoba_percent_contact']
|
582 |
for fl in float_3_list:
|
583 |
# Subset of column names
|
584 |
subset_columns = [fl]
|