Spaces:
Build error
Build error
Commit
·
13a3a28
1
Parent(s):
aaf4937
Update app
Browse files- demo.py +6 -7
- gradio_function.py +11 -9
demo.py
CHANGED
|
@@ -18,12 +18,12 @@ css = '''
|
|
| 18 |
.pitch-loc {height: 256px}
|
| 19 |
.pitch-loc .js-plotly-plot {height: 100%}
|
| 20 |
|
| 21 |
-
.pitch-velo-summary {height:
|
| 22 |
.pitch-velo-summary .js-plotly-plot {height: 100%}
|
| 23 |
'''
|
| 24 |
-
#
|
| 25 |
-
#
|
| 26 |
-
#
|
| 27 |
|
| 28 |
with gr.Blocks(css=css) as demo:
|
| 29 |
gr.Markdown('''
|
|
@@ -72,11 +72,11 @@ with gr.Blocks(css=css) as demo:
|
|
| 72 |
with pitch_group:
|
| 73 |
pitch_names.append(gr.Markdown(f'### Pitch {col+1}', visible=visible))
|
| 74 |
pitch_infos.append(gr.DataFrame(pd.DataFrame([{'Whiff%': None, 'CSW%': None}]), interactive=False, visible=visible))
|
| 75 |
-
pitch_velos.append(gr.Plot(
|
| 76 |
pitch_maps.append(gr.Plot(label='Pitch location', elem_classes='pitch-loc', visible=visible))
|
| 77 |
|
| 78 |
gr.Markdown('## Pitch Velocity')
|
| 79 |
-
pitch_velo_summary = gr.Plot(
|
| 80 |
|
| 81 |
gr.Markdown('## Bugs and other notes')
|
| 82 |
with gr.Accordion('Click to open', open=False):
|
|
@@ -84,7 +84,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 84 |
- Whiff% and CSW% has not been verified
|
| 85 |
- No padding in pie charts leads to hovertext getting cut off near the bottom for some players
|
| 86 |
- Y axis ticks messy when no velocity distribution is plotted
|
| 87 |
-
- No padding in pitch velo chart leads to top row being hard to read
|
| 88 |
'''
|
| 89 |
)
|
| 90 |
|
|
|
|
| 18 |
.pitch-loc {height: 256px}
|
| 19 |
.pitch-loc .js-plotly-plot {height: 100%}
|
| 20 |
|
| 21 |
+
.pitch-velo-summary {height: 384px}
|
| 22 |
.pitch-velo-summary .js-plotly-plot {height: 100%}
|
| 23 |
'''
|
| 24 |
+
# display: flex;
|
| 25 |
+
# align-items: center;
|
| 26 |
+
# justify-content: center;
|
| 27 |
|
| 28 |
with gr.Blocks(css=css) as demo:
|
| 29 |
gr.Markdown('''
|
|
|
|
| 72 |
with pitch_group:
|
| 73 |
pitch_names.append(gr.Markdown(f'### Pitch {col+1}', visible=visible))
|
| 74 |
pitch_infos.append(gr.DataFrame(pd.DataFrame([{'Whiff%': None, 'CSW%': None}]), interactive=False, visible=visible))
|
| 75 |
+
pitch_velos.append(gr.Plot(show_label=False, elem_classes='pitch-velo', visible=visible))
|
| 76 |
pitch_maps.append(gr.Plot(label='Pitch location', elem_classes='pitch-loc', visible=visible))
|
| 77 |
|
| 78 |
gr.Markdown('## Pitch Velocity')
|
| 79 |
+
pitch_velo_summary = gr.Plot(show_label=False, elem_classes='pitch-velo-summary')
|
| 80 |
|
| 81 |
gr.Markdown('## Bugs and other notes')
|
| 82 |
with gr.Accordion('Click to open', open=False):
|
|
|
|
| 84 |
- Whiff% and CSW% has not been verified
|
| 85 |
- No padding in pie charts leads to hovertext getting cut off near the bottom for some players
|
| 86 |
- Y axis ticks messy when no velocity distribution is plotted
|
|
|
|
| 87 |
'''
|
| 88 |
)
|
| 89 |
|
gradio_function.py
CHANGED
|
@@ -229,7 +229,7 @@ def plot_empty_pitch_velo():
|
|
| 229 |
x=(170+125)/2,
|
| 230 |
y=0.3/2,
|
| 231 |
text='No visualization<br>as less than 10 pitches thrown',
|
| 232 |
-
showarrow=False
|
| 233 |
)
|
| 234 |
fig.update_layout(
|
| 235 |
xaxis=dict(
|
|
@@ -242,8 +242,10 @@ def plot_empty_pitch_velo():
|
|
| 242 |
range=[0, 0.3],
|
| 243 |
scaleanchor='x',
|
| 244 |
scaleratio=1,
|
| 245 |
-
tickvals=np.linspace(0, 0.3, 3),
|
| 246 |
-
ticktext=np.linspace(0, 0.3, 3),
|
|
|
|
|
|
|
| 247 |
),
|
| 248 |
autosize=True,
|
| 249 |
# width=512,
|
|
@@ -255,7 +257,7 @@ def plot_empty_pitch_velo():
|
|
| 255 |
|
| 256 |
def plot_all_pitch_velo(player=None, player_df=None, pitch_counts=None, min_pitches=10):
|
| 257 |
# assert not ((player is None and player_df is None) or (player is not None and player_df is not None)), 'exactly one of `player` or `player_df` must be specified'
|
| 258 |
-
|
| 259 |
if player_df is None and player is not None:
|
| 260 |
assert pitch_counts is None, '`pitch_counts` must be `None` if `player_df` is None'
|
| 261 |
player_df = df.sort_values('name').set_index('name').loc[player].sort_values('pitch_name').set_index('pitch_name')
|
|
@@ -264,7 +266,7 @@ def plot_all_pitch_velo(player=None, player_df=None, pitch_counts=None, min_pitc
|
|
| 264 |
league_df = df.set_index('pitch_name')
|
| 265 |
|
| 266 |
fig = go.Figure()
|
| 267 |
-
|
| 268 |
velo_center = (player_df['release_speed'].min() + player_df['release_speed'].max()) / 2
|
| 269 |
for i, (pitch_name, count) in enumerate(pitch_counts.items()):
|
| 270 |
velos = player_df.loc[pitch_name, 'release_speed']
|
|
@@ -292,7 +294,7 @@ def plot_all_pitch_velo(player=None, player_df=None, pitch_counts=None, min_pitc
|
|
| 292 |
meanline_visible=True,
|
| 293 |
points=False,
|
| 294 |
legendgroup=pitch_name,
|
| 295 |
-
legendrank=2+i,
|
| 296 |
name=pitch_name
|
| 297 |
))
|
| 298 |
else:
|
|
@@ -304,7 +306,7 @@ def plot_all_pitch_velo(player=None, player_df=None, pitch_counts=None, min_pitc
|
|
| 304 |
hovertext=False,
|
| 305 |
mode="lines+text",
|
| 306 |
legendgroup=pitch_name,
|
| 307 |
-
legendrank=2+i,
|
| 308 |
name=pitch_name,
|
| 309 |
))
|
| 310 |
|
|
@@ -333,7 +335,7 @@ def plot_all_pitch_velo(player=None, player_df=None, pitch_counts=None, min_pitc
|
|
| 333 |
))
|
| 334 |
|
| 335 |
fig.update_xaxes(title='Velocity')
|
| 336 |
-
|
| 337 |
return fig
|
| 338 |
|
| 339 |
|
|
@@ -383,6 +385,6 @@ def get_data(player):
|
|
| 383 |
pitch_velos.append(gr.update(value=None, visible=False))
|
| 384 |
pitch_maps.append(gr.update(value=None, visible=False))
|
| 385 |
|
| 386 |
-
pitch_velo_summary = plot_all_pitch_velo(player=player, player_df=_df_by_pitch_name, pitch_counts=pitch_counts)
|
| 387 |
|
| 388 |
return player_name, usage_fig, *pitch_groups, *pitch_names, *pitch_infos, *pitch_velos, *pitch_maps, pitch_velo_summary
|
|
|
|
| 229 |
x=(170+125)/2,
|
| 230 |
y=0.3/2,
|
| 231 |
text='No visualization<br>as less than 10 pitches thrown',
|
| 232 |
+
showarrow=False,
|
| 233 |
)
|
| 234 |
fig.update_layout(
|
| 235 |
xaxis=dict(
|
|
|
|
| 242 |
range=[0, 0.3],
|
| 243 |
scaleanchor='x',
|
| 244 |
scaleratio=1,
|
| 245 |
+
# tickvals=np.linspace(0, 0.3, 3),
|
| 246 |
+
# ticktext=np.linspace(0, 0.3, 3),
|
| 247 |
+
tickvals=[0.15],
|
| 248 |
+
ticktext=[0.15]
|
| 249 |
),
|
| 250 |
autosize=True,
|
| 251 |
# width=512,
|
|
|
|
| 257 |
|
| 258 |
def plot_all_pitch_velo(player=None, player_df=None, pitch_counts=None, min_pitches=10):
|
| 259 |
# assert not ((player is None and player_df is None) or (player is not None and player_df is not None)), 'exactly one of `player` or `player_df` must be specified'
|
| 260 |
+
|
| 261 |
if player_df is None and player is not None:
|
| 262 |
assert pitch_counts is None, '`pitch_counts` must be `None` if `player_df` is None'
|
| 263 |
player_df = df.sort_values('name').set_index('name').loc[player].sort_values('pitch_name').set_index('pitch_name')
|
|
|
|
| 266 |
league_df = df.set_index('pitch_name')
|
| 267 |
|
| 268 |
fig = go.Figure()
|
| 269 |
+
|
| 270 |
velo_center = (player_df['release_speed'].min() + player_df['release_speed'].max()) / 2
|
| 271 |
for i, (pitch_name, count) in enumerate(pitch_counts.items()):
|
| 272 |
velos = player_df.loc[pitch_name, 'release_speed']
|
|
|
|
| 294 |
meanline_visible=True,
|
| 295 |
points=False,
|
| 296 |
legendgroup=pitch_name,
|
| 297 |
+
legendrank=2+(len(pitch_counts) - i),
|
| 298 |
name=pitch_name
|
| 299 |
))
|
| 300 |
else:
|
|
|
|
| 306 |
hovertext=False,
|
| 307 |
mode="lines+text",
|
| 308 |
legendgroup=pitch_name,
|
| 309 |
+
legendrank=2+(len(pitch_counts) - i),
|
| 310 |
name=pitch_name,
|
| 311 |
))
|
| 312 |
|
|
|
|
| 335 |
))
|
| 336 |
|
| 337 |
fig.update_xaxes(title='Velocity')
|
| 338 |
+
|
| 339 |
return fig
|
| 340 |
|
| 341 |
|
|
|
|
| 385 |
pitch_velos.append(gr.update(value=None, visible=False))
|
| 386 |
pitch_maps.append(gr.update(value=None, visible=False))
|
| 387 |
|
| 388 |
+
pitch_velo_summary = plot_all_pitch_velo(player=player, player_df=_df_by_pitch_name, pitch_counts=pitch_counts.sort_values(ascending=True))
|
| 389 |
|
| 390 |
return player_name, usage_fig, *pitch_groups, *pitch_names, *pitch_infos, *pitch_velos, *pitch_maps, pitch_velo_summary
|