Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -84,11 +84,20 @@ def get_box_score_data(links: list) -> dict:
|
|
84 |
|
85 |
@tool
|
86 |
def get_stats_from_boxScore_data(url: str, stat: str) -> dict:
|
87 |
-
"""A tool that fetches the player names and box score statistic for the provided box score url
|
88 |
Args:
|
89 |
-
url: A string representing the URL to the box score for a game
|
90 |
-
stat: A string representing the statistic that this function will return for each player the box score
|
|
|
|
|
91 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
try:
|
93 |
box_scores = get_box_score_data(url)
|
94 |
stats = {}
|
@@ -98,7 +107,7 @@ def get_stats_from_boxScore_data(url: str, stat: str) -> dict:
|
|
98 |
if stat_key in player:
|
99 |
if player[stat_key] is not None:
|
100 |
if player[stat_key].replace('.', '').isdigit():
|
101 |
-
stats[player[list(player.keys())[0]]]=pd.to_numeric(player[stat_key], errors='coerce')
|
102 |
return stats
|
103 |
except Exception as e:
|
104 |
return {"Error": f"Error fetching boxScore data for given statistic: {str(e)}"}
|
|
|
84 |
|
85 |
@tool
|
86 |
def get_stats_from_boxScore_data(url: str, stat: str) -> dict:
|
87 |
+
"""A tool that fetches the player names and box score statistic for the provided box score url.
|
88 |
Args:
|
89 |
+
url: A string representing the URL to the box score for a game.
|
90 |
+
stat: A string representing the statistic that this function will return for each player in the box score.
|
91 |
+
Must be one of: 'MP', 'FG', 'FGA', 'FG%', '3P', '3PA', '3P%', 'FT', 'FTA', 'FT%',
|
92 |
+
'ORB', 'DRB', 'TRB', 'AST', 'STL', 'BLK', 'TOV', 'PF', 'PTS', 'GmSc', '+/-'
|
93 |
"""
|
94 |
+
# Define the allowed stats
|
95 |
+
allowed_stats = ['MP', 'FG', 'FGA', 'FG%', '3P', '3PA', '3P%', 'FT', 'FTA', 'FT%',
|
96 |
+
'ORB', 'DRB', 'TRB', 'AST', 'STL', 'BLK', 'TOV', 'PF', 'PTS',
|
97 |
+
'GmSc', '+/-']
|
98 |
+
# Check if stat is valid
|
99 |
+
if stat not in allowed_stats:
|
100 |
+
return {"Error": f"Invalid stat '{stat}'. Allowed values are: {', '.join(allowed_stats)}"}
|
101 |
try:
|
102 |
box_scores = get_box_score_data(url)
|
103 |
stats = {}
|
|
|
107 |
if stat_key in player:
|
108 |
if player[stat_key] is not None:
|
109 |
if player[stat_key].replace('.', '').isdigit():
|
110 |
+
stats[player[list(player.keys())[0]]] = pd.to_numeric(player[stat_key], errors='coerce')
|
111 |
return stats
|
112 |
except Exception as e:
|
113 |
return {"Error": f"Error fetching boxScore data for given statistic: {str(e)}"}
|