fix bug with pre / post shift constraints

This commit is contained in:
Ross
2025-06-22 10:53:17 +01:00
parent fc3102ec47
commit 8402cc92fd
3 changed files with 381 additions and 40 deletions
+8 -37
View File
@@ -2626,10 +2626,9 @@ class RotaBuilder(object):
):
for n in range(0, constraint_shift.constraint_options["pre"]):
if day in constraint_shift.days:
# week_start_date = self.get_week_start_date(week)
# try:
# if constraint_shift.start_date <= week_start_date < constraint_shift.end_date:
# works = 1
# Only apply if worker can work this shift
if worker.site not in constraint_shift.sites:
continue
try:
works = self.model.works[
worker.id, week, day, constraint_shift.name
@@ -2649,50 +2648,23 @@ class RotaBuilder(object):
)
if shiftname != constraint_shift.name
for w in workers
if w.site in constraint_shift.sites # Only workers who can work this shift
)
)
# for constraint_shift in self.get_shifts_with_constraint( "pre"):
# to_sum = []
# for n in range(
# 0, constraint_shift.constraint_options["pre"]
# ):
# for w in workers:
# for wk, dy, shiftname in self.get_week_day_shift_names_by_week_day(
# pre_map[n][1], pre_map[n][2]
# ):
# if shiftname != constraint_shift.name:
# to_sum.append(pre_map[n][0]
# * self.model.works[
# w.id, wk, dy, shiftname
# ])
# if day in constraint_shift.days:
# self.model.constraints.add(
# 1
# >= self.model.works[
# worker.id, week, day, constraint_shift.name
# ]
# + sum(
# to_sum
# )
# )
for constraint_shift in self.get_shifts_with_constraints(
"post" # , week=week
):
for n in range(0, constraint_shift.constraint_options["post"]):
if day in constraint_shift.days:
# week_start_date = self.get_week_start_date(week)
# if constraint_shift.start_date <= week_start_date < constraint_shift.end_date:
# works = 1
# else:
# Only apply if worker can work this shift
if worker.site not in constraint_shift.sites:
continue
try:
works = self.model.works[
worker.id, week, day, constraint_shift.name
]
except KeyError:
# If we can't find the key the shift is not assigned
# so we don't need to worry about it
continue
self.model.constraints.add(
1
@@ -2707,10 +2679,9 @@ class RotaBuilder(object):
)
if shiftname != constraint_shift.name
for w in workers
if w.site in constraint_shift.sites # Only workers who can work this shift
)
)
# except KeyError:
# pass
# Night constraint means we won't assign a shift the day before
# an unavailability