continue
This commit is contained in:
+2539
-233
File diff suppressed because one or more lines are too long
@@ -24,7 +24,9 @@ class SingleShift(object):
|
|||||||
name,
|
name,
|
||||||
length,
|
length,
|
||||||
shift_days,
|
shift_days,
|
||||||
balance_by_site=True,
|
# balance_by_site=True,
|
||||||
|
balance_offset=1, # this could be generated dynamically
|
||||||
|
balance_weighting=1, # this could be generated dynamically
|
||||||
workers_required=1,
|
workers_required=1,
|
||||||
rota_on_nwds=False,
|
rota_on_nwds=False,
|
||||||
):
|
):
|
||||||
@@ -32,10 +34,19 @@ class SingleShift(object):
|
|||||||
self.name = name
|
self.name = name
|
||||||
self.length = length
|
self.length = length
|
||||||
self.shift_days = shift_days
|
self.shift_days = shift_days
|
||||||
self.balance_by_site = balance_by_site
|
# self.balance_by_site = balance_by_site
|
||||||
|
# balance_offset defines the max difference in allocated shifts
|
||||||
|
# versus target shifts (hard constraint)
|
||||||
|
# if 0 exactly equal shifts must be assigend (unlikely to be possible)
|
||||||
|
self.balance_offset = balance_offset
|
||||||
|
|
||||||
|
# weight the shift for balancing, default is 1
|
||||||
|
self.balance_weighting = balance_weighting
|
||||||
|
|
||||||
self.workers_required = workers_required
|
self.workers_required = workers_required
|
||||||
self.rota_on_nwds = rota_on_nwds
|
self.rota_on_nwds = rota_on_nwds
|
||||||
|
|
||||||
|
self.total_shifts = length * len(days) * len(shift_days)
|
||||||
|
|
||||||
class ShiftCollection(object):
|
class ShiftCollection(object):
|
||||||
"""Class to hold and manipulate shifts"""
|
"""Class to hold and manipulate shifts"""
|
||||||
@@ -51,6 +62,8 @@ class ShiftCollection(object):
|
|||||||
self.rota_days_length = len(self.weeks) * 7
|
self.rota_days_length = len(self.weeks) * 7
|
||||||
self.rota_end_date = self.start_date + datetime.timedelta(self.rota_days_length)
|
self.rota_end_date = self.start_date + datetime.timedelta(self.rota_days_length)
|
||||||
|
|
||||||
|
self.unavailable_to_work = set()
|
||||||
|
|
||||||
def add_shift(self, shift):
|
def add_shift(self, shift):
|
||||||
"""Add a shift to the collection
|
"""Add a shift to the collection
|
||||||
|
|
||||||
@@ -151,8 +164,12 @@ class ShiftCollection(object):
|
|||||||
"""
|
"""
|
||||||
return self.week_day_shift_product
|
return self.week_day_shift_product
|
||||||
|
|
||||||
def GetAllShiftsAsClass(self) -> List[SingleShift]:
|
def GetAllShiftsAsClass(self) -> List[Tuple[WeekInt, DayStr, SingleShift]]:
|
||||||
""" """
|
"""Returns a list of all possible week / day / shift combinations
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: contains tuple of all possible week / day / shift combinations
|
||||||
|
"""
|
||||||
return self.week_day_shiftclass_product
|
return self.week_day_shiftclass_product
|
||||||
|
|
||||||
def GetAllWeeksDays(self) -> list:
|
def GetAllWeeksDays(self) -> list:
|
||||||
|
|||||||
+6
-3
@@ -1,10 +1,11 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
from shifts import SingleShift, ShiftCollection, days, sites
|
from shifts import SingleShift, ShiftCollection, days, sites
|
||||||
|
|
||||||
|
|
||||||
class Worker:
|
class Worker:
|
||||||
def __init__(self, Shifts, id, name, site, grade, fte=100, nwd=[], end_date=None, oop=None):
|
def __init__(self, Shifts, id, name, site, grade, fte=100, nwd=None, end_date=None, oop=None):
|
||||||
self.id = id
|
self.id = id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.site = site
|
self.site = site
|
||||||
@@ -13,6 +14,8 @@ class Worker:
|
|||||||
self.nwd = nwd
|
self.nwd = nwd
|
||||||
self.proportion_rota_to_work = 1
|
self.proportion_rota_to_work = 1
|
||||||
|
|
||||||
|
self.shift_target_number = defaultdict(int)
|
||||||
|
|
||||||
days_to_work = Shifts.rota_days_length
|
days_to_work = Shifts.rota_days_length
|
||||||
|
|
||||||
if end_date is None:
|
if end_date is None:
|
||||||
@@ -28,7 +31,7 @@ class Worker:
|
|||||||
# add unavalabilities
|
# add unavalabilities
|
||||||
for weeks_days in Shifts.weeks_days_product[days_to_work:]:
|
for weeks_days in Shifts.weeks_days_product[days_to_work:]:
|
||||||
week, day = weeks_days
|
week, day = weeks_days
|
||||||
unavailable_to_work.add((self.id, week, day))
|
Shifts.unavailable_to_work.add((self.id, week, day))
|
||||||
|
|
||||||
if oop is not None:
|
if oop is not None:
|
||||||
start_oop, end_oop = oop
|
start_oop, end_oop = oop
|
||||||
@@ -45,7 +48,7 @@ class Worker:
|
|||||||
|
|
||||||
for weeks_days in Shifts.weeks_days_product[days_until_oop:days_until_oop+oop_length]:
|
for weeks_days in Shifts.weeks_days_product[days_until_oop:days_until_oop+oop_length]:
|
||||||
week, day = weeks_days
|
week, day = weeks_days
|
||||||
unavailable_to_work.add((self.id, week, day))
|
Shifts.unavailable_to_work.add((self.id, week, day))
|
||||||
|
|
||||||
|
|
||||||
self.proportion_rota_to_work = days_to_work / Shifts.rota_days_length
|
self.proportion_rota_to_work = days_to_work / Shifts.rota_days_length
|
||||||
|
|||||||
Reference in New Issue
Block a user