DimaKudosh / pydfs-lineup-optimizer

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

Still having trouble uploading lineups from exported csv to FanDuel #131

Closed BenikaH closed 4 years ago

BenikaH commented 4 years ago

Was the FanDuel ID format changed in the CSVLineupExporter in 2.7.0? Still can't upload the lineups generated using 2.7. Gives an Invalid entry error.

I'm thinking its because the ID is no longer Name(ID) but it is now ID:Name. Any thoughts here?

Denwen12 commented 4 years ago

how does your export look?, cause mine uploads fine

BenikaH commented 4 years ago

nba-rand-1.xlsx

BenikaH commented 4 years ago

The players are printed like this;

Trae Young(42351-84671)

Is yours that way as well?

Denwen12 commented 4 years ago

can I see the code your using to print

BenikaH commented 4 years ago

for lineup in lineups: print(lineup)
exporter = CSVLineupExporter(lineups) exporter.export('/Users/BH/Downloads/nba-rand-1.csv')

Denwen12 commented 4 years ago

for lineup in lineups: print(lineup) exporter = CSVLineupExporter(lineups) exporter.export('/Users/BH/Downloads/nba-rand-1.csv', lambda p: p.id)

Try that and let me know if that worked

BenikaH commented 4 years ago

Ok I’ll try when I get home. Yours doesn’t export that way?

Denwen12 commented 4 years ago

no mine just exports id

BenikaH commented 4 years ago

No, that gives an error. TypeError: __init__() takes 2 positional arguments but 3 were given

Denwen12 commented 4 years ago

exporter.export('/Users/BH/Downloads/nba-rand-1.csv', p.id)

see what that does

Denwen12 commented 4 years ago

I'll check mine at home in an hour for you

BenikaH commented 4 years ago

That is odd.

Denwen12 commented 4 years ago

what is odd?

Denwen12 commented 4 years ago

i noticed you had a question about grouping players but i cant seem to get that right... Have you and gotten that to work?

BenikaH commented 4 years ago

Oh, its odd that its printing the names at all. Maybe because I'm getting the players by name. Sure, go to this post, Sansbacon offered a great solution for the two scenarios I wanted. https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/105#issuecomment-540873508

Denwen12 commented 4 years ago

i tryed adding the code but its not working for me

BenikaH commented 4 years ago

`from pydfs_lineup_optimizer import get_optimizer, Site, Sport, CSVLineupExporter optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASKETBALL) optimizer.load_players_from_csv('/Users/bc/Downloads/DKSalaries (8).csv')

optimizer.set_team_stacking([2,2])

optimizer.set_teams_max_exposure({team: 0.45 for team in optimizer.available_teams})

optimizer.set_min_salary_cap(49000)

optimizer.set_max_repeating_players(5)

optimizer.remove_player_from_lineup(optimizer.get_player_by_name('Davante Adams'))

lineups=[]

make a list of list of desired combinations

player_groups = [['James Harden', 'C.J. McCollum','Hassan Whiteside' ], ['James Harden','Russell Westbrook', 'Derrick Favors']]#,['Lou Williams','Jayson Tatum', 'Montrezl Harrell']] n = 20

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, randomness=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)

exporter = CSVLineupExporter(lineups)`

Denwen12 commented 4 years ago

how does your python code look when you run it, i tryed all kinds of ways to use that

BenikaH commented 4 years ago

Try that above. I started with NFL and then used the same approach with NBA.

Denwen12 commented 4 years ago

okay testing now

Denwen12 commented 4 years ago

seems to not like me for group in player_groups: ... File "", line 2

^

IndentationError: expected an indented block

for group in player_groups: ... for player_name in group: ... optimizer.add_player_to_lineup(optimizer.get_player_by_name(player_name)

BenikaH commented 4 years ago

Now, that I'm thinking about it. It may be because I'm getting the player by the name and printing it that way. I'll have to adjust it then because FD does not like it the way it prints out.

BenikaH commented 4 years ago

That's because of the code marks. ` from pydfs_lineup_optimizer import get_optimizer, Site, Sport, CSVLineupExporter optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASKETBALL) optimizer.load_players_from_csv('/Users/bc/Downloads/DKSalaries (8).csv')

optimizer.set_team_stacking([2,2])

optimizer.set_teams_max_exposure({team: 0.45 for team in optimizer.available_teams})

optimizer.set_min_salary_cap(49000)

optimizer.set_max_repeating_players(5)

optimizer.remove_player_from_lineup(optimizer.get_player_by_name('Davante Adams'))

lineups=[]

make a list of list of desired combinations

player_groups = [['James Harden', 'C.J. McCollum','Hassan Whiteside' ], ['James Harden','Russell Westbrook', 'Derrick Favors']]#,['Lou Williams','Jayson Tatum', 'Montrezl Harrell']] n = 20

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, randomness=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)

exporter = CSVLineupExporter(lineups)

`

Denwen12 commented 4 years ago

i must of gotten something to work but now i get

Traceback (most recent call last): File "/usr/local/lib/python3.7/dist-packages/pydfs_lineup_optimizer/lineup_optimizer.py", line 305, in remove_player_from_lineup self._lineup.remove(player) ValueError: list.remove(x): x not in list

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "Fanduel.py", line 31, in optimizer.remove_player_from_lineup(optimizer.get_player_by_name(player_name)) File "/usr/local/lib/python3.7/dist-packages/pydfs_lineup_optimizer/lineup_optimizer.py", line 307, in remove_player_from_lineup raise LineupOptimizerException('Player not in line up!') pydfs_lineup_optimizer.exceptions.LineupOptimizerException: Player not in line up! root@localhost:~#

BenikaH commented 4 years ago

Check the player groups you have and the csv you're using. Make sure the player is there in the csv.

Denwen12 commented 4 years ago

can you check over the python script? i have the guys in the import file

import pulp from pulp.solvers import COIN_CMD from pydfs_lineup_optimizer import get_optimizer, Site, Sport,CSVLineupExporter from pydfs_lineup_optimizer.solvers.pulp_solver import PuLPSolver import time

start_time = time.time()

class COIN_CMDSolver(PuLPSolver): LP_SOLVER = COIN_CMD(msg=0)

optimizer = get_optimizer(Site.FANDUEL, Sport.BASKETBALL, solver=COIN_CMDSolver) optimizer.load_players_from_csv('/root/Downloads/players-list.csv')

optimizer.set_team_stacking([2,2])

optimizer.set_teams_max_exposure({team: 0.45 for team in optimizer.available_teams})

optimizer.set_min_salary_cap(59000)

optimizer.set_max_repeating_players(5)

optimizer.remove_player_from_lineup(optimizer.get_player_by_name('Davante Adams'))

player_groups = [['John Collins', 'Trae Young','Cam Reddish' ], ['Tristan Thompson','Kevin Love', 'Collin Sexton'],['Dwight Powell','Luka Doncic', 'Tim Hardaway']] n = 20

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, randomness=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)

BenikaH commented 4 years ago

Let me check, hold on.

Denwen12 commented 4 years ago

or i could be thinking this wrong i want groups of players together during optimizing

Denwen12 commented 4 years ago

i get this now pydfs_lineup_optimizer.exceptions.LineupOptimizerException: You're already select all C's

Denwen12 commented 4 years ago

i got it too work a little but its only using the first group

BenikaH commented 4 years ago

Oh yeah, remove one of the Centers and re-run.

BenikaH commented 4 years ago

You're thinking of it correctly. I don't have all of the solvers installed so I had to install them.

Denwen12 commented 4 years ago

finally got it working

BenikaH commented 4 years ago

Good. How does your csv look? Name and ID or just IDs?

Denwen12 commented 4 years ago
PG PG SG SG SF SF PF PF C Budget FPPG
42769-84671 42769-84667 42769-19067 42769-15595 42769-110339 42769-80809 42769-9874 42769-66236 42769-14501 59800 297.183
42769-84671 42769-84667 42769-19067 42769-15595 42769-110339 42769-15904 42769-9874 42769-66236 42769-14501 59800 293.619
Denwen12 commented 4 years ago

i am on fanduel by the way

Denwen12 commented 4 years ago

i can check on draftkings if thats what your useing to make sure

Denwen12 commented 4 years ago

draftkings sould be like this

PG SG SF PF C G F UTIL
Donte DiVincenzo (14151787) Spencer Dinwiddie (14151732) Khris Middleton (14151721) Derrick Favors (14151728) Brook Lopez (14151764) Kyrie Irving (14151707) Wilson Chandler (14151841) Giannis Antetokounmpo (14151692)
Denwen12 commented 4 years ago

for lineup in lineups: print(lineup) exporter = CSVLineupExporter(lineups) exporter.export('/root/result.csv', lambda p: p.id)

BenikaH commented 4 years ago

Wow, so why is mine doing the Name and ID like that? What line do have for exporter?

Denwen12 commented 4 years ago

change the directory

Denwen12 commented 4 years ago

let me know what you get

BenikaH commented 4 years ago

Now it works! I must have had an old version cached. I re-installed 2.7.0 and ignored old versions. Then I put in the lambda p: p.id and it worked. Before, it would throw a Type error. Thanks.

Denwen12 commented 4 years ago

your welcome and thanks for the help also

BenikaH commented 4 years ago

No problem! I want to ask you about COINMD solver. I'll send outside of this thread.

Denwen12 commented 4 years ago

anytime