Add functionality to handle missing shifts in RotaBuilder and include worker grades in the timetable

This commit is contained in:
Ross
2026-01-07 22:14:43 +00:00
parent 277f14747a
commit 64c4189d5f
3 changed files with 205 additions and 151 deletions
+146 -145
View File
@@ -84,149 +84,149 @@ def main(
#]
Rota.add_shifts(
SingleShift(
sites=(
"exeter",
"exeter twilights and weekends",
"exeter no nights",
"exeter twilights",
),
name="exeter_twilight",
length=12.5,
days=days[:5],
balance_offset=2,
constraints=[MaxShiftsPerWeekConstraint(max_shifts=1)],
),
SingleShift(
sites=(
"truro",
"truro no nights",
"truro twilights",
"truro twilights and weekends",
"truro twilights and weekend nights",
"truro twilights, weekends and weekend nights",
),
name="truro_twilight",
length=12.5,
days=days[:4],
balance_offset=4,
constraints=[MaxShiftsPerWeekConstraint(max_shifts=1)],
),
SingleShift(
sites=("torbay", "torbay twilights", "torbay twilights and weekends"),
name="torbay_twilight",
length=12.5,
days=days[:4],
balance_offset=2,
assign_as_block=True,
),
SingleShift(
sites=(
"plymouth",
"plymouth twilights",
"plymouth twilights and weekends",
"plymouth twilights, weekends and weekend nights",
),
name="plymouth_twilight",
length=12.5,
days=days[:5],
balance_offset=2,
workers_required=1,
constraints=[MaxShiftsPerWeekConstraint(max_shifts=2)],
),
SingleShift(
sites=(
"exeter",
"exeter twilights and weekends",
"exeter no nights",
"exeter weekends",
#"exeter twilights",
),
name="weekend_exeter",
length=12.5,
days=days[5:],
#balance_offset=2,
rota_on_nwds=True,
force_as_block=True,
constraints=[PostShiftConstraint(days=2), PreShiftConstraint(days=2)],
# constraint=[{"name": "pre", "options": 2}, {"name": "post", "options": 2},],
),
SingleShift(
sites=(
"truro",
"truro no nights",
"truro twilights and weekends",
"truro weekends",
"truro twilights, weekends and weekend nights",
),
name="weekend_truro",
length=12.5,
days=days[4:],
#balance_offset=3,
rota_on_nwds=True,
force_as_block=True,
#assign_as_block=True,
constraints=[PreShiftConstraint(days=2), PostShiftConstraint(days=2)],
# force_as_block_unless_nwd=True
),
SingleShift(
sites=("torbay", "torbay twilights and weekends"),
name="weekend_torbay",
length=12.5,
days=days[4:],
#balance_offset=2,
rota_on_nwds=True,
force_as_block=True,
constraints=[PreShiftConstraint(days=2), PostShiftConstraint(days=2)],
# force_as_block_unless_nwd=True
),
SingleShift(
sites=(
"plymouth",
"plymouth twilights and weekends",
"plymouth first on weekends only",
"plymouth twilights, weekends and weekend nights",
),
name="weekend_plymouth1",
length=8,
days=days[5:],
#balance_offset=2.9,
workers_required=1,
rota_on_nwds=True,
force_as_block=True,
constraints=[PreShiftConstraint(days=2), PostShiftConstraint(days=2)],
),
SingleShift(
sites=(
"plymouth",
"plymouth twilights and weekends",
"plymouth twilights, weekends and weekend nights",
),
name="weekend_plymouth2",
length=8,
days=days[5:],
#balance_offset=2.9,
workers_required=1,
rota_on_nwds=True,
force_as_block=True,
constraints=[PreShiftConstraint(days=2), PostShiftConstraint(days=2)],
),
SingleShift(
sites=(
"plymouth",
"plymouth twilights",
"plymouth twilights and weekends",
"plymouth twilights, weekends and weekend nights",
),
name="plymouth_bank_holidays",
length=8,
days=days[5:],
balance_offset=1,
workers_required=1,
rota_on_nwds=True,
force_as_block=False,
bank_holidays_only=True,
),
#SingleShift(
# sites=(
# "exeter",
# "exeter twilights and weekends",
# "exeter no nights",
# "exeter twilights",
# ),
# name="exeter_twilight",
# length=12.5,
# days=days[:5],
# balance_offset=2,
# constraints=[MaxShiftsPerWeekConstraint(max_shifts=1)],
#),
#SingleShift(
# sites=(
# "truro",
# "truro no nights",
# "truro twilights",
# "truro twilights and weekends",
# "truro twilights and weekend nights",
# "truro twilights, weekends and weekend nights",
# ),
# name="truro_twilight",
# length=12.5,
# days=days[:4],
# balance_offset=4,
# constraints=[MaxShiftsPerWeekConstraint(max_shifts=1)],
#),
#SingleShift(
# sites=("torbay", "torbay twilights", "torbay twilights and weekends"),
# name="torbay_twilight",
# length=12.5,
# days=days[:4],
# balance_offset=2,
# assign_as_block=True,
#),
#SingleShift(
# sites=(
# "plymouth",
# "plymouth twilights",
# "plymouth twilights and weekends",
# "plymouth twilights, weekends and weekend nights",
# ),
# name="plymouth_twilight",
# length=12.5,
# days=days[:5],
# balance_offset=2,
# workers_required=1,
# constraints=[MaxShiftsPerWeekConstraint(max_shifts=2)],
#),
#SingleShift(
# sites=(
# "exeter",
# "exeter twilights and weekends",
# "exeter no nights",
# "exeter weekends",
# #"exeter twilights",
# ),
# name="weekend_exeter",
# length=12.5,
# days=days[5:],
# #balance_offset=2,
# rota_on_nwds=True,
# force_as_block=True,
# constraints=[PostShiftConstraint(days=2), PreShiftConstraint(days=2)],
# # constraint=[{"name": "pre", "options": 2}, {"name": "post", "options": 2},],
#),
#SingleShift(
# sites=(
# "truro",
# "truro no nights",
# "truro twilights and weekends",
# "truro weekends",
# "truro twilights, weekends and weekend nights",
# ),
# name="weekend_truro",
# length=12.5,
# days=days[4:],
# #balance_offset=3,
# rota_on_nwds=True,
# force_as_block=True,
# #assign_as_block=True,
# constraints=[PreShiftConstraint(days=2), PostShiftConstraint(days=2)],
# # force_as_block_unless_nwd=True
#),
#SingleShift(
# sites=("torbay", "torbay twilights and weekends"),
# name="weekend_torbay",
# length=12.5,
# days=days[4:],
# #balance_offset=2,
# rota_on_nwds=True,
# force_as_block=True,
# constraints=[PreShiftConstraint(days=2), PostShiftConstraint(days=2)],
# # force_as_block_unless_nwd=True
#),
#SingleShift(
# sites=(
# "plymouth",
# "plymouth twilights and weekends",
# "plymouth first on weekends only",
# "plymouth twilights, weekends and weekend nights",
# ),
# name="weekend_plymouth1",
# length=8,
# days=days[5:],
# #balance_offset=2.9,
# workers_required=1,
# rota_on_nwds=True,
# force_as_block=True,
# constraints=[PreShiftConstraint(days=2), PostShiftConstraint(days=2)],
#),
#SingleShift(
# sites=(
# "plymouth",
# "plymouth twilights and weekends",
# "plymouth twilights, weekends and weekend nights",
# ),
# name="weekend_plymouth2",
# length=8,
# days=days[5:],
# #balance_offset=2.9,
# workers_required=1,
# rota_on_nwds=True,
# force_as_block=True,
# constraints=[PreShiftConstraint(days=2), PostShiftConstraint(days=2)],
#),
#SingleShift(
# sites=(
# "plymouth",
# "plymouth twilights",
# "plymouth twilights and weekends",
# "plymouth twilights, weekends and weekend nights",
# ),
# name="plymouth_bank_holidays",
# length=8,
# days=days[5:],
# balance_offset=1,
# workers_required=1,
# rota_on_nwds=True,
# force_as_block=False,
# bank_holidays_only=True,
#),
SingleShift(
sites=sites,
name="night_weekday",
@@ -280,10 +280,11 @@ def main(
# Prevent shifts for ST2s for 2 weeks
#Rota.add_grade_constraint_by_week([2], [1, 2], [shift.name for shift in Rota.shifts])
Rota.add_min_summed_grade_by_shifts_per_day_constraint(["weekend_plymouth1", "weekend_plymouth2"], 6)
Rota.add_min_summed_grade_by_shifts_per_day_constraint(["plymouth_twilight", "plymouth_bank_holidays"], 6)
#Rota.add_min_summed_grade_by_shifts_per_day_constraint(["weekend_plymouth1", "weekend_plymouth2"], 6)
#Rota.add_min_summed_grade_by_shifts_per_day_constraint(["plymouth_twilight", "plymouth_bank_holidays"], 6)
Rota.add_min_summed_grade_by_shifts_per_day_constraint(["night_weekday"], 12)
Rota.add_min_summed_grade_by_shifts_per_day_constraint(["night_weekend"], 12)
Rota.terminate_on_warning.remove("Worker/no valid shifts")