Update app.py
Browse files
app.py
CHANGED
|
@@ -43,7 +43,7 @@ st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
|
| 43 |
markdown_text = """
|
| 44 |
## Catch Probability Lookup Tool
|
| 45 |
|
| 46 |
-
This Streamlit app retrieves catch probability data for a selected fielder from Baseball Savant.
|
| 47 |
The app displays the fielder's data in a table and allows the user to select a
|
| 48 |
row to view the corresponding catch video.
|
| 49 |
|
|
@@ -51,10 +51,12 @@ Catch probability data is only available for outfielders.
|
|
| 51 |
|
| 52 |
#### What is Catch Probability?
|
| 53 |
*From MLB:*
|
|
|
|
| 54 |
**Catch Probability** expresses the likelihood for a ball to be caught by an outfielder based on opportunity time,
|
| 55 |
distance needed, and direction. “Opportunity time” starts when the ball is released by the pitcher,
|
| 56 |
and “distance needed” is the shortest distance needed to make the catch.
|
| 57 |
-
Learn more about how direction is accounted for here
|
|
|
|
| 58 |
|
| 59 |
*Columns:*
|
| 60 |
- **Batter Name**: Name of the batter
|
|
@@ -63,9 +65,9 @@ Learn more about how direction is accounted for here. [Read more about the detai
|
|
| 63 |
- **Position**: Position of the fielder
|
| 64 |
- **Event**: Type of play
|
| 65 |
- **Out**: Was the ball caught?
|
| 66 |
-
- **Wall**: Did the fielder catch the ball at the wall?
|
| 67 |
-
- **Back**: Did the fielder catch the ball while moving back?
|
| 68 |
-
- **Stars**: Number of stars assigned to the play (1-5)
|
| 69 |
- **Distance**: Distance required to make the catch in feet
|
| 70 |
- **Hang Time**: Hang time of the ball in seconds
|
| 71 |
- **Catch Rate**: Probability of the catch being made
|
|
@@ -84,7 +86,7 @@ fielders = df.drop_duplicates(['batter_id']).sort_values(['batter_name']).set_in
|
|
| 84 |
fielders_reversed = {v: k for k, v in fielders.items()}
|
| 85 |
|
| 86 |
# Create a selectbox for selecting a key from the dictionary
|
| 87 |
-
selected_fielder = st.selectbox("Select Fielder:", list(fielders_reversed.keys()))
|
| 88 |
|
| 89 |
# Retrieve the corresponding pitcher ID
|
| 90 |
fielder_select = fielders_reversed[selected_fielder]
|
|
@@ -118,7 +120,7 @@ df_merge = df.merge(df_catch, on='play_id', how='right', suffixes=('', '_fielder
|
|
| 118 |
# Format the 'catch_rate' column as a percentage
|
| 119 |
df_merge['catch_rate'] = df_merge['catch_rate'].astype(float).apply(lambda x: f"{x:.0%}")
|
| 120 |
|
| 121 |
-
|
| 122 |
df_merge['Position'] = df_merge['pos'].map(pos_dict)
|
| 123 |
|
| 124 |
column_names = ['game_date','batter_name', 'pitcher_name', 'name_display_first_last', 'Position','event', 'out', 'wall', 'back', 'stars', 'distance', 'hang_time', 'catch_rate']
|
|
|
|
| 43 |
markdown_text = """
|
| 44 |
## Catch Probability Lookup Tool
|
| 45 |
|
| 46 |
+
This Streamlit app retrieves catch probability data for a selected fielder from [Baseball Savant](https://baseballsavant.mlb.com/leaderboard/catch_probability).
|
| 47 |
The app displays the fielder's data in a table and allows the user to select a
|
| 48 |
row to view the corresponding catch video.
|
| 49 |
|
|
|
|
| 51 |
|
| 52 |
#### What is Catch Probability?
|
| 53 |
*From MLB:*
|
| 54 |
+
|
| 55 |
**Catch Probability** expresses the likelihood for a ball to be caught by an outfielder based on opportunity time,
|
| 56 |
distance needed, and direction. “Opportunity time” starts when the ball is released by the pitcher,
|
| 57 |
and “distance needed” is the shortest distance needed to make the catch.
|
| 58 |
+
[Learn more about how direction is accounted for here](https://www.mlb.com/news/catch-probability-updated-to-include-direction-c232532408).
|
| 59 |
+
[Read more about the details of how Catch Probability works here](https://www.mlb.com/news/statcast-introduces-catch-probability-for-2017-c217802340).
|
| 60 |
|
| 61 |
*Columns:*
|
| 62 |
- **Batter Name**: Name of the batter
|
|
|
|
| 65 |
- **Position**: Position of the fielder
|
| 66 |
- **Event**: Type of play
|
| 67 |
- **Out**: Was the ball caught?
|
| 68 |
+
- **Wall**: [Did the fielder catch the ball at the wall?](https://www.mlb.com/news/catch-probability-updated-to-account-for-walls-c269814542)
|
| 69 |
+
- **Back**: [Did the fielder catch the ball while moving back?](https://www.mlb.com/news/catch-probability-updated-to-include-direction-c232532408)
|
| 70 |
+
- **Stars**: [Number of stars assigned to the play (1-5)](https://baseballsavant.mlb.com/leaderboard/catch_probability)
|
| 71 |
- **Distance**: Distance required to make the catch in feet
|
| 72 |
- **Hang Time**: Hang time of the ball in seconds
|
| 73 |
- **Catch Rate**: Probability of the catch being made
|
|
|
|
| 86 |
fielders_reversed = {v: k for k, v in fielders.items()}
|
| 87 |
|
| 88 |
# Create a selectbox for selecting a key from the dictionary
|
| 89 |
+
selected_fielder = st.selectbox("### Select Fielder:", list(fielders_reversed.keys()))
|
| 90 |
|
| 91 |
# Retrieve the corresponding pitcher ID
|
| 92 |
fielder_select = fielders_reversed[selected_fielder]
|
|
|
|
| 120 |
# Format the 'catch_rate' column as a percentage
|
| 121 |
df_merge['catch_rate'] = df_merge['catch_rate'].astype(float).apply(lambda x: f"{x:.0%}")
|
| 122 |
|
| 123 |
+
df_merge['pos'] = df_merge['pos'].astype(int)
|
| 124 |
df_merge['Position'] = df_merge['pos'].map(pos_dict)
|
| 125 |
|
| 126 |
column_names = ['game_date','batter_name', 'pitcher_name', 'name_display_first_last', 'Position','event', 'out', 'wall', 'back', 'stars', 'distance', 'hang_time', 'catch_rate']
|