Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Late Swap #398

Open
chrisbach1 opened this issue Dec 31, 2022 · 16 comments
Open

Late Swap #398

chrisbach1 opened this issue Dec 31, 2022 · 16 comments

Comments

@chrisbach1
Copy link

Has anyone ever had a problem with Late Swap on NBA? It seems like my optimizer will get stuck and stop running. I removed all Exposures and restrictions but it just stops after a few lineups are built. Here is my error:

File "C:\Users\chris\Desktop\Own\LATE_SWAP.PY", line 27, in
for lineup in optimizer.optimize_lineups(lineups):
File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 494, in optimize_lineups
generated_lineup = self._build_lineup(lineup_players, context, unswappable_players)
File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 534, in _build_lineup
players_with_positions = link_players_with_positions(players, positions)
File "C:\Users\chris\AppData\Local\Programs\Python\Python310\lib\site-packages\pydfs_lineup_optimizer\utils.py", line 109, in link_players_with_positions
raise LineupOptimizerException('Unable to build lineup')
pydfs_lineup_optimizer.exceptions.LineupOptimizerException: Unable to build lineup
*

@lightninglarry
Copy link

I hadnt tried to use my late swap code yet this season. It had been 10 months since i used it, and tried last night on the NBA slate as Ja Morant was scratched.

Got the same error you got. Code worked last season.

@Dr-Two-Inch
Copy link

It stopped because the loop most likely hit a lineup with all players that could not be swapped remove those with a preliminary step and it should work.

@chrisbach1
Copy link
Author

@Dr-Two-Inch - is there an easy way to know which lineups have all players who's games have started? If I have a csv with 150 lineups generated all I can see is player ID's. That would take me hours to weed out certain lineups.

@Denwen12
Copy link

Denwen12 commented Jan 20, 2023 via email

@Dr-Two-Inch
Copy link

@chrisbach1 - I'm sure there is a better programmatic solution but right now I just use a quick excel function ( COUNTIF(E2:L2,"(LOCKED)") ) to look at each lineup in my DKEntries.csv file and manually remove any lineup that has all 8 players locked. It does take some time it makes the process a lot faster than manually inspecting every cell.

@lightninglarry
Copy link

@Dr-Two-Inch This is brilliant. I just want to make sure im following your instructions.
Grab the csv after lock and use your excel function to spot all 9 spots locked. Delete those rows, so the optimizer wont be stopped because of this. Say you had 150 lineups, and you deleted 25 lineups/rows. Then you would just optimize 125 and copy/paste over the 125 rows remaining in your DKEntries.csv file, that way it never touches the 25 where theres nothing to do the lineup since all are locked.

Am i correct?
This would have been great last night as we had like 5 or more guys scratched due to the upcoming all star break.

@Dr-Two-Inch
Copy link

@lightninglarry That's it for the most part if the function reads 8 delete the row, what works best for me is to sort by the column with the function in it (smallest - largest) then delete the rows with 8 spots locked all at once. This way is also important because the solver will also encounter an issue if there is an empty row as well.

@Dr-Two-Inch
Copy link

@lightninglarry & @chrisbach1 to clarify one thing all of this only works after the game has actually tipped that way the DKEntries file will read "In progress" for the locked players. So for example typically between the 6 and 6:30 pm game locks, I will not actually download the DKEntries file until ~6:15 pm.

@lightninglarry
Copy link

@Dr-Two-Inch i assume you would use same steps if playing on Fanduel as well?

@Dr-Two-Inch
Copy link

@lightninglarry There are some minor differences for how FD handles lock times and locked players but the concepts should all stay the same. I would encourage you to practice on a short slate where you expect much less news like tonight (3-game slate) for example.

@lightninglarry
Copy link

lightninglarry commented Feb 24, 2023

So I got my late swap functioning, much props @Dr-Two-Inch .
Fanduel is a bigger hurdle.
After slate locks, and you download the live csv, it just gives you numbers 3333-3333 as a players id. No name, no nothing. So unless you know who 3333-3333 is , you have no idea if his game has started. on DK it will say (LOCKED) after players name so you can tell.

Only thing I can say is to run the latevswap and if it doesn't crash, you didn't have all 9 spots locked, if it crashes, well I dont know then. Late swap in nba is usually a mad dash versus time and unless I'm missing something it would be hard to determine if all 9 spots are filled just looking at the live csv.

@chrisbach1
Copy link
Author

chrisbach1 commented Mar 10, 2023

I wrote a script to remove all the rows from the csv if all players are locked. Takes like a second to run. Let me know if you guys are interested. I can post the code

If you want to do a lateswap, you have to redownload your "EDIT ENTRIES" csv from draftkings. Thats where it will contain all the locked lineups.

I only use it for NBA just FYI

@lightninglarry
Copy link

im game to try it out @chrisbach1 .

Do you have any advice for my FD issue from my comment above when it doesnt say locked at all on live entries from Fanduel?

@chrisbach1
Copy link
Author

Im not sure about fanduel. I dont use it too often. I would need a sample csv with lineups currently in progress

@chrisbach1
Copy link
Author

import csv

with open('DKEntries.csv', 'r') as input_file, open('output.csv', 'w', newline='') as output_file:
reader = csv.reader(input_file)
writer = csv.writer(output_file)

headers = next(reader)
writer.writerow(headers)

for row in reader:
    if all('LOCKED' in cell for cell in row[4:12]):
        continue
    writer.writerow(row)

@chrisbach1
Copy link
Author

This will read your Draftkings file and it needs to be labeled 'DKEntries'. It will then create a new csv without the rows that have all positions locked. The output csv is titles 'output.csv'

The output.csv needs to be where you are fetching lineups from in the latewap feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants