rairo commited on
Commit
59c2b4c
·
verified ·
1 Parent(s): dc98378

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +10 -5
main.py CHANGED
@@ -1035,23 +1035,28 @@ def get_player_playoff_stats():
1035
  logging.error(f"Error in /api/nba/player_playoff_stats: {e}")
1036
  return jsonify({'error': str(e)}), 500
1037
 
 
 
1038
  @app.route('/api/nba/team_stats', methods=['POST'])
1039
  @cross_origin()
1040
  def get_team_stats():
1041
- """Retrieves team standings for selected NBA teams and a specific season."""
 
 
1042
  try:
1043
  data = request.get_json()
1044
  selected_teams = data.get('teams')
1045
  selected_season_str = data.get('season')
1046
 
1047
  if not selected_teams or not selected_season_str:
 
1048
  return jsonify({'error': 'Teams and season are required'}), 400
1049
 
1050
  year_for_team_stats = int(selected_season_str.split('–')[1])
1051
- # Use the new BRScraper-based function for team standings
1052
  tm_df = get_team_standings_brscraper(year_for_team_stats)
1053
 
1054
  if tm_df.empty:
 
1055
  return jsonify({'error': f'No team data available for {selected_season_str}'}), 404
1056
 
1057
  stats = []
@@ -1067,17 +1072,17 @@ def get_team_stats():
1067
  teams_with_no_data.append(t)
1068
 
1069
  if not stats:
 
1070
  return jsonify({
1071
  'error': 'No data available for selected teams.',
1072
  'teams_with_no_data': teams_with_no_data
1073
  }), 404
1074
 
1075
  comp = pd.DataFrame(stats)
1076
- # Ensure numeric columns are correctly typed for JSON output
1077
- for col in ['WINS', 'LOSSES', 'WIN_LOSS_PCT', 'RANK']: # Adjust columns based on standings data
1078
  if col in comp.columns:
1079
  comp[col] = pd.to_numeric(comp[col], errors='coerce')
1080
- comp = comp.replace({np.nan: None}) # Ensure NaN are None for JSON compliance
1081
 
1082
  return jsonify({
1083
  'team_stats': comp.to_dict(orient='records'),
 
1035
  logging.error(f"Error in /api/nba/player_playoff_stats: {e}")
1036
  return jsonify({'error': str(e)}), 500
1037
 
1038
+ # In your Flask script (app.py or main.py on Hugging Face)
1039
+
1040
  @app.route('/api/nba/team_stats', methods=['POST'])
1041
  @cross_origin()
1042
  def get_team_stats():
1043
+ # --- ADD THIS LINE AT THE VERY TOP OF THE FUNCTION ---
1044
+ logging.info("DEBUG: Request successfully entered get_team_stats function!")
1045
+ # --- END ADDITION ---
1046
  try:
1047
  data = request.get_json()
1048
  selected_teams = data.get('teams')
1049
  selected_season_str = data.get('season')
1050
 
1051
  if not selected_teams or not selected_season_str:
1052
+ # This would return a 400, not a 404
1053
  return jsonify({'error': 'Teams and season are required'}), 400
1054
 
1055
  year_for_team_stats = int(selected_season_str.split('–')[1])
 
1056
  tm_df = get_team_standings_brscraper(year_for_team_stats)
1057
 
1058
  if tm_df.empty:
1059
+ # This would return a 404 with a specific message
1060
  return jsonify({'error': f'No team data available for {selected_season_str}'}), 404
1061
 
1062
  stats = []
 
1072
  teams_with_no_data.append(t)
1073
 
1074
  if not stats:
1075
+ # This would return a 404 with a specific message
1076
  return jsonify({
1077
  'error': 'No data available for selected teams.',
1078
  'teams_with_no_data': teams_with_no_data
1079
  }), 404
1080
 
1081
  comp = pd.DataFrame(stats)
1082
+ for col in ['WINS', 'LOSSES', 'WIN_LOSS_PCT', 'RANK']:
 
1083
  if col in comp.columns:
1084
  comp[col] = pd.to_numeric(comp[col], errors='coerce')
1085
+ comp = comp.replace({np.nan: None})
1086
 
1087
  return jsonify({
1088
  'team_stats': comp.to_dict(orient='records'),