Skip to content

Commit

Permalink
Enforce C/1B
Browse files Browse the repository at this point in the history
  • Loading branch information
BenBrostoff committed Jan 29, 2024
1 parent 3ec8b7b commit 71cb575
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion draftfast/optimizer.py
Expand Up @@ -39,7 +39,7 @@ def __init__(
self.lineup_constraints = lineup_constraints
self.banned_for_exposure = exposure_dict.get("banned", [])
self.locked_for_exposure = exposure_dict.get("locked", [])
self.custom_rules = settings.custom_rules
self.custom_rules = (rule_set.custom_rules or []) + (settings.custom_rules or [])
self.min_teams = rule_set.min_teams or settings.min_teams
self.min_matchups = rule_set.min_matchups or settings.min_matchups
self.position_per_team_rules = rule_set.position_per_team_rules
Expand Down
12 changes: 12 additions & 0 deletions draftfast/rules.py
Expand Up @@ -3,6 +3,7 @@
NBA_GENERAL_POSITIONS,
POSITIONS_BY_SITE_BY_LEAGUE,
)
from draftfast.settings import CustomRule
from draftfast.constants.roster_size import ROSTER_SIZE_BY_SITE_BY_SPORT
from draftfast.constants.salary_cap import SALARY_CAP_BY_SITE_BY_LEAGUE

Expand All @@ -27,6 +28,7 @@ def __init__(
min_teams=None,
min_matchups=None,
position_per_team_rules=None,
custom_rules=None,
game_type="classic",
):
self.site = site
Expand All @@ -43,6 +45,7 @@ def __init__(
self.position_per_team_rules = position_per_team_rules
self.min_teams = min_teams
self.min_matchups = min_matchups
self.custom_rules = custom_rules

def __eq__(self, other):
if not other:
Expand Down Expand Up @@ -247,6 +250,15 @@ def __eq__(self, other):
position_per_team_rules=[
[lambda pos: "P" not in pos, 4],
],

# Handle C/1B minimums,
custom_rules=[
CustomRule(
group_a=lambda p: p.pos in ['C', '1B'],
group_b=lambda p: p,
comparison=lambda sum, a, b: sum(a) == 1,
)
]
)

DK_SOCCER_RULE_SET = RuleSet(
Expand Down

0 comments on commit 71cb575

Please sign in to comment.