lrschuman17 commited on
Commit
c23fe35
·
verified ·
1 Parent(s): 559d270

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -19
app.py CHANGED
@@ -235,29 +235,60 @@ def main():
235
  player_name = st.sidebar.selectbox("Select Player", player_list)
236
 
237
  if player_name:
 
238
  player_row = player_data[player_data['player_name'] == player_name]
239
  team_name = player_row.iloc[0]['team_abbreviation']
240
  position = player_row.iloc[0]['position']
241
 
242
- stats_columns = ['age', 'player_height', 'player_weight']
243
- default_stats = {stat: player_row.iloc[0][stat] for stat in stats_columns}
244
-
245
- for stat in default_stats.keys():
246
- default_stats[stat] = st.sidebar.number_input(f"{stat}", value=default_stats[stat])
247
-
248
- injury_type = st.sidebar.selectbox("Select Hypothetical Injury", injury_types)
249
- default_days_injured = average_days_injured.get(injury_type, 30)
250
- days_injured = st.sidebar.slider("Estimated Days Injured", 0, 365, int(default_days_injured))
251
- injury_occurrences = st.sidebar.number_input("Injury Occurrences", min_value=0, value=1)
252
-
253
- input_data = pd.DataFrame([{
254
- "days_injured": days_injured,
255
- "injury_occurrences": injury_occurrences,
256
- "position": position_mapping.get(position, 0),
257
- "injury_type": injury_type,
258
- **default_stats
259
- }])
260
- input_data["injury_type"] = pd.factorize(input_data["injury_type"])[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
 
262
  st.divider()
263
  st.header("Player Overview")
 
235
  player_name = st.sidebar.selectbox("Select Player", player_list)
236
 
237
  if player_name:
238
+ # Retrieve player details
239
  player_row = player_data[player_data['player_name'] == player_name]
240
  team_name = player_row.iloc[0]['team_abbreviation']
241
  position = player_row.iloc[0]['position']
242
 
243
+ if not player_row.empty:
244
+ position = player_row.iloc[0]['position']
245
+ position_numeric = position_mapping.get(position, 0)
246
+
247
+ st.sidebar.write(f"**Position**: {position} (Numeric: {position_numeric})")
248
+
249
+ # Default values for features
250
+ stats_columns = ['age', 'player_height', 'player_weight']
251
+ default_stats = {
252
+ stat: player_row.iloc[0][stat] if stat in player_row.columns else 0
253
+ for stat in stats_columns
254
+ }
255
+
256
+ # Allow manual adjustment of stats
257
+ for stat in default_stats.keys():
258
+ default_stats[stat] = st.sidebar.number_input(f"{stat}", value=default_stats[stat])
259
+
260
+ # Injury details
261
+ injury_type = st.sidebar.selectbox("Select Hypothetical Injury", injury_types)
262
+ # Replace slider with default average based on injury type
263
+ default_days_injured = average_days_injured[injury_type] or 30 # Use 30 if None
264
+ days_injured = st.sidebar.slider(
265
+ "Estimated Days Injured",
266
+ 0,
267
+ 365,
268
+ int(default_days_injured),
269
+ help=f"Default days for {injury_type}: {int(default_days_injured) if default_days_injured else 'N/A'}"
270
+ )
271
+ injury_occurrences = st.sidebar.number_input("Injury Occurrences", min_value=0, value=1)
272
+
273
+ # Prepare input data
274
+ input_data = pd.DataFrame([{
275
+ "days_injured": days_injured,
276
+ "injury_occurrences": injury_occurrences,
277
+ "position": position_numeric,
278
+ "injury_type": injury_type, # Include the selected injury type
279
+ **default_stats
280
+ }])
281
+
282
+ # Encode injury type
283
+ input_data["injury_type"] = pd.factorize(input_data["injury_type"])[0]
284
+
285
+ # Load Random Forest model
286
+ try:
287
+ rf_model = load_rf_model()
288
+
289
+ # Align input data with the model's feature names
290
+ expected_features = rf_model.feature_names_in_
291
+ input_data = input_data.reindex(columns=rf_model.feature_names_in_, fill_value=0)
292
 
293
  st.divider()
294
  st.header("Player Overview")