def update_records_and_teams(query: Query, league_settings: Sequence[LeagueSetting], year: int): """ Update records and teams for the current year. :param query: the query object :param league_settings: the league settings for the current year :param year: the current year :return: None """ records = set(r for r in query.get_records(year=year)) teams = set(t for t in query.get_teams(year=year)) current_records, current_teams = get_current_records_and_teams(league_settings=league_settings) update_records(query=query, current_records=current_records, records=records) update_teams(query=query, current_teams=current_teams, teams=teams)
def update_teams(query: Query, current_teams: Set[Teams], teams: Set[Teams]): """ Update teams for the current year. :param query: the query object :param current_teams: the teams for the current year from the api :param teams: the teams for the current year from the db :return: None """ current_teams = current_teams - teams count = len(current_teams) if count == 0: logging.info("No teams to update") return logging.info(f"Updating {count} teams") query.upsert_teams(current_teams)
def update_records(query: Query, current_records: Set[Records], records: Set[Records]): """ Update records for the given year. :param query: the query object :param current_records: the records for the current year from the api :param records: the records for the current year from the db :return: """ current_records = current_records - records count = len(current_records) if count == 0: logging.info("No records to update") return logging.info(f"Updating {count} records") query.upsert_records(current_records)
def update_matchups(query: Query, league_settings: Sequence[LeagueSetting], year: int): """ Update matchups for the current year. :param query: the query object :param league_settings: the league settings for the current year :param year: the current year :return: None """ matchups = set(m for m in query.get_matchups(year=year)) current_matchups = get_current_matchups(league_settings=league_settings) - matchups count = len(current_matchups) if count == 0: logging.info("No matchups to update") return logging.info(f"Updating {count} matchup scores") query.upsert_matchups(current_matchups)
def main(): args = parse_args() environment = args.get("environment") year = args.get("year") week = args.get("week") app.config.from_object(util.get_config(environment)) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = app.config.get("DB_URI") db.init_app(app) query = Query(db) with app.app_context(): team_ids = set(query.get_distinct_matchup_team_ids(year)[week]) team_id_to_team_name = query.get_team_id_to_team_name(year) matchups = [ m for m in query.get_matchups(year) if m.matchup_id == week and m.team_id in team_ids ] for m in matchups: team_name = team_id_to_team_name.get(m.team_id) opponent_name = team_id_to_team_name.get(m.opponent_team_id) team_filename = get_filename(year, week, m.team_id) generate_recap_template(team_filename, team_name, opponent_name)
def main(): args = parse_args() environment = args.get("environment") config = util.get_config(environment) app.config.from_object(util.get_config(environment)) util.set_logger(config=config, filename=__file__) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = app.config.get("DB_URI") db.init_app(app) query = Query(db) with app.app_context(): league_settings = api.get_league_settings(config=config, years=[config.CURRENT_YEAR]) update(query=query, league_settings=league_settings, year=config.CURRENT_YEAR)
LOG_FORMAT = "%(asctime)s %(levelname)s %(pathname)s %(lineno)d: %(message)s" app = Flask(__name__) app.config.from_object(util.get_config(sys.argv[2])) app.register_blueprint(awards) app.register_blueprint(champions) app.register_blueprint(h2h_records) app.register_blueprint(matchup_history) app.register_blueprint(playoffs) app.register_blueprint(recap) app.register_blueprint(standings) app.static_folder = "web/static" app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = app.config.get("DB_URI") db.init_app(app) query = Query(db) app.config['QUERY'] = query @app.template_filter() def points_format(value): return "{:,}".format(value) @app.template_filter() def percentage_format(value): return "{:.4f}".format(value) def get_template_path_vars_for_nav(relative_path, pattern, splitter=None): matching_paths = glob.glob(relative_path + pattern)
def main(): with app.app_context(): q = Query(db) playoff_standings = q.get_playoff_standings(year=2014) for p in playoff_standings: print(p)