Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update tm scraper #539

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions airsenal/framework/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,8 @@ def was_historic_absence(player, gameweek, season, dbsession=None):
dbsession.query(Absence)
.filter_by(season=season)
.filter_by(player=player)
.filter(Absence.gw_from <= gameweek)
.filter(Absence.gw_until >= gameweek) # should this be > rather than >= ?
.filter(Absence.gw_from < gameweek)
.filter(Absence.gw_until > gameweek)
.first()
)
if absence:
Expand Down
27 changes: 24 additions & 3 deletions airsenal/scripts/airsenal_run_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
get_entry_start_gameweek,
get_gameweeks_array,
get_latest_prediction_tag,
get_past_seasons,
)
from airsenal.scripts.fill_db_init import check_clean_db, make_init_db
from airsenal.scripts.fill_predictedscore_table import (
Expand Down Expand Up @@ -79,6 +80,17 @@
help="Play bench_boost in the specified week. Choose 0 for 'any week'.",
default=-1,
)
@click.option(
"--n_previous",
help="specify how many seasons to look back into the past for (defaults to 3)",
type=int,
default=3,
)
@click.option(
"--no_current_season",
help="If set, does not include CURRENT_SEASON in database",
is_flag=True,
)
def run_pipeline(
num_thread,
weeks_ahead,
Expand All @@ -89,6 +101,8 @@ def run_pipeline(
free_hit_week,
triple_captain_week,
bench_boost_week,
n_previous,
no_current_season,
):
"""
Run the full pipeline, from setting up the database and filling
Expand All @@ -109,7 +123,9 @@ def run_pipeline(
with session_scope() as dbsession:
if check_clean_db(clean, dbsession):
click.echo("Setting up Database..")
setup_ok = setup_database(fpl_team_id, dbsession)
setup_ok = setup_database(
fpl_team_id, n_previous, no_current_season, dbsession
)
if not setup_ok:
raise RuntimeError("Problem setting up initial db")
click.echo("Database setup complete..")
Expand Down Expand Up @@ -156,11 +172,16 @@ def run_pipeline(
click.echo("Pipeline finished OK!")


def setup_database(fpl_team_id, dbsession):
def setup_database(fpl_team_id, n_previous, no_current_season, dbsession):
"""
Set up database
"""
return make_init_db(fpl_team_id, dbsession)
if no_current_season:
seasons = get_past_seasons(n_previous)
else:
seasons = [CURRENT_SEASON] + get_past_seasons(n_previous)

return make_init_db(fpl_team_id, seasons, dbsession)


def setup_chips(wildcard_week, free_hit_week, triple_captain_week, bench_boost_week):
Expand Down