From ab41e8f2647dc7e41d0246dc799fea099d066a79 Mon Sep 17 00:00:00 2001 From: stefiosif Date: Sat, 28 Feb 2026 09:58:03 +0200 Subject: [PATCH] Adjust max workload calculation to take into account residents with reduced load --- src-tauri/src/workload.rs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src-tauri/src/workload.rs b/src-tauri/src/workload.rs index 6638fba..4af0d58 100644 --- a/src-tauri/src/workload.rs +++ b/src-tauri/src/workload.rs @@ -45,7 +45,11 @@ impl WorkloadBounds { } 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); for r in residents { @@ -150,25 +154,17 @@ impl WorkloadTracker { pub fn reached_workload_limit(&self, bounds: &WorkloadBounds, r_id: &ResidentId) -> bool { let current_load = self.current_workload(r_id); - if let Some(&max) = bounds.max_workloads.get(r_id) { - if current_load >= max { - return true; - } + return current_load >= max; } - false } pub fn reached_holiday_limit(&self, bounds: &WorkloadBounds, r_id: &ResidentId) -> bool { let current_load = self.current_holiday_workload(r_id); - if let Some(&max) = bounds.max_holiday_shifts.get(r_id) { - if current_load >= max { - return true; - } + return current_load >= max; } - false } @@ -178,12 +174,10 @@ impl WorkloadTracker { r_id: &ResidentId, shift_type: ShiftType, ) -> 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)) { - return *current_load >= max; + return current_load >= max; } - false } } @@ -203,7 +197,8 @@ mod tests { // Testing WorkloadBounds #[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); assert_eq!(9, bounds.max_workloads[&ResidentId(1)]); assert_eq!(9, bounds.max_workloads[&ResidentId(2)]);