Skip to content

Commit

Permalink
Merge pull request #503 from alan-turing-institute/develop
Browse files Browse the repository at this point in the history
Recent development (AIrsenal v1.5.0)
  • Loading branch information
nbarlowATI authored Sep 1, 2022
2 parents e9df380 + b7f34cb commit 23d7ca3
Show file tree
Hide file tree
Showing 38 changed files with 1,213 additions and 1,777 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ jobs:
poetry run flake8
- name: Tests
env:
FPL_TEAM_ID: 863052
FPL_TEAM_ID: 2779516
run: poetry run pytest
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*FD_API_KEY
*FPL_LOGIN
*FPL_PASSWORD
*AIrsenalDBFile
*AIrsenalDBUri
*AIrsenalDBUser
*AIrsenalDBPassword
*AIRSENAL_DB_FILE
*AIRSENAL_DB_URI
*AIRSENAL_DB_USER
*AIRSENAL_DB_PASSWORD

# compiled stan models
stan_model/
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ For some background information and details see https://www.turing.ac.uk/researc

We welcome contributions and comments - if you'd like to join the AIrsenal community please refer to our [contribution guidelines](https://github.com/alan-turing-institute/AIrsenal/blob/master/CONTRIBUTING.md)

## NEW (1st September 2022)
Changes merged from `develop` branch - See [here](#configuration) for new instructions on setting your Team ID, Username etc.

## Mini-league for 2022/23 season

We have made a mini-league **"Prem-AI League"** for players using this software. To join, login to the FPL website, and navigate to the page to join a league: https://fantasy.premierleague.com/leagues/create-join then click "join a league or cup".
Expand Down Expand Up @@ -100,23 +103,29 @@ Once you've installed the module, you will need to set the following parameters:

**Optional:**

2. `FPL_LEAGUE_ID`: a league ID for FPL (this is only required for plotting FPL league standings).
2. `FPL_LOGIN`: your FPL login, usually email (this is only required to get FPL league standings, or automating transfers via the API).

3. `FPL_PASSWORD`: your FPL password (this is only required to get FPL league standings, or automating transfers via the API).

3. `FPL_LOGIN`: your FPL login, usually email (this is only required to get FPL league standings, or automating transfers via the API).
4. `FPL_LEAGUE_ID`: a league ID for FPL (this is only required for plotting FPL league standings).

4. `FPL_PASSWORD`: your FPL password (this is only required to get FPL league standings, or automating transfers via the API).
5. `AIRSENAL_DB_FILE`: Local path to where you would like to store the AIrsenal sqlite3 database. If not set `AIRSENAL_HOME/data.db` will be used by default.

5. `AIrsenalDBFile`: Local path to where you would like to store the AIrsenal sqlite3 database. If not set a temporary directory will be used by default (`/tmp/data.db` on Unix systems).
The values for these should be defined either in environment variables with the names given above, or as files in `AIRSENAL_HOME` (a directory AIrsenal creates on your system to save config files and the database).

The values for these should be defined either in environment variables with the names given above, or as files in the `airsenal/data` directory with the names given above. For example, to set your team ID you can create the file `airsenal/data/FPL_TEAM_ID` (with no file extension) and its contents should be your team ID and nothing else. So the contents of the file would just be something like:
To view the location of `AIRSENAL_HOME` and the current values of all set AIrsenal environment variables run:

```text
1234567
```bash
airsenal_env get
```

Where `1234567` is your team ID.
Use `airsenal_env set` to set values and store them for future use. For example:

```bash
airsenal_env set -k FPL_TEAM_ID -v 123456
```

If you do create the files in `airsenal/data`, you should do ```pip install .``` again to ensure they are copied to the correct location for the installed package.
See `airsenal_env --help` for other options.

## Getting Started

Expand Down
8 changes: 1 addition & 7 deletions airsenal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@
___init__.py for airsenal
"""

import os
import tempfile

import pkg_resources

# AIrsenal package version.
__version__ = pkg_resources.get_distribution("airsenal").version

# Cross-platform temporary directory
TMPDIR = "/tmp/" if os.name == "posix" else tempfile.gettempdir()
__version__ = pkg_resources.get_distribution(__name__).version
25 changes: 13 additions & 12 deletions airsenal/conftest.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import os
import random
from contextlib import contextmanager
from pathlib import Path
from tempfile import mkdtemp

import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from airsenal import TMPDIR
from airsenal.framework.mappings import alternative_team_names
from airsenal.framework.schema import Base, Player, PlayerAttributes
from airsenal.framework.utils import CURRENT_SEASON
from airsenal.tests.resources import dummy_players
from airsenal.framework import env

env.AIRSENAL_HOME = Path(mkdtemp())

from airsenal.framework.mappings import alternative_team_names # noqa: E402
from airsenal.framework.schema import Base, Player, PlayerAttributes # noqa: E402
from airsenal.framework.utils import CURRENT_SEASON # noqa: E402
from airsenal.tests.resources import dummy_players # noqa: E402

API_SESSION_ID = "TESTSESSION"

testengine_dummy = create_engine("sqlite:///{}/test.db".format(TMPDIR))
# testengine_past = create_engine(
# "sqlite:////Users/nbarlow/AIrsenal/airsenal/tests/testdata/testdata_1718_1819.db"
# ).format(os.path.dirname(__file__)))
testengine_dummy = create_engine(f"sqlite:///{env.AIRSENAL_HOME}/test.db")

testengine_past = create_engine(
"sqlite:///{}/tests/testdata/testdata_1718_1819.db".format(
os.path.dirname(__file__)
)
f"sqlite:///{os.path.dirname(__file__)}/tests/testdata/testdata_1718_1819.db"
)


Base.metadata.create_all(testengine_dummy)

Base.metadata.bind = testengine_dummy
Expand Down
58 changes: 58 additions & 0 deletions airsenal/data/alternative_player_names.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Emerson Leite de Souza Junior,Emerson Aparecido Leite de Souza Junior
Pablo Fornals Malla,Pablo Fornals
Bernardo Veiga de Carvalho e Silva,Bernardo Mota Veiga de Carvalho e Silva
Moisés Caicedo Corozo,Moisés Caicedo
Lyanco Silveira Neves Vojnovic,Lyanco Evangelista Silveira Neves Vojnovic
Diogo Dalot Teixeira,José Diogo Dalot Teixeira
Jeremy Sarmiento Morante,Jeremy Sarmiento
Son Heung-min,Heung-Min Son
Asmir Begović,Asmir Begovic
Gabriel Martinelli Silva,Gabriel Teodoro Martinelli Silva
Kaine Kesler Hayden,Kaine Hayden
Matija Šarkić,Matija Sarkic
Rúben da Silva Neves,Rúben Diogo da Silva Neves
Tino Livramento,Valentino Livramento
Rúben Nascimento Vinagre,Rúben Gonçalo Silva Nascimento Vinagre
Eddie Nketiah,Edward Nketiah
Matt Clarke,Matthew Clarke
Emiliano Martínez Romero,Emiliano Martínez
Ben Chilwell,Benjamin Chilwell
Fin Stevens,Finley Stevens
Xande Nascimento da Costa Silva,Alexandre Nascimento Costa Silva
Matty Cash,Matthew Cash
Roméo Lavia,Romeo Lavia
Paulo Gazzaniga Farias,Paulo Gazzaniga
Sergi Canós Tenés,Sergi Canós
Cédric Alves Soares,Cédric Soares
Junior Firpo Adames,Héctor Junior Firpo Adames
Ricardo Barbosa Pereira,Ricardo Domingos Barbosa Pereira
Lucas Torreira di Pascua,Lucas Torreira
Hugo Bueno López,Hugo Bueno
Andreas Hoelgebaum Pereira,Andreas Pereira
Rayan Aït-Nouri,Rayan Ait Nouri
Luke Mbete-Tabu,Luke Mbete
Marc Cucurella Saseta,Marc Cucurella
Will Smallbone,William Smallbone
Miguel Almirón Rejala,Miguel Almirón
Josh Dasilva,Pelenda Joshua Dasilva
Joe Willock,Joseph Willock
Josh Wilson-Esbrand,Joshua Wilson-Esbrand
Rúben Gato Alves Dias,Rúben Santos Gato Alves Dias
Pablo Marí Villar,Pablo Marí
Gabriel dos Santos Magalhães,Gabriel Magalhães
Ivan Neves Abreu Cavaleiro,Ivan Ricardo Neves Abreu Cavaleiro
Adama Traoré Diarra,Adama Traoré
Bruno Borges Fernandes,Bruno Miguel Borges Fernandes
Dele Alli,Bamidele Alli
Bobby De Cordova-Reid,Bobby Decordova-Reid
Hwang Hee-chan,Hee-Chan Hwang
Alex Telles,Alex Nicolao Telles
André Tavares Gomes,André Filipe Tavares Gomes
Jefferson Lerma Solís,Jefferson Lerma
Benjamin White,Ben White
Javier Manquillo Gaitán,Javier Manquillo
Boubacar Kamara,Aboubakar Kamara
Facundo Pellistri Rebollo,Facundo Pellistri
Solly March,Solomon March
David De Gea Quintana,David de Gea
João Cancelo,João Pedro Cavaco Cancelo
5 changes: 5 additions & 0 deletions airsenal/data/duplicate_player_names.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name,season,id
Daniel Carl Ward,1819,105
Benjamin Keith Davies,2021,653
Benjamin Keith Davies,2122,248
\u00c1lvaro Fern\u00e1ndez Llorente,2122,556
121 changes: 121 additions & 0 deletions airsenal/data/new_players_2223.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name,player_id,team,position
Jefferson Lerma Solís,67,BOU,MID
Lewis Cook,70,BOU,MID
Rúben Gato Alves Dias,349,MCI,DEF
Matija Šarkić,552,WOL,GK
Jamal Lowe,64,BOU,MID
Jay Stansfield,244,FUL,FWD
Sepp van den Berg,335,LIV,DEF
Neeskens Kebano,229,FUL,MID
Jack Colback,423,NFO,MID
Benjamin White,9,ARS,DEF
Hwang Hee-chan,541,WOL,MID
Rayan Aït-Nouri,547,WOL,DEF
Kieffer Moore,65,BOU,FWD
Emerson Leite de Souza Junior,498,TOT,DEF
Cédric Alves Soares,1,ARS,DEF
Marc Cucurella Saseta,124,BHA,DEF
Josh Wilson-Esbrand,357,MCI,DEF
Junior Stanislas,61,BOU,MID
Brennan Johnson,436,NFO,FWD
Javier Manquillo Gaitán,403,NEW,DEF
Bruno Borges Fernandes,369,MUN,MID
Philip Billing,73,BOU,MID
Sam Surridge,433,NFO,FWD
Bernardo Veiga de Carvalho e Silva,348,MCI,MID
Antonee Robinson,242,FUL,DEF
Tosin Adarabioyo,234,FUL,DEF
Jackson Smith,557,WOL,GK
Gabriel Martinelli Silva,18,ARS,MID
Aleksandar Mitrović,235,FUL,FWD
Pablo Marí Villar,19,ARS,DEF
Sam Johnstone,193,CRY,GK
Rodrigo Muniz Carvalho,243,FUL,FWD
Jaidon Anthony,78,BOU,MID
Jack Stacey,68,BOU,DEF
Emiliano Marcondes,66,BOU,MID
Solly March,119,BHA,MID
Harry Wilson,237,FUL,MID
Adama Traoré Diarra,551,WOL,MID
Ricardo Barbosa Pereira,258,LEI,DEF
Luke Mbete-Tabu,356,MCI,DEF
João Cancelo,343,MCI,DEF
Luke Harris,249,FUL,MID
Adam Smith,60,BOU,DEF
Son Heung-min,481,TOT,MID
Diogo Dalot Teixeira,378,MUN,DEF
Tom Cairney,225,FUL,MID
Mohamed Dräger,428,NFO,DEF
Oliver Hammond,449,NFO,MID
Hugo Bueno López,558,WOL,DEF
Dele Alli,203,EVE,MID
Lloyd Kelly,76,BOU,DEF
Cheick Doucouré,196,CRY,MID
Luke Plange,195,CRY,FWD
Tyrese Francois,247,FUL,MID
Ryan Christie,72,BOU,MID
Gabriel dos Santos Magalhães,15,ARS,DEF
Jordan Zemura,79,BOU,DEF
Joe Willock,413,NEW,MID
Joe Worrall,430,NFO,DEF
Fin Stevens,111,BRE,DEF
Kaoru Mitoma,136,BHA,MID
Alex Mighten,437,NFO,MID
Rúben da Silva Neves,540,WOL,MID
Emiliano Martínez Romero,31,AVL,GK
Jeremy Sarmiento Morante,131,BHA,MID
Ivan Neves Abreu Cavaleiro,239,FUL,MID
Moussa Niakhaté,442,NFO,DEF
Dominic Solanke,69,BOU,FWD
Ben Pearson,71,BOU,MID
Bobby De Cordova-Reid,230,FUL,MID
Loïc Mbe Soh,435,NFO,DEF
Paulo Gazzaniga Farias,232,FUL,GK
Ryan Yates,429,NFO,MID
Facundo Pellistri Rebollo,382,MUN,MID
James Hill,83,BOU,DEF
Daniel Iversen,276,LEI,GK
Tim Ream,226,FUL,DEF
Braian Ojeda Rodríguez,438,NFO,MID
Luis Sinisterra Lucumí,306,LEE,MID
Kaine Kesler Hayden,58,AVL,DEF
Jan Paul van Hecke,141,BHA,DEF
Calvin Ramsay,331,LIV,DEF
Marek Rodák,238,FUL,GK
Joe Bryan,231,FUL,DEF
Zidane Iqbal,388,MUN,MID
Sergi Canós Tenés,88,BRE,DEF
Djed Spence,509,TOT,DEF
Junior Firpo Adames,296,LEE,DEF
Lyle Taylor,422,NFO,FWD
Siriki Dembélé,77,BOU,MID
Lucas Torreira di Pascua,21,ARS,MID
Scott McKenna,427,NFO,DEF
Carlos Ribeiro Dias,425,NFO,MID
Chris Mepham,74,BOU,DEF
Harrison Reed,236,FUL,MID
Diogo Teixeira da Silva,322,LIV,FWD
Alex Telles,370,MUN,DEF
Will Dennis,80,BOU,GK
Miguel Almirón Rejala,409,NEW,MID
Matt Clarke,140,BHA,DEF
Ben Chilwell,154,CHE,DEF
Kenny Tete,240,FUL,DEF
David Brooks,63,BOU,MID
Anthony Knockaert,227,FUL,MID
Brice Samba,424,NFO,GK
Mohamed Elneny,3,ARS,MID
Josh Dasilva,89,BRE,MID
Matty Cash,43,AVL,DEF
Terence Kongolo,233,FUL,DEF
Lyanco Silveira Neves Vojnovic,464,SOU,DEF
Mark Travers,75,BOU,GK
Pablo Fornals Malla,525,WHU,MID
Josh Onomah,241,FUL,MID
André Tavares Gomes,206,EVE,MID
Steve Cook,421,NFO,DEF
David De Gea Quintana,363,MUN,GK
Joe Lolley,426,NFO,MID
Troy Parrott,506,TOT,FWD
Eddie Nketiah,10,ARS,FWD
Moisés Caicedo Corozo,132,BHA,MID
2 changes: 1 addition & 1 deletion airsenal/data/player_details_1718.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion airsenal/data/player_details_1819.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion airsenal/data/player_details_2021.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion airsenal/data/player_details_2122.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions airsenal/framework/api_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
Functions used by the AIrsenal API
"""
from flask import jsonify
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.orm import scoped_session

from airsenal.framework.optimization_transfers import (
make_optimum_double_transfer,
make_optimum_single_transfer,
)
from airsenal.framework.schema import Player, SessionBudget, SessionSquad, engine
from airsenal.framework.schema import Player, SessionBudget, SessionSquad, session
from airsenal.framework.squad import Squad
from airsenal.framework.utils import (
CURRENT_SEASON,
Expand All @@ -25,7 +25,7 @@
list_teams,
)

DBSESSION = scoped_session(sessionmaker(bind=engine))
DBSESSION = scoped_session(session)


def remove_db_session(dbsession=DBSESSION):
Expand Down
8 changes: 2 additions & 6 deletions airsenal/framework/aws_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import time

import boto3
from sqlalchemy.orm import sessionmaker

from airsenal.framework.fpl_team_utils import (
get_league_standings,
get_overall_points,
get_overall_ranking,
)
from airsenal.framework.schema import Player, TransferSuggestion


def download_sqlite_file():
Expand Down Expand Up @@ -64,11 +64,7 @@ def get_suggestions_string():

time.sleep(1)
try:
from airsenal.framework.schema import Base, Player, TransferSuggestion, engine

Base.metadata.bind = engine
DBSession = sessionmaker()
session = DBSession()
from airsenal.framework.schema import session
except Exception as e:
return "Problem importing stuff {}".format(e)
try:
Expand Down
Loading

0 comments on commit 23d7ca3

Please sign in to comment.