Adjust max workload calculation to take into account residents with reduced load

This commit is contained in:
2026-02-28 09:58:03 +02:00
parent 76d308351a
commit ab41e8f264

View File

@@ -45,7 +45,11 @@ impl WorkloadBounds {
} }
let total_manual_workload: u8 = residents.iter().map(|r| r.max_shifts.unwrap_or(0)).sum(); let total_manual_workload: u8 = residents.iter().map(|r| r.max_shifts.unwrap_or(0)).sum();
let remaining_slots = total_slots - total_manual_workload; let total_reduced_workload: u8 = residents
.iter()
.map(|r| if r.reduced_load { 1 } else { 0 })
.sum();
let remaining_slots = total_slots - total_manual_workload + total_reduced_workload;
let workload_share = remaining_slots.div_ceil(non_manual_residents.len() as u8); let workload_share = remaining_slots.div_ceil(non_manual_residents.len() as u8);
for r in residents { for r in residents {
@@ -150,25 +154,17 @@ impl WorkloadTracker {
pub fn reached_workload_limit(&self, bounds: &WorkloadBounds, r_id: &ResidentId) -> bool { pub fn reached_workload_limit(&self, bounds: &WorkloadBounds, r_id: &ResidentId) -> bool {
let current_load = self.current_workload(r_id); let current_load = self.current_workload(r_id);
if let Some(&max) = bounds.max_workloads.get(r_id) { if let Some(&max) = bounds.max_workloads.get(r_id) {
if current_load >= max { return current_load >= max;
return true;
} }
}
false false
} }
pub fn reached_holiday_limit(&self, bounds: &WorkloadBounds, r_id: &ResidentId) -> bool { pub fn reached_holiday_limit(&self, bounds: &WorkloadBounds, r_id: &ResidentId) -> bool {
let current_load = self.current_holiday_workload(r_id); let current_load = self.current_holiday_workload(r_id);
if let Some(&max) = bounds.max_holiday_shifts.get(r_id) { if let Some(&max) = bounds.max_holiday_shifts.get(r_id) {
if current_load >= max { return current_load >= max;
return true;
} }
}
false false
} }
@@ -178,12 +174,10 @@ impl WorkloadTracker {
r_id: &ResidentId, r_id: &ResidentId,
shift_type: ShiftType, shift_type: ShiftType,
) -> bool { ) -> bool {
let current_load = self.type_counts.get(&(*r_id, shift_type)).unwrap_or(&0); let current_load = self.current_shift_type_workload(r_id, shift_type);
if let Some(&max) = bounds.max_by_shift_type.get(&(*r_id, shift_type)) { if let Some(&max) = bounds.max_by_shift_type.get(&(*r_id, shift_type)) {
return *current_load >= max; return current_load >= max;
} }
false false
} }
} }
@@ -203,7 +197,8 @@ mod tests {
// Testing WorkloadBounds // Testing WorkloadBounds
#[rstest] #[rstest]
fn test_max_workloads(minimal_config: UserConfig) { fn test_max_workloads(mut minimal_config: UserConfig) {
minimal_config.update_month(4);
let bounds = WorkloadBounds::new_with_config(&minimal_config); let bounds = WorkloadBounds::new_with_config(&minimal_config);
assert_eq!(9, bounds.max_workloads[&ResidentId(1)]); assert_eq!(9, bounds.max_workloads[&ResidentId(1)]);
assert_eq!(9, bounds.max_workloads[&ResidentId(2)]); assert_eq!(9, bounds.max_workloads[&ResidentId(2)]);