More refactoring and documenting
This commit is contained in:
+60
@@ -0,0 +1,60 @@
|
||||
import datetime
|
||||
|
||||
from shifts import SingleShift, ShiftCollection, days, sites
|
||||
|
||||
|
||||
class Worker:
|
||||
def __init__(self, Shifts, id, name, site, grade, fte=100, nwd=[], end_date=None, oop=None):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.site = site
|
||||
self.grade = grade
|
||||
self.fte = fte
|
||||
self.nwd = nwd
|
||||
self.proportion_rota_to_work = 1
|
||||
|
||||
days_to_work = Shifts.rota_days_length
|
||||
|
||||
if end_date is None:
|
||||
self.end_date = None
|
||||
else:
|
||||
self.end_date = datetime.datetime.strptime(end_date, '%Y/%m/%d').date()
|
||||
|
||||
if self.end_date > Shifts.rota_end_date:
|
||||
self.end_date = Shifts.rota_end_date
|
||||
else:
|
||||
days_to_work = (self.end_date - Shifts.start_date).days
|
||||
|
||||
# add unavalabilities
|
||||
for weeks_days in Shifts.weeks_days_product[days_to_work:]:
|
||||
week, day = weeks_days
|
||||
unavailable_to_work.add((self.id, week, day))
|
||||
|
||||
if oop is not None:
|
||||
start_oop, end_oop = oop
|
||||
start_oop_date = datetime.datetime.strptime(start_oop, '%Y/%m/%d').date()
|
||||
end_oop_date = datetime.datetime.strptime(end_oop, '%Y/%m/%d').date()
|
||||
|
||||
if end_oop_date > Shifts.rota_end_date:
|
||||
end_oop_date = Shifts.rota_end_date
|
||||
|
||||
oop_length = (end_oop_date - start_oop_date).days
|
||||
days_to_work = days_to_work - oop_length
|
||||
|
||||
days_until_oop = (start_oop_date - Shifts.start_date).days
|
||||
|
||||
for weeks_days in Shifts.weeks_days_product[days_until_oop:days_until_oop+oop_length]:
|
||||
week, day = weeks_days
|
||||
unavailable_to_work.add((self.id, week, day))
|
||||
|
||||
|
||||
self.proportion_rota_to_work = days_to_work / Shifts.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
|
||||
|
||||
def __lt__(self, other):
|
||||
return (self.site, self.grade, self.name) < (other.site, other.grade, other.name)
|
||||
|
||||
def get_details(self):
|
||||
return "{} {} {}".format(self.id, self.site[0], self.grade)
|
||||
Reference in New Issue
Block a user