BenBrostoff / draftfast

A tool to automate and optimize DraftKings and FanDuel lineup construction.
277 stars 113 forks source link

NOT an issue. a suggestion #200

Closed NahomKun closed 1 year ago

NahomKun commented 1 year ago

Another user alluded this but they did not go in full detail. I was wondering if its possible to set a global max exposure meaning players without specified max or min exposure are capped at n percent exposure while players with specified max and min exposure are subject to those constraints. Thanks.

BenBrostoff commented 1 year ago

It's definitely possible and I have a few scripts I use that does exactly this so you can implement with draftfast but at this point not part of the core library. My recommendation would be something like the following

rosters = []
constraints = some_initial_constraints

for r in range(iterations):
    roster = run(
        rule_set=ruleset,
        player_pool=player_pool,
        constraints=constraints,
        optimizer_settings=settings.OptimizerSettings(
            existing_rosters=rosters,
        ),
    )
    rosters.append(roster)

    # As a side effect, update your constraints every iteration
    _update_exposure_settings(
        selected_players,
        max_player_exposure, # This is a list of dicts [{ player, min_exp, max_exp }, ...]
        iterations,
        rosters,
        constraints,
        exposure_list, # This tracks your existing exposure
    )

So each roster iteration, you need to recompute:

Let me know if this is helpful! There are multiple ways to implement this that take a stance on how it should be done (mainly all need to have an opinion on how diverse your lineups are - if you try to increase exposure to players on subsequent iterations, for instance, you'll wind up with that player grouped with the same players). The many ways to implement is why I have avoided adding in core library and generally do this as a consulting service upon request so I can adjust to specific asks.

NahomKun commented 1 year ago

appreciate the quick response. I tried implementing the code u provided, however, I get an error. Not sure if i am applying it properly. Can you tell me how i can go about fixing this issue where the two players are fixed at .4 and .6 exposure while setting the rest of the player pool at max exposure of .4. I have attached file and code below.

`players = salary_download.generate_players_from_csvs( salary_file_location='/path/to/file/Projection/projections/DKNBA.csv', game=rules.DRAFT_KINGS, )

rosters = [] constraints = exposure_bounds=[ { 'name': 'Stephen Curry', 'min': 0.4, 'max': 0.6, }, { 'name': 'Bogdan Bogdanovic', 'min': 0.4, 'max': 0.6, }, ]

for r in range(20): roster = run_multi( iterations=20, rule_set=rules.DK_NBA_RULE_SET, player_pool=players, constraints=constraints, ) rosters.append(roster)

# As a side effect, update your constraints every iteration
_update_exposure_settings(
    selected_players,
    max_player_exposure, # This is a list of dicts [{ player, min_exp, max_exp }, ...]
    iterations,
    rosters,
    constraints,
    exposure_list,
)`

DKNBA.csv

BenBrostoff commented 1 year ago

What's the error? If you send the full code in a repl.it or something like that with everything running this might be easier to debug.

NahomKun commented 1 year ago

There is no error, I was just having a hard time implementing the code how i wanted however I got it to work. Now I am having a hard time writing my fanduel nba lineups to my local for upload. Am I required to have a specific file ready? I thought it would write the lineups to a csv file in the path given by creating its own file. Thanks :)

BenBrostoff commented 1 year ago

Did you use FanDuelNBAUploader? https://github.com/BenBrostoff/draftfast/blob/master/draftfast/csv_parse/uploaders.py#L147-L171 . There is a test that shows example usage here https://github.com/BenBrostoff/draftfast/blob/b6072a98927863b9b465501a118525f50ec61827/draftfast/test/test_csv_upload.py#L113-L134

NahomKun commented 1 year ago

When i run the code below the optimizer works as intended but when I run the upload line I get an error saying "InvalidCSVUploadFileException: Check that you're using the DK CSV upload template, which can be found at https://www.draftkings.com/lineup/upload." and I just dont understand what DK has anything to do with Fanduel upload hence why i asked if i need to have a file pre existing for an override. I also ran the test code and the code runs without an error but there is no file written on my computer. I feel like i am missing something and i just dont know what

file: FDNBA.csv

players = salary_download.generate_players_from_csvs(
    salary_file_location='/Projection/projections/FDNBA.csv',
    game=rules.FAN_DUEL,
)

rosters= run_multi(
    iterations=20,
    rule_set=rules.FD_NBA_RULE_SET,
    player_pool=players,
    verbose=True,
    constraints=LineupConstraints(
        locked=['Chris Paul'],

    ),
    exposure_bounds=[
        {
            'name': 'Drew Eubanks',
            'min': 0.1,
            'max': 0.5
        },
    ],
)

upload=uploaders.FanDuelNBAUploader(
    pid_file='/Save/to/Desktop/fd-nba-pids.csv',
)
upload.write_rosters(rosters)