go
This commit is contained in:
+37
-17
@@ -5,18 +5,22 @@ from collections import defaultdict
|
||||
|
||||
|
||||
class Worker:
|
||||
def __init__(self,
|
||||
Rota,
|
||||
id,
|
||||
name,
|
||||
site,
|
||||
grade,
|
||||
fte=100,
|
||||
nwd=None,
|
||||
end_date=None,
|
||||
oop=None,
|
||||
pref_not_to_work=None,
|
||||
work_requests=None,):
|
||||
def __init__(
|
||||
self,
|
||||
Rota,
|
||||
id,
|
||||
name,
|
||||
site,
|
||||
grade,
|
||||
fte=100,
|
||||
nwd=None,
|
||||
end_date=None,
|
||||
oop=None,
|
||||
not_available_to_work=None,
|
||||
pref_not_to_work=None,
|
||||
work_requests=None,
|
||||
night_at_derriford=0,
|
||||
):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.site = site
|
||||
@@ -26,6 +30,7 @@ class Worker:
|
||||
self.fte = fte
|
||||
self.nwd = nwd
|
||||
self.proportion_rota_to_work = 1
|
||||
self.night_at_derriford = night_at_derriford
|
||||
|
||||
self.shift_target_number = defaultdict(int)
|
||||
|
||||
@@ -54,7 +59,6 @@ class Worker:
|
||||
end_oop_date = datetime.datetime.strptime(end_oop,
|
||||
"%Y/%m/%d").date()
|
||||
|
||||
print(start_oop_date, end_oop_date)
|
||||
if end_oop_date > Rota.rota_end_date:
|
||||
end_oop_date = Rota.rota_end_date
|
||||
|
||||
@@ -74,27 +78,43 @@ class Worker:
|
||||
if pref_not_to_work is not None:
|
||||
# loop throught dates converting to week / day combination
|
||||
for date in pref_not_to_work:
|
||||
days_from_start = (datetime.datetime.strptime(date, "%Y/%m/%d").date() - Rota.start_date).days
|
||||
days_from_start = (
|
||||
datetime.datetime.strptime(date, "%Y/%m/%d").date() -
|
||||
Rota.start_date).days
|
||||
week = days_from_start // 7 + 1
|
||||
day = Rota.days[(days_from_start % 7)]
|
||||
# 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
|
||||
# a single (or fewer) request(s)
|
||||
Rota.pref_not_to_work[(self.id, week, day)] = 1 / (len(pref_not_to_work) + 1)
|
||||
Rota.pref_not_to_work[(self.id, week,
|
||||
day)] = 1 / (len(pref_not_to_work) + 1)
|
||||
|
||||
if not_available_to_work is not None:
|
||||
# loop throught dates converting to week / day combination
|
||||
for date in not_available_to_work:
|
||||
days_from_start = (
|
||||
datetime.datetime.strptime(date, "%d/%m/%Y").date() -
|
||||
Rota.start_date).days
|
||||
week = days_from_start // 7 + 1
|
||||
day = Rota.days[(days_from_start % 7)]
|
||||
Rota.unavailable_to_work.add((self.id, week, day))
|
||||
|
||||
if work_requests is not None:
|
||||
for date, shift in work_requests:
|
||||
days_from_start = (datetime.datetime.strptime(date, "%Y/%m/%d").date() - Rota.start_date).days
|
||||
days_from_start = (
|
||||
datetime.datetime.strptime(date, "%d/%m/%Y").date() -
|
||||
Rota.start_date).days
|
||||
week = days_from_start // 7 + 1
|
||||
day = Rota.days[(days_from_start % 7)]
|
||||
Rota.work_requests.add((self.id, week, day, shift))
|
||||
|
||||
|
||||
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
|
||||
self.fte_adj = self.fte * self.proportion_rota_to_work
|
||||
|
||||
# print(self.name, self.nwd)
|
||||
|
||||
def __lt__(self, other):
|
||||
return (self.site, self.grade, self.fte_adj, self.name) < (
|
||||
other.site,
|
||||
|
||||
Reference in New Issue
Block a user