Update main.py
Browse files
main.py
CHANGED
|
@@ -573,8 +573,7 @@ def get_team_standings_brscraper(year):
|
|
| 573 |
logging.info(f"Scraping team standings for {year} (cache stale or not found).")
|
| 574 |
df = _scrape_team_standings_brscraper(year)
|
| 575 |
if not df.empty:
|
| 576 |
-
|
| 577 |
-
df_cleaned_for_firebase = clean_df_for_firebase(df.copy()) # Use a copy to avoid modifying original df if it's used later
|
| 578 |
db_ref.set({
|
| 579 |
'last_updated': datetime.utcnow().isoformat(),
|
| 580 |
'data': df_cleaned_for_firebase.to_dict(orient='records')
|
|
@@ -729,6 +728,8 @@ def get_dashboard_info_brscraper():
|
|
| 729 |
logging.info("Scraping dashboard info (cache stale or not found).")
|
| 730 |
data = _scrape_dashboard_info_brscraper()
|
| 731 |
if data:
|
|
|
|
|
|
|
| 732 |
db_ref.set({
|
| 733 |
'last_updated': datetime.utcnow().isoformat(),
|
| 734 |
'data': data
|
|
@@ -741,6 +742,13 @@ def _scrape_dashboard_info_brscraper():
|
|
| 741 |
try:
|
| 742 |
mvp_2025_df = nba.get_award_votings('mvp', 2025)
|
| 743 |
if not mvp_2025_df.empty:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 744 |
mvp_2025_df = clean_df_for_firebase(mvp_2025_df)
|
| 745 |
dashboard_data['mvp_2025_votings'] = mvp_2025_df.replace({np.nan: None}).to_dict(orient='records')
|
| 746 |
else:
|
|
@@ -749,6 +757,16 @@ def _scrape_dashboard_info_brscraper():
|
|
| 749 |
|
| 750 |
east_probs_df = nba.get_playoffs_probs('east')
|
| 751 |
if not east_probs_df.empty:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
east_probs_df = clean_df_for_firebase(east_probs_df)
|
| 753 |
dashboard_data['playoff_probs_east'] = east_probs_df.replace({np.nan: None}).to_dict(orient='records')
|
| 754 |
else:
|
|
@@ -757,6 +775,16 @@ def _scrape_dashboard_info_brscraper():
|
|
| 757 |
|
| 758 |
west_probs_df = nba.get_playoffs_probs('west')
|
| 759 |
if not west_probs_df.empty:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 760 |
west_probs_df = clean_df_for_firebase(west_probs_df)
|
| 761 |
dashboard_data['playoff_probs_west'] = west_probs_df.replace({np.nan: None}).to_dict(orient='records')
|
| 762 |
else:
|
|
|
|
| 573 |
logging.info(f"Scraping team standings for {year} (cache stale or not found).")
|
| 574 |
df = _scrape_team_standings_brscraper(year)
|
| 575 |
if not df.empty:
|
| 576 |
+
df_cleaned_for_firebase = clean_df_for_firebase(df.copy())
|
|
|
|
| 577 |
db_ref.set({
|
| 578 |
'last_updated': datetime.utcnow().isoformat(),
|
| 579 |
'data': df_cleaned_for_firebase.to_dict(orient='records')
|
|
|
|
| 728 |
logging.info("Scraping dashboard info (cache stale or not found).")
|
| 729 |
data = _scrape_dashboard_info_brscraper()
|
| 730 |
if data:
|
| 731 |
+
# Apply clean_df_for_firebase to the dataframes before saving to cache
|
| 732 |
+
# This is done inside _scrape_dashboard_info_brscraper now
|
| 733 |
db_ref.set({
|
| 734 |
'last_updated': datetime.utcnow().isoformat(),
|
| 735 |
'data': data
|
|
|
|
| 742 |
try:
|
| 743 |
mvp_2025_df = nba.get_award_votings('mvp', 2025)
|
| 744 |
if not mvp_2025_df.empty:
|
| 745 |
+
# Rename 'Share' to 'Votes' for frontend consistency
|
| 746 |
+
if 'Share' in mvp_2025_df.columns:
|
| 747 |
+
mvp_2025_df = mvp_2025_df.rename(columns={'Share': 'Votes'})
|
| 748 |
+
# Ensure 'Votes' is numeric, convert percentage strings if necessary
|
| 749 |
+
if 'Votes' in mvp_2025_df.columns:
|
| 750 |
+
mvp_2025_df['Votes'] = mvp_2025_df['Votes'].astype(str).str.replace('%', '').astype(float) * 100 # Convert share to percentage points
|
| 751 |
+
|
| 752 |
mvp_2025_df = clean_df_for_firebase(mvp_2025_df)
|
| 753 |
dashboard_data['mvp_2025_votings'] = mvp_2025_df.replace({np.nan: None}).to_dict(orient='records')
|
| 754 |
else:
|
|
|
|
| 757 |
|
| 758 |
east_probs_df = nba.get_playoffs_probs('east')
|
| 759 |
if not east_probs_df.empty:
|
| 760 |
+
# Rename the team column to 'Team' for consistency
|
| 761 |
+
if 'Eastern Conference' in east_probs_df.columns: # BRScraper might return this
|
| 762 |
+
east_probs_df = east_probs_df.rename(columns={'Eastern Conference': 'Team'})
|
| 763 |
+
elif 'Tm' in east_probs_df.columns: # Or this
|
| 764 |
+
east_probs_df = east_probs_df.rename(columns={'Tm': 'Team'})
|
| 765 |
+
|
| 766 |
+
# Clean team names (remove playoff seeds)
|
| 767 |
+
if 'Team' in east_probs_df.columns:
|
| 768 |
+
east_probs_df['Team'] = east_probs_df['Team'].astype(str).apply(clean_team_name)
|
| 769 |
+
|
| 770 |
east_probs_df = clean_df_for_firebase(east_probs_df)
|
| 771 |
dashboard_data['playoff_probs_east'] = east_probs_df.replace({np.nan: None}).to_dict(orient='records')
|
| 772 |
else:
|
|
|
|
| 775 |
|
| 776 |
west_probs_df = nba.get_playoffs_probs('west')
|
| 777 |
if not west_probs_df.empty:
|
| 778 |
+
# Rename the team column to 'Team' for consistency
|
| 779 |
+
if 'Western Conference' in west_probs_df.columns: # BRScraper might return this
|
| 780 |
+
west_probs_df = west_probs_df.rename(columns={'Western Conference': 'Team'})
|
| 781 |
+
elif 'Tm' in west_probs_df.columns: # Or this
|
| 782 |
+
west_probs_df = west_probs_df.rename(columns={'Tm': 'Team'})
|
| 783 |
+
|
| 784 |
+
# Clean team names (remove playoff seeds)
|
| 785 |
+
if 'Team' in west_probs_df.columns:
|
| 786 |
+
west_probs_df['Team'] = west_probs_df['Team'].astype(str).apply(clean_team_name)
|
| 787 |
+
|
| 788 |
west_probs_df = clean_df_for_firebase(west_probs_df)
|
| 789 |
dashboard_data['playoff_probs_west'] = west_probs_df.replace({np.nan: None}).to_dict(orient='records')
|
| 790 |
else:
|