Spaces:
Running
Running
James McCool commited on
Commit ·
fd9f490
1
Parent(s): 34e1454
Adding some prints to check for stint stat matching.
Browse files- src/streamlit_app.py +28 -2
src/streamlit_app.py
CHANGED
|
@@ -181,12 +181,28 @@ def init_baselines(data_req: str):
|
|
| 181 |
cursor = collection.find()
|
| 182 |
stint_stats = pd.DataFrame(list(cursor))
|
| 183 |
|
|
|
|
|
|
|
| 184 |
if len(stint_stats) > 0:
|
| 185 |
# Create stint_id in game_rot for merging (ensure float format to match data hook)
|
| 186 |
game_rot['stint_id'] = (game_rot['GAME_ID'].astype(str) + '_' +
|
| 187 |
game_rot['PERSON_ID'].astype(str) + '_' +
|
| 188 |
game_rot['Start'].apply(lambda x: str(float(x))))
|
| 189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
# Select columns to merge from stint_stats
|
| 191 |
stint_cols = ['stint_id', 'stint_PTS', 'stint_FGM', 'stint_FGA', 'stint_FG3M', 'stint_FG3A',
|
| 192 |
'stint_FTM', 'stint_FTA', 'stint_REB', 'stint_OREB', 'stint_DREB',
|
|
@@ -195,21 +211,31 @@ def init_baselines(data_req: str):
|
|
| 195 |
|
| 196 |
# Keep only columns that exist
|
| 197 |
available_cols = [col for col in stint_cols if col in stint_stats.columns]
|
| 198 |
-
stint_stats_subset = stint_stats[available_cols]
|
| 199 |
|
| 200 |
# Convert stint stats to numeric
|
| 201 |
numeric_cols = [col for col in available_cols if col != 'stint_id']
|
| 202 |
stint_stats_subset[numeric_cols] = stint_stats_subset[numeric_cols].apply(pd.to_numeric, errors='coerce')
|
| 203 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
# Merge stint stats with rotations
|
| 205 |
game_rot = game_rot.merge(stint_stats_subset, on='stint_id', how='left')
|
| 206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
# Fill NaN stint stats with 0
|
| 208 |
for col in numeric_cols:
|
| 209 |
if col in game_rot.columns:
|
| 210 |
game_rot[col] = game_rot[col].fillna(0)
|
| 211 |
except Exception as e:
|
| 212 |
-
print(f"
|
|
|
|
|
|
|
| 213 |
|
| 214 |
return gamelog_table, game_rot, timestamp
|
| 215 |
|
|
|
|
| 181 |
cursor = collection.find()
|
| 182 |
stint_stats = pd.DataFrame(list(cursor))
|
| 183 |
|
| 184 |
+
print(f"DEBUG: Loaded {len(stint_stats)} stint_stats records")
|
| 185 |
+
|
| 186 |
if len(stint_stats) > 0:
|
| 187 |
# Create stint_id in game_rot for merging (ensure float format to match data hook)
|
| 188 |
game_rot['stint_id'] = (game_rot['GAME_ID'].astype(str) + '_' +
|
| 189 |
game_rot['PERSON_ID'].astype(str) + '_' +
|
| 190 |
game_rot['Start'].apply(lambda x: str(float(x))))
|
| 191 |
|
| 192 |
+
# DEBUG: Show sample stint_ids from both sources
|
| 193 |
+
print(f"DEBUG: Sample game_rot stint_id: {game_rot['stint_id'].iloc[0]}")
|
| 194 |
+
print(f"DEBUG: Sample stint_stats stint_id: {stint_stats['stint_id'].iloc[0]}")
|
| 195 |
+
|
| 196 |
+
# DEBUG: Check for MPJ specifically
|
| 197 |
+
mpj_rot = game_rot[(game_rot['PERSON_ID'] == 1629008) & (game_rot['GAME_ID'] == '0022500656')]
|
| 198 |
+
mpj_stint = stint_stats[stint_stats['stint_id'] == '0022500656_1629008_0.0']
|
| 199 |
+
print(f"DEBUG: MPJ rotation records: {len(mpj_rot)}")
|
| 200 |
+
print(f"DEBUG: MPJ stint_stats records: {len(mpj_stint)}")
|
| 201 |
+
if len(mpj_rot) > 0:
|
| 202 |
+
print(f"DEBUG: MPJ rotation stint_id: '{mpj_rot.iloc[0]['stint_id']}'")
|
| 203 |
+
if len(mpj_stint) > 0:
|
| 204 |
+
print(f"DEBUG: MPJ stint_stats stint_PTS: {mpj_stint.iloc[0]['stint_PTS']}")
|
| 205 |
+
|
| 206 |
# Select columns to merge from stint_stats
|
| 207 |
stint_cols = ['stint_id', 'stint_PTS', 'stint_FGM', 'stint_FGA', 'stint_FG3M', 'stint_FG3A',
|
| 208 |
'stint_FTM', 'stint_FTA', 'stint_REB', 'stint_OREB', 'stint_DREB',
|
|
|
|
| 211 |
|
| 212 |
# Keep only columns that exist
|
| 213 |
available_cols = [col for col in stint_cols if col in stint_stats.columns]
|
| 214 |
+
stint_stats_subset = stint_stats[available_cols].copy()
|
| 215 |
|
| 216 |
# Convert stint stats to numeric
|
| 217 |
numeric_cols = [col for col in available_cols if col != 'stint_id']
|
| 218 |
stint_stats_subset[numeric_cols] = stint_stats_subset[numeric_cols].apply(pd.to_numeric, errors='coerce')
|
| 219 |
|
| 220 |
+
# DEBUG: Check matching before merge
|
| 221 |
+
matching_ids = set(game_rot['stint_id']).intersection(set(stint_stats_subset['stint_id']))
|
| 222 |
+
print(f"DEBUG: Matching stint_ids before merge: {len(matching_ids)}")
|
| 223 |
+
|
| 224 |
# Merge stint stats with rotations
|
| 225 |
game_rot = game_rot.merge(stint_stats_subset, on='stint_id', how='left')
|
| 226 |
|
| 227 |
+
# DEBUG: Check result after merge
|
| 228 |
+
non_zero_pts = (game_rot['stint_PTS'] > 0).sum() if 'stint_PTS' in game_rot.columns else 0
|
| 229 |
+
print(f"DEBUG: After merge - non-zero stint_PTS count: {non_zero_pts}")
|
| 230 |
+
|
| 231 |
# Fill NaN stint stats with 0
|
| 232 |
for col in numeric_cols:
|
| 233 |
if col in game_rot.columns:
|
| 234 |
game_rot[col] = game_rot[col].fillna(0)
|
| 235 |
except Exception as e:
|
| 236 |
+
print(f"ERROR loading stint stats: {e}")
|
| 237 |
+
import traceback
|
| 238 |
+
traceback.print_exc()
|
| 239 |
|
| 240 |
return gamelog_table, game_rot, timestamp
|
| 241 |
|