### Full Base Usage Example Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md A complete example demonstrating initialization, loading players from CSV, and generating/printing optimal lineups with their details. ```python optimizer = get_optimizer(Site.YAHOO, Sport.BASKETBALL) optimizer.load_players_from_csv("yahoo-NBA.csv") for lineup in optimizer.optimize(n=10): print(lineup) print(lineup.players) # list of players print(lineup.fantasy_points_projection) print(lineup.salary_costs) ``` -------------------------------- ### Install pydfs-lineup-optimizer with pip Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/installation.md Use this command to install the library. Ensure you have Python 3.6 or later installed. ```bash pip install pydfs-lineup-optimizer ``` -------------------------------- ### Install pydfs-lineup-optimizer Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/README.md Install the pydfs-lineup-optimizer library using pip. ```bash $ pip install pydfs-lineup-optimizer ``` -------------------------------- ### Late-Swap Optimization for FanDuel with Manual Game Start Times Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Performs late-swap optimization for FanDuel by loading lineups from CSV. Since FanDuel doesn't provide game start times, this example shows how to manually mark games as started. ```python csv_filename = "fd_nba.csv" optimizer = get_optimizer(Site.FANDUEL, Sport.BASKETBALL) optimizer.load_players_from_csv(csv_filename) lineups = optimizer.load_lineups_from_csv(csv_filename) locked_teams = {'DET', 'MIA', 'BOS', 'NYK'} for game in optimizer.games: if game.home_team in locked_teams or game.away_team in locked_teams: game.game_started = True for lineup in optimizer.optimize_lineups(lineups): print(lineup) ``` -------------------------------- ### Use GLPK Solver with PuLP Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/performance-and-optimization.md Change the default PuLP solver to GLPK for potentially faster optimization. Ensure GLPK is installed and provide the correct path to the solver executable. ```python # install glpk: https://www.gnu.org/software/glpk/ from pulp import GLPK_CMD # You can find names of other solvers in pulp docs from pydfs_lineup_optimizer.solvers import PuLPSolver class GLPKPuLPSolver(PuLPSolver): LP_SOLVER = GLPK_CMD(path='', msg=False) optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASEBALL, solver=GLPKPuLPSolver) ``` -------------------------------- ### Use MiP Solver Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/performance-and-optimization.md Replace the default PuLP solver with the MiP solver for potentially faster performance, especially when using PyPy. Install MiP via pip: pip install mip. ```python from pydfs_lineup_optimizer.solvers.mip_solver import MIPSolver optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASEBALL, solver=MIPSolver) ``` -------------------------------- ### Generate Optimal Yahoo NBA Lineups Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/README.md Example of generating optimal Yahoo fantasy NBA lineups. Loads players from a CSV file and optimizes for the top 10 lineups. ```python from pydfs_lineup_optimizer import Site, Sport, get_optimizer optimizer = get_optimizer(Site.YAHOO, Sport.BASKETBALL) optimizer.load_players_from_csv("yahoo-NBA.csv") for lineup in optimizer.optimize(10): print(lineup) ``` -------------------------------- ### Get All Players Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Retrieve a list of all loaded players from the optimizer. ```python optimizer.players ``` -------------------------------- ### Get Player by Exact Name Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Retrieve a single player object that has the closest name match to the provided string. ```python optimizer.get_player_by_name('Rodney Hood') ``` -------------------------------- ### Late-Swap Optimization for DraftKings Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Re-optimizes existing lineups for DraftKings by loading lineups from a CSV and then optimizing, locking players whose games have already started. This allows for late swaps. ```python csv_filename = "dk_nba.csv" optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASKETBALL) optimizer.load_players_from_csv(csv_filename) lineups = optimizer.load_lineups_from_csv(csv_filename) for lineup in optimizer.optimize_lineups(lineups): print(lineup) ``` -------------------------------- ### String Representation of a Lineup Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Get a string representation of a lineup object, which includes its details. ```python str(lineup) ``` -------------------------------- ### Retrieve Player from Pool Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Get a specific player from the optimizer's player pool by name, ID, or a combination of name and position. ```python pool = optimizer.player_pool player = pool.get_player_by_name('Tom Brady') # using player name player = pool.get_player_by_id('00000001') # using player id player = pool.get_player_by_name('Tom Brady', 'CPT') # using player name and position ``` -------------------------------- ### Retrieve Multiple Players from Pool Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Get multiple players from the pool using various filtering criteria including names, IDs, PlayerFilter objects for positions, teams, or value thresholds. ```python from pydfs_lineup_optimizer import PlayerFilter pool = optimizer.player_pool players = pool.get_players('Tom Brady', 'Rob Gronkowski', 'Chris Godwin') # get players by name players = pool.get_players('Tom Brady', '00001', pool.get_player_by_name('Rob Gronkowski', 'CPT')) # get players using name, id and player object players = pool.get_players(PlayerFilter(positions=['QB'])) # get all QB players = pool.get_players(PlayerFilter(teams=['Tampa Bay'])) # get all players from team Tampa Bay players = pool.get_players(PlayerFilter(from_value=10, filter_by='fppg')) # get all players with points >= 10 players = pool.get_players(PlayerFilter(teams=['Tampa Bay'], positions=['WR'], from_value=10)) # combined ``` -------------------------------- ### Initialize Optimizer Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Create an optimizer instance by specifying the daily fantasy site and sport. Raises NotImplementedError if the site does not support the sport. ```python from pydfs_lineup_optimizer import get_optimizer, Site, Sport optimizer = get_optimizer(Site.FANDUEL, Sport.BASKETBALL) ``` -------------------------------- ### Initialize LineupOptimizer Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Create an instance of LineupOptimizer, passing the desired settings class as an argument. ```python optimizer = LineupOptimizer(YahooBasketballSettings) ``` -------------------------------- ### Import Optimizer and Settings Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Import the necessary classes, LineupOptimizer and YahooBasketballSettings, to begin optimizing lineups for Yahoo Fantasy NBA. ```python from pydfs_lineup_optimizer import LineupOptimizer, YahooBasketballSettings ``` -------------------------------- ### Define Custom Sport Settings Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/custom-settings.md Create a custom settings class by inheriting from BaseSettings to define parameters for a new sport or DFS site. This includes site name, sport name, budget, and allowed lineup positions. ```python from pydfs_lineup_optimizer import LineupOptimizer from pydfs_lineup_optimizer.settings import BaseSettings, LineupPosition class CustomSettings(BaseSettings): site = 'Site Name' sport = 'Sport Name' budget = 100 # budget you want to use max_from_one_team = None # if needed min_teams = None # if needed min_games = None # if needed csv_importer = None # If player will be imported using load_players_from_csv method positions = [ LineupPosition('G', ('PG', 'SG')), ] optimizer = LineupOptimizer(CustomSettings) ``` -------------------------------- ### Iterate Through Optimized Lineups Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Loop through the generated lineups to access player details, fantasy points projection, and salary costs for each lineup. ```python lineups = optimizer.optimize(n=10) for lineup in lineups: print(lineup.lineup) # list of players print(lineup.fantasy_points_projection) print(lineup.salary_costs) ``` -------------------------------- ### Set Minimum Starters Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Ensure a minimum number of starters are included in each lineup. Players can be marked as starters via the Player object or a CSV column. ```python optimizer.set_min_starters(4) ``` -------------------------------- ### Advanced Lineup Generation with Player Constraints Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Demonstrates advanced usage by loading players from CSV, filtering the player pool, setting individual player max exposures, locking specific players, and then optimizing lineups. ```python optimizer = get_optimizer(Site.YAHOO, Sport.BASKETBALL) optimizer.load_players_from_csv("yahoo-NBA.csv") pool = optimizer.player_pool for player in pool.get_players(PlayerFilter(positions=['C'], teams=['Nets'])): pool.remove_player(player) # Remove all Nets centers from optimizer harden = pool.get_player_by_name('Harden') westbrook = pool.get_player_by_name('Westbrook') # Get Harden and Westbrook harden.max_exposure = 0.6 westbrook.max_exposure = 0.4 # Set exposures for Harden and Westbrook optimizer.lock_player(harden) optimizer.lock_player(westbrook) # Lock Harden and Westbrook for lineup in optimizer.optimize(n=10, max_exposure=0.3): print(lineup) ``` -------------------------------- ### Optimize Lineups (Default) Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Generate optimal lineups. If n is not specified, it returns a generator yielding all possible lineups from highest to lowest fppg. ```python lineups = optimizer.optimize(n=10) ``` -------------------------------- ### Optimize Lineups with AfterEachExposureStrategy Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Generates lineups with a specified maximum exposure per player, applying the exposure calculation after each lineup is generated. This can lead to unordered lineups but ensures better distribution. ```python from pydfs_lineup_optimizer import AfterEachExposureStrategy lineups = optimizer.optimize(n=10, max_exposure=0.3, exposure_strategy=AfterEachExposureStrategy) ``` -------------------------------- ### Load Players from List Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Load players into the optimizer by providing a list of Player objects to the player_pool.load_players method. ```python from pydfs_lineup_optimizer import Player optimizer.player_pool.load_players(players) # players is list of Player objects ``` -------------------------------- ### Optimize Lineups with Team Constraint Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Generate optimal lineups while enforcing constraints, such as a maximum number of players from a specific team. ```python lineups = optimizer.optimize(teams={'OKC': 4}) ``` -------------------------------- ### Load Players from CSV Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Load player data into the optimizer from a CSV file. The CSV format must match the export file format of the DFS site. Raises NotImplementedError for sites without CSV export. ```python optimizer.load_players_from_csv("path_to_csv") ``` -------------------------------- ### Load Players from CSV Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Load player data into the optimizer by providing the path to a CSV file downloaded from your DFS site. ```python optimizer.load_players_from_CSV("path_to_csv") ``` -------------------------------- ### Decrease Optimization Complexity with Player Filters Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/performance-and-optimization.md Reduce solving time by filtering the player pool based on fppg, efficiency, and salary. Exclude specific teams to further narrow down the optimization scope. ```python optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASEBALL) optimizer.load_players_from_csv('dk_mlb.csv') optimizer.player_pool.add_filters( PlayerFilter(from_value=5), # use only players with points >= 5 PlayerFilter(from_value=2, filter_by='efficiency'), # and efficiency(points/salary) >= 2 PlayerFilter(from_value=2000, filter_by='salary'), # and salary >= 3000 ) optimizer.player_pool.exclude_teams(['Seattle Mariners']) for lineup in optimizer.optimize(100): print(lineup) ``` -------------------------------- ### Set Player Exposure Limits Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Set maximum and minimum exposure percentages for individual players or globally for all players during optimization. Exposure can be set directly on Player objects or via optimize method parameters. ```python player = optimizer.player_pool.get_player_by_name('Tom Brady') player.max_exposure = 0.5 # set 50% max exposure player.min_exposure = 0.3 # set 30% min exposure lineups = optimizer.optimize(n=10, max_exposure=0.3) # set 30% exposure for all players ``` -------------------------------- ### Add Custom Player Group Stack Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Create custom stacking rules by grouping specific players. This allows for targeted stacks with defined exposure limits. ```python rodgers_adams_group = PlayersGroup(optimizer.player_pool.get_players('Aaron Rodgers', 'Davante Adams'), max_exposure=0.5) brees_thomas_group = PlayersGroup(optimizer.player_pool.get_players('Drew Brees', 'Michael Thomas'), max_exposure=0.5) optimizer.add_stack(Stack([rodgers_adams_group, brees_thomas_group])) ``` -------------------------------- ### Export Lineups to CSV Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Generates lineups and then exports them to a CSV file. This can be done either by printing lineups to the console first or by directly optimizing and exporting. ```python from pydfs_lineup_optimizer import get_optimizer, Site, Sport, CSVLineupExporter optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASKETBALL) optimizer.load_players_from_csv("players.csv") # if you want to see lineups on screen for lineup in optimizer.optimize(10): print(lineup) optimizer.export('result.csv') # if you don't need to see lineups on screen lineups = list(optimizer.optimize(10)) optimizer.export('result.csv') ``` -------------------------------- ### Add Game Stack Rule Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Configure stacking rules to include a specified number of players from the same game in a lineup. Can also enforce minimum players per team within the game stack. ```python optimizer.add_stack(GameStack(3)) # stack 3 players from the same game ``` ```python optimizer.add_stack(GameStack(5, min_from_team=2)) # stack 5 players from the same game, 3 from one team and 2 from another ``` -------------------------------- ### Print Optimization Statistics Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Prints a summary of player statistics based on the generated lineups to the console. This is useful for reviewing player usage after optimization. ```default optimizer.print_statistic() ``` -------------------------------- ### Add Players to a Group Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Use this snippet to create a group of players and add them to the optimizer. This is useful for ensuring specific players are considered together. ```python group = PlayersGroup(optimizer.player_pool.get_players('LeBron James', 'Anthony Davis')) optimizer.add_players_group(group) ``` -------------------------------- ### Group Players with a Maximum Limit Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md This snippet demonstrates how to group players while also specifying a maximum number of players from that group that can be included in a lineup. Useful for scenarios where you want to select at most one player from a set. ```python group = PlayersGroup(optimizer.player_pool.get_players('LeBron James', 'Anthony Davis'), max_from_group=1) optimizer.add_players_group(group) ``` -------------------------------- ### Exclude Duplicate Lineups from Optimization Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Generates a set of initial lineups and then optimizes further while excluding those already generated. This helps avoid duplicate lineups in the final results. ```python # Setup optimizer lineups = set(optimizer.optimize(5)) # Change optimizer settings or players settings lineups.update(optimizer.optimize(5, exclude_lineups=lineups)) for lineup in lineups: print(lineup) optimizer.print_statistic() optimizer.export('export.csv') ``` -------------------------------- ### Set Minimum Salary Cap Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Enforces a minimum total salary for the generated lineups. If the minimum salary cap exceeds the maximum budget, a LineupOptimizerException will be raised. ```python optimizer.set_min_salary_cap(49000) ``` -------------------------------- ### Set Random Fantasy Points Strategy with Custom Deviation Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Applies a random fantasy points strategy with a specified maximum deviation. Individual player deviations and projection ranges can also be set. ```python optimizer.set_fantasy_points_strategy(RandomFantasyPointsStrategy(max_deviation=0.2)) # set random strategy with custom max_deviation harden = optimizer.player_pool.get_player_by_name('Harden') harden.min_deviation = 0.3 harden.max_deviation = 0.6 # Set different deviation for player westbrook = optimizer.player_pool.get_player_by_name('Westbrook') westbrook.min_deviation = 0 # Disable randomness for this player westbrook.max_deviation = 0 doncic = optimizer.player_pool.get_player_by_name('Doncic') doncic.fppg_floor = 60 # Randomize using projection range doncic.fppg_ceil = 90 lineups = optimizer.optimize(n=10) ``` -------------------------------- ### Add Player to Lineup Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Add a specific player object to the lineup, even if the optimizer would not have selected them otherwise. ```python optimizer.add_player_to_lineup(player) ``` -------------------------------- ### Find Players by Name Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Search for players with names similar to the provided string. ```python optimizer.find_players('james') ``` -------------------------------- ### Reset Lineup Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Clear the current lineup using the reset_lineup method. ```python optimizer.reset_lineup() ``` -------------------------------- ### Set Progressive Fantasy Points Strategy Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Applies a progressive fantasy points strategy that increases player points based on unselected instances. Custom progressive scales can be set for individual players. ```python optimizer.set_fantasy_points_strategy(ProgressiveFantasyPointsStrategy(0.01)) # Set progressive strategy that increase player points by 1% optimizer.player_pool.get_player_by_name('Stephen Curry').progressive_scale = 0.02 # For curry points will be increased by 2% ``` -------------------------------- ### Set Minimum and Maximum Total Teams Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Control the total number of teams included in the generated lineups. You can specify a minimum, maximum, or an exact number of teams. ```python optimizer.set_total_teams(min_teams=4) # At least 4 teams should be in the lineup ``` ```python optimizer.set_total_teams(max_teams=6) # Maximum 6 teams should be in the lineup ``` ```python optimizer.set_total_teams(min_teams=5, max_teams=6) # 5 or 6 teams should be in the lineup ``` ```python optimizer.set_total_teams(min_teams=5, max_teams=5) # Exact 5 teams should be in the lineup ``` -------------------------------- ### Add Team Stack Rule Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Configure stacking rules to include a specific number of players from the same team in a lineup. Supports specifying teams, positions, and exposure limits. ```python optimizer.add_stack(TeamStack(3)) # stack 3 players ``` ```python optimizer.add_stack(TeamStack(3, for_teams=['NE', 'BAL', 'KC'])) # stack 3 players from any of specified teams ``` ```python optimizer.add_stack(TeamStack(3, for_positions=['QB', 'WR', 'TE'])) # stack 3 players with any of specified positions ``` ```python optimizer.add_stack(TeamStack(3, spacing=2)) # stack 3 players close to each other in range of 2 spots. ``` ```python optimizer.add_stack(TeamStack(3, max_exposure=0.5)) # stack 3 players from same team with 0.5 exposure for all team stacks ``` ```python optimizer.add_stack(TeamStack(3, max_exposure=0.5, max_exposure_per_team={'MIA': 0.6})) # stack 3 players from same team with 0.5 exposure for all team stacks and 0.6 exposure for MIA ``` -------------------------------- ### Set Spacing for Positions Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Selects players based on their lineup order, ensuring they are close to each other within a specified range. Useful for sports like baseball. ```python optimizer.set_spacing_for_positions(['1B', '2B', '3B'], 3) ``` -------------------------------- ### Set Max Players with Same Position Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Configure the maximum number of players allowed for a specific position. This is particularly useful for sites with multi-position slots. Note: This rule has no effect on sites without multi-position slots. ```python optimizer.set_players_with_same_position({'PG': 2}) ``` -------------------------------- ### Add Positions Stack Rule Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Create stacking rules based on a specific list of player positions from the same team. Supports filtering by teams and setting exposure limits. ```python optimizer.add_stack(PositionsStack(['QB', 'WR'])) # stack QB and WR from same team ``` ```python optimizer.add_stack(PositionsStack(['QB', ('WR', 'TE')])) # stack QB and WR or TE from same team ``` ```python optimizer.add_stack(PositionsStack(['QB', 'WR'], for_teams=['NO', 'MIA', 'KC'])) # stack QB and WR for one of provided teams ``` ```python optimizer.add_stack(PositionsStack(['QB', 'WR'], max_exposure=0.5)) # stack QB and WR with 0.5 exposure for all team stacks ``` ```python optimizer.add_stack(PositionsStack(['QB', 'WR'], max_exposure=0.5, max_exposure_per_team={'MIA': 0.6})) # stack QB and WR with 0.5 exposure for all team stacks and 0.6 exposure for MIA ``` -------------------------------- ### Set Max Players from One Team Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Use this method to enforce a limit on the number of players selected from a single team. It accepts a dictionary mapping team names to the maximum allowed players. ```python optimizer.set_players_from_one_team({'OKC': 4}) ``` -------------------------------- ### Set Maximum Team Exposures Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Limit the number of lineups a player from a specific team can appear in. This can be set globally or for individual teams. ```python optimizer.set_teams_max_exposures(0.5) # Set 0.5 exposure for all teams ``` ```python optimizer.set_teams_max_exposures(0.5, exposures_by_team={'NYY': 0.8}) # Set 0.5 exposure for all teams except NYY and 0.8 exposure for NYY ``` ```python optimizer.set_teams_max_exposures(exposures_by_team={'NYY': 0.8}) # Set 0.5 exposure only for NYY ``` ```python optimizer.set_teams_max_exposures(exposures_by_team={'NYY': 0.5, 'NYM': 0.5}, exposure_strategy=AfterEachExposureStrategy) # Use another exposure strategy ``` -------------------------------- ### Lock Players for Lineups Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Lock specific players into lineups using their name, ID, or player object. Players can also be locked for a specific position. ```python optimizer.player_pool.lock_player('Tom Brady') # using player name optimizer.player_pool.lock_player('ID00001') # using player id tom_brady_captain = optimizer.player_pool.get_player_by_name('Tom Brady', position='CPT') optimizer.player_pool.lock_player(tom_brady_captain) # using player optimizer.player_pool.lock_player('Chris Godwin', 'FLEX') # Lock Chris Godwin on FLEX position # Locked players can be unlocked as well optimizer.player_pool.unlock_player('Tom Brady') ``` -------------------------------- ### Set Maximum Repeating Players Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Introduces a constraint to prevent combinations of players that have appeared in previous lineups, promoting more random lineups. Accepts the number of maximum repeating player combinations. ```python optimizer.set_max_repeating_players(5) ``` -------------------------------- ### Conditional Player Grouping Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md This snippet shows how to create a player group that is conditionally added to the lineup based on the selection of another player. The `strict_depend` argument can be set to `False` to allow the group to be included even if the dependent player is not selected. ```python group = PlayersGroup( optimizer.player_pool.get_players('Tyreek Hill', 'Travis Kelce'), max_from_group=1, depends_on=optimizer.player_pool.get_player_by_name('Patrick Mahomes'), strict_depend=False, # if you want to generate lineups with Hill/Kelce but without Mahomes ) optimizer.add_players_group(group) ``` -------------------------------- ### Set Projected Ownership Constraint Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Limits the average projected ownership of players within generated lineups. Ensure player projected ownership is set before calling this method. It accepts maximum and minimum projected ownership percentages. ```python for player in optimizer.players: player.projected_ownership = 0.1 optimizer.set_projected_ownership(max_projected_ownership=0.6) ``` -------------------------------- ### Exclude Players and Teams Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Remove specific players or entire teams from the optimization process. Players and teams can be restored if needed. ```python optimizer.player_pool.remove_player('Tom Brady') optimizer.player_pool.restore_player('Tom Brady') optimizer.player_pool.exclude_teams(['Jets']) ``` -------------------------------- ### Force Players from Opposing Team by Position Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Ensures that players from opposing teams are included based on specified position pairings. Accepts tuples of positions. ```python optimizer.force_positions_for_opposing_team(('QB', 'WR')) ``` -------------------------------- ### Set Timezone for Date Parsing Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/usage.md Sets the timezone used by the library for parsing game dates. Defaults to 'US/Eastern' for DraftKings. ```python from pydfs_lineup_optimizer import set_timezone set_timezone('UTC') ``` -------------------------------- ### Restrict Players from Same Team by Position Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Applies constraints to prevent selecting multiple players from the same team who occupy specific positions. Accepts tuples of positions to restrict. ```python optimizer.restrict_positions_for_same_team(('RB', 'RB')) ``` ```python optimizer.restrict_positions_for_same_team(('QB', 'DST'), ('RB', 'DST')) ``` -------------------------------- ### Remove Player from Lineup Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Remove a specific player object from the current lineup. This operation may throw a LineupOptimizerException if it's not possible. ```python optimizer.remove_player_from_lineup(player) ``` -------------------------------- ### Remove Player from List Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/wiki/Home Remove a specific player object from the optimizer's player list. ```python optimizer.remove_player(player) ``` -------------------------------- ### Restrict Players from Opposing Teams Source: https://github.com/dimakudosh/pydfs-lineup-optimizer/blob/master/docs/rules.md Prevents lineups containing players from opposing teams, such as pitchers and hitters from the same game. This method accepts lists of positions for each team and an optional maximum number of opposing players allowed. ```python optimizer.restrict_positions_for_opposing_team(['P'], ['C', 'SS', 'OF', '1B', '2B', '3B']) ``` ```python optimizer.restrict_positions_for_opposing_team(['P'], ['C', 'SS', 'OF', '1B', '2B', '3B'], 1) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.