James McCool commited on
Commit
dc792cb
·
1 Parent(s): 6fa2bde

Adding some active debugging rather than passive.

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +6 -24
src/streamlit_app.py CHANGED
@@ -176,13 +176,13 @@ def init_baselines(data_req: str):
176
  game_rot['GAME_DATE'] = pd.to_datetime(game_rot['GAME_DATE']).dt.date
177
 
178
  # Query play-by-play stint stats
179
- print("DEBUG: ===== ATTEMPTING TO LOAD STINT STATS =====")
180
  try:
181
  collection = db["playbyplay_stints"]
182
  cursor = collection.find()
183
  stint_stats = pd.DataFrame(list(cursor))
184
 
185
- print(f"DEBUG: Loaded {len(stint_stats)} stint_stats records")
186
 
187
  if len(stint_stats) > 0:
188
  # Create stint_id in game_rot for merging (ensure float format to match data hook)
@@ -190,20 +190,6 @@ def init_baselines(data_req: str):
190
  game_rot['PERSON_ID'].astype(str) + '_' +
191
  game_rot['Start'].apply(lambda x: str(float(x))))
192
 
193
- # DEBUG: Show sample stint_ids from both sources
194
- print(f"DEBUG: Sample game_rot stint_id: {game_rot['stint_id'].iloc[0]}")
195
- print(f"DEBUG: Sample stint_stats stint_id: {stint_stats['stint_id'].iloc[0]}")
196
-
197
- # DEBUG: Check for MPJ specifically
198
- mpj_rot = game_rot[(game_rot['PERSON_ID'] == 1629008) & (game_rot['GAME_ID'] == '0022500656')]
199
- mpj_stint = stint_stats[stint_stats['stint_id'] == '0022500656_1629008_0.0']
200
- print(f"DEBUG: MPJ rotation records: {len(mpj_rot)}")
201
- print(f"DEBUG: MPJ stint_stats records: {len(mpj_stint)}")
202
- if len(mpj_rot) > 0:
203
- print(f"DEBUG: MPJ rotation stint_id: '{mpj_rot.iloc[0]['stint_id']}'")
204
- if len(mpj_stint) > 0:
205
- print(f"DEBUG: MPJ stint_stats stint_PTS: {mpj_stint.iloc[0]['stint_PTS']}")
206
-
207
  # Select columns to merge from stint_stats
208
  stint_cols = ['stint_id', 'stint_PTS', 'stint_FGM', 'stint_FGA', 'stint_FG3M', 'stint_FG3A',
209
  'stint_FTM', 'stint_FTA', 'stint_REB', 'stint_OREB', 'stint_DREB',
@@ -220,27 +206,23 @@ def init_baselines(data_req: str):
220
 
221
  # DEBUG: Check matching before merge
222
  matching_ids = set(game_rot['stint_id']).intersection(set(stint_stats_subset['stint_id']))
223
- print(f"DEBUG: Matching stint_ids before merge: {len(matching_ids)}")
224
 
225
  # Merge stint stats with rotations
226
  game_rot = game_rot.merge(stint_stats_subset, on='stint_id', how='left')
227
 
228
  # DEBUG: Check result after merge
229
  non_zero_pts = (game_rot['stint_PTS'] > 0).sum() if 'stint_PTS' in game_rot.columns else 0
230
- print(f"DEBUG: After merge - non-zero stint_PTS count: {non_zero_pts}")
231
 
232
  # Fill NaN stint stats with 0
233
  for col in numeric_cols:
234
  if col in game_rot.columns:
235
  game_rot[col] = game_rot[col].fillna(0)
236
  except Exception as e:
237
- print(f"DEBUG: ===== EXCEPTION IN STINT STATS =====")
238
- print(f"ERROR loading stint stats: {e}")
239
- import traceback
240
- traceback.print_exc()
241
- print(f"DEBUG: ===== END EXCEPTION =====")
242
 
243
- print(f"DEBUG: ===== STINT STATS SECTION COMPLETE =====")
244
 
245
  return gamelog_table, game_rot, timestamp
246
 
 
176
  game_rot['GAME_DATE'] = pd.to_datetime(game_rot['GAME_DATE']).dt.date
177
 
178
  # Query play-by-play stint stats
179
+ st.toast("DEBUG: Attempting to load stint stats...")
180
  try:
181
  collection = db["playbyplay_stints"]
182
  cursor = collection.find()
183
  stint_stats = pd.DataFrame(list(cursor))
184
 
185
+ st.toast(f"DEBUG: Loaded {len(stint_stats)} stint_stats records")
186
 
187
  if len(stint_stats) > 0:
188
  # Create stint_id in game_rot for merging (ensure float format to match data hook)
 
190
  game_rot['PERSON_ID'].astype(str) + '_' +
191
  game_rot['Start'].apply(lambda x: str(float(x))))
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  # Select columns to merge from stint_stats
194
  stint_cols = ['stint_id', 'stint_PTS', 'stint_FGM', 'stint_FGA', 'stint_FG3M', 'stint_FG3A',
195
  'stint_FTM', 'stint_FTA', 'stint_REB', 'stint_OREB', 'stint_DREB',
 
206
 
207
  # DEBUG: Check matching before merge
208
  matching_ids = set(game_rot['stint_id']).intersection(set(stint_stats_subset['stint_id']))
209
+ st.toast(f"DEBUG: {len(matching_ids)} matching stint_ids")
210
 
211
  # Merge stint stats with rotations
212
  game_rot = game_rot.merge(stint_stats_subset, on='stint_id', how='left')
213
 
214
  # DEBUG: Check result after merge
215
  non_zero_pts = (game_rot['stint_PTS'] > 0).sum() if 'stint_PTS' in game_rot.columns else 0
216
+ st.toast(f"DEBUG: {non_zero_pts} non-zero stint_PTS after merge")
217
 
218
  # Fill NaN stint stats with 0
219
  for col in numeric_cols:
220
  if col in game_rot.columns:
221
  game_rot[col] = game_rot[col].fillna(0)
222
  except Exception as e:
223
+ st.error(f"ERROR loading stint stats: {e}")
 
 
 
 
224
 
225
+ st.toast("DEBUG: Stint stats section complete")
226
 
227
  return gamelog_table, game_rot, timestamp
228