Skip to content

Commit

Permalink
Merge pull request #424 from alan-turing-institute/develop
Browse files Browse the repository at this point in the history
Recent Developments
  • Loading branch information
jack89roberts authored Sep 24, 2021
2 parents beb4966 + f59be35 commit f909224
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
2 changes: 1 addition & 1 deletion airsenal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import tempfile

# AIrsenal package version.
__version__ = "1.1.0"
__version__ = "1.1.1"

# Cross-platform temporary directory
TMPDIR = "/tmp/" if os.name == "posix" else tempfile.gettempdir()
3 changes: 1 addition & 2 deletions airsenal/framework/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ def get_current_players(gameweek=None, season=None, fpl_team_id=None, dbsession=
def get_squad_value(
squad,
gameweek=NEXT_GAMEWEEK,
season=CURRENT_SEASON,
use_api=False,
):
"""
Expand All @@ -186,7 +185,7 @@ def get_squad_value(

for p in squad.players:
total_value += squad.get_sell_price_for_player(
p, use_api=use_api, season=season, gameweek=gameweek
p, use_api=use_api, gameweek=gameweek
)

return total_value
Expand Down
63 changes: 60 additions & 3 deletions airsenal/scripts/airsenal_run_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,40 @@
is_flag=True,
help="If set, go ahead and make the transfers via the API.",
)
def run_pipeline(num_thread, weeks_ahead, fpl_team_id, clean, apply_transfers):
@click.option(
"--wildcard_week",
type=int,
help=(
"If set to 0, consider playing wildcard in any gameweek. "
"If set to a specific gameweek, it'll be played for that particular gameweek."
),
)
@click.option(
"--free_hit_week",
type=int,
help="Play free hit in the specified week. Choose 0 for 'any week'.",
)
@click.option(
"--triple_captain_week",
type=int,
help="Play triple captain in the specified week. Choose 0 for 'any week'.",
)
@click.option(
"--bench_boost_week",
type=int,
help="Play bench_boost in the specified week. Choose 0 for 'any week'.",
)
def run_pipeline(
num_thread,
weeks_ahead,
fpl_team_id,
clean,
apply_transfers,
wildcard_week,
free_hit_week,
triple_captain_week,
bench_boost_week,
):
"""
Run the full pipeline, from setting up the database and filling
with players, teams, fixtures, and results (if it didn't already exist),
Expand Down Expand Up @@ -95,7 +128,12 @@ def run_pipeline(num_thread, weeks_ahead, fpl_team_id, clean, apply_transfers):
raise RuntimeError("Problem creating a new squad")
else:
click.echo("Running optimization..")
opt_ok = run_optimize_squad(num_thread, weeks_ahead, fpl_team_id, dbsession)
chips_played = setup_chips(
wildcard_week, free_hit_week, triple_captain_week, bench_boost_week
)
opt_ok = run_optimize_squad(
num_thread, weeks_ahead, fpl_team_id, dbsession, chips_played
)
if not opt_ok:
raise RuntimeError("Problem running optimization")

Expand All @@ -119,6 +157,24 @@ def setup_database(fpl_team_id, dbsession):
return make_init_db(fpl_team_id, dbsession)


def setup_chips(wildcard_week, free_hit_week, triple_captain_week, bench_boost_week):
"""
Set up chips to be played for particular gameweeks. Specifically: wildcard,
free_hit, triple_captain, bench_boost
"""
chips_gameweeks = {}
if wildcard_week:
chips_gameweeks["wildcard"] = wildcard_week
if free_hit_week:
chips_gameweeks["free_hit"] = free_hit_week
if triple_captain_week:
chips_gameweeks["triple_captain"] = triple_captain_week
if bench_boost_week:
chips_gameweeks["bench_boost"] = bench_boost_week

return chips_gameweeks


def update_database(fpl_team_id, attr, dbsession):
"""
Update database
Expand Down Expand Up @@ -175,7 +231,7 @@ def run_make_squad(weeks_ahead, fpl_team_id, dbsession):
return True


def run_optimize_squad(num_thread, weeks_ahead, fpl_team_id, dbsession):
def run_optimize_squad(num_thread, weeks_ahead, fpl_team_id, dbsession, chips_played):
"""
Build the initial squad
"""
Expand All @@ -190,6 +246,7 @@ def run_optimize_squad(num_thread, weeks_ahead, fpl_team_id, dbsession):
season=season,
fpl_team_id=fpl_team_id,
num_thread=num_thread,
chip_gameweeks=chips_played,
)
return True

Expand Down

0 comments on commit f909224

Please sign in to comment.