James McCool commited on
Commit
d515342
·
1 Parent(s): a88a14d

Refactor Go binary execution in lineup generator to dynamically determine binary path and improve error handling.

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +24 -17
src/streamlit_app.py CHANGED
@@ -147,23 +147,24 @@ def run_go_classic_lineup_generator(site="DK", sport="NHL"):
147
  st.write(f"Starting Go {sport} lineup generation...")
148
  start_time = time.time()
149
 
150
- # Run the Go executable
 
 
151
  if site == "DK":
152
- result = subprocess.run(
153
- ["./dk_nhl_go/NHL_seed_frames", site, sport], # Linux binary
154
- capture_output=True,
155
- text=True,
156
- check=True,
157
- cwd=".." # Run from /app directory
158
- )
159
  else:
160
- result = subprocess.run(
161
- ["./fd_nhl_go/NHL_seed_frames", site, sport], # Linux binary
162
- capture_output=True,
163
- text=True,
164
- check=True,
165
- cwd=".." # Run from /app directory
166
- )
 
 
 
 
 
167
 
168
  end_time = time.time()
169
  st.write(f"Go {sport} processing completed in {end_time - start_time:.2f} seconds")
@@ -182,8 +183,14 @@ def run_go_classic_lineup_generator(site="DK", sport="NHL"):
182
  if e.stderr:
183
  st.write("Error output:", e.stderr)
184
  return False
185
- except FileNotFoundError:
186
- st.write("Error: NHL_seed_frames.exe not found. Make sure it's compiled and in the current directory.")
 
 
 
 
 
 
187
  return False
188
 
189
  def init_team_results(model_source: DataFrame, position_reqs: dict, salary_cap: int, max_skaters: int, teams_to_optimize: list, combos: int):
 
147
  st.write(f"Starting Go {sport} lineup generation...")
148
  start_time = time.time()
149
 
150
+ # Determine the path to the Go binary (from /app directory)
151
+ app_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Get /app from /app/src
152
+
153
  if site == "DK":
154
+ go_binary = os.path.join(app_dir, "dk_nhl_go", "NHL_seed_frames")
 
 
 
 
 
 
155
  else:
156
+ go_binary = os.path.join(app_dir, "fd_nhl_go", "NHL_seed_frames")
157
+
158
+ st.write(f"Looking for binary at: {go_binary}")
159
+
160
+ # Run the Go executable
161
+ result = subprocess.run(
162
+ [go_binary, site, sport],
163
+ capture_output=True,
164
+ text=True,
165
+ check=True,
166
+ cwd=app_dir # Run from /app directory
167
+ )
168
 
169
  end_time = time.time()
170
  st.write(f"Go {sport} processing completed in {end_time - start_time:.2f} seconds")
 
183
  if e.stderr:
184
  st.write("Error output:", e.stderr)
185
  return False
186
+ except FileNotFoundError as e:
187
+ st.write(f"Error: Go binary not found at {go_binary}")
188
+ st.write(f"FileNotFoundError: {e}")
189
+ st.write(f"Current working directory: {os.getcwd()}")
190
+ st.write(f"App directory: {app_dir}")
191
+ return False
192
+ except Exception as e:
193
+ st.write(f"Unexpected error: {e}")
194
  return False
195
 
196
  def init_team_results(model_source: DataFrame, position_reqs: dict, salary_cap: int, max_skaters: int, teams_to_optimize: list, combos: int):