pydfs-lineup-optimizer icon indicating copy to clipboard operation
pydfs-lineup-optimizer copied to clipboard

optimizer.restrict_positions_for_same_team(('RB', 'RB'))

Open lightninglarry opened this issue 2 years ago • 17 comments

Getting ready for nfl season , and this might have been addressed. This code works, but it will allow a RB into the flex/util from same team. How do your restrict that?

example Nick Chubb at RB1, Kareem Hunt at FLEX/UTIL?

lightninglarry avatar Jul 16 '21 20:07 lightninglarry

Hi, what optimizer are you using? If you do restrict_positions_for_same_team(('RB', 'RB')) it shouldn't allow to add RB as FLEX from same team. RB is the name of player position, not position slot in dfs site.

DimaKudosh avatar Jul 19 '21 19:07 DimaKudosh

Not sure which version @DimaKudosh , how can i tell? I just did this sample run from Fanduel(used an csv from last season where i changed 2 rbs from the panthers(mccaffrey and m.davis) spit out 2 lineups

  1. QB Kyler Murray QB ARI ARI@CAR 28.38 8400.0$
  2. RB Nick Chubb RB CLE CLE@DAL 99.0 8300.0$
  3. RB Mike Davis RB CAR ARI@CAR 661.0 6300.0$
  4. WR Tyler Lockett WR SEA SEA@MIA 20.633 7500.0$
  5. WR Kenny Golladay WR DET NO@DET 14.7 7300.0$
  6. WR Andy Isabella WR ARI ARI@CAR 12.9 5000.0$
  7. TE Tyler Higbee TE LAR NYG@LAR 12.8 6000.0$
  8. FLEX Christian McCaffrey RB CAR ARI@CAR 199.0 6000.0$
  9. DEF Indianapolis Colts D IND IND@CHI 15.0 4900.0$

Fantasy Points 1063.41 Salary 59700.00

  1. QB Dak Prescott QB DAL CLE@DAL 28.973 8200.0$
  2. RB Nick Chubb RB CLE CLE@DAL 99.0 8300.0$
  3. RB Mike Davis RB CAR ARI@CAR 661.0 6300.0$
  4. WR Tyler Lockett WR SEA SEA@MIA 20.633 7500.0$
  5. WR Stefon Diggs WR BUF BUF@LV 16.933 7000.0$
  6. WR Cedrick Wilson WR DAL CLE@DAL 25.2 5000.0$
  7. TE Mark Andrews TE BAL BAL@WAS 9.133 7400.0$
  8. FLEX Christian McCaffrey RB CAR ARI@CAR 199.0 6000.0$
  9. DEF Arizona Cardinals D ARI ARI@CAR 99.0 3800.0$

lightninglarry avatar Jul 19 '21 21:07 lightninglarry

May I ask how you came up with those fantasy points?

Denwen12 avatar Jul 19 '21 22:07 Denwen12

most of them are just their fppg on the season, although i changed chubb, mccaffrey, davis, and hunt just to test to see if it would put rbs from same team in lineup, it does unfortunately

lightninglarry avatar Jul 19 '21 22:07 lightninglarry

Could you provide a full code sample?

DimaKudosh avatar Jul 20 '21 17:07 DimaKudosh

@DimaKudosh from pydfs_lineup_optimizer import get_optimizer, Site, Sport, CSVLineupExporter, PositionsStack, PlayersGroup

class CustomExporter(CSVLineupExporter): @staticmethod def render_player(player): result = f'{player.id}:{player.full_name}' if player.lineup_position != 'UTIL': result += f' - {player.lineup_position}' return result

optimizer = get_optimizer(Site.FANDUEL, Sport.FOOTBALL) optimizer.settings.csv_exporter = CustomExporter # replace default exporter with custom optimizer.load_players_from_csv(r"C:\Users\brand\Desktop\PYTHON\NFL\fdnfl.csv")

kyler = optimizer.get_player_by_name("Kyler Murray") optimizer.add_player_to_lineup(kyler) kyler.max_exposure = 1 kyler.max_exposure = .10

#rodgers_adams_group = PlayersGroup([optimizer.get_player_by_name(name) for name in ('Aaron Rodgers', 'Davante Adams')], max_exposure=0.5) #optimizer.add_stack(PositionsStack(['QB', ('WR', 'TE')])) # stack QB and WR or TE from same team optimizer.add_stack(PositionsStack(['QB', 'TE'], for_teams=['LAR'])) # stack QB and TE for one of provided teams optimizer.add_stack(PositionsStack(['QB', 'WR'], for_teams=['DAL', 'ARI', 'BUF', 'GB'])) # stack QB and WR for one of provided teams optimizer.set_min_salary_cap(59500) optimizer.set_max_repeating_players(7) optimizer.restrict_positions_for_same_team(('QB', 'D'), ('RB', 'RB')) optimizer.force_positions_for_opposing_team(('QB', 'WR'), ('WR', 'WR')) lineups = optimizer.optimize(n=10) for lineup in lineups: print(lineup) optimizer.export(r"C:\Users\brand\Desktop\PYTHON\NFL\NFLFANDUEL.csv") import pandas as pd df = pd.read_csv(r"C:\Users\brand\Desktop\PYTHON\NFL\NFLFANDUEL.csv") optimizer.print_statistic()

lightninglarry avatar Jul 20 '21 22:07 lightninglarry

I can't reproduce this bug. Are you using the latest version of library?

DimaKudosh avatar Jul 21 '21 18:07 DimaKudosh

how do you i know @DimaKudosh . im a noob at this. Do i just re run the install pydfs line again at the top?

lightninglarry avatar Jul 21 '21 18:07 lightninglarry

from pydfs_lineup_optimizer import __version__
print(__version__)

DimaKudosh avatar Jul 21 '21 18:07 DimaKudosh

3.4.0

How do i run the 3.5 latest version? again im a noob and appreciate your help.

lightninglarry avatar Jul 21 '21 21:07 lightninglarry

pip install pydfs-lineup-optimizer -U

DimaKudosh avatar Jul 22 '21 17:07 DimaKudosh

awesome @DimaKudosh was able to update, now with the same above code the lineups dont come through, but this error.

GenerateLineupException: Can't generate lineups. Following constraints are not valid: max_from_one_team_MIN,max_from_one_team_DET,max_from_one_team_CAR,max_from_one_team_LV

lightninglarry avatar Jul 22 '21 22:07 lightninglarry

You have the code wrong

On Thu, Jul 22, 2021, 6:27 PM lightninglarry @.***> wrote:

awesome @DimaKudosh https://github.com/DimaKudosh was able to update, now with the same above code the lineups dont come through, but this error.

GenerateLineupException: Can't generate lineups. Following constraints are not valid: max_from_one_team_MIN,max_from_one_team_DET,max_from_one_team_CAR,max_from_one_team_LV

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/279#issuecomment-885276193, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANBWO7WG3CYUPTAYZNWROPDTZCLOTANCNFSM5AQHZARA .

Denwen12 avatar Jul 22 '21 23:07 Denwen12

You have the code wrong On Thu, Jul 22, 2021, 6:27 PM lightninglarry @.***> wrote: awesome @DimaKudosh https://github.com/DimaKudosh was able to update, now with the same above code the lineups dont come through, but this error. GenerateLineupException: Can't generate lineups. Following constraints are not valid: max_from_one_team_MIN,max_from_one_team_DET,max_from_one_team_CAR,max_from_one_team_LV — You are receiving this because you commented. Reply to this email directly, view it on GitHub <#279 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANBWO7WG3CYUPTAYZNWROPDTZCLOTANCNFSM5AQHZARA .

can you help a brother out @Denwen12 .

lightninglarry avatar Jul 23 '21 01:07 lightninglarry

can anyone pinpoint what is wrong with the above code? I comment some things out and it runs, but not all together.

lightninglarry avatar Aug 06 '21 22:08 lightninglarry

Can you post your whole code

On Fri, Aug 6, 2021, 6:20 PM lightninglarry @.***> wrote:

can anyone pinpoint what is wrong with the above code? I comment some things out and it runs, but not all together.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/279#issuecomment-894546673, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANBWO7RZBXLG2DU7NRSY4ATT3RN3TANCNFSM5AQHZARA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

Denwen12 avatar Aug 06 '21 23:08 Denwen12

@Denwen12 from pydfs_lineup_optimizer import get_optimizer, Site, Sport, CSVLineupExporter, PositionsStack, PlayersGroup

class CustomExporter(CSVLineupExporter): @staticmethod def render_player(player): result = f'{player.id}:{player.full_name}' if player.lineup_position != 'UTIL': result += f' - {player.lineup_position}' return result

optimizer = get_optimizer(Site.FANDUEL, Sport.FOOTBALL) optimizer.settings.csv_exporter = CustomExporter # replace default exporter with custom optimizer.load_players_from_csv(r"C:\Users\brand\Desktop\PYTHON\NFL\fdnfl.csv")

kyler = optimizer.get_player_by_name("Kyler Murray") optimizer.add_player_to_lineup(kyler) kyler.max_exposure = 1 kyler.max_exposure = .10

#rodgers_adams_group = PlayersGroup([optimizer.get_player_by_name(name) for name in ('Aaron Rodgers', 'Davante Adams')], max_exposure=0.5) #optimizer.add_stack(PositionsStack(['QB', ('WR', 'TE')])) # stack QB and WR or TE from same team optimizer.add_stack(PositionsStack(['QB', 'TE'], for_teams=['LAR'])) # stack QB and TE for one of provided teams optimizer.add_stack(PositionsStack(['QB', 'WR'], for_teams=['DAL', 'ARI', 'BUF', 'GB'])) # stack QB and WR for one of provided teams optimizer.set_min_salary_cap(59500) optimizer.set_max_repeating_players(7) optimizer.restrict_positions_for_same_team(('QB', 'D'), ('RB', 'RB')) optimizer.force_positions_for_opposing_team(('QB', 'WR'), ('WR', 'WR')) lineups = optimizer.optimize(n=10) for lineup in lineups: print(lineup) optimizer.export(r"C:\Users\brand\Desktop\PYTHON\NFL\NFLFANDUEL.csv")

lightninglarry avatar Aug 07 '21 00:08 lightninglarry