Add forced shift assignment functionality for workers and update tests

This commit is contained in:
Ross
2025-08-08 08:23:42 +01:00
parent cf48c3c168
commit 6bd47ba5b4
4 changed files with 135 additions and 3 deletions
+6 -1
View File
@@ -118,6 +118,7 @@ class Worker(BaseModel):
hard_day_exclusions: list[tuple[str, str]] = [] # e.g. [("Fri", "Sun")]
force_assign_with: dict[str, list[str]] = {} # e.g. {"oncall": ["weekend"]}
max_shifts_per_week_by_shift_name: dict[str, int] = {} # e.g. {"night": 2, "a": 3}
forced_assignments: List[tuple[int, str, str]] = [] # (week, day, shift_name)
assign_as_block_preferences: dict[str, float] = {} # shift_name -> weight (positive = prefer block)
@@ -430,4 +431,8 @@ class Worker(BaseModel):
"""Helper to set the maximum number of shifts of a given type per week for this worker."""
if not hasattr(self, "max_shifts_per_week_by_shift_name"):
self.max_shifts_per_week_by_shift_name = {}
self.max_shifts_per_week_by_shift_name[shift_name] = max_per_week
self.max_shifts_per_week_by_shift_name[shift_name] = max_per_week
def force_assign_shift(self, week: int, day: str, shift_name: str):
"""Force this worker to be assigned to a shift on a specific week/day."""
self.forced_assignments.append((week, day, shift_name))