Add ignore_shifts parameter to PostShiftConstraint and PreShiftConstraint

This commit is contained in:
Ross
2025-08-11 13:56:43 +01:00
parent 76f3b48c1d
commit b72d33189c
2 changed files with 7 additions and 3 deletions
+1 -1
View File
@@ -353,7 +353,7 @@ def main(
#{"name": "pre", "options": 2}, #{"name": "pre", "options": 2},
#{"name": "post", "options": 1}, #{"name": "post", "options": 1},
PostShiftConstraint(days=1, start_date="2025-11-24"), PostShiftConstraint(days=1, start_date="2025-11-17", ignore_shifts=["oncall"]),
], ],
display_char="a", display_char="a",
#force_assign_with=["oncall"] #force_assign_with=["oncall"]
+6 -2
View File
@@ -96,9 +96,11 @@ class NightConstraint(BaseShiftConstraint):
class PreShiftConstraint(BaseShiftConstraint): class PreShiftConstraint(BaseShiftConstraint):
days: Any = None days: Any = None
ignore_shifts: List[str] = []
class PostShiftConstraint(BaseShiftConstraint): class PostShiftConstraint(BaseShiftConstraint):
days: Any = None days: Any = None
ignore_shifts: List[str] = []
class BalanceAcrossGroupsConstraint(BaseShiftConstraint): class BalanceAcrossGroupsConstraint(BaseShiftConstraint):
"""""" """"""
@@ -2898,6 +2900,7 @@ class RotaBuilder(object):
PreShiftConstraint PreShiftConstraint
): ):
constraint = constraint_shift.get_constraint(PreShiftConstraint) constraint = constraint_shift.get_constraint(PreShiftConstraint)
ignore_shifts = constraint.ignore_shifts + [constraint_shift.name]
if week not in constraint.weeks: if week not in constraint.weeks:
continue continue
for n in range(0, constraint.days): for n in range(0, constraint.days):
@@ -2922,7 +2925,7 @@ class RotaBuilder(object):
for shiftname in self.get_shift_names_by_week_day( for shiftname in self.get_shift_names_by_week_day(
pre_map[n][1], pre_map[n][2] pre_map[n][1], pre_map[n][2]
) )
if shiftname != constraint_shift.name if shiftname not in ignore_shifts
for w in workers for w in workers
if w.site in constraint_shift.sites # Only workers who can work this shift if w.site in constraint_shift.sites # Only workers who can work this shift
) )
@@ -2932,6 +2935,7 @@ class RotaBuilder(object):
PostShiftConstraint PostShiftConstraint
): ):
constraint = constraint_shift.get_constraint(PostShiftConstraint) constraint = constraint_shift.get_constraint(PostShiftConstraint)
ignore_shifts = constraint.ignore_shifts + [constraint_shift.name]
if week not in constraint.weeks: if week not in constraint.weeks:
continue continue
for n in range(0, constraint.days): for n in range(0, constraint.days):
@@ -2956,7 +2960,7 @@ class RotaBuilder(object):
for shiftname in self.get_shift_names_by_week_day( for shiftname in self.get_shift_names_by_week_day(
post_map[n][1], post_map[n][2] post_map[n][1], post_map[n][2]
) )
if shiftname != constraint_shift.name if shiftname not in ignore_shifts
for w in workers for w in workers
if w.site in constraint_shift.sites # Only workers who can work this shift if w.site in constraint_shift.sites # Only workers who can work this shift
) )