Skip to content

Commit

Permalink
Merge pull request #627 from alan-turing-institute/develop
Browse files Browse the repository at this point in the history
[develop] Next AIrsenal Release
  • Loading branch information
jack89roberts authored Oct 1, 2023
2 parents 7cc3f6d + df5b1d8 commit aa7c7ab
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
11 changes: 8 additions & 3 deletions airsenal/framework/data_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import getpass
import json
import time
import warnings

import requests

Expand All @@ -23,6 +24,7 @@ def __init__(self, fpl_team_id=None, rsession=None):
self.rsession = rsession or requests.session()
self.logged_in = False
self.login_failed = False
self.continue_without_login = False
self.current_summary_data = None
self.current_event_data = None
self.current_player_data = None
Expand Down Expand Up @@ -108,7 +110,7 @@ def login(self, attempts=3):
"""
only needed for accessing mini-league data, or team info for current gw.
"""
if self.logged_in:
if self.logged_in or self.continue_without_login:
return
if self.login_failed:
raise RuntimeError(
Expand Down Expand Up @@ -137,9 +139,12 @@ def login(self, attempts=3):
self.get_fpl_credentials()
else:
self.login_failed = True
raise RuntimeError(
"Requested logging into the FPL API but no credentials provided."
self.continue_without_login = True
warnings.warn(
"Skipping login which means AIrsenal may have out of date "
"information for your team."
)
return
headers = {
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 5.1; PRO 5 Build/LMY47D)"
}
Expand Down
2 changes: 1 addition & 1 deletion airsenal/framework/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# Cross-platform data directory
if "AIRSENAL_HOME" in os.environ.keys():
AIRSENAL_HOME = os.environ["AIRSENAL_HOME"]
AIRSENAL_HOME = Path(os.environ["AIRSENAL_HOME"])
else:
AIRSENAL_HOME = Path(user_data_dir("airsenal"))
os.makedirs(AIRSENAL_HOME, exist_ok=True)
Expand Down
3 changes: 3 additions & 0 deletions airsenal/scripts/fill_player_attributes_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def fill_attributes_table_from_file(
else None
)
dbsession.add(pa)
dbsession.commit()


def fill_attributes_table_from_api(
Expand Down Expand Up @@ -114,6 +115,7 @@ def fill_attributes_table_from_api(
pa = get_player_attributes(
player.player_id, season=season, gameweek=next_gw, dbsession=dbsession
)

if pa:
# found pre-existing attributes for this gameweek
update = True
Expand Down Expand Up @@ -204,6 +206,7 @@ def fill_attributes_table_from_api(
dbsession.add(pa)

break # done this gameweek now
dbsession.commit()


def make_attributes_table(
Expand Down
12 changes: 5 additions & 7 deletions airsenal/scripts/fill_transfersuggestion_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,9 @@ def run_optimization(
fpl_team_id = fetcher.FPL_TEAM_ID

# see if we are at the start of a season, or
if gameweeks[0] == 1 or gameweeks[0] == get_entry_start_gameweek(fpl_team_id):
if gameweeks[0] == 1 or gameweeks[0] == get_entry_start_gameweek(
fpl_team_id, apifetcher=fetcher
):
print(
"This is the start of the season or a new team - will make a squad "
"from scratch"
Expand All @@ -440,12 +442,8 @@ def run_optimization(
)
return

# give the user the option to login
if season == CURRENT_SEASON:
fetcher.login()

print(f"Running optimization with fpl_team_id {fpl_team_id}")
use_api = fetcher.logged_in if season == CURRENT_SEASON and not is_replay else False
use_api = season == CURRENT_SEASON and not is_replay
try:
starting_squad = get_starting_squad(
next_gw=gameweeks[0],
Expand All @@ -466,7 +464,6 @@ def run_optimization(
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?
Expand All @@ -478,6 +475,7 @@ def run_optimization(
apifetcher=fetcher,
is_replay=is_replay,
)

# create the output directory for temporary json files
# giving the points prediction for each strategy
shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "airsenal"
version = "1.7.4"
version = "1.7.5"
description = "AI manager for Fantasy Premier League"
authors = [
"Angus Williams <anguswilliams91@gmail.com>",
Expand Down

0 comments on commit aa7c7ab

Please sign in to comment.