class DraftKingsNascarSettings(DraftKingsSettings): sport = Sport.NASCAR lineup_printer = IndividualSportLineupPrinter positions = [ LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), ]
class DraftKingsTennisSettings(DraftKingsSettings): sport = Sport.TENNIS lineup_printer = IndividualSportLineupPrinter positions = [ LineupPosition('P', ('P',)), LineupPosition('P', ('P',)), LineupPosition('P', ('P',)), LineupPosition('P', ('P',)), LineupPosition('P', ('P',)), LineupPosition('P', ('P',)), ]
class DraftKingsGolfSettings(DraftKingsSettings): sport = Sport.GOLF lineup_printer = IndividualSportLineupPrinter positions = [ LineupPosition('G', ('G',)), LineupPosition('G', ('G',)), LineupPosition('G', ('G',)), LineupPosition('G', ('G',)), LineupPosition('G', ('G',)), LineupPosition('G', ('G',)), ]
class DraftKingsMMA(DraftKingsSettings): sport = Sport.MMA lineup_printer = IndividualSportLineupPrinter positions = [ LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), ]
class DraftKingsWNBASettings(DraftKingsSettings): sport = Sport.WNBA min_games = 2 positions = [ LineupPosition('G', ('PG', 'SG')), LineupPosition('G', ('PG', 'SG')), LineupPosition('F', ('SF', 'PF')), LineupPosition('F', ('SF', 'PF')), LineupPosition('F', ('SF', 'PF')), LineupPosition('UTIL', ('PG', 'SG', 'PF', 'SF', 'C')) ]
class DraftKingsCaptainModeSettings(BaseSettings): site = Site.DRAFTKINGS_CAPTAIN_MODE budget = 50000 max_from_one_team = 5 positions = [ LineupPosition('CPT', ('CPT', )), LineupPosition('UTIL', ('UTIL', )), LineupPosition('UTIL', ('UTIL', )), LineupPosition('UTIL', ('UTIL', )), LineupPosition('UTIL', ('UTIL', )), LineupPosition('UTIL', ('UTIL', )), ]
class FanDuelLOLSettings(FanDuelSettings): sport = Sport.LEAGUE_OF_LEGENDS max_from_one_team = None min_teams = None csv_importer = FanDuelMVPCSVImporter extra_rules = [FanduelSingleGameMVPRule] # type: List[Type[OptimizerRule]] positions = [ LineupPosition('MVP', ('TOP', 'MID', 'ADC', 'JNG', 'SUP', 'TEAM'), for_rank=PlayerRank.MVP), LineupPosition('TOP', ('TOP', )), LineupPosition('MID', ('MID', )), LineupPosition('ADC', ('ADC', )), LineupPosition('JNG', ('JNG', )), LineupPosition('SUP', ('SUP', )), LineupPosition('TEAM', ('TEAM', )), ]
class FanDuelGolfSettings(FanDuelSettings): sport = Sport.GOLF max_from_one_team = None extra_rules = [] # type: List[Type[OptimizerRule]] lineup_printer = IndividualSportLineupPrinter positions = [ LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), ]
class DraftKingsShowdownGolfModeSettings(BaseSettings): site = Site.DRAFTKINGS_SHOWDOWN_GOLF budget = 50000 max_from_one_team = 6 csv_importer = DraftKingsShowdownGolfModeCSVImporter positions = [ LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), ]
class DraftKingsFormula1Settings(DraftKingsSettings): sport = Sport.F1 max_from_one_team = 2 csv_importer = DraftKingsCaptainModeCSVImporter lineup_printer = IndividualSportLineupPrinter positions = [ LineupPosition('CPT', ('CPT', )), LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), LineupPosition('CNSTR', ('CNSTR', )), ]
class DraftKingsCollegeFootballSettings(DraftKingsSettings): sport = Sport.CANADIAN_FOOTBALL min_games = 2 positions = [ LineupPosition('QB', ('QB', )), LineupPosition('RB', ('RB', )), LineupPosition('RB', ('RB', )), LineupPosition('WR', ('WR', )), LineupPosition('WR', ('WR', )), LineupPosition('WR', ('WR', )), LineupPosition('FLEX', ( 'RB', 'WR', )), LineupPosition('SUPER FLEX', ( 'QB', 'RB', 'WR', )), ]
class DraftKingsCanadianFootballSettings(DraftKingsSettings): sport = Sport.CANADIAN_FOOTBALL positions = [ LineupPosition('QB', ('QB', )), LineupPosition('RB', ('RB', )), LineupPosition('WR', ('WR', )), LineupPosition('WR', ('WR', )), LineupPosition('FLEX', ( 'RB', 'WR', )), LineupPosition('FLEX', ( 'RB', 'WR', )), LineupPosition('DST', ('DST', )), ]
class DraftKingsCSGOSettings(DraftKingsSettings): sport = Sport.CS max_from_one_team = 3 min_games = 2 csv_importer = DraftKingsCaptainModeCSVImporter lineup_printer = IndividualSportLineupPrinter positions = [ LineupPosition('CPT', ('CPT', )), LineupPosition('FLEX', ('FLEX', )), LineupPosition('FLEX', ('FLEX', )), LineupPosition('FLEX', ('FLEX', )), LineupPosition('FLEX', ('FLEX', )), LineupPosition('FLEX', ('FLEX', )), ]
class FanDuelMMASettings(FanDuelSettings): sport = Sport.MMA max_from_one_team = None min_teams = None budget = 100 csv_importer = FanDuelMVPCSVImporter lineup_printer = IndividualSportLineupPrinter positions = [ LineupPosition('MVP', ('MVP', )), LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), ]
class FanDuelLOLSettings(FanDuelSettings): sport = Sport.LEAGUE_OF_LEGENDS max_from_one_team = 4 min_teams = 3 csv_importer = build_fanduel_single_game_importer(mvp=False, star=True, pro=False) extra_rules = [FanduelSingleGameStarRule ] # type: List[Type[OptimizerRule]] positions = [ LineupPosition('STAR', ('TOP', 'MID', 'ADC', 'JNG', 'SUP'), for_rank=PlayerRank.STAR), LineupPosition('TOP', ('TOP', )), LineupPosition('JNG', ('JNG', )), LineupPosition('MID', ('MID', )), LineupPosition('ADC', ('ADC', )), LineupPosition('SUP', ('SUP', )), LineupPosition('TEAM', ('TEAM', )), ]
def test_optimizer_positions_processing(self): positions = [ LineupPosition('1', ('1', )), LineupPosition('2', ('2', )), LineupPosition('3', ('3', )), LineupPosition('23', ('2', '3')), LineupPosition('23', ('2', '3')), LineupPosition('all', ('1', '2', '3')), LineupPosition('all', ('1', '2', '3')), ] test_settings = type('TestSettings', (settings.BaseSettings, ), {}) test_settings.positions = positions optimizer = LineupOptimizer(test_settings, None) positions = optimizer.get_positions_for_optimizer() self.assertEqual(len(positions), 7) self.assertEqual(positions[('1', )], 1) self.assertEqual(positions[('2', )], 1) self.assertEqual(positions[('3', )], 1) self.assertEqual(positions[('2', '3')], 4) self.assertEqual(positions[('1', '2')], 2) self.assertEqual(positions[('1', '3')], 2) self.assertEqual(positions[('1', '2', '3')], 7)
def LineUpOptimizer(site, count, export): oSite = Site.FANDUEL # if site == 'DraftKings': # oSite = Site.DRAFTKINGS # elif site == 'Yahoo': # oSite = Site.YAHOO oSport = Sport.FOOTBALL optimizer = get_optimizer(oSite, oSport) # Players # players = GetPlayersFromRotoWire(site) # players = GetPlayersFromFile(export) page = open(os.path.dirname(os.path.abspath(__file__)) + '/' + export + '_players.json', 'r').read() # page = open(os.path.dirname(os.path.abspath(__file__)) + '/' + '_players.json', 'r').read() data = json.loads(page) [players, in_players, ex_players] = GetPlayersFromJSON(data['players'], data['exposures']) optimizer.load_players(players) # Include / Exclude Players for player in in_players: optimizer.add_player_to_lineup(player) for player in ex_players: optimizer.remove_player(player) # Settings settings = data['settings'] if settings['min_salary'] != '': optimizer.set_min_salary_cap(int(settings['min_salary'])) if settings['max_salary'] != '': optimizer.settings.budget = float(settings['max_salary']) if settings['min_projection'] != '': # optimizer.min_projected_ownership = int(settings['min_projection']) optimizer.set_projected_ownership(min_projected_ownership=float(settings['min_projection'])) if settings['allow_players']: pass positions = [] if settings['position_rb'] is True: positions.append('RB') if settings['position_wr'] is True: positions.append('WR') if settings['position_te'] is True: positions.append('TE') # if len(positions) > 0: # optimizer.set_spacing_for_positions(positions, 1) optimizer.settings.positions = [ LineupPosition('QB', ('QB',)), LineupPosition('RB', ('RB',)), LineupPosition('RB', ('RB',)), LineupPosition('WR', ('WR',)), LineupPosition('WR', ('WR',)), LineupPosition('WR', ('WR',)), LineupPosition('TE', ('TE',)), LineupPosition('FLEX', positions), LineupPosition('D', ('D',)) ] # optimizer.set_players_with_same_position({'RB': 0}) # Stacks stacks = data['stacks'] teams = GetTeamsFromJson(data['players']) positions = GetPositionsFromJson(data['players']) optimizer.settings.max_from_one_team = 5 for stack in stacks: stack_teams = list(filter(lambda x: x in teams, stack['includeTeams'])) stack_positions = list(filter(lambda x: x in positions, stack['includePositions'])) # print(stack_teams) # print(stack_positions) if stack['scaleStandard'] == 'At least': # for stack_count in range(int(stack['scaleNumber']), 5): # optimizer.add_stack(TeamStack(stack_count, for_teams=stack_teams, for_positions=stack_positions)) optimizer.add_stack(TeamStack(int(stack['scaleNumber']), for_teams=stack_teams, for_positions=stack_positions)) # pass else: # for stack_count in range(0, int(stack['scaleNumber'])): # optimizer.add_stack(TeamStack(stack_count, for_teams=stack_teams, for_positions=stack_positions)) optimizer.settings.max_from_one_team = int(stack['scaleNumber']) # pass result = [] for lineup in optimizer.optimize(count): inresult = [] for lineupplayer in lineup.players: i = players.index(lineupplayer) inresult.append(players[i].id) result.append(inresult) # pass # print(json.dumps(result)) optimizer.export(os.path.dirname(os.path.abspath(__file__)) + '/../download/' + export + '.csv') return result
class YahooSoccerSettings(YahooSettings): sport = Sport.SOCCER positions = [ LineupPosition('GK', ('GK', )), LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), LineupPosition('D', ('D', )), LineupPosition('M', ('M', )), LineupPosition('M', ('M', )), LineupPosition('M', ('M', )), LineupPosition('M', ('M', )), LineupPosition('F', ('F', )), LineupPosition('F', ('F', )), LineupPosition('UTIL', ('D', 'M', 'F')), ]
from pydfs_lineup_optimizer.settings import BaseSettings, LineupPosition from pydfs_lineup_optimizer.constants import Sport, Site from pydfs_lineup_optimizer.sites.sites_registry import SitesRegistry from pydfs_lineup_optimizer.sites.draftkings.captain_mode.importer import DraftKingsCaptainModeCSVImporter POSITIONS_WITH_FLEX = [ LineupPosition('CPT', ('CPT', )), LineupPosition('FLEX', ('FLEX', )), LineupPosition('FLEX', ('FLEX', )), LineupPosition('FLEX', ('FLEX', )), LineupPosition('FLEX', ('FLEX', )), LineupPosition('FLEX', ('FLEX', )), ] class DraftKingsCaptainModeSettings(BaseSettings): site = Site.DRAFTKINGS_CAPTAIN_MODE budget = 50000 max_from_one_team = 5 csv_importer = DraftKingsCaptainModeCSVImporter positions = [ LineupPosition('CPT', ('CPT', )), LineupPosition('UTIL', ('UTIL', )), LineupPosition('UTIL', ('UTIL', )), LineupPosition('UTIL', ('UTIL', )), LineupPosition('UTIL', ('UTIL', )), LineupPosition('UTIL', ('UTIL', )), ] @SitesRegistry.register_settings
from pydfs_lineup_optimizer.settings import BaseSettings, LineupPosition from pydfs_lineup_optimizer.constants import Sport, Site from pydfs_lineup_optimizer.sites.sites_registry import SitesRegistry from pydfs_lineup_optimizer.sites.draftkings.showdown.importer import DraftKingsShowdownGolfModeCSVImporter POSITIONS = [ LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), ] class DraftKingsShowdownGolfModeSettings(BaseSettings): site = Site.DRAFTKINGS_SHOWDOWN_GOLF budget = 50000 max_from_one_team = 6 csv_importer = DraftKingsShowdownGolfModeCSVImporter positions = [ LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), LineupPosition('G', ('G', )), ] @SitesRegistry.register_settings