James McCool commited on
Commit
415709d
·
1 Parent(s): 6bf2ff4

Refactor NHL lineup generation in streamlit_app.py by removing redundant variable initializations and updating player name mappings. Adjust path handling in nhl_functions.py to ensure correct binary execution from project root.

Browse files
src/sports/nhl_functions.py CHANGED
@@ -96,12 +96,15 @@ def run_go_classic_lineup_generator(site="DK", sport="NHL"):
96
  start_time = time.time()
97
 
98
  # Determine the path to the Go binary (from /app/func directory)
99
- app_dir = os.path.dirname(os.path.abspath(__file__)) # Now at /app/func
 
 
 
100
 
101
  if site == "DK":
102
- go_binary = os.path.join(app_dir, "dk_nhl_go", "NHL_seed_frames")
103
  else:
104
- go_binary = os.path.join(app_dir, "fd_nhl_go", "NHL_seed_frames")
105
 
106
  st.write(f"Looking for binary at: {go_binary}")
107
 
@@ -111,7 +114,7 @@ def run_go_classic_lineup_generator(site="DK", sport="NHL"):
111
  capture_output=True,
112
  text=True,
113
  check=True,
114
- cwd=app_dir # Run from /app directory
115
  )
116
 
117
  end_time = time.time()
@@ -135,7 +138,7 @@ def run_go_classic_lineup_generator(site="DK", sport="NHL"):
135
  st.write(f"Error: Go binary not found at {go_binary}")
136
  st.write(f"FileNotFoundError: {e}")
137
  st.write(f"Current working directory: {os.getcwd()}")
138
- st.write(f"App directory: {app_dir}")
139
  return False
140
  except Exception as e:
141
  st.write(f"Unexpected error: {e}")
 
96
  start_time = time.time()
97
 
98
  # Determine the path to the Go binary (from /app/func directory)
99
+ # __file__ is at src/sports/nhl_functions.py, so we need to go up to project root
100
+ current_dir = os.path.dirname(os.path.abspath(__file__)) # src/sports/
101
+ project_root = os.path.dirname(os.path.dirname(current_dir)) # Go up to project root
102
+ func_dir = os.path.join(project_root, "func")
103
 
104
  if site == "DK":
105
+ go_binary = os.path.join(func_dir, "dk_nhl_go", "NHL_seed_frames")
106
  else:
107
+ go_binary = os.path.join(func_dir, "fd_nhl_go", "NHL_seed_frames")
108
 
109
  st.write(f"Looking for binary at: {go_binary}")
110
 
 
114
  capture_output=True,
115
  text=True,
116
  check=True,
117
+ cwd=project_root # Run from project root
118
  )
119
 
120
  end_time = time.time()
 
138
  st.write(f"Error: Go binary not found at {go_binary}")
139
  st.write(f"FileNotFoundError: {e}")
140
  st.write(f"Current working directory: {os.getcwd()}")
141
+ st.write(f"App directory: {func_dir}")
142
  return False
143
  except Exception as e:
144
  st.write(f"Unexpected error: {e}")
src/streamlit_app.py CHANGED
@@ -67,27 +67,6 @@ if st.button(f"{sport_icons[selected_sport]} Generate {selected_sport} Lineups",
67
 
68
  # Route to sport-specific pipeline
69
  if selected_sport == "NHL":
70
- nan_value = float("NaN")
71
- sim_teams = []
72
- cut_slate = 0
73
- total_sims = 1000
74
- model_version = 1
75
-
76
- sh = gc.open_by_url(NHL_Master_hold)
77
- worksheet = sh.worksheet('Slate_Info')
78
- slate_info = DataFrame(worksheet.get_all_records())
79
- slate_info = slate_info.replace('', np_nan)
80
- slate_options = ['Main Slate', 'Secondary Slate', 'Late Slate']
81
-
82
- dk_player_hold = DataFrame(columns=['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'Small Field Own%', 'Large Field Own%', 'Cash Own%', 'CPT_Own', 'Site', 'Type', 'Slate', 'player_id'])
83
- dk_stacks_hold = DataFrame(columns=['Player', 'SK1', 'SK2', 'SK3', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '50+%', '2x%', '3x%', '4x%', 'Own', 'Site', 'Type', 'Slate'])
84
- dk_pp_stacks_hold = DataFrame(columns=['Player', 'SK1', 'SK2', 'SK3', 'SK4', 'SK5', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '75+%', '2x%', '3x%', '4x%', 'Own', 'Site', 'Type', 'Slate'])
85
- fd_player_hold = DataFrame(columns=['Player', 'Position', 'Team', 'Opp', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '20+%', '2x%', '3x%', '4x%', 'Own', 'Small Field Own%', 'Large Field Own%', 'Cash Own%', 'CPT_Own', 'Site', 'Type', 'Slate', 'player_id'])
86
- fd_stacks_hold = DataFrame(columns=['Player', 'SK1', 'SK2', 'SK3', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '50+%', '2x%', '3x%', '4x%', 'Own', 'Site', 'Type', 'Slate'])
87
- fd_pp_stacks_hold = DataFrame(columns=['Player', 'SK1', 'SK2', 'SK3', 'SK4', 'SK5', 'Salary', 'Floor', 'Median', 'Ceiling', 'Top_finish', 'Top_5_finish', 'Top_10_finish', '75+%', '2x%', '3x%', '4x%', 'Own', 'Site', 'Type', 'Slate'])
88
-
89
- wrong_names = ['Arseniy Gritsyuk', 'Benjamin Kindel', 'Christopher Tanev', 'Fredrick Gaudreau', 'Jack Hughes', 'Joshua Mahura', 'Maxim Shabanov', 'Mikey Eyssimont', 'Nate Bastian', 'Zachary Aston-Reese', 'Zachary Bolduc', 'Jacob Middleton', 'Mitchell Marner', 'Maxwell Crozier']
90
- right_names = ['Arseny Gritsyuk', 'Ben Kindel', 'Chris Tanev', 'Freddy Gaudreau', 'Jack Hughes', 'Josh Mahura', 'Max Shabanov', 'Michael Eyssimont', 'Nathan Bastian', 'Zach Aston-Reese', 'Zack Bolduc', 'Jake Middleton', 'Mitch Marner', 'Max Crozier']
91
 
92
  st.write("Starting prop betting table generation...")
93
  build_prop_betting_table(nhl_db)
 
67
 
68
  # Route to sport-specific pipeline
69
  if selected_sport == "NHL":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  st.write("Starting prop betting table generation...")
72
  build_prop_betting_table(nhl_db)