<commit_before>from nflpool.data.dbsession import DbSessionFactory
from sqlalchemy.orm import joinedload
from nflpool.data.player_picks import PlayerPicks
from nflpool.data.weekly_player_results import WeeklyPlayerResults
from _datetime import datetime
from nflpool.data.seasoninfo import SeasonInfo


def get_seasons():
    session = DbSessionFactory.create_session()
    season_row = session.query(SeasonInfo).filter(SeasonInfo.id == '1').first()
    current_season = season_row.current_season

    return current_season


def get_week():
    session = DbSessionFactory.create_session()

    season_row = session.query(SeasonInfo).filter(SeasonInfo.id == '1').first()
    season_start = season_row.season_start_date
    season_start = datetime.strptime(season_start, "%Y-%m-%d")

    diff = datetime.now() - season_start
    print(diff.days)
    week = int((diff.days / 7) + 1)
    print(week)

#    week = 17           # ------------------------------- TESTING ------------------- remove this line after test.
    return week


class StandingsService:
    def display_player_standings(player_id, season=None):
        if season is None:
            season = get_seasons()

        sqlstr = "SELECT coalesce(w.points_earned,0) as points, a.first_name, a.last_name, w.pick_id, p.pick_type, p.rank, p.multiplier, t.name, "
        sqlstr += "c.conference, d.division, ap.firstname, ap.lastname "
        sqlstr += "FROM PlayerPicks p, Account a "
        sqlstr += "LEFT JOIN WeeklyPlayerResults w on p.pick_id = w.pick_id "
        sqlstr += "AND w.week = (SELECT MAX(week) from WeeklyPlayerResults  WHERE season=" + str(season) + ") "
        sqlstr += "LEFT JOIN  DivisionInfo d on p.division_id=d.division_id "
        sqlstr += "LEFT JOIN ConferenceInfo c ON p.conf_id= c.conf_id "
        sqlstr += "LEFT JOIN TeamInfo t ON p.team_id = t.team_id "
        sqlstr += "LEFT JOIN ActiveNFLPlayers ap ON p.player_id = ap.player_id AND p.season = ap.season "
        sqlstr += "WHERE "
        sqlstr += "p.user_id = a.id "
        sqlstr += "AND p.season = " + str(season) + " "
        sqlstr += "AND p.user_id = '" + player_id +"'"

        session = DbSessionFactory.create_session()
        standings = session.execute(sqlstr)

        dict_standings = [dict(row) for row in standings]

        session.close()
        return dict_standings

    def display_weekly_standings(season=None):

        #return list that contains player standings for most recent week in results table
        if season is None:
            season = get_seasons()

        sqlstr = "SELECT SUM(w.points_earned) as total_points, a.first_name, a.last_name, a.id from WeeklyPlayerResults w, PlayerPicks p, Account a "
        sqlstr += "WHERE w.pick_id = p.pick_id AND p.user_id = a.id "
        sqlstr += "AND w.season = " + str(season) + " "
        sqlstr += "AND w.week = (SELECT MAX(week) from WeeklyPlayerResults WHERE season = " + str(season) + ") "
        sqlstr += "GROUP BY p.user_id "
        sqlstr += "ORDER BY total_points DESC"

        session = DbSessionFactory.create_session()
        standings = session.execute(sqlstr)

        dict_standings = [dict(row) for row in standings]

        session.close()
        return dict_standings

    def update_player_pick_points():
        season = get_seasons()
        week = get_week()

        session = DbSessionFactory.create_session()

        #starting values
        conf = 0
        i = 4

        while (conf < 2):
            # start with pick type 4 and continue through 8

            if i == 4:
                cattype = "passyds"
            elif i == 5:
                cattype ="rushyds"
            elif i == 6:
                cattype ="recyds"<commit_msg>Fix comments to be PEP8 compliant<commit_after>from nflpool.data.dbsession import DbSessionFactory
from sqlalchemy.orm import joinedload
from nflpool.data.player_picks import PlayerPicks
from nflpool.data.weekly_player_results import WeeklyPlayerResults
from _datetime import datetime
from nflpool.data.seasoninfo import SeasonInfo


def get_seasons():
    session = DbSessionFactory.create_session()
    season_row = session.query(SeasonInfo).filter(SeasonInfo.id == '1').first()
    current_season = season_row.current_season

    return current_season


def get_week():
    session = DbSessionFactory.create_session()

    season_row = session.query(SeasonInfo).filter(SeasonInfo.id == '1').first()
    season_start = season_row.season_start_date
    season_start = datetime.strptime(season_start, "%Y-%m-%d")

    diff = datetime.now() - season_start
    print(diff.days)
    week = int((diff.days / 7) + 1)
    print(week)

#    week = 17           # ------------------------------- TESTING ------------------- remove this line after test.
    return week


class StandingsService:
    def display_player_standings(player_id, season=None):
        if season is None:
            season = get_seasons()

        sqlstr = "SELECT coalesce(w.points_earned,0) as points, a.first_name, a.last_name, w.pick_id, p.pick_type, p.rank, p.multiplier, t.name, "
        sqlstr += "c.conference, d.division, ap.firstname, ap.lastname "
        sqlstr += "FROM PlayerPicks p, Account a "
        sqlstr += "LEFT JOIN WeeklyPlayerResults w on p.pick_id = w.pick_id "
        sqlstr += "AND w.week = (SELECT MAX(week) from WeeklyPlayerResults  WHERE season=" + str(season) + ") "
        sqlstr += "LEFT JOIN  DivisionInfo d on p.division_id=d.division_id "
        sqlstr += "LEFT JOIN ConferenceInfo c ON p.conf_id= c.conf_id "
        sqlstr += "LEFT JOIN TeamInfo t ON p.team_id = t.team_id "
        sqlstr += "LEFT JOIN ActiveNFLPlayers ap ON p.player_id = ap.player_id AND p.season = ap.season "
        sqlstr += "WHERE "
        sqlstr += "p.user_id = a.id "
        sqlstr += "AND p.season = " + str(season) + " "
        sqlstr += "AND p.user_id = '" + player_id +"'"

        session = DbSessionFactory.create_session()
        standings = session.execute(sqlstr)

        dict_standings = [dict(row) for row in standings]

        session.close()
        return dict_standings

    def display_weekly_standings(season=None):

        # return list that contains player standings for most recent week in results table
        if season is None:
            season = get_seasons()

        sqlstr = "SELECT SUM(w.points_earned) as total_points, a.first_name, a.last_name, a.id from WeeklyPlayerResults w, PlayerPicks p, Account a "
        sqlstr += "WHERE w.pick_id = p.pick_id AND p.user_id = a.id "
        sqlstr += "AND w.season = " + str(season) + " "
        sqlstr += "AND w.week = (SELECT MAX(week) from WeeklyPlayerResults WHERE season = " + str(season) + ") "
        sqlstr += "GROUP BY p.user_id "
        sqlstr += "ORDER BY total_points DESC"

        session = DbSessionFactory.create_session()
        standings = session.execute(sqlstr)

        dict_standings = [dict(row) for row in standings]

        session.close()
        return dict_standings

    def update_player_pick_points():
        season = get_seasons()
        week = get_week()

        session = DbSessionFactory.create_session()

        # starting values
        conf = 0
        i = 4

        while (conf < 2):
            # start with pick type 4 and continue through 8

            if i == 4:
                cattype = "passyds"
            elif i == 5:
                cattype ="rushyds"
            elif i == 6:
                cattype ="recyds"
{'fraction_non_alphanumeric': 0.11370340573880397, 'fraction_numerical': 0.004156610351300617, 'mean_word_length': 2.4887745556594947, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2349259', 'n_tokens_mistral': 2368, 'n_tokens_neox': 2231, 'n_words': 600}