Add missing shift type check
This commit is contained in:
@@ -165,7 +165,7 @@ mod tests {
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
bounds::WorkloadBounds, config::UserConfig, resident::Resident, schedule::MonthlySchedule,
|
bounds::WorkloadBounds, config::UserConfig, resident::Resident, schedule::MonthlySchedule,
|
||||||
scheduler::Scheduler, slot::Slot,
|
scheduler::Scheduler,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[fixture]
|
#[fixture]
|
||||||
|
|||||||
@@ -67,15 +67,17 @@ impl Scheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Return all valid residents for the current slot
|
/// Return all valid residents for the current slot
|
||||||
pub fn valid_residents(&self, slot: Slot, schedule: &MonthlySchedule) -> Vec<ResidentId> {
|
pub fn valid_residents(&self, slot: Slot, schedule: &MonthlySchedule) -> Vec<&ResidentId> {
|
||||||
let other_slot_resident_id = schedule.get_resident_id(&slot.other_position());
|
let required_type = slot.shift_type(); // Calculate once here
|
||||||
|
let other_resident = schedule.get_resident_id(&slot.other_position());
|
||||||
|
|
||||||
self.config
|
self.config
|
||||||
.residents
|
.residents
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|r| Some(&r.id) != other_slot_resident_id)
|
.filter(|r| Some(&r.id) != other_resident)
|
||||||
.filter(|r| !r.negative_shifts.contains(&slot.day))
|
.filter(|r| !r.negative_shifts.contains(&slot.day))
|
||||||
.map(|r| r.id.clone())
|
.filter(|r| r.allowed_types.contains(&required_type))
|
||||||
|
.map(|r| &r.id)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use chrono::{Datelike, NaiveDate, Weekday};
|
use chrono::{Datelike, NaiveDate, Weekday};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::schedule::ShiftType;
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, PartialEq, PartialOrd, Ord, Eq, Debug, Hash, Clone, Copy)]
|
#[derive(Serialize, Deserialize, PartialEq, PartialOrd, Ord, Eq, Debug, Hash, Clone, Copy)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub struct Slot {
|
pub struct Slot {
|
||||||
@@ -88,6 +90,14 @@ impl Slot {
|
|||||||
position: other_pos,
|
position: other_pos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn shift_type(&self) -> ShiftType {
|
||||||
|
match (self.is_open_shift(), self.position) {
|
||||||
|
(true, ShiftPosition::First) => ShiftType::OpenFirst,
|
||||||
|
(true, ShiftPosition::Second) => ShiftType::OpenSecond,
|
||||||
|
(false, _) => ShiftType::Closed,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Slot {
|
impl Default for Slot {
|
||||||
|
|||||||
Reference in New Issue
Block a user