pydfs-lineup-optimizer
pydfs-lineup-optimizer copied to clipboard
Error When Setting Max Exposure To 0
Hello, I am optimizing lineups for tonight's NBA slate and I wanted to set max exposure for a particular player to zero, in effect removing him from my player pool. However, I get a Key Error for that player when attempting to do so. I don't want to set the projection to zero because my projections column has a formula. Maybe this is a bug in the code?
KeyError Traceback (most recent call last)
----> 7 for lineup in optimizer.optimize(10): 8 print(lineup) 9 #optimizer.export('entries.csv')
~/python/site-packages/pydfs_lineup_optimizer/lineup_optimizer.py in optimize(self, n, max_exposure, randomness, with_injured, exposure_strategy) 375 constraints = [constraint(self, players_dict, context) for constraint in rules] 376 for constraint in constraints: --> 377 constraint.apply(base_solver) 378 previous_lineup = None 379 for _ in range(n):
~/python/site-packages/pydfs_lineup_optimizer/rules.py in apply(self, solver) 561 variable = solver.add_variable('total_game_%s_%s' % (game.home_team, game.away_team)) 562 game_variables.append(variable) --> 563 variables = [self.players_dict[player] for player in game_players] 564 solver.add_constraint(variables, None, SolverSign.LTE, variable * total_players) 565 solver.add_constraint(variables, None, SolverSign.GTE, variable)
~/python3.8/site-packages/pydfs_lineup_optimizer/rules.py in
I'm not exactly sure how to set max exposure to 0 but would the drop feature do the trick? It's what I use to exclude players from my player pool.
drop = optimizer.get_player_by_name('Player Name') optimizer.remove_player(drop)
I'm having the same issue. Works fine with FanDuel, but getting that key error in DraftKings.
Find the player with get_player_by_id
and then use optimizer.remove_player
If you want to remove them all in one fell swoop, then you could use the following:
for p in optimizer.players:
if p.max_exposure == 0:
optimizer.remove_player(p)
This method has the benefit of not needing to find a player by name or id, you can just pass the player object itself to remove_player when max_exposure is zero.
Find the player with
get_player_by_id
and then useoptimizer.remove_player
If you want to remove them all in one fell swoop, then you could use the following:for p in optimizer.players: if p.max_exposure == 0: optimizer.remove_player(p)
This method has the benefit of not needing to find a player by name or id, you can just pass the player object itself to remove_player when max_exposure is zero.
Hmm maybe i did something wrong, but that didn't seem to work for me. I set max_exposure to 0 and then copy and pasted your code as written. Still got 100% of the player.