diff --git a/runfixnights.py b/runfixnights.py index cd2ea2c..33cc05d 100644 --- a/runfixnights.py +++ b/runfixnights.py @@ -74,6 +74,7 @@ Rota.constraint_options["prevent_thursdays_before_full_weekends"] = [ "exeter", "truro no proc", ] +Rota.constraint_options["require_presence_at_site_overnight"] = ["plymouth"] Rota.add_shifts( SingleShift( @@ -322,7 +323,7 @@ else: oop, not_available_to_work=leave_requests, work_requests=work_requests, - proc_site=site_pref, + night_site=site_pref, previous_shifts=previous_shifts, pair=pair, shift_balance_extra=w["shift_balance_extra"], diff --git a/shifts.py b/shifts.py index 3d6b3c4..6ba6a24 100644 --- a/shifts.py +++ b/shifts.py @@ -181,6 +181,8 @@ class RotaBuilder(object): "prevent_monday_and_tuesday_after_full_weekends": [], "prevent_fridays_before_full_weekends": [], "prevent_thursdays_before_full_weekends": [], + # This may be better defined on the shift? + "require_presence_at_site_overnight": [], "avoid_st2_first_month": False, "hard_constrain_pair_separation": False, } @@ -739,24 +741,47 @@ class RotaBuilder(object): rule=nightShiftMinST4Rule, ) - def nightShiftDerrifordRule(model, week, shift): - derriford_workers = [w for w in self.workers if w.night_at_derriford >= 1] - # if not derriford_workers: - # return Constraint.Skip + # def nightShiftDerrifordRule(model, week, shift): + # derriford_workers = [w for w in self.workers if w.night_at_derriford >= 1] + # # if not derriford_workers: + # # return Constraint.Skip + # return ( + # sum( + # model.shift_week_worker_assigned[shift, week, w.id] + # for w in derriford_workers + # ) + # >= 1 + # ) + + # if self.constraint_options["ensure_derriford_reg_for_nights"]: + # self.model.night_shifts_derriford_rule = Constraint( + # [week for week in self.weeks], + # [shift.name for shift in self.get_shifts_with_constraint("night")], + # rule=nightShiftDerrifordRule, + # ) + + def presenceAtSiteOvernight(model, week, shift, required_site): + required_site_workers = [ + w for w in self.workers if required_site == w.night_site + ] + return ( sum( model.shift_week_worker_assigned[shift, week, w.id] - for w in derriford_workers + for w in required_site_workers ) >= 1 ) - if self.constraint_options["ensure_derriford_reg_for_nights"]: - self.model.night_shifts_derriford_rule = Constraint( - [week for week in self.weeks], - [shift.name for shift in self.get_shifts_with_constraint("night")], - rule=nightShiftDerrifordRule, - ) + if self.constraint_options["require_presence_at_site_overnight"]: + + for site in self.constraint_options["require_presence_at_site_overnight"]: + self.model.require_presence_at_site_overnight_rule = Constraint( + [week for week in self.weeks], + [shift.name for shift in self.get_shifts_with_constraint("night")], + [site], + rule=presenceAtSiteOvernight, + ) # # Count the number of workers from each site on each night shift # # As 1 or 0 is optimum we can simply subtract 1 from the number diff --git a/workers.py b/workers.py index 42d10d3..c7ade52 100644 --- a/workers.py +++ b/workers.py @@ -20,7 +20,7 @@ class Worker: not_available_to_work=None, pref_not_to_work=None, work_requests=None, - proc_site: str = "plymouth", # We set a default proc_site + night_site: str = "plymouth", # We set a default proc_site previous_shifts: dict = {}, shift_balance_extra: dict = {}, bank_holiday_extra: int = 0, @@ -44,8 +44,8 @@ class Worker: self.shift_balance_extra = shift_balance_extra self.bank_holiday_extra = bank_holiday_extra - self.proc_site = proc_site - if proc_site == "plymouth" or proc_site == "": + self.proc_site = night_site + if night_site == "plymouth" or night_site == "": self.night_at_derriford = 1 else: self.night_at_derriford = 0