Skip to content

Commit

Permalink
Merge pull request #468 from alan-turing-institute/develop
Browse files Browse the repository at this point in the history
Merge v1.3.1
  • Loading branch information
jack89roberts authored Mar 11, 2022
2 parents 359ebbc + 3c369ce commit 6e71fd5
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ This will take a while, but should eventually provide a printout of the optimal

Note that `airsenal_run_optimization` should only be used for transfer suggestions after the season has started. If it's before the season has started and you want to generate a full squad for gameweek one you should instead use:
```shell
airsenal_make_squad --num_gw 3
airsenal_make_squad --num_gameweeks 3
```
This can also be used during the season to generate a full new squad (e.g. for wildcards).

Expand Down
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.3.0"
__version__ = "1.3.1"

# Cross-platform temporary directory
TMPDIR = "/tmp/" if os.name == "posix" else tempfile.gettempdir()
5 changes: 4 additions & 1 deletion airsenal/framework/data_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,15 @@ def login(self):
return

headers = {
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 5.1; PRO 5 Build/LMY47D)"
}
data = {
"login": self.FPL_LOGIN,
"password": self.FPL_PASSWORD,
"app": "plfpl-web",
"redirect_uri": self.FPL_LOGIN_REDIRECT_URL,
}
response = self.rsession.post(self.FPL_LOGIN_URL, data=headers)
response = self.rsession.post(self.FPL_LOGIN_URL, data=data, headers=headers)
if response.status_code != 200:
print(f"Error loging in: {response.content}")
else:
Expand Down
4 changes: 4 additions & 0 deletions airsenal/framework/optimization_transfers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def make_optimum_single_transfer(
else:
if verbose:
print("Failed to add {}".format(p_in[0].name))
if not new_squad.is_complete():
if verbose:
print(f"Failed to find a valid replacement for {p_out.player_id}")
continue
total_points = 0.0
for gw in gameweek_range:
if gw == bench_boost_gw:
Expand Down
26 changes: 14 additions & 12 deletions airsenal/scripts/fill_transfersuggestion_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def run_optimization(
chip_gameweeks={},
num_free_transfers=None,
max_total_hit=None,
allow_unused_transfers=True,
allow_unused_transfers=False,
max_transfers=2,
num_iterations=100,
num_thread=4,
Expand Down Expand Up @@ -642,10 +642,12 @@ def sanity_check_args(args):
"""
Check that command-line arguments are self-consistent.
"""
if args.weeks_ahead and (args.gw_start or args.gw_end):
raise RuntimeError("Please only specify weeks_ahead OR gw_start/end")
elif (args.gw_start and not args.gw_end) or (args.gw_end and not args.gw_start):
raise RuntimeError("Need to specify both gw_start and gw_end")
if args.weeks_ahead and (args.gameweek_start or args.gameweek_end):
raise RuntimeError("Please only specify weeks_ahead OR gameweek_start/end")
elif (args.gameweek_start and not args.gameweek_end) or (
args.gameweek_end and not args.gameweek_start
):
raise RuntimeError("Need to specify both gameweek_start and gameweek_end")
if args.num_free_transfers and args.num_free_transfers not in range(1, 3):
raise RuntimeError("Number of free transfers must be 1 or 2")
return True
Expand All @@ -659,8 +661,8 @@ def main():
description="Try some different transfer strategies"
)
parser.add_argument("--weeks_ahead", help="how many weeks ahead", type=int)
parser.add_argument("--gw_start", help="first gameweek to consider", type=int)
parser.add_argument("--gw_end", help="last gameweek to consider", type=int)
parser.add_argument("--gameweek_start", help="first gameweek to consider", type=int)
parser.add_argument("--gameweek_end", help="last gameweek to consider", type=int)
parser.add_argument("--tag", help="specify a string identifying prediction set")
parser.add_argument(
"--wildcard_week",
Expand Down Expand Up @@ -732,14 +734,14 @@ def main():

sanity_check_args(args)
season = args.season
# default weeks ahead is not specified (or gw_end is not specified) is three
# default weeks ahead is not specified (or gameweek_end is not specified) is three
if args.weeks_ahead:
gameweeks = get_gameweeks_array(args.weeks_ahead)
elif args.gw_start:
if args.gw_end:
gameweeks = list(range(args.gw_start, args.gw_end))
elif args.gameweek_start:
if args.gameweek_end:
gameweeks = list(range(args.gameweek_start, args.gameweek_end))
else:
gameweeks = list(range(args.gw_start, args.gw_start + 3))
gameweeks = list(range(args.gameweek_start, args.gameweek_start + 3))
else:
gameweeks = list(range(get_next_gameweek(), get_next_gameweek() + 3))

Expand Down
14 changes: 7 additions & 7 deletions airsenal/scripts/squad_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def main():
"--budget", help="budget, in 0.1 millions", type=int, default=1000
)
parser.add_argument("--season", help="season, in format e.g. 1819")
parser.add_argument("--gw_start", help="gameweek to start from", type=int)
parser.add_argument("--gameweek_start", help="gameweek to start from", type=int)
parser.add_argument(
"--num_gw", help="how many gameweeks to consider", type=int, default=3
"--num_gameweeks", help="how many gameweeks to consider", type=int, default=3
)
parser.add_argument(
"--algorithm",
Expand Down Expand Up @@ -74,8 +74,8 @@ def main():
args = parser.parse_args()
season = args.season or get_current_season()
budget = args.budget
gw_start = args.gw_start or NEXT_GAMEWEEK
gw_range = list(range(gw_start, min(38, gw_start + args.num_gw)))
gameweek_start = args.gameweek_start or NEXT_GAMEWEEK
gw_range = list(range(gameweek_start, min(38, gameweek_start + args.num_gameweeks)))
tag = get_latest_prediction_tag(season)
if not check_tag_valid(tag, gw_range, season=season):
print(
Expand Down Expand Up @@ -127,9 +127,9 @@ def main():
"something went wrong with the squad expected points calculation."
)

points = best_squad.get_expected_points(gw_start, tag)
points = best_squad.get_expected_points(gameweek_start, tag)
print("---------------------")
print("Best expected points for gameweek {}: {}".format(gw_start, points))
print("Best expected points for gameweek {}: {}".format(gameweek_start, points))
print("---------------------")
print(best_squad)

Expand All @@ -139,5 +139,5 @@ def main():
fpl_team_id,
tag,
season=season,
gameweek=gw_start,
gameweek=gameweek_start,
)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ flask==2.0.1
flask_cors==3.0.10
flask_session==0.4.0
jupyter==1.0.0
lxml==4.6.3
lxml==4.6.5
matplotlib==3.4.2
numpyro==0.6.0
pandas==1.3.1
Expand Down

0 comments on commit 6e71fd5

Please sign in to comment.