DimaKudosh / pydfs-lineup-optimizer

Daily Fantasy Sports lineup optimzer for all popular daily fantasy sports sites
MIT License
418 stars 157 forks source link

Is there a way to accept a list of groups? #105

Closed BenikaH closed 4 years ago

BenikaH commented 4 years ago

I want to know is there a way to pass in groups of players that may not be on the same team. For instance, if I want to group Christian McCaffrey and Dalvin Cook and do another group with Matt Ryan, Hooper and Ridley. I want to optimize with both of those groups but not necessarily in the same lineup. Give me all optimal lineups for all groups I pass to the optimizer. Ex. one lineup may have Matt Ryan, Fournette, McCoy, Ridley, Landry, Tate, Hooper, Zeke and Steelers and another lineup may have Dak, McCaffrey, Cook, Beckham, Shepard, Boyd, Zeke and Bucs. Is this functionality available?

sansbacon commented 4 years ago

Do you want to specify the groups ahead of time or randomly assign the groups from a pool?

If you specify the groups ahead of time, it would look something like this:

lineups = []

# make a list of list of desired combinations
player_groups = [['Christian McCaffrey', 'Dalvin Cook'], 
                            ['Matt Ryan', 'Austin Hooper', 'Calvin Ridley']]

n = 10

for group in player_groups:
    for player_name in group:
        optimizer.add_player_to_lineup(optimizer.get_player_by_name(player_name))
    for lineup in optimizer.optimize(n, randomize=True):
        lineups.append(lineup)
    for player_name in group:
        optimizer.remove_player_from_lineup(optimizer.get_player_by_name(player_name))

for lineup in lineups:
    print(lineup)

If you want to randomize the groups, it would look something like this:

from itertools import combinations
import random

lineups = []
pool = ['Christian McCaffrey', 'Dalvin Cook', 
            'Matt Ryan', 'Austin Hooper', 'Calvin Ridley']
n_iterations = 10
n_combos = 10

combinations = list(combinations(pool, 2)) + list(combinations(pool, 3)) 

for combo in random.sample(combinations, n_combos):
    for player_name in combo:
        optimizer.add_player_to_lineup(optimizer.get_player_by_name(player_name))
    for lineup in optimizer.optimize(n_iterations, randomize=True):
        lineups.append(lineup)
    for player_name in combo:
        optimizer.remove_player_from_lineup(optimizer.get_player_by_name(player_name))

for lineup in lineups:
    print(lineup)
BenikaH commented 4 years ago

@sansbacon Yes, this is exactly what I was looking to do. At the moment I was only getting one big group which is not the expected result. Thanks so much. I can close this question.

Denwen12 commented 1 year ago

Hey @sansbacon I like @BenikaH idea there ultimately can we change that out for a position stack combos?