Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run fill_initial_squad instead of running optimization, if next gw is 1, or no existing squad found #498

Merged
merged 3 commits into from
Aug 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions airsenal/scripts/fill_transfersuggestion_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
get_latest_prediction_tag,
get_player_name,
)
from airsenal.scripts.squad_builder import fill_initial_squad

TMPDIR = "/tmp/" if os.name == "posix" else "%TMP%"
OUTPUT_DIR = os.path.join(TMPDIR, "airsopt")
Expand Down Expand Up @@ -412,10 +413,42 @@ def run_optimization(
if fpl_team_id is None:
fpl_team_id = fetcher.FPL_TEAM_ID

# see if we are at the start of a season, or
if gameweeks[0] == 1:
print("Starting a new season - will make squad from scratch")
fill_initial_squad(
tag=tag,
gw_range=gameweeks,
season=season,
fpl_team_id=fpl_team_id,
num_iterations=num_iterations,
)
return

# give the user the option to login
fetcher.login()

print("Running optimization with fpl_team_id {}".format(fpl_team_id))
use_api = fetcher.logged_in if season == CURRENT_SEASON else False
try:
starting_squad = get_starting_squad(
season=season, fpl_team_id=fpl_team_id, use_api=use_api, apifetcher=fetcher
)
except (ValueError, TypeError):
# first week for this squad?
print("No existing squad or transfers found for team_id {}".format(fpl_team_id))
print("Will suggest a new starting squad:")
fill_initial_squad(
tag=tag,
gw_range=gameweeks,
season=season,
fpl_team_id=fpl_team_id,
num_iterations=num_iterations,
)
return

# if we got to here, we can assume we are optimizing an existing squad.

# How many free transfers are we starting with?
if not num_free_transfers:
num_free_transfers = get_free_transfers(
Expand Down Expand Up @@ -478,11 +511,6 @@ def update_progress(increment=1, index=None):
progress_bars[index].update(increment)
progress_bars[index].refresh()

use_api = fetcher.logged_in if season == CURRENT_SEASON else False
starting_squad = get_starting_squad(
season=season, fpl_team_id=fpl_team_id, use_api=use_api, apifetcher=fetcher
)

if not allow_unused_transfers and (
num_weeks > 1 or (num_weeks == 1 and num_free_transfers == 2)
):
Expand Down Expand Up @@ -732,6 +760,7 @@ def main():
)

num_iterations = args.num_iterations

if args.num_free_transfers:
num_free_transfers = args.num_free_transfers
else:
Expand Down