DimaKudosh / pydfs-lineup-optimizer

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

How To Use Multiple Player Groups #293

Closed kryptickevin closed 3 years ago

kryptickevin commented 3 years ago

Currently when using the following code from @DimaKudosh for constraining ownership in my lineups, I am only able to execute it successfully for one group.

optimizer.add_players_group(PlayersGroup( players=[player for player in optimizer.players if player.projected_ownership <= 0.05], min_from_group=1, max_from_group=2, ))

Ideally I would have 3-4 more of these groups with different ownership levels. How would I achieve this?

lightninglarry commented 3 years ago

optimizer.add_players_group(PlayersGroup( players=[player for player in optimizer.players if player.projected_ownership <= 0.05], min_from_group=1, max_from_group=2, ))

how do u get that to work, ive tried this and heres the error i get:

TypeError: '<=' not supported between instances of 'NoneType' and 'float'

how is your projected_ownership field look like? .25 25%, how do you have it set up?

kryptickevin commented 3 years ago

Can you show me your current Python script? It might be something else that is messing with this.

My column in my csv is named "Projected Ownership" and it is in decimal form, so 20% is .2.

On Thu, Sep 9, 2021, 6:45 PM lightninglarry @.***> wrote:

optimizer.add_players_group(PlayersGroup( players=[player for player in optimizer.players if player.projected_ownership <= 0.05], min_from_group=1, max_from_group=2, ))

how do u get that to work, ive tried this and heres the error i get:

TypeError: '<=' not supported between instances of 'NoneType' and 'float'

how is your projected_ownership field look like? .25 25%, how do you have it set up?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/293#issuecomment-916490686, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARXSUG6CMQMRTN4LVJUVOM3UBE2H5ANCNFSM5DXKKSBA .

lightninglarry commented 3 years ago

https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/283

kryptickevin commented 3 years ago

Where in your script is this block of code though? I only see this same block of code.

Copy and paste your whole python script, remove your custom stuff of you want.

lightninglarry commented 3 years ago

from pydfs_lineup_optimizer import get_optimizer, Site, Sport, CSVLineupExporter from pydfs_lineup_optimizer.stacks import TeamStack, PositionsStack, PlayersGroup from pydfs_lineup_optimizer import AfterEachExposureStrategy

class CustomExporter(CSVLineupExporter): @staticmethod def render_player(player): result = f'{player.id}:{player.full_name}' if player.lineup_position != 'UTIL': result += f' - {player.lineup_position}' return result

optimizer = get_optimizer(Site.FANDUEL, Sport.FOOTBALL) optimizer.settings.csv_exporter = CustomExporter # replace default exporter with custom optimizer.load_players_from_csv(r"C:\Users\brand\Desktop\PYTHON\NFL\wk1\FanDuel-NFL-2021 ET-09 ET-12 ET-62415-players-list.csv")

optimizer.add_players_group(PlayersGroup( players=[player for player in optimizer.players if player.projected_ownership <= 0.05], min_from_group=1, max_from_group=2, ))

rodgers_adams_group = PlayersGroup([optimizer.get_player_by_name(name) for name in ('Aaron Rodgers', 'Davante Adams')], max_exposure=0.5)

optimizer.add_stack(PositionsStack(['QB', ('WR', 'TE')])) # stack QB and WR or TE from same team

optimizer.add_stack(PositionsStack(['QB', 'TE'], for_teams=['KC'])) # stack QB and TE for one of provided teams

optimizer.add_stack(PositionsStack(['QB', 'WR'], for_teams=['MIN', 'ARI', 'BUF', 'CIN'])) # stack QB and WR for one of provided teams

optimizer.set_deviation(0.4, 0.12) # i think this is the randomness feature

optimizer.add_stack(PositionsStack(['QB', 'WR', ('WR', 'TE')], for_teams=['MIN', 'ARI', 'BUF', 'CIN']))

optimizer.add_stack(TeamStack(3, for_positions=['QB', 'WR', 'TE'], for_teams=['MIN', 'ARI', 'BUF', 'CIN'])) # stack 3 players with any of specified positions

optimizer.set_min_salary_cap(59500) optimizer.set_max_repeating_players(7) optimizer.restrict_positions_for_same_team(('QB', 'D'), ('RB', 'WR'),('RB', 'RB')) optimizer.force_positions_for_opposing_team(('QB', 'WR')) optimizer.restrict_positions_for_opposing_team(('RB'),('RB'))

lineups = optimizer.optimize(100 , max_exposure=0.50 , exposure_strategy=AfterEachExposureStrategy) for lineup in lineups: print(lineup) optimizer.export(r"C:\Users\brand\Desktop\PYTHON\NFL\NFLFANDUEL.csv") optimizer.print_statistic()

kryptickevin commented 3 years ago

Can you confirm the name of your ownership column in your csv file is "Projected Ownership"? Can you also confirm that you have someone with less than 5% projected ownership? Change the min_from_group=1 to min_from_group=0 and see if it will run.

lightninglarry commented 3 years ago

Can you confirm the name of your ownership column in your csv file is "Projected Ownership"? Can you also confirm that you have someone with less than 5% projected ownership? Change the min_from_group=1 to min_from_group=0 and see if it will run. @kryptickevin

still get same error when i change to your suggestion my field in csv is called projected_ownership with 22.5 in the field of csv representing 22.5%


TypeError Traceback (most recent call last)

in 15 optimizer.load_players_from_csv(r"C:\Users\brand\Desktop\PYTHON\NFL\wk1\FanDuel-NFL-2021 ET-09 ET-12 ET-62415-players-list.csv") 16 ---> 17 optimizer.add_players_group(PlayersGroup( players=[player for player in optimizer.players if player.projected_ownership <= 5], min_from_group=0, max_from_group=2)) 18 19 #rodgers_adams_group = PlayersGroup([optimizer.get_player_by_name(name) for name in ('Aaron Rodgers', 'Davante Adams')], max_exposure=0.5) in (.0) 15 optimizer.load_players_from_csv(r"C:\Users\brand\Desktop\PYTHON\NFL\wk1\FanDuel-NFL-2021 ET-09 ET-12 ET-62415-players-list.csv") 16 ---> 17 optimizer.add_players_group(PlayersGroup( players=[player for player in optimizer.players if player.projected_ownership <= 5], min_from_group=0, max_from_group=2)) 18 19 #rodgers_adams_group = PlayersGroup([optimizer.get_player_by_name(name) for name in ('Aaron Rodgers', 'Davante Adams')], max_exposure=0.5) TypeError: '<=' not supported between instances of 'NoneType' and 'int'
kryptickevin commented 3 years ago

I believe you are incorrectly naming your column in your csv. See this code:

@classmethod def get_player_extra(cls, row: Dict[str, str]) -> Dict[str, Any]: roster_order = row.get('Roster Order') fppg_floor = row.get('Projection Floor') fppg_ceil = row.get('Projection Ceil') return { 'max_exposure': cls._parse_percents(row.get('Max Exposure')), 'min_exposure': cls._parse_percents(row.get('Min Exposure')), 'roster_order': int(roster_order) if roster_order else None, 'projected_ownership': cls._parse_percents(row.get('Projected Ownership')), 'min_deviation': cls._parse_percents(row.get('Min Deviation')), 'max_deviation': cls._parse_percents(row.get('Max Deviation')), 'is_confirmed_starter': bool(row.get('Confirmed Starter')), 'fppg_floor': float(fppg_floor) if fppg_floor else None, 'fppg_ceil': float(fppg_ceil) if fppg_ceil else None, 'progressive_scale': cls._parse_percents(row.get('Progressive Scale')), }

It is looking for a column in your csv named "Projected Ownership" and you have named it "projected_ownership". Try switching it to "Projected Ownership" and see if it works for you.

lightninglarry commented 3 years ago

@kryptickevin i think you are right, anyway you can email me to help me with something about this file?

larry.mcdonald002@gmail.com

kryptickevin commented 3 years ago

Done.