Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -766,12 +766,13 @@ def server(input, output, session):
|
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
-
brushed_df_final = (((brushed_df.group_by(['pitcher_id', '
|
| 770 |
pl.col('is_pitch').drop_nans().count().alias('pitches'),
|
| 771 |
pl.col('start_speed').drop_nans().mean().round(1).alias('start_speed'),
|
| 772 |
pl.col('vb').drop_nans().mean().round(1).alias('vb'),
|
| 773 |
pl.col('ivb').drop_nans().mean().round(1).alias('ivb'),
|
| 774 |
pl.col('hb').drop_nans().mean().round(1).alias('hb'),
|
|
|
|
| 775 |
pl.col('spin_rate').drop_nans().mean().alias('spin_rate'),
|
| 776 |
pl.col('release_pos_x').drop_nans().mean().round(1).alias('x0'),
|
| 777 |
pl.col('release_pos_z').drop_nans().mean().round(1).alias('z0'),
|
|
@@ -785,21 +786,22 @@ def server(input, output, session):
|
|
| 785 |
.alias('proportion')
|
| 786 |
)
|
| 787 |
)).sort('proportion', descending=True).
|
| 788 |
-
select(["
|
| 789 |
"spin_rate", "x0", "z0",'tj_stuff_plus','pitch_grade'])
|
| 790 |
.with_columns(
|
| 791 |
-
pl.when(pl.col("
|
| 792 |
.then(pl.lit("4-Seam"))
|
| 793 |
-
.otherwise(pl.col("
|
| 794 |
-
.alias("
|
| 795 |
)
|
| 796 |
.rename({
|
| 797 |
-
'
|
| 798 |
'pitches': 'Pitches',
|
| 799 |
'proportion': 'Prop',
|
| 800 |
'start_speed': 'Velo',
|
| 801 |
'ivb': 'iVB',
|
| 802 |
'hb': 'HB',
|
|
|
|
| 803 |
'spin_rate': 'Spin',
|
| 804 |
'x0': 'hRel',
|
| 805 |
'z0': 'vRel',
|
|
@@ -849,7 +851,7 @@ def server(input, output, session):
|
|
| 849 |
.set_properties(subset=brushed_df_final.columns, **{'height': '30px'})
|
| 850 |
.set_table_styles([{'selector': 'thead th', 'props': [('height', '30px')]}], overwrite=False)
|
| 851 |
# .set_table_styles([{'selector': 'table', 'props': [('width', '100px')]}], overwrite=False)
|
| 852 |
-
.set_table_styles([{'selector': 'thead th:nth-child(1)', 'props': [('min-width', '
|
| 853 |
.set_table_styles([{'selector': 'thead th:nth-child(2)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 854 |
.set_table_styles([{'selector': 'thead th:nth-child(3)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 855 |
.set_table_styles([{'selector': 'thead th:nth-child(4)', 'props': [('min-width', '40px')]}], overwrite=False)
|
|
@@ -858,6 +860,7 @@ def server(input, output, session):
|
|
| 858 |
.set_table_styles([{'selector': 'thead th:nth-child(7)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 859 |
.set_table_styles([{'selector': 'thead th:nth-child(8)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 860 |
.set_table_styles([{'selector': 'thead th:nth-child(9)', 'props': [('min-width', '40px')]}], overwrite=False)
|
|
|
|
| 861 |
.background_gradient(cmap=cmap_sum,subset = (brushed_df_final.columns[-2]),vmin=80,vmax=120)
|
| 862 |
.background_gradient(cmap=cmap_sum,subset = (brushed_df_final.columns[-1]),vmin=20,vmax=80)
|
| 863 |
.applymap(lambda x: f'background-color: {dict_pitch_name.get(x, "")}80', subset=['Pitch Type'])
|
|
|
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
+
brushed_df_final = (((brushed_df.group_by(['pitcher_id', 'pitch_type']).agg([
|
| 770 |
pl.col('is_pitch').drop_nans().count().alias('pitches'),
|
| 771 |
pl.col('start_speed').drop_nans().mean().round(1).alias('start_speed'),
|
| 772 |
pl.col('vb').drop_nans().mean().round(1).alias('vb'),
|
| 773 |
pl.col('ivb').drop_nans().mean().round(1).alias('ivb'),
|
| 774 |
pl.col('hb').drop_nans().mean().round(1).alias('hb'),
|
| 775 |
+
pl.col('vaa').drop_nans().mean().round(1).alias('vaa'),
|
| 776 |
pl.col('spin_rate').drop_nans().mean().alias('spin_rate'),
|
| 777 |
pl.col('release_pos_x').drop_nans().mean().round(1).alias('x0'),
|
| 778 |
pl.col('release_pos_z').drop_nans().mean().round(1).alias('z0'),
|
|
|
|
| 786 |
.alias('proportion')
|
| 787 |
)
|
| 788 |
)).sort('proportion', descending=True).
|
| 789 |
+
select(["pitch_type", "pitches", "proportion", "start_speed", "ivb", "hb",
|
| 790 |
"spin_rate", "x0", "z0",'tj_stuff_plus','pitch_grade'])
|
| 791 |
.with_columns(
|
| 792 |
+
pl.when(pl.col("pitch_type") == "Four-Seam Fastball")
|
| 793 |
.then(pl.lit("4-Seam"))
|
| 794 |
+
.otherwise(pl.col("pitch_type"))
|
| 795 |
+
.alias("pitch_type")
|
| 796 |
)
|
| 797 |
.rename({
|
| 798 |
+
'pitch_type': 'Pitch Type',
|
| 799 |
'pitches': 'Pitches',
|
| 800 |
'proportion': 'Prop',
|
| 801 |
'start_speed': 'Velo',
|
| 802 |
'ivb': 'iVB',
|
| 803 |
'hb': 'HB',
|
| 804 |
+
'vaa': 'VAA',
|
| 805 |
'spin_rate': 'Spin',
|
| 806 |
'x0': 'hRel',
|
| 807 |
'z0': 'vRel',
|
|
|
|
| 851 |
.set_properties(subset=brushed_df_final.columns, **{'height': '30px'})
|
| 852 |
.set_table_styles([{'selector': 'thead th', 'props': [('height', '30px')]}], overwrite=False)
|
| 853 |
# .set_table_styles([{'selector': 'table', 'props': [('width', '100px')]}], overwrite=False)
|
| 854 |
+
.set_table_styles([{'selector': 'thead th:nth-child(1)', 'props': [('min-width', '115px')]}], overwrite=False)
|
| 855 |
.set_table_styles([{'selector': 'thead th:nth-child(2)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 856 |
.set_table_styles([{'selector': 'thead th:nth-child(3)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 857 |
.set_table_styles([{'selector': 'thead th:nth-child(4)', 'props': [('min-width', '40px')]}], overwrite=False)
|
|
|
|
| 860 |
.set_table_styles([{'selector': 'thead th:nth-child(7)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 861 |
.set_table_styles([{'selector': 'thead th:nth-child(8)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 862 |
.set_table_styles([{'selector': 'thead th:nth-child(9)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 863 |
+
.set_table_styles([{'selector': 'thead th:nth-child(10)', 'props': [('min-width', '40px')]}], overwrite=False)
|
| 864 |
.background_gradient(cmap=cmap_sum,subset = (brushed_df_final.columns[-2]),vmin=80,vmax=120)
|
| 865 |
.background_gradient(cmap=cmap_sum,subset = (brushed_df_final.columns[-1]),vmin=20,vmax=80)
|
| 866 |
.applymap(lambda x: f'background-color: {dict_pitch_name.get(x, "")}80', subset=['Pitch Type'])
|