Beispiel #1
0
def fillScores(scores_df):
    """ Fill in weekly scores DB. """
    for i in scores_df.index:
        score = scores_df.loc[i]
        command = "insert into thisWeekScores \
                    values (%d, %d)" % (i, score)
        get_db().execute(command)
Beispiel #2
0
def executeAdd(p, team_id):
    """ Add players to SQL DB. """
    name = p.name.replace("'", "''")
    command = "insert into players values ('%s', \
        %d, %d, '%s', '%s', %d)" % (name, p.points, p.projected_points,
                                    p.position, p.slot_position, team_id)
    get_db().execute(command)
Beispiel #3
0
def getYearlyInfo(league, year):
    """ Insert necessary info into years SQL DB. """
    scores_df = createScoresDf(league)
    rot = getRotisserie(league, scores_df)
    for team in league.teams:
        t_id = team.team_id
        t_name = team.team_name.replace("'","''")
        p_for = round(team.points_for, 1)
        r_w = rot.loc[t_id, 'wins']
        r_l = rot.loc[t_id, 'losses']
        r_t = rot.loc[t_id, 'ties']
        command = "insert into years values \
                    (%d, '%s', %d, %d, %d, \
                    %d, %d, %d, %d, %d)" % (t_id,
                    t_name, year, team.wins, team.losses, 
                    p_for, team.final_standing, 
                    r_w, r_l, r_t)
        get_db().execute(command)
        storeFinalRosters(team, year)
    r_weeks = league.settings.reg_season_count
    p_teams = league.settings.playoff_team_count
    command = "insert into yearSettings values \
                (%d, %d, %d)" % (year,
                r_weeks, p_teams)
    get_db().execute(command)
Beispiel #4
0
def getTeams(league):
    """ Fill Teams DB. """
    for t in league.teams:
        t_id = t.team_id
        owner = checkOwnership(t.owner).replace("'", "''")
        name = cleanNames(t.team_name.replace("'", "''"))
        command = "insert into teams (teamId, owner, teamname)\
            values (%d, '%s', '%s')" % (t_id, owner, name)
        get_db().execute(command)
Beispiel #5
0
def weeklyAwards(scores_df, year, week):
    """ Calculate weekly awards for homepage. """
    i_max = scores_df.values.argmax()
    max_team = scores_df.index[i_max]
    i_min = scores_df.values.argmin()
    min_team = scores_df.index[i_min]
    command = "insert into thisWeekSummary values (%d, \
                %d, %d, %d, %d, %d, \
                %d)" % (week, year, max_team, 
                min_team, scores_df.median(), 
                scores_df.max(), scores_df.min())
    get_db().execute(command)
Beispiel #6
0
def storeFinalRosters(team, year):
    roster = [[p.name, p.eligibleSlots, 
                p.proTeam, p.posRank] 
                for p in team.roster]
    # Flatten the roster
    roster = [i for s in roster for i in s]
    # If position rank is a list (is for 2014-2018),
    # then just make it a zero for SQL purposes.
    for i in range(3, len(roster), 4):
        if isinstance(roster[i], list):
            roster[i] = 0
    # Get only one position from position rank
    for i in range(1, len(roster), 4):
        slots = roster[i]
        roster[i] = slots[0]
        s_i = 1
        while '/' in roster[i] and roster[i] != 'D/ST':
            roster[i] = slots[s_i]
    while len(roster) < ROSTER_SIZE * 4:
        roster.append("Empty")
    params = ['?' for r in roster]
    command = "insert into historicalRosters values \
                (%d, %d, %s);" % (team.team_id, year, ','.join(params))
    get_db().execute(command, roster)
Beispiel #7
0
def getYearlyInfo(league, year):
    """ Insert necessary info into years SQL DB. """
    scoresDf = createScoresDf(league)
    rotRecords = getRotisserie(league, scoresDf)
    for team in league.teams:
        teamId = team.team_id
        teamName = team.team_name.replace("'","''")
        wins = team.wins
        losses = team.losses
        pointsFor = round(team.points_for, 1)
        standing = team.final_standing
        rotWins = rotRecords.loc[teamId, 'wins']
        rotLosses = rotRecords.loc[teamId, 'losses']
        rotTies = rotRecords.loc[teamId, 'ties']
        command = "insert into years values \
                    (%d, '%s', %d, %d, %d, %d, %d, %d, %d, %d)" % (teamId,
                    teamName, year, wins, losses, 
                    pointsFor, standing, rotWins, rotLosses, rotTies)
        get_db().execute(command)
    regSeasonWeeks = league.settings.reg_season_count
    playoffTeams = league.settings.playoff_team_count
    command = "insert into yearSettings values (%d, %d, %d)" %(year,
                regSeasonWeeks, playoffTeams)
    get_db().execute(command)