Spaces:
Sleeping
Sleeping
Commit
·
6a02cc9
1
Parent(s):
11cdf80
Update app
Browse files- data.py +21 -0
- gradio_function.py +29 -27
data.py
CHANGED
|
@@ -41,6 +41,21 @@ pitch_df = pl.concat(pitch_df)
|
|
| 41 |
player_df = pl.read_csv('player.csv')
|
| 42 |
|
| 43 |
# translate pa data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
# pa_df['_des'] = pa_df['des'].str.strip()
|
| 45 |
# pa_df['des'] = pa_df['des'].str.strip()
|
| 46 |
# pa_df['des_more'] = pa_df['des_more'].str.strip()
|
|
@@ -84,6 +99,12 @@ pa_df = (
|
|
| 84 |
.with_columns(
|
| 85 |
pl.col('des').map_elements(translate_pa_outcome, return_dtype=str)
|
| 86 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
)
|
| 88 |
|
| 89 |
# translate pitch data
|
|
|
|
| 41 |
player_df = pl.read_csv('player.csv')
|
| 42 |
|
| 43 |
# translate pa data
|
| 44 |
+
|
| 45 |
+
def identify_bb_type(hit_type):
|
| 46 |
+
if hit_type in list(range(1, 10)) + list(range(40, 49)):
|
| 47 |
+
return 'ground_ball'
|
| 48 |
+
elif hit_type in list(range(58, 67))+list(range(201, 209)):
|
| 49 |
+
return 'line_drive'
|
| 50 |
+
elif hit_type in list(range(28, 31)) + list(range(55, 58)) + list(range(107, 110)) + list(range(247, 251)):
|
| 51 |
+
return 'fly_ball'
|
| 52 |
+
elif hit_type in list(range(49, 55)) + list(range(103, 107)) + list(range(242, 248)):
|
| 53 |
+
return 'pop_up'
|
| 54 |
+
elif hit_type in [31, 32]:
|
| 55 |
+
return None
|
| 56 |
+
else:
|
| 57 |
+
raise Exception(f'Unexpect hit_type {hit_type}')
|
| 58 |
+
|
| 59 |
# pa_df['_des'] = pa_df['des'].str.strip()
|
| 60 |
# pa_df['des'] = pa_df['des'].str.strip()
|
| 61 |
# pa_df['des_more'] = pa_df['des_more'].str.strip()
|
|
|
|
| 99 |
.with_columns(
|
| 100 |
pl.col('des').map_elements(translate_pa_outcome, return_dtype=str)
|
| 101 |
)
|
| 102 |
+
.with_columns(
|
| 103 |
+
pl.col('bb_type').alias('hit_type').str.strip_prefix('dakyu').cast(int).alias('hit_type')
|
| 104 |
+
)
|
| 105 |
+
.with_columns(
|
| 106 |
+
pl.col('hit_type').map_elements(lambda hit_type: identify_bb_type(hit_type), return_dtype=str).alias('bb_type')
|
| 107 |
+
)
|
| 108 |
)
|
| 109 |
|
| 110 |
# translate pitch data
|
gradio_function.py
CHANGED
|
@@ -203,7 +203,8 @@ def plot_velo_summary(df, league_df, player):
|
|
| 203 |
legendgroup='NPB',
|
| 204 |
legendrank=1,
|
| 205 |
# visible='legendonly',
|
| 206 |
-
showlegend=False,
|
|
|
|
| 207 |
name='NPB',
|
| 208 |
))
|
| 209 |
if count >= min_pitches:
|
|
@@ -215,7 +216,7 @@ def plot_velo_summary(df, league_df, player):
|
|
| 215 |
meanline_visible=True,
|
| 216 |
points=False,
|
| 217 |
legendgroup=pitch_name,
|
| 218 |
-
legendrank=2+(len(pitch_counts) - i),
|
| 219 |
name=pitch_name
|
| 220 |
))
|
| 221 |
else:
|
|
@@ -227,37 +228,38 @@ def plot_velo_summary(df, league_df, player):
|
|
| 227 |
hovertext=False,
|
| 228 |
mode="lines+text",
|
| 229 |
legendgroup=pitch_name,
|
| 230 |
-
legendrank=2+(len(pitch_counts) - i),
|
| 231 |
name=pitch_name,
|
| 232 |
))
|
| 233 |
|
| 234 |
-
fig.add_trace(go.Violin(
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
))
|
| 247 |
-
fig.add_trace(go.Violin(
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
))
|
| 257 |
|
| 258 |
# fig.update_xaxes(title='Velocity', range=[player_df['release_speed'].dropna().min() - 2, player_df['release_speed'].dropna().max() + 2])
|
| 259 |
fig.update_xaxes(title='Velocity', range=[player_df['release_speed'].min() - 2, player_df['release_speed'].max() + 2])
|
| 260 |
-
fig.update_yaxes(range=[0, len(pitch_counts)+1-0.25], visible=False)
|
|
|
|
| 261 |
fig.update_layout(
|
| 262 |
violingap=0,
|
| 263 |
violingroupgap=0,
|
|
|
|
| 203 |
legendgroup='NPB',
|
| 204 |
legendrank=1,
|
| 205 |
# visible='legendonly',
|
| 206 |
+
# showlegend=False,
|
| 207 |
+
showlegend=i==0,
|
| 208 |
name='NPB',
|
| 209 |
))
|
| 210 |
if count >= min_pitches:
|
|
|
|
| 216 |
meanline_visible=True,
|
| 217 |
points=False,
|
| 218 |
legendgroup=pitch_name,
|
| 219 |
+
legendrank=len(pitch_counts) - i, #2+(len(pitch_counts) - i),
|
| 220 |
name=pitch_name
|
| 221 |
))
|
| 222 |
else:
|
|
|
|
| 228 |
hovertext=False,
|
| 229 |
mode="lines+text",
|
| 230 |
legendgroup=pitch_name,
|
| 231 |
+
legendrank=len(pitch_counts) - i, #2+(len(pitch_counts) - i),
|
| 232 |
name=pitch_name,
|
| 233 |
))
|
| 234 |
|
| 235 |
+
# fig.add_trace(go.Violin(
|
| 236 |
+
# x=league_df['release_speed'],
|
| 237 |
+
# y=[player]*len(league_df),
|
| 238 |
+
# line_color='gray',
|
| 239 |
+
# side='positive',
|
| 240 |
+
# orientation='h',
|
| 241 |
+
# meanline_visible=True,
|
| 242 |
+
# points=False,
|
| 243 |
+
# legendgroup='NPB',
|
| 244 |
+
# legendrank=1,
|
| 245 |
+
# # visible='legendonly',
|
| 246 |
+
# name='NPB',
|
| 247 |
+
# ))
|
| 248 |
+
# fig.add_trace(go.Violin(
|
| 249 |
+
# x=player_df['release_speed'],
|
| 250 |
+
# y=[player]*len(player_df),
|
| 251 |
+
# side='positive',
|
| 252 |
+
# orientation='h',
|
| 253 |
+
# meanline_visible=True,
|
| 254 |
+
# points=False,
|
| 255 |
+
# legendrank=0,
|
| 256 |
+
# name=player
|
| 257 |
+
# ))
|
| 258 |
|
| 259 |
# fig.update_xaxes(title='Velocity', range=[player_df['release_speed'].dropna().min() - 2, player_df['release_speed'].dropna().max() + 2])
|
| 260 |
fig.update_xaxes(title='Velocity', range=[player_df['release_speed'].min() - 2, player_df['release_speed'].max() + 2])
|
| 261 |
+
# fig.update_yaxes(range=[0, len(pitch_counts)+1-0.25], visible=False)
|
| 262 |
+
fig.update_yaxes(range=[0, len(pitch_counts)-0.25], visible=False)
|
| 263 |
fig.update_layout(
|
| 264 |
violingap=0,
|
| 265 |
violingroupgap=0,
|