trial switching to generic night site
This commit is contained in:
@@ -63,6 +63,7 @@ Rota.constraint_options["prevent_thursdays_before_full_weekends"] = [
|
|||||||
"exeter",
|
"exeter",
|
||||||
"truro no proc",
|
"truro no proc",
|
||||||
]
|
]
|
||||||
|
Rota.constraint_options["require_presence_at_site_overnight"] = ["plymouth"]
|
||||||
|
|
||||||
Rota.add_shifts(
|
Rota.add_shifts(
|
||||||
SingleShift(
|
SingleShift(
|
||||||
@@ -327,7 +328,7 @@ else:
|
|||||||
oop,
|
oop,
|
||||||
not_available_to_work=leave_requests,
|
not_available_to_work=leave_requests,
|
||||||
work_requests=work_requests,
|
work_requests=work_requests,
|
||||||
proc_site=site_pref,
|
night_site=site_pref,
|
||||||
previous_shifts=previous_shifts,
|
previous_shifts=previous_shifts,
|
||||||
pair=pair,
|
pair=pair,
|
||||||
)
|
)
|
||||||
|
|||||||
+36
-33
@@ -1,7 +1,7 @@
|
|||||||
import datetime
|
import datetime
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
#from shifts import RotaBuilder, days, sites
|
# from shifts import RotaBuilder, days, sites
|
||||||
|
|
||||||
|
|
||||||
class Worker:
|
class Worker:
|
||||||
@@ -19,9 +19,9 @@ class Worker:
|
|||||||
not_available_to_work=None,
|
not_available_to_work=None,
|
||||||
pref_not_to_work=None,
|
pref_not_to_work=None,
|
||||||
work_requests=None,
|
work_requests=None,
|
||||||
proc_site="plymouth",
|
night_site="plymouth", # We set a default night_site
|
||||||
previous_shifts={},
|
previous_shifts={},
|
||||||
pair=0
|
pair=0,
|
||||||
):
|
):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
@@ -34,11 +34,7 @@ class Worker:
|
|||||||
self.proportion_rota_to_work = 1
|
self.proportion_rota_to_work = 1
|
||||||
self.pair = pair
|
self.pair = pair
|
||||||
|
|
||||||
self.proc_site = proc_site
|
self.night_site = night_site
|
||||||
if proc_site == "plymouth" or proc_site == "":
|
|
||||||
self.night_at_derriford = 1
|
|
||||||
else:
|
|
||||||
self.night_at_derriford = 0
|
|
||||||
|
|
||||||
self.previous_shifts = previous_shifts
|
self.previous_shifts = previous_shifts
|
||||||
|
|
||||||
@@ -49,8 +45,7 @@ class Worker:
|
|||||||
if end_date is None:
|
if end_date is None:
|
||||||
self.end_date = None
|
self.end_date = None
|
||||||
else:
|
else:
|
||||||
self.end_date = datetime.datetime.strptime(end_date,
|
self.end_date = datetime.datetime.strptime(end_date, "%d/%m/%y").date()
|
||||||
"%d/%m/%y").date()
|
|
||||||
|
|
||||||
if self.end_date > Rota.rota_end_date:
|
if self.end_date > Rota.rota_end_date:
|
||||||
self.end_date = Rota.rota_end_date
|
self.end_date = Rota.rota_end_date
|
||||||
@@ -58,20 +53,18 @@ class Worker:
|
|||||||
if self.end_date > Rota.start_date:
|
if self.end_date > Rota.start_date:
|
||||||
days_to_work = (self.end_date - Rota.start_date).days
|
days_to_work = (self.end_date - Rota.start_date).days
|
||||||
|
|
||||||
|
|
||||||
# add unavalabilities
|
# add unavalabilities
|
||||||
for weeks_days in Rota.weeks_days_product[days_to_work:]:
|
for weeks_days in Rota.weeks_days_product[days_to_work:]:
|
||||||
week, day = weeks_days
|
week, day = weeks_days
|
||||||
Rota.unavailable_to_work.add((self.id, week, day))
|
Rota.unavailable_to_work.add((self.id, week, day))
|
||||||
Rota.unavailable_to_work_reason[(self.id, week, day)] = "END DATE"
|
Rota.unavailable_to_work_reason[
|
||||||
|
(self.id, week, day)
|
||||||
|
] = "END DATE"
|
||||||
|
|
||||||
if oop is not None:
|
if oop is not None:
|
||||||
start_oop, end_oop = oop
|
start_oop, end_oop = oop
|
||||||
start_oop_date = datetime.datetime.strptime(start_oop,
|
start_oop_date = datetime.datetime.strptime(start_oop, "%d/%m/%y").date()
|
||||||
"%d/%m/%y").date()
|
end_oop_date = datetime.datetime.strptime(end_oop, "%d/%m/%y").date()
|
||||||
end_oop_date = datetime.datetime.strptime(end_oop,
|
|
||||||
"%d/%m/%y").date()
|
|
||||||
|
|
||||||
|
|
||||||
# ignore oops if they finish before the rota start date
|
# ignore oops if they finish before the rota start date
|
||||||
print(end_oop_date, Rota.start_date)
|
print(end_oop_date, Rota.start_date)
|
||||||
@@ -85,58 +78,63 @@ class Worker:
|
|||||||
if start_oop_date < Rota.start_date:
|
if start_oop_date < Rota.start_date:
|
||||||
start_oop_date = Rota.start_date
|
start_oop_date = Rota.start_date
|
||||||
|
|
||||||
|
|
||||||
oop_length = (end_oop_date - start_oop_date).days
|
oop_length = (end_oop_date - start_oop_date).days
|
||||||
days_to_work = days_to_work - oop_length
|
days_to_work = days_to_work - oop_length
|
||||||
|
|
||||||
days_until_oop = (start_oop_date - Rota.start_date).days
|
days_until_oop = (start_oop_date - Rota.start_date).days
|
||||||
|
|
||||||
for weeks_days in Rota.weeks_days_product[
|
for weeks_days in Rota.weeks_days_product[
|
||||||
days_until_oop:days_until_oop + oop_length]:
|
days_until_oop : days_until_oop + oop_length
|
||||||
|
]:
|
||||||
week, day = weeks_days
|
week, day = weeks_days
|
||||||
Rota.unavailable_to_work.add((self.id, week, day))
|
Rota.unavailable_to_work.add((self.id, week, day))
|
||||||
Rota.unavailable_to_work_reason[(self.id, week, day)] = "OOP ()".format(oop)
|
Rota.unavailable_to_work_reason[
|
||||||
|
(self.id, week, day)
|
||||||
|
] = "OOP ()".format(oop)
|
||||||
|
|
||||||
if pref_not_to_work is not None:
|
if pref_not_to_work is not None:
|
||||||
# loop throught dates converting to week / day combination
|
# loop throught dates converting to week / day combination
|
||||||
for date in pref_not_to_work:
|
for date in pref_not_to_work:
|
||||||
days_from_start = (
|
days_from_start = (
|
||||||
datetime.datetime.strptime(date, "%d/%m/%y").date() -
|
datetime.datetime.strptime(date, "%d/%m/%y").date()
|
||||||
Rota.start_date).days
|
- Rota.start_date
|
||||||
|
).days
|
||||||
week = days_from_start // 7 + 1
|
week = days_from_start // 7 + 1
|
||||||
day = Rota.days[(days_from_start % 7)]
|
day = Rota.days[(days_from_start % 7)]
|
||||||
# Weight the value to take into account the number of preferences
|
# Weight the value to take into account the number of preferences
|
||||||
# 1 is added to the total number of requests to ensure they do not outweight
|
# 1 is added to the total number of requests to ensure they do not outweight
|
||||||
# a single (or fewer) request(s)
|
# a single (or fewer) request(s)
|
||||||
Rota.pref_not_to_work[(self.id, week,
|
Rota.pref_not_to_work[(self.id, week, day)] = 1 / (
|
||||||
day)] = 1 / (len(pref_not_to_work) + 1)
|
len(pref_not_to_work) + 1
|
||||||
|
)
|
||||||
|
|
||||||
if not_available_to_work is not None:
|
if not_available_to_work is not None:
|
||||||
#print(not_available_to_work)
|
# print(not_available_to_work)
|
||||||
# loop throught dates converting to week / day combination
|
# loop throught dates converting to week / day combination
|
||||||
for date, reason in not_available_to_work:
|
for date, reason in not_available_to_work:
|
||||||
days_from_start = (
|
days_from_start = (
|
||||||
datetime.datetime.strptime(date, "%d/%m/%y").date() -
|
datetime.datetime.strptime(date, "%d/%m/%y").date()
|
||||||
Rota.start_date).days
|
- Rota.start_date
|
||||||
|
).days
|
||||||
week = days_from_start // 7 + 1
|
week = days_from_start // 7 + 1
|
||||||
day = Rota.days[(days_from_start % 7)]
|
day = Rota.days[(days_from_start % 7)]
|
||||||
Rota.unavailable_to_work.add((self.id, week, day))
|
Rota.unavailable_to_work.add((self.id, week, day))
|
||||||
Rota.unavailable_to_work_reason[(self.id, week, day)] = reason
|
Rota.unavailable_to_work_reason[(self.id, week, day)] = reason
|
||||||
|
|
||||||
|
|
||||||
if work_requests is not None:
|
if work_requests is not None:
|
||||||
for date, shift in work_requests:
|
for date, shift in work_requests:
|
||||||
days_from_start = (
|
days_from_start = (
|
||||||
datetime.datetime.strptime(date, "%d/%m/%y").date() -
|
datetime.datetime.strptime(date, "%d/%m/%y").date()
|
||||||
Rota.start_date).days
|
- Rota.start_date
|
||||||
|
).days
|
||||||
week = days_from_start // 7 + 1
|
week = days_from_start // 7 + 1
|
||||||
day = Rota.days[(days_from_start % 7)]
|
day = Rota.days[(days_from_start % 7)]
|
||||||
Rota.work_requests.add((self.id, week, day, shift))
|
Rota.work_requests.add((self.id, week, day, shift))
|
||||||
|
|
||||||
print(days_to_work, Rota.rota_days_length)
|
# Calculate the proportion of the rota that is being worked
|
||||||
self.proportion_rota_to_work = days_to_work / Rota.rota_days_length
|
self.proportion_rota_to_work = days_to_work / Rota.rota_days_length
|
||||||
|
|
||||||
# We had to adjust the full time equivalent for people who CCT / leave the rota early
|
# We have to adjust the full time equivalent for people who CCT / leave the rota early
|
||||||
self.fte_adj = self.fte * self.proportion_rota_to_work
|
self.fte_adj = self.fte * self.proportion_rota_to_work
|
||||||
|
|
||||||
if self.fte_adj > 100:
|
if self.fte_adj > 100:
|
||||||
@@ -155,7 +153,12 @@ class Worker:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
||||||
nwd = ", ".join([str(i) for i in self.nwd]) if self.nwd is not None else ""
|
nwd = ", ".join([str(i) for i in self.nwd]) if self.nwd is not None else ""
|
||||||
return "{} {} [{}] PROC SITE:{} ({})".format(self.name, (self.site, self.grade, self.fte_adj), nwd, self.proc_site, self.night_at_derriford)
|
return "{} {} [{}] PROC SITE:{} ({})".format(
|
||||||
|
self.name,
|
||||||
|
(self.site, self.grade, self.fte_adj),
|
||||||
|
nwd,
|
||||||
|
self.night_site,
|
||||||
|
)
|
||||||
|
|
||||||
def get_details(self):
|
def get_details(self):
|
||||||
return "{} {} {}".format(self.id, self.site[0], self.grade)
|
return "{} {} {}".format(self.id, self.site[0], self.grade)
|
||||||
|
|||||||
Reference in New Issue
Block a user