-
Notifications
You must be signed in to change notification settings - Fork 156
Home
Installing pydfs-lineup-optimizer is simple with pip, just run this in your terminal:
$ pip install pydfs-lineup-optimizer
Creating optimal lineups with pydfs-lineup-optimizer is very simple. Begin by importing Optimizer and Settings from the pydfs_lineup_optimizer module. For example, if you want optimize lineup for Yahoo Fantasy NBA it will look like this:
>>> from pydfs_lineup_optimizer import LineupOptimizer, YahooBasketballSettings
and now you can create optimizer. Optimizer constructor takes only settings argument:
optimizer = LineupOptimizer(YahooBasketballSettings)
Now you must load player list. Firstly you must download csv file from your dfs site and then pass path to it to your optimizer:
optimizer.load_players_from_CSV("path_to_csv")
You can get all players:
optimizer.players
And remove some players from list using remove player method:
optimizer.remove_player(player)
Also if you want to add some player for your lineup even optimizer doesn't select it you can do it using add_player_to_lineup, and remove it using remove_player_from_lineup:
optimizer.add_player_to_lineup(player)
optimizer remove_player_from_lineup(player)
If it's impossible to add or remove player for some reasons it's will throw LineupOptimizerException.
Then you can optimize lineup using optimize method:
optimizer.optimize()
If you want some players from same team or from same position you can add unnecessary teams or positions arguments. This arguments are dictionaries where key name of team/position and value number of players for this team/position:
optimizer.optimize(teams={'OKC': 4})
If it's impossible to evaluate optimal lineup it will throw LineupOptimizerException. Now you can get all players from your lineup and projection/budget for your lineup:
optimizer.lineup
optimizer.lineup_fantasy_points_projection
optimizer.lineup_salary_costs
Or can output your lineup to console using print_lineup method:
optimizer.print_lineup()
You can clear your lineup using reset_lineup method:
optimizer.reset_lineup()