SebastianAndreu commited on
Commit
007aa04
·
verified ·
1 Parent(s): 625be8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -17
app.py CHANGED
@@ -543,25 +543,20 @@ def create_model_input_and_predict(receiver_name, passer_name, week, season):
543
 
544
  # Use spread and total from ESPN API
545
  # ESPN spread is from HOME team perspective
 
546
  espn_spread_home = espn_info["pregame_spread"]
547
  pregame_total = espn_info["pregame_total"]
548
 
549
- # Convert spread based on receiver's team perspective
550
- # If receiver is on away team: spread = -home_spread (away team perspective)
551
- # If receiver is on home team: spread = home_spread (keep as is)
552
- if receiver_is_home:
553
- # Receiver is home, so use home team perspective
554
- pregame_spread = espn_spread_home
555
- else:
556
- # Receiver is away, so flip the spread to away team perspective
557
- pregame_spread = -espn_spread_home
558
 
559
  print(f"\n=== Spread Conversion ===")
560
- print(f"ESPN spread (home team perspective): {espn_spread_home}")
 
561
  print(f"Receiver team: {receiver_team} ({'HOME' if receiver_is_home else 'AWAY'})")
562
- print(f"Home team: {home_team}")
563
- print(f"Away team: {away_team}")
564
- print(f"Final spread for model (receiver's team perspective): {pregame_spread}")
565
 
566
  model_input = {
567
  "receiver_player_id": receiver_id,
@@ -594,6 +589,12 @@ def create_model_input_and_predict(receiver_name, passer_name, week, season):
594
  prediction_text = "⚠️ Unavailable"
595
  predicted_value = "Prediction unavailable"
596
 
 
 
 
 
 
 
597
  output = f"""
598
  🏈 **Game Information:**
599
  • Matchup: {away_team} @ {home_team} (Week {week}, {season})
@@ -609,10 +610,9 @@ def create_model_input_and_predict(receiver_name, passer_name, week, season):
609
  • Humidity: {game_data['humidity_pct']}%
610
  • Wind: {game_data['wind_mph']} mph
611
  • Conditions: {'Dome' if is_dome else 'Rain' if game_data['is_rain'] else 'Snow' if game_data['is_snow'] else 'Clear'}
612
- 💰 **Betting Lines (ESPN API):**
613
- • Spread (receiver's team perspective): {pregame_spread if pregame_spread != 0 else 'Not available'} ({receiver_team} {'favored' if pregame_spread < 0 else 'underdog'} by {abs(pregame_spread)} points)
614
- • Total: {pregame_total if pregame_total != 0 else 'Not available'}
615
- • Model Input Spread: {pregame_spread} (from {receiver_team}'s perspective)
616
  """
617
 
618
  return prediction_text, predicted_value, output, receiver_headshot, passer_headshot
 
543
 
544
  # Use spread and total from ESPN API
545
  # ESPN spread is from HOME team perspective
546
+ # MODEL ALWAYS USES AWAY TEAM PERSPECTIVE
547
  espn_spread_home = espn_info["pregame_spread"]
548
  pregame_total = espn_info["pregame_total"]
549
 
550
+ # Convert to away team perspective for the model
551
+ # If home is -7.5, away is +7.5
552
+ # If home is +3, away is -3
553
+ pregame_spread = -espn_spread_home
 
 
 
 
 
554
 
555
  print(f"\n=== Spread Conversion ===")
556
+ print(f"ESPN spread (home team {home_team} perspective): {espn_spread_home}")
557
+ print(f"Converted to away team ({away_team}) perspective: {pregame_spread}")
558
  print(f"Receiver team: {receiver_team} ({'HOME' if receiver_is_home else 'AWAY'})")
559
+ print(f"Model Input Spread: {pregame_spread} (always from {away_team}'s perspective)")
 
 
560
 
561
  model_input = {
562
  "receiver_player_id": receiver_id,
 
589
  prediction_text = "⚠️ Unavailable"
590
  predicted_value = "Prediction unavailable"
591
 
592
+ # Calculate receiver's team spread for display purposes
593
+ if receiver_is_home:
594
+ receiver_team_spread = espn_spread_home
595
+ else:
596
+ receiver_team_spread = pregame_spread
597
+
598
  output = f"""
599
  🏈 **Game Information:**
600
  • Matchup: {away_team} @ {home_team} (Week {week}, {season})
 
610
  • Humidity: {game_data['humidity_pct']}%
611
  • Wind: {game_data['wind_mph']} mph
612
  • Conditions: {'Dome' if is_dome else 'Rain' if game_data['is_rain'] else 'Snow' if game_data['is_snow'] else 'Clear'}
613
+ 💰 **Betting Lines:**
614
+ • Spread: {receiver_team} {receiver_team_spread if receiver_team_spread != 0 else 'N/A'}
615
+ • Total: {pregame_total if pregame_total != 0 else 'N/A'}
 
616
  """
617
 
618
  return prediction_text, predicted_value, output, receiver_headshot, passer_headshot