Update app.py
Browse files
app.py
CHANGED
|
@@ -107,33 +107,34 @@ selected_fielder = st.selectbox('',list(fielders_reversed.keys()))
|
|
| 107 |
fielder_select = fielders_reversed[selected_fielder]
|
| 108 |
|
| 109 |
# Define the URL
|
| 110 |
-
url = f
|
| 111 |
|
| 112 |
-
# Make the GET request
|
| 113 |
-
response = requests.get(url)
|
| 114 |
|
| 115 |
-
# Check if the request was successful
|
| 116 |
-
if response.status_code == 200:
|
| 117 |
-
|
| 118 |
-
else:
|
| 119 |
-
|
| 120 |
|
| 121 |
-
# Format the string as a JSON array
|
| 122 |
-
text = response.text
|
| 123 |
-
dict_catch = text.split('rangeLine')[1].split('data')[0].split('[')[1].split(']')[0]
|
| 124 |
-
formatted_dict_catch = f'[{dict_catch}]'
|
| 125 |
|
| 126 |
-
# Convert the formatted string to a list of dictionaries
|
| 127 |
-
dict_catch_list = json.loads(formatted_dict_catch)
|
| 128 |
|
| 129 |
-
|
|
|
|
| 130 |
df_catch['hang_time'] = df_catch['hang_time'].astype(float).round(1)
|
| 131 |
df_catch['distance'] = df_catch['distance'].astype(float).round(1)
|
| 132 |
|
| 133 |
df_merge = df.merge(df_catch, on='play_id', how='right', suffixes=('', '_fielder')).reset_index(drop=True)
|
| 134 |
|
| 135 |
# Format the 'catch_rate' column as a percentage
|
| 136 |
-
df_merge['catch_rate'] = df_merge['catch_rate'].astype(float).apply(lambda x: f"{x:.0%}")
|
| 137 |
|
| 138 |
df_merge['pos'] = df_merge['pos'].astype(int)
|
| 139 |
df_merge['Position'] = df_merge['pos'].map(pos_dict)
|
|
|
|
| 107 |
fielder_select = fielders_reversed[selected_fielder]
|
| 108 |
|
| 109 |
# Define the URL
|
| 110 |
+
url = f"https://baseballsavant.mlb.com/player-services/range?playerId={player_id}&season=2024&playerType=fielder"
|
| 111 |
|
| 112 |
+
# # Make the GET request
|
| 113 |
+
# response = requests.get(url)
|
| 114 |
|
| 115 |
+
# # Check if the request was successful
|
| 116 |
+
# if response.status_code == 200:
|
| 117 |
+
# print(response.status_code)
|
| 118 |
+
# else:
|
| 119 |
+
# print(f"Failed to fetch data, status code: {response.status_code}")
|
| 120 |
|
| 121 |
+
# # Format the string as a JSON array
|
| 122 |
+
# text = response.text
|
| 123 |
+
# dict_catch = text.split('rangeLine')[1].split('data')[0].split('[')[1].split(']')[0]
|
| 124 |
+
# formatted_dict_catch = f'[{dict_catch}]'
|
| 125 |
|
| 126 |
+
# # Convert the formatted string to a list of dictionaries
|
| 127 |
+
# dict_catch_list = json.loads(formatted_dict_catch)
|
| 128 |
|
| 129 |
+
data = requests.get(url).json()
|
| 130 |
+
df_catch = pd.DataFrame(data)
|
| 131 |
df_catch['hang_time'] = df_catch['hang_time'].astype(float).round(1)
|
| 132 |
df_catch['distance'] = df_catch['distance'].astype(float).round(1)
|
| 133 |
|
| 134 |
df_merge = df.merge(df_catch, on='play_id', how='right', suffixes=('', '_fielder')).reset_index(drop=True)
|
| 135 |
|
| 136 |
# Format the 'catch_rate' column as a percentage
|
| 137 |
+
#df_merge['catch_rate'] = df_merge['catch_rate'].astype(float).apply(lambda x: f"{x:.0%}")
|
| 138 |
|
| 139 |
df_merge['pos'] = df_merge['pos'].astype(int)
|
| 140 |
df_merge['Position'] = df_merge['pos'].map(pos_dict)
|