nesticot commited on
Commit
07b3375
·
verified ·
1 Parent(s): 8d95317

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -8,6 +8,18 @@ import streamlit as st
8
  import pandas as pd
9
  from st_aggrid import AgGrid, GridOptionsBuilder, GridUpdateMode
10
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  # Set Streamlit page configuration
12
  st.set_page_config(layout="wide")
13
 
@@ -39,12 +51,24 @@ Catch probability data is only available for outfielders.
39
 
40
  #### What is Catch Probability?
41
  *From MLB:*
42
-
43
  **Catch Probability** expresses the likelihood for a ball to be caught by an outfielder based on opportunity time,
44
  distance needed, and direction. “Opportunity time” starts when the ball is released by the pitcher,
45
  and “distance needed” is the shortest distance needed to make the catch.
46
  Learn more about how direction is accounted for here. [Read more about the details of how Catch Probability works here](https://www.mlb.com/news/statcast-introduces-catch-probability-for-2017-c217802340).
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  """
49
 
50
  # Display the markdown text in Streamlit
@@ -92,15 +116,29 @@ df_catch['distance'] = df_catch['distance'].astype(float).round(1)
92
  df_merge = df.merge(df_catch, on='play_id', how='right', suffixes=('', '_fielder')).reset_index(drop=True)
93
 
94
  # Format the 'catch_rate' column as a percentage
95
- df_merge['catch_rate'] = df_merge['catch_rate'].astype(float).apply(lambda x: f"{x:.2%}")
 
 
 
 
 
 
 
 
 
 
96
 
97
- column_names = ['batter_name', 'pitcher_name', 'name_display_first_last', 'event', 'out', 'wall', 'back', 'stars', 'distance', 'hang_time', 'catch_rate']
98
 
99
  # Use a container to control the width of the AgGrid display
100
  with st.container():
101
  st.write("### Fielder Data")
102
  # Configure the AgGrid options
103
  gb = GridOptionsBuilder.from_dataframe(df_merge[column_names])
 
 
 
 
 
104
  gb.configure_selection('single', use_checkbox=True)
105
  grid_options = gb.build()
106
 
 
8
  import pandas as pd
9
  from st_aggrid import AgGrid, GridOptionsBuilder, GridUpdateMode
10
 
11
+
12
+ pos_dict = {1 :'P',
13
+ 2 :'C',
14
+ 3 :'1B',
15
+ 4 :'2B',
16
+ 5 :'3B',
17
+ 6 :'SS',
18
+ 7 :'LF',
19
+ 8 :'CF',
20
+ 9 :'RF',
21
+ 10 :'DH'}
22
+
23
  # Set Streamlit page configuration
24
  st.set_page_config(layout="wide")
25
 
 
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. [Read more about the details of how Catch Probability works here](https://www.mlb.com/news/statcast-introduces-catch-probability-for-2017-c217802340).
58
 
59
+ *Columns:*
60
+ - **Batter Name**: Name of the batter
61
+ - **Pitcher Name**: Name of the pitcher
62
+ - **Fielder Name**: Name of the fielder
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
72
  """
73
 
74
  # Display the markdown text in Streamlit
 
116
  df_merge = df.merge(df_catch, on='play_id', how='right', suffixes=('', '_fielder')).reset_index(drop=True)
117
 
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']
125
+
126
+ column_names_display = ['Game Date','Batter Name', 'Pitcher Name', 'Fielder Name', 'Position','Event', 'Out', 'Wall', 'Back', 'Stars', 'Distance', 'Hang Time', 'Catch Rate']
127
+
128
+
129
+
130
 
 
131
 
132
  # Use a container to control the width of the AgGrid display
133
  with st.container():
134
  st.write("### Fielder Data")
135
  # Configure the AgGrid options
136
  gb = GridOptionsBuilder.from_dataframe(df_merge[column_names])
137
+ # Set display names for columns
138
+ for col, display_name in zip(column_names, column_names_display):
139
+ gb.configure_column(col, headerName=display_name)
140
+
141
+
142
  gb.configure_selection('single', use_checkbox=True)
143
  grid_options = gb.build()
144