Add constraints for maximum days and unique shifts per week block in worker model

This commit is contained in:
Ross
2026-05-19 21:23:09 +01:00
parent a071b1b027
commit dee80ed4fa
5 changed files with 192 additions and 4 deletions
+28
View File
@@ -135,6 +135,32 @@ class AvoidShiftOnDates(BaseModel):
raise ValueError(f"Cannot parse date: {v}")
class MaxDaysPerWeekBlockConstraint(BaseModel):
max_days: int = Field(
...,
ge=1,
description="Maximum number of worked days allowed inside each sliding week block.",
)
week_block: int = Field(
...,
ge=1,
description="Length of the sliding week block (for example, 2 means every consecutive 2-week window).",
)
class MaxUniqueShiftsPerWeekBlockConstraint(BaseModel):
max_unique_shifts: int = Field(
...,
ge=1,
description="Maximum number of distinct shift names allowed inside each sliding week block.",
)
week_block: int = Field(
...,
ge=1,
description="Length of the sliding week block (for example, 2 means every consecutive 2-week window).",
)
class Worker(BaseModel):
name: str
site: str
@@ -171,6 +197,8 @@ class Worker(BaseModel):
forced_assignments: List[tuple[int, str, str]] = [] # (week, day, shift_name)
forced_assignments_by_date: List[tuple[datetime.date, str]] = [] # (date, shift_name)
max_days_worked_per_week: int | None= None # Default: no limit, can be set to a specific number
max_days_per_week_block: list[MaxDaysPerWeekBlockConstraint] = []
max_unique_shifts_per_week_block: list[MaxUniqueShiftsPerWeekBlockConstraint] = []
assign_as_block_preferences: dict[str, float] = {} # shift_name -> weight (positive = prefer block)