def generate_player(pos, row, game): ''' Parses CSV row for DraftKings or FanDuel and returns a player. Note that DraftKings has different CSV formats for different sports. ''' avg_key = GAME_KEY_MAP[game]['avg'] name_key = GAME_KEY_MAP[game]['name'] team_key = GAME_KEY_MAP[game]['team'] team_alt_key = GAME_KEY_MAP[game]['team_alt'] game_key = GAME_KEY_MAP[game]['game'] game_alt_key = GAME_KEY_MAP[game]['game_alt'] avg = float(row.get(avg_key, 0)) player = Player( pos, row[name_key], row['Salary'], possible_positions=row['Position'], multi_position='/' in row['Position'], team=row.get(team_key) or row.get(team_alt_key), matchup=row.get(game_key) or row.get(game_alt_key), average_score=avg, ) return player
def test_roster_set(): player_a = Player(pos='RB', name='A', cost=1, team='X') player_b = Player(pos='QB', name='B', cost=1, team='X') player_c = Player(pos='QB', name='C', cost=1, team='X') roster_a = NFLRoster() roster_a.add_player(player_a) roster_a.add_player(player_b) roster_b = NFLRoster() roster_b.add_player(player_a) roster_b.add_player(player_b) roster_c = NFLRoster() roster_c.add_player(player_a) roster_c.add_player(player_c) ntool.assert_true(len(set([roster_a, roster_b, roster_c])), 2)
def capt_boost(p): return Player( name=p.name, team=p.team, matchup=p.matchup, pos=p.pos, cost=p.cost * 1.5, proj=p.proj * 1.5, )
def test_roster_equality(): player_a = Player(pos='RB', name='A', cost=1, team='X') player_b = Player(pos='QB', name='B', cost=1, team='X') player_c = Player(pos='QB', name='C', cost=1, team='X') roster_a = NFLRoster() roster_a.add_player(player_a) roster_a.add_player(player_b) roster_b = NFLRoster() roster_b.add_player(player_a) roster_b.add_player(player_b) roster_c = NFLRoster() roster_c.add_player(player_a) roster_c.add_player(player_c) ntool.assert_false(roster_a == roster_c) ntool.assert_true(roster_a == roster_b)
def test_roster_equality(): player_a = Player(pos='RB', name='A', cost=1) player_b = Player(pos='QB', name='B', cost=1) player_c = Player(pos='QB', name='C', cost=1) roster_a = NFLRoster() roster_a.add_player(player_a) roster_a.add_player(player_b) roster_b = NFLRoster() roster_b.add_player(player_a) roster_b.add_player(player_b) roster_c = NFLRoster() roster_c.add_player(player_a) roster_c.add_player(player_c) ntool.assert_not_equals(roster_a == roster_c, True) ntool.assert_equals(roster_a == roster_b, True)
def test_roster_group(): player_a = Player(pos='RB', name='A', cost=1, team='X') player_b = Player(pos='QB', name='B', cost=1, team='X') player_c = Player(pos='QB', name='C', cost=1, team='X') roster_a = NFLRoster() roster_a.add_player(player_a) roster_a.add_player(player_b) roster_b = NFLRoster() roster_b.add_player(player_a) roster_b.add_player(player_b) roster_c = NFLRoster() roster_c.add_player(player_a) roster_c.add_player(player_c) rg = RosterGroup(rosters=[roster_a, roster_b]) ntool.assert_equal(rg.get_similarity_score(), 1) ntool.assert_equal(rg.get_salary_frequency(), [(2, 2)]) ntool.assert_equal(rg.get_player_frequency(), [(player_a, 2), (player_b, 2)]) rg_2 = RosterGroup(rosters=[roster_a, roster_c]) ntool.assert_equal(rg_2.get_similarity_score(), 0.5) rg_3 = RosterGroup(rosters=[roster_a, roster_b, roster_c]) ntool.assert_equal( rg_3.get_similarity_score(), # (1 + 0.5 + 0.5)/3 2 / 3) roster_d = NFLRoster() roster_d.add_player(player_a) roster_d.add_player(Player(pos='QB', name='D', cost=1, team='X')) # All lineups share half of the same players rg_4 = RosterGroup(rosters=[roster_a, roster_c, roster_d]) ntool.assert_equal( rg_4.get_similarity_score(), # (0.5 + 0.5 + 0.5)/3 0.5)
def test_roster_equality_with_position_shuffle(): player_a = Player(pos='RB', name='A', cost=1, team='X') player_a_new_pos = Player(pos='WR', name='A', cost=1, team='X') player_b = Player(pos='QB', name='B', cost=1, team='X') player_c = Player(pos='QB', name='C', cost=1, team='X') roster_a = NFLRoster() roster_a.add_player(player_a) roster_a.add_player(player_b) roster_b = NFLRoster() roster_b.add_player(player_a_new_pos) roster_b.add_player(player_b) roster_c = NFLRoster() roster_c.add_player(player_a) roster_c.add_player(player_c) ntool.assert_false(roster_a == roster_c) ntool.assert_true(roster_a == roster_b)
def test_showdown_roster_equality_and_position_shuffle(): """ In Showdown, point changes result from CPT assignment, so two lineups are not equal given the same player. """ player_a = Player(pos='FLEX', name='A', cost=1, team='A') player_a_new_pos = Player(pos='CPT', name='A', cost=1, team='A') player_b = Player(pos='FLEX', name='B', cost=1, team='C') player_c = Player(pos='FLEX', name='C', cost=1, team='D') roster_a = ShowdownRoster() roster_a.add_player(player_a) roster_a.add_player(player_b) roster_b = ShowdownRoster() roster_b.add_player(player_a_new_pos) roster_b.add_player(player_b) roster_c = ShowdownRoster() roster_c.add_player(player_a) roster_c.add_player(player_c) ntool.assert_false(roster_a == roster_c) ntool.assert_false(roster_a == roster_b)
def Optimize(date, top_k, slate_id, projection_source = 'rotogrinders'): projections_path = GetMetaDataPath() + '/rotogrinders/projections/%s.csv' % (date) if not os.path.exists(projections_path): print("projections for %s not exists" % date) return projections = pd.read_csv(projections_path, header = 0, index_col = 0) slates_path = GetMetaDataPath() + '/draftkings/slates/%s.csv' % (date) if not os.path.exists(slates_path): print("slates for %s not exists" % date) return slates = pd.read_csv(slates_path, header = 0, index_col = 0) if slate_id not in slates['SLATE_ID'].tolist(): print("slate %d not exist!" % slate_id) return if slates[slates['SLATE_ID'] == slate_id]['SLATE_TYPE'].values[0] != 'CLASSIC': print("slate type %s not supported!" % slate_type) return players_path = GetMetaDataPath() + '/draftkings/players/%s.csv' % (date) players = pd.read_csv(players_path, header = 0, index_col = 0) players = players[players['SLATE_ID'] == slate_id] players.set_index('NAME', inplace=True) players_with_projection = projections.join(players, how='inner') player_pool = [] for name, data in players_with_projection.iterrows(): for pos in data['POSITION'].split('/'): player_pool.append(Player( name=name, cost=data['SALARY'], proj=data['PROJECTION'], pos=pos, possible_positions=data['POSITION'], multi_position='/' in data['POSITION'], team=data['TEAM'], matchup=data['GAME_INFO'], average_score=data['DKP'],)) roster = run_multi( iterations=top_k, rule_set=rules.DK_NBA_RULE_SET, player_pool=player_pool, verbose=True, )
def test_golf_dk(): player_pool = [ Player(name='G1', cost=5500, proj=55, pos=GOLFER), Player(name='G2', cost=5600, proj=55, pos=GOLFER), Player(name='G3', cost=5700, proj=55, pos=GOLFER), Player(name='G4', cost=5800, proj=55, pos=GOLFER), Player(name='G5', cost=5800, proj=55, pos=GOLFER), Player(name='G6', cost=5900, proj=55, pos=GOLFER), Player(name='G7', cost=10000, proj=155, pos=GOLFER), ] roster = run( rule_set=rules.DK_PGA_RULE_SET, player_pool=player_pool, verbose=True, ) ntools.assert_not_equal(roster, None)
def test_golf_dk_captain(): player_pool = [ Player(name='G1', cost=5500, proj=1, pos=CPT), Player(name='G2', cost=5600, proj=55, pos=GOLFER), Player(name='G3', cost=5700, proj=55, pos=GOLFER), Player(name='G4', cost=5800, proj=55, pos=GOLFER), Player(name='G5', cost=5800, proj=55, pos=GOLFER), Player(name='G6', cost=5900, proj=55, pos=GOLFER), Player(name='G7', cost=10000, proj=155, pos=GOLFER), ] roster = run( rule_set=rules.DK_PGA_SHOWDOWN_CAPTAIN_RULE_SET, player_pool=player_pool, verbose=True, ) ntools.assert_not_equal(roster, None) ntools.assert_equal(roster.projected(), 376)
def test_general_guard(): pg = Player(name='A', cost=1, proj=1, pos='PG') ntools.assert_equal(pg.nba_general_position, 'G') sg = Player(name='A', cost=1, proj=1, pos='SG') ntools.assert_equal(sg.nba_general_position, 'G')
import random from nose import tools as ntools from draftfast.player_pool import filter_pool from draftfast.orm import Player from draftfast.settings import PlayerPoolSettings p_a, p_b, p_c = [ Player(name='A1', cost=5500, proj=20, pos='PG'), Player(name='A2', cost=7000, proj=30, pos='PG'), Player(name='A3', cost=10000, proj=55, pos='PG'), ] mock_player_pool = [p_a, p_b, p_c] def test_no_settings(): pool = filter_pool(mock_player_pool, PlayerPoolSettings()) ntools.assert_equals(pool, mock_player_pool) def test_respects_min_proj(): pool = filter_pool(mock_player_pool, PlayerPoolSettings(min_proj=50)) ntools.assert_equals(pool, [p_c]) def test_respects_max_proj(): pool = filter_pool(mock_player_pool, PlayerPoolSettings(max_proj=50)) ntools.assert_equals(pool, [p_a, p_b]) def test_respects_min_cost(): pool = filter_pool(mock_player_pool, PlayerPoolSettings(min_salary=7001))
def test_general_center(): pg = Player(name='A', cost=1, proj=1, pos='C') ntools.assert_equal(pg.nba_general_position, 'C')
def test_no_opposing_def_dk_nfl_mock(): mock_pool = [ Player(name='A1', cost=5500, proj=40, pos='QB', team='X', matchup='X@Y'), Player(name='A2', cost=5500, proj=41, pos='QB', team='Y', matchup='X@Y'), Player(name='A11', cost=5500, proj=50, pos='WR', team='X', matchup='X@Y'), Player(name='A3', cost=5500, proj=42, pos='WR', team='Y', matchup='X@Y'), Player(name='A4', cost=5500, proj=43, pos='WR', team='X', matchup='X@Y'), Player(name='A5', cost=5500, proj=44, pos='WR', team='Y', matchup='X@Y'), Player(name='A111', cost=5500, proj=50, pos='WR', team='X', matchup='X@Y'), Player(name='A31', cost=5500, proj=42, pos='WR', team='Y', matchup='X@Y'), Player(name='A41', cost=5500, proj=62, pos='WR', team='X', matchup='X@Y'), Player(name='A51', cost=5500, proj=63, pos='WR', team='Y', matchup='X@Y'), Player(name='A6', cost=5500, proj=45, pos='RB', team='X', matchup='X@Y'), Player(name='A7', cost=5500, proj=46, pos='RB', team='Y', matchup='X@Y'), Player(name='A8', cost=5500, proj=47, pos='RB', team='X', matchup='X@Y'), Player(name='A71', cost=5500, proj=46, pos='RB', team='Y', matchup='X@Y'), Player(name='A81', cost=5500, proj=47, pos='RB', team='X', matchup='X@Y'), Player(name='A711', cost=5500, proj=46, pos='RB', team='Y', matchup='X@Y'), Player(name='A9', cost=5500, proj=48, pos='TE', team='X', matchup='X@Y'), Player(name='A10', cost=5500, proj=49, pos='TE', team='Y', matchup='X@Y'), Player(name='A12', cost=5500, proj=51, pos='DST', team='X', matchup='X@Y'), Player(name='A13', cost=5500, proj=500, pos='DST', team='Y', matchup='X@Y'), ] # mock pool is constructed such that optimal lineup has qb opposing dst roster = run(rule_set=rules.DK_NFL_RULE_SET, player_pool=mock_pool, verbose=True) ntools.assert_equal(roster.projected(), 909) qb_team = roster.sorted_players()[0].team dst_team = roster.sorted_players()[-1].team ntools.assert_equal(qb_team, dst_team) # this will fail to produce a roster because we only have 2 teams (X and Y) roster = run( rule_set=rules.DK_NFL_RULE_SET, player_pool=mock_pool, optimizer_settings=OptimizerSettings(no_offense_against_defense=True), verbose=True) ntools.assert_equal(roster, None) # relax min teams roster = run(rule_set=rules.DK_NFL_RULE_SET, player_pool=mock_pool, optimizer_settings=OptimizerSettings( min_teams=1, no_offense_against_defense=True, ), verbose=True) ntools.assert_equal(roster.projected(), 877) ntools.assert_equal(len(set([p.team for p in roster.players])), 1) # add a player from a third team, min 2 teams mock_pool.append( Player(name='B2', cost=5500, proj=70, pos='QB', team='Q', matchup='Q@Z')) roster = run( rule_set=rules.DK_NFL_RULE_SET, player_pool=deepcopy(mock_pool), optimizer_settings=OptimizerSettings(no_offense_against_defense=True), verbose=True) for p in roster.players: if p.pos in rules.DK_NFL_RULE_SET.offensive_positions: ntools.assert_not_equal(p.team, 'X')
def test_five_batters_max(): player_pool = [ Player(pos='P', name='A', cost=5000, team='C'), Player(pos='P', name='B', cost=5000, team='B'), Player(pos='1B', name='C', cost=5000, team='C'), Player(pos='OF', name='H', cost=5000, team='C'), Player(pos='OF', name='I', cost=5000, team='C'), Player(pos='C', name='F', cost=5000, team='C'), Player(pos='2B', name='D', cost=5000, team='C'), Player(pos='2B', name='E', cost=5000, team='C'), Player(pos='3B', name='E', cost=5000, team='C'), Player(pos='SS', name='G', cost=5000, team='Q'), Player(pos='OF', name='J', cost=5000, team='G'), ] roster = run( rule_set=rules.DK_MLB_RULE_SET, player_pool=player_pool, verbose=True, ) assert roster is None player_pool.append(Player(pos='3B', name='EA', cost=5000, team='A')) roster = run( rule_set=rules.DK_MLB_RULE_SET, player_pool=player_pool, verbose=True, ) c_in_roster = [ x for x in roster.players if x.team == 'C' and x.pos != 'P' ] assert len(c_in_roster) < 6
import os from copy import deepcopy from nose import tools as ntools from draftfast.optimize import run from draftfast import rules from draftfast.orm import Player from draftfast.csv_parse import salary_download from draftfast.settings import OptimizerSettings, Stack from draftfast.lineup_constraints import LineupConstraints mock_nba_pool = [ Player(name='A1', cost=5500, proj=40, pos='PG'), Player(name='A2', cost=5500, proj=41, pos='PG'), Player(name='A11', cost=5500, proj=50, pos='PG'), Player(name='A3', cost=5500, proj=42, pos='SG'), Player(name='A4', cost=5500, proj=43, pos='SG'), Player(name='A5', cost=5500, proj=44, pos='SF'), Player(name='A6', cost=5500, proj=45, pos='SF'), Player(name='A7', cost=5500, proj=46, pos='PF'), Player(name='A8', cost=5500, proj=47, pos='PF'), Player(name='A9', cost=5500, proj=48, pos='C'), Player(name='A10', cost=5500, proj=49, pos='C'), ] mock_nfl_pool = [ Player(name='A1', cost=5500, proj=40, pos='QB'), Player(name='A2', cost=5500, proj=41, pos='QB'), Player(name='A11', cost=5500, proj=50, pos='WR'), Player(name='A3', cost=5500, proj=42, pos='WR'), Player(name='A4', cost=5500, proj=43, pos='WR'), Player(name='A5', cost=5500, proj=44, pos='WR'),
def test_multi_position_group_constraint(): players = [ Player(name='A', cost=5500, proj=400, pos='QB', possible_positions='QB/WR', multi_position=True), Player(name='A', cost=5500, proj=400, pos='WR', possible_positions='QB/WR', multi_position=True), Player(name='B', cost=5500, proj=41, pos='QB'), Player(name='C', cost=5500, proj=500, pos='WR', possible_positions='RB/WR', multi_position=True), Player(name='C', cost=5500, proj=500, pos='RB', possible_positions='RB/WR', multi_position=True), Player(name='D', cost=5500, proj=42, pos='WR'), Player(name='E', cost=5500, proj=43, pos='WR'), Player(name='F', cost=5500, proj=44, pos='WR'), Player(name='G', cost=5500, proj=45, pos='RB'), Player(name='H', cost=5500, proj=46, pos='RB'), Player(name='I', cost=5500, proj=47, pos='RB'), Player(name='J', cost=5500, proj=480, pos='TE', possible_positions='TE/WR', multi_position=True), Player(name='J', cost=5500, proj=480, pos='WR', possible_positions='TE/WR', multi_position=True), Player(name='K', cost=5500, proj=49, pos='TE'), Player(name='L', cost=5500, proj=51, pos='DST'), Player(name='M', cost=5500, proj=52, pos='DST'), ] grouped_players = ('A', 'C', 'J') roster = run(rule_set=rules.DK_NFL_RULE_SET, player_pool=players, constraints=LineupConstraints(groups=[ [grouped_players, 2], ]), verbose=True) group_count = len( [x for x in roster.sorted_players() if x.name in grouped_players]) ntools.assert_equal(group_count, 2) ntools.assert_equal(roster.projected(), 1304)
def _build_mock_player_pool(): player_pool = [ Player(name='A1', cost=5500, proj=100, pos='QB', team='X', matchup='X@Y'), Player(name='A2', cost=5500, proj=41, pos='QB', team='X', matchup='X@Y'), Player(name='A11', cost=5500, proj=50, pos='WR', team='X', matchup='X@Y'), Player(name='A3', cost=5500, proj=42, pos='WR', team='X', matchup='X@Y'), Player(name='A4', cost=5500, proj=43, pos='WR', team='X', matchup='X@Y'), Player(name='A5', cost=5500, proj=44, pos='WR', team='X', matchup='X@Y'), Player(name='A6', cost=5500, proj=45, pos='RB', team='X', matchup='X@Y'), # Test that max players per team works. Everyone # on Y is projected for 1 point, under normal # opto should never be picked. Player(name='A7', cost=5500, proj=1, pos='RB', team='Y', matchup='X@Y'), Player(name='A8', cost=5500, proj=1, pos='RB', team='Y', matchup='X@Y'), Player(name='A9', cost=5500, proj=1, pos='TE', team='Y', matchup='X@Y'), ] def capt_boost(p): return Player( name=p.name, team=p.team, matchup=p.matchup, pos=p.pos, cost=p.cost * 1.5, proj=p.proj * 1.5, ) captain_pool = [capt_boost(p) for p in player_pool] mock_dk_pool = [] for p in player_pool: mock_dk_pool.append(ShowdownPlayer(p)) for p in captain_pool: mock_dk_pool.append(ShowdownPlayer(p, captain=True)) return mock_dk_pool
from draftfast import rules from draftfast.optimize import run from draftfast.orm import Player from draftfast.showdown.orm import ShowdownPlayer player_pool = [ Player(name='A1', cost=5500, proj=100, pos='QB', team='X', matchup='X@Y'), Player(name='A2', cost=5500, proj=41, pos='QB', team='X', matchup='X@Y'), Player(name='A11', cost=5500, proj=50, pos='WR', team='X', matchup='X@Y'), Player(name='A3', cost=5500, proj=42, pos='WR', team='X', matchup='X@Y'), Player(name='A4', cost=5500, proj=43, pos='WR', team='X', matchup='X@Y'), Player(name='A5', cost=5500, proj=44, pos='WR', team='X', matchup='X@Y'), Player(name='A6', cost=5500, proj=45, pos='RB', team='X', matchup='X@Y'), Player(name='A7', cost=5500, proj=46, pos='RB', team='X', matchup='X@Y'), Player(name='A8', cost=5500, proj=47, pos='RB', team='X', matchup='X@Y'), Player(name='A9', cost=5500, proj=48, pos='TE', team='X', matchup='X@Y'), Player(name='A10', cost=5500, proj=49, pos='TE', team='X', matchup='X@Y'), Player(name='A12', cost=5500, proj=51, pos='DST', team='X', matchup='X@Y'), Player(name='A14', cost=5500, proj=40, pos='QB',
from nose import tools as ntools from draftfast.optimize import run from draftfast import rules from draftfast.orm import Player from draftfast.settings import OptimizerSettings, CustomRule mock_nba_pool = [ Player(name='A1', cost=5500, proj=100, pos='PG'), Player(name='A2', cost=5500, proj=41, pos='PG'), Player(name='A100', cost=5500, proj=501, pos='PG'), Player(name='A101', cost=5500, proj=500, pos='PG'), Player(name='A11', cost=5500, proj=50, pos='PG'), Player(name='A3', cost=5500, proj=42, pos='SG'), Player(name='A4', cost=5500, proj=0, pos='SG'), Player(name='A5', cost=5500, proj=44, pos='SF'), Player(name='A6', cost=5500, proj=45, pos='SF'), Player(name='A7', cost=5500, proj=46, pos='PF'), Player(name='A8', cost=5500, proj=47, pos='PF'), Player(name='A9', cost=5500, proj=0, pos='C'), Player(name='A10', cost=5500, proj=49, pos='C'), ] team = 0 for p in mock_nba_pool: team += 1 if p.name in ['A101', 'A100', 'A10']: p.team = 'SomeTeam' else: p.team = str(team)
def _build_mock_player_pool(): player_pool = [ Player(name='A1', cost=5500, proj=100, pos='QB', team='X', matchup='X@Y'), Player(name='A2', cost=5500, proj=41, pos='QB', team='X', matchup='X@Y'), Player(name='A11', cost=5500, proj=50, pos='WR', team='X', matchup='X@Y'), Player(name='A3', cost=5500, proj=42, pos='WR', team='X', matchup='X@Y'), Player(name='A4', cost=5500, proj=43, pos='WR', team='X', matchup='X@Y'), Player(name='A5', cost=5500, proj=44, pos='WR', team='X', matchup='X@Y'), Player(name='A6', cost=5500, proj=45, pos='RB', team='X', matchup='X@Y'), Player(name='A7', cost=5500, proj=46, pos='RB', team='X', matchup='X@Y'), Player(name='A8', cost=5500, proj=47, pos='RB', team='X', matchup='X@Y'), Player(name='A9', cost=5500, proj=48, pos='TE', team='X', matchup='X@Y'), Player(name='A10', cost=5500, proj=49, pos='TE', team='X', matchup='X@Y'), Player(name='A12', cost=5500, proj=51, pos='DST', team='X', matchup='X@Y'), Player(name='A14', cost=5500, proj=40, pos='QB', team='Y', matchup='X@Y'), Player(name='A21', cost=5500, proj=41, pos='QB', team='Y', matchup='X@Y'), Player(name='A11', cost=5500, proj=50, pos='WR', team='Y', matchup='X@Y'), Player(name='A31', cost=5500, proj=42, pos='WR', team='Y', matchup='X@Y'), Player(name='A41', cost=5500, proj=43, pos='WR', team='Y', matchup='X@Y'), Player(name='A51', cost=5500, proj=54, pos='WR', team='Y', matchup='X@Y'), Player(name='A61', cost=5500, proj=45, pos='RB', team='Y', matchup='X@Y'), Player(name='A71', cost=5500, proj=56, pos='RB', team='Y', matchup='X@Y'), Player(name='A81', cost=5500, proj=47, pos='RB', team='Y', matchup='X@Y'), Player(name='A91', cost=5500, proj=48, pos='TE', team='Y', matchup='X@Y'), Player(name='A110', cost=5500, proj=49, pos='TE', team='Y', matchup='X@Y'), Player(name='A112', cost=5500, proj=60, pos='DST', team='Y', matchup='X@Y'), ] def capt_boost(p): return Player( name=p.name, team=p.team, matchup=p.matchup, pos=p.pos, cost=p.cost * 1.5, proj=p.proj * 1.5, ) captain_pool = [capt_boost(p) for p in player_pool] mock_dk_pool = [] for p in player_pool: mock_dk_pool.append(ShowdownPlayer(p)) for p in captain_pool: mock_dk_pool.append(ShowdownPlayer(p, captain=True)) return mock_dk_pool
from draftfast.lineup_contraints import LineupConstraints import csv player_pool = [] with open('input.csv') as inputfile: csvreader = csv.reader(inputfile) isHeader = True for row in csvreader: if isHeader: minSalary = float(row[0]) maxSalary = float(row[1]) lineups = int(row[2]) isHeader = False else: player = Player(name=row[1] + '(' + row[0] + ')', cost=float(row[2]), proj=float(row[5]), pos='D') player_pool.append(player) player_settings = PlayerPoolSettings(min_salary=minSalary, max_salary=maxSalary) rosters = run_multi(lineups, rule_set=rules.FD_NASCAR_RULE_SET, player_pool=player_pool, verbose=True) with open('output.csv', 'w') as outputfile: csvwriter = csv.writer(outputfile) for roster in rosters[0]: players = roster.players cost = players[0].cost + players[1].cost + players[2].cost + players[3].cost + players[4].cost + players[5].cost csvwriter.writerow([players[0].name, players[1].name, players[2].name, players[3].name, players[4].name, players[5].name, cost])
def test_nfl_dk_mock(): mock_dk_pool = [ Player(name='A1', cost=5500, proj=40, pos='QB'), Player(name='A2', cost=5500, proj=41, pos='QB'), Player(name='A11', cost=5500, proj=50, pos='WR'), Player(name='A3', cost=5500, proj=42, pos='WR'), Player(name='A4', cost=5500, proj=43, pos='WR'), Player(name='A5', cost=5500, proj=44, pos='WR'), Player(name='A6', cost=5500, proj=45, pos='RB'), Player(name='A7', cost=5500, proj=46, pos='RB'), Player(name='A8', cost=5500, proj=47, pos='RB'), Player(name='A9', cost=5500, proj=48, pos='TE'), Player(name='A10', cost=5500, proj=49, pos='TE'), Player(name='A12', cost=5500, proj=51, pos='DST'), Player(name='A13', cost=5500, proj=52, pos='DST'), ] roster = run( rule_set=rules.DK_NFL_RULE_SET, player_pool=mock_dk_pool, ) ntools.assert_not_equal(roster, None) ntools.assert_equal(roster.projected(), 420.0)
def test_player_value(): pg = Player(name='A', cost=5500, proj=55, pos='PG') ntools.assert_equal(pg.value, 10)
def construct_pool(): mock_nba_pool = [ Player(name='A1', cost=5500, proj=100, pos='PG'), Player(name='A2', cost=5500, proj=41, pos='PG'), Player(name='A100', cost=5500, proj=501, pos='PG'), Player(name='A101', cost=5500, proj=500, pos='PG'), Player(name='A11', cost=5500, proj=50, pos='PG'), Player(name='A3', cost=5500, proj=42, pos='SG'), Player(name='A4', cost=5500, proj=0, pos='SG'), Player(name='A5', cost=5500, proj=44, pos='SF'), Player(name='A6', cost=5500, proj=45, pos='SF'), Player(name='A7', cost=5500, proj=46, pos='PF'), Player(name='A8', cost=5500, proj=47, pos='PF'), Player(name='A9', cost=5500, proj=0, pos='C'), Player(name='A10', cost=5500, proj=49, pos='C'), ] team = 0 for p in mock_nba_pool: team += 1 if p.name in ['A101', 'A100', 'A10']: p.team = 'SomeTeam' else: p.team = str(team) return mock_nba_pool
def _build_mock_player_pool(): player_pool = [ Player(name='A1', cost=5500, proj=100, pos='QB', team='X', matchup='X@Y'), Player(name='A2', cost=5500, proj=41, pos='QB', team='X', matchup='X@Y'), Player(name='A11', cost=5500, proj=50, pos='WR', team='X', matchup='X@Y'), Player(name='A3', cost=5500, proj=42, pos='WR', team='X', matchup='X@Y'), Player(name='A4', cost=5500, proj=43, pos='WR', team='X', matchup='X@Y'), Player(name='A5', cost=5500, proj=44, pos='WR', team='X', matchup='X@Y'), Player(name='A6', cost=5500, proj=45, pos='RB', team='X', matchup='X@Y'), Player(name='A7', cost=5500, proj=46, pos='RB', team='X', matchup='X@Y'), Player(name='A8', cost=5500, proj=47, pos='RB', team='X', matchup='X@Y'), Player(name='A9', cost=5500, proj=48, pos='TE', team='X', matchup='X@Y'), Player(name='A10', cost=5500, proj=49, pos='TE', team='X', matchup='X@Y'), Player(name='A12', cost=5500, proj=51, pos='DST', team='X', matchup='X@Y'), Player(name='A14', cost=5500, proj=40, pos='QB', team='Y', matchup='X@Y'), Player(name='A21', cost=5500, proj=41, pos='QB', team='Y', matchup='X@Y'), Player(name='A11', cost=5500, proj=50, pos='WR', team='Y', matchup='X@Y'), Player(name='A31', cost=5500, proj=42, pos='WR', team='Y', matchup='X@Y'), Player(name='A41', cost=5500, proj=43, pos='WR', team='Y', matchup='X@Y'), Player(name='A51', cost=5500, proj=54, pos='WR', team='Y', matchup='X@Y'), Player(name='A61', cost=5500, proj=45, pos='RB', team='Y', matchup='X@Y'), Player(name='A71', cost=5500, proj=56, pos='RB', team='Y', matchup='X@Y'), Player(name='A81', cost=5500, proj=47, pos='RB', team='Y', matchup='X@Y'), Player(name='A91', cost=5500, proj=48, pos='TE', team='Y', matchup='X@Y'), Player(name='A110', cost=5500, proj=49, pos='TE', team='Y', matchup='X@Y'), Player(name='A112', cost=5500, proj=60, pos='DST', team='Y', matchup='X@Y'), ] mock_dk_pool = [ShowdownPlayer(p) for p in player_pool] + \ [ShowdownPlayer(p, captain=True) for p in player_pool] return mock_dk_pool