Skip to content

Commit

Permalink
Merge branch 'alan-turing-institute:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tdarnell authored Aug 13, 2023
2 parents 33b7553 + 1c06a86 commit 644ec71
Show file tree
Hide file tree
Showing 21 changed files with 70 additions and 119 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ you can reinstall AIrsenal from our `develop` branch - there are instructions

### When this PR is ready to merge:

- [ ] **Before merging:** Update the AIrsenal package version in `airsenal/__init__.py`. If new
- [ ] **Before merging:** Update the AIrsenal package version in `pyproject.toml`. If new
features have been added increment the middle number, e.g. 0.1.0 -> 0.2.0,
or if bug fixes only change the last number, e.g. 0.1.0 -> 0.1.1.

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
docker run airsenal poetry run pre-commit run --all-files
- name: Tests
run: |
docker run -e "FPL_TEAM_ID=2779516" airsenal poetry run pytest
docker run -e "FPL_TEAM_ID=1822891" airsenal poetry run pytest
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: ["3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand All @@ -37,5 +37,5 @@ jobs:
poetry run flake8
- name: Tests
env:
FPL_TEAM_ID: 2779516
FPL_TEAM_ID: 1822891
run: poetry run pytest
Empty file removed .gitmodules
Empty file.
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ repos:
rev: 23.7.0
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
Expand Down
59 changes: 0 additions & 59 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9-slim-buster
FROM python:3.11-slim-buster

RUN apt-get update && \
apt-get install build-essential git sqlite3 curl -y && \
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

6 changes: 3 additions & 3 deletions airsenal/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@


@contextmanager
def test_session_scope():
def session_scope():
"""Provide a transactional scope around a series of operations."""
db_session = sessionmaker(bind=testengine_dummy)
testsession = db_session()
Expand All @@ -48,7 +48,7 @@ def test_session_scope():


@contextmanager
def test_past_data_session_scope():
def past_data_session_scope():
"""Provide a transactional scope around a series of operations."""
db_session = sessionmaker(bind=testengine_past)
testsession = db_session()
Expand Down Expand Up @@ -85,7 +85,7 @@ def fill_players():
team_list = list(alternative_team_names.keys())
season = CURRENT_SEASON
gameweek = 1
with test_session_scope() as ts:
with session_scope() as ts:
if len(ts.query(Player).all()) > 0:
return
for i, n in enumerate(dummy_players):
Expand Down
3 changes: 1 addition & 2 deletions airsenal/framework/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from contextlib import contextmanager

from sqlalchemy import Column, Float, ForeignKey, Integer, String, create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
from sqlalchemy.orm import declarative_base, relationship, sessionmaker

from airsenal.framework.env import AIRSENAL_HOME, get_env

Expand Down
14 changes: 11 additions & 3 deletions airsenal/framework/transaction_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,19 @@ def fill_initial_squad(
)
)
if NEXT_GAMEWEEK == 1:
# Season hasn't started yet - there won't be a team in the DB
return True
print("Season hasn't started yet so nothing to add to the DB.")
return

starting_gw = get_entry_start_gameweek(fpl_team_id)
print(f"Got starting squad from gameweek {starting_gw}. Adding player data...")
print(f"Got starting squad from gameweek {starting_gw}.")
if starting_gw == NEXT_GAMEWEEK:
print(
"This is team {fpl_team_id}'s first gameweek so nothing to add to the DB "
"yet."
)
return

print("Adding player data...")

init_players = get_players_for_gameweek(starting_gw, fpl_team_id)
free_hit = free_hit_used_in_gameweek(starting_gw, fpl_team_id)
Expand Down
8 changes: 6 additions & 2 deletions airsenal/scripts/fill_transfersuggestion_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
from airsenal.framework.utils import (
CURRENT_SEASON,
fetcher,
get_entry_start_gameweek,
get_free_transfers,
get_gameweeks_array,
get_latest_prediction_tag,
Expand Down Expand Up @@ -425,8 +426,11 @@ 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:
print("Starting a new season - will make squad from scratch")
if gameweeks[0] == 1 or gameweeks[0] == get_entry_start_gameweek(fpl_team_id):
print(
"This is the start of the season or a new team - will make a squad "
"from scratch"
)
fill_initial_squad(
tag=tag,
gw_range=gameweeks,
Expand Down
20 changes: 10 additions & 10 deletions airsenal/tests/test_api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import re

from airsenal.conftest import API_SESSION_ID, test_session_scope
from airsenal.conftest import API_SESSION_ID, session_scope
from airsenal.framework.api_utils import (
add_session_player,
get_session_budget,
Expand All @@ -19,7 +19,7 @@


def test_reset_session_squad():
with test_session_scope() as ts:
with session_scope() as ts:
assert reset_session_squad(session_id=API_SESSION_ID, dbsession=ts)
st = ts.query(SessionSquad).filter_by(session_id=API_SESSION_ID).all()
assert len(st) == 0
Expand All @@ -30,7 +30,7 @@ def test_reset_session_squad():


def test_list_all_players(fill_players):
with test_session_scope() as ts:
with session_scope() as ts:
player_list = list_players_teams_prices(dbsession=ts, gameweek=1)
assert isinstance(player_list, list)
assert len(player_list) > 0
Expand All @@ -40,7 +40,7 @@ def test_list_all_players(fill_players):


def test_add_player(fill_players):
with test_session_scope() as ts:
with session_scope() as ts:
assert reset_session_squad(session_id=API_SESSION_ID, dbsession=ts)
assert add_session_player(12, API_SESSION_ID, ts)
players = get_session_players(API_SESSION_ID, ts)
Expand All @@ -49,7 +49,7 @@ def test_add_player(fill_players):


def test_cant_add_same_player_twice(fill_players):
with test_session_scope() as ts:
with session_scope() as ts:
assert reset_session_squad(session_id=API_SESSION_ID, dbsession=ts)
assert add_session_player(33, API_SESSION_ID, ts)
assert not add_session_player(33, API_SESSION_ID, ts)
Expand All @@ -59,7 +59,7 @@ def test_cant_add_same_player_twice(fill_players):


def test_remove_player(fill_players):
with test_session_scope() as ts:
with session_scope() as ts:
assert reset_session_squad(session_id=API_SESSION_ID, dbsession=ts)
assert add_session_player(12, API_SESSION_ID, ts)
assert remove_session_player(12, API_SESSION_ID, ts)
Expand All @@ -68,20 +68,20 @@ def test_remove_player(fill_players):


def test_get_budget():
with test_session_scope() as ts:
with session_scope() as ts:
assert reset_session_squad(session_id=API_SESSION_ID, dbsession=ts)
assert get_session_budget(API_SESSION_ID, ts) == 1000


def test_set__get_budget():
with test_session_scope() as ts:
with session_scope() as ts:
assert reset_session_squad(session_id=API_SESSION_ID, dbsession=ts)
assert set_session_budget(500, API_SESSION_ID, ts)
assert get_session_budget(API_SESSION_ID, ts) == 500


def test_invalid_session_squad(fill_players):
with test_session_scope() as ts:
with session_scope() as ts:
reset_session_squad(session_id=API_SESSION_ID, dbsession=ts)
assert not validate_session_squad(API_SESSION_ID, ts)
# add one player - check it is still invalid
Expand All @@ -90,7 +90,7 @@ def test_invalid_session_squad(fill_players):


def test_valid_session_squad(fill_players):
with test_session_scope() as ts:
with session_scope() as ts:
reset_session_squad(API_SESSION_ID, ts)
for pid in range(15):
assert add_session_player(pid, API_SESSION_ID, ts)
Expand Down
4 changes: 4 additions & 0 deletions airsenal/tests/test_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from operator import itemgetter
from unittest import mock

import pytest

from airsenal.framework.optimization_transfers import (
make_optimum_double_transfer,
make_optimum_single_transfer,
Expand All @@ -16,6 +18,8 @@
)
from airsenal.framework.squad import Squad

pytestmark = pytest.mark.filterwarnings("ignore:Using purchase price as sale price")


class DummyPlayer(object):
"""
Expand Down
Loading

0 comments on commit 644ec71

Please sign in to comment.