...
This commit is contained in:
+4
-4
@@ -591,7 +591,7 @@ class TestShiftWorkerRequirements:
|
||||
SingleShift(
|
||||
sites=("group1", "group2"), name="a", length= 12.5, days=days[:4],
|
||||
assign_as_block=True,
|
||||
force_as_block=True,
|
||||
#force_as_block=True,
|
||||
workers_required=wr,
|
||||
#start_date=(Rota.start_date + datetime.timedelta(days=7)),
|
||||
#end_date=(Rota.start_date + datetime.timedelta(days=((7*6)-1))),
|
||||
@@ -619,7 +619,7 @@ class TestShiftWorkerRequirements:
|
||||
SingleShift(
|
||||
sites=("group1", "group2"), name="a", length= 12.5, days=days[:4],
|
||||
assign_as_block=True,
|
||||
force_as_block=True,
|
||||
#force_as_block=True,
|
||||
workers_required=wr,
|
||||
#start_date=(Rota.start_date + datetime.timedelta(days=7)),
|
||||
#end_date=(Rota.start_date + datetime.timedelta(days=((7*6)-1))),
|
||||
@@ -686,7 +686,7 @@ class TestShiftWorkerRequirements:
|
||||
SingleShift(
|
||||
sites=("group1", "group2"), name="b", length= 12.5, days=days[4:],
|
||||
assign_as_block=True,
|
||||
force_as_block=True,
|
||||
#force_as_block=True,
|
||||
workers_required=2,
|
||||
#start_date=(Rota.start_date + datetime.timedelta(days=7)),
|
||||
#end_date=(Rota.start_date + datetime.timedelta(days=((7*6)-1))),
|
||||
@@ -694,7 +694,7 @@ class TestShiftWorkerRequirements:
|
||||
SingleShift(
|
||||
sites=("group1", "group2"), name="a", length= 12.5, days=days[:4],
|
||||
assign_as_block=True,
|
||||
force_as_block=True,
|
||||
#force_as_block=True,
|
||||
workers_required=wr,
|
||||
#start_date=(Rota.start_date + datetime.timedelta(days=7)),
|
||||
#end_date=(Rota.start_date + datetime.timedelta(days=((7*6)-1))),
|
||||
|
||||
@@ -95,7 +95,7 @@ class TestWorkerRequests:
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
Rota.export_rota_to_html("preferences_not_to_work2")
|
||||
Rota.export_rota_to_html("preferences_not_to_work2", timestamp_filename=False)
|
||||
|
||||
shift_summary = Rota.get_shift_summary_dict()
|
||||
for worker_name in shift_summary:
|
||||
|
||||
+183
-10
@@ -2,7 +2,8 @@ import pytest
|
||||
from rota.shifts import NoWorkers, RotaBuilder, SingleShift, WarningTermination, WorkerRequirement, days
|
||||
|
||||
import datetime
|
||||
from rota.workers import NotAvailableToWork, Worker, generate_not_available_to_works
|
||||
from rota.workers import NonWorkingDays, NotAvailableToWork, Worker, generate_not_available_to_works
|
||||
from rota.workers import WorkRequests
|
||||
|
||||
|
||||
def generate_basic_rota(
|
||||
@@ -619,6 +620,7 @@ class TestComplexWorkers:
|
||||
# assert worker.get_fte("b") == 50
|
||||
# assert total_shifts[worker.name] == 20
|
||||
#total_shifts = Rota.get_workers_total_shifts()
|
||||
assert Rota.results.solver.status == "ok"
|
||||
for worker in Rota.get_workers():
|
||||
shift_string = Rota.get_worker_shift_list_string(worker)
|
||||
assert shift_string.count("cccc") == shift_string.count("c") / 4
|
||||
@@ -674,30 +676,198 @@ class TestComplexWorkers:
|
||||
Rota.build_and_solve()
|
||||
|
||||
Rota.export_rota_to_html("test_split")
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
|
||||
class TestLocums:
|
||||
def test_locums(self):
|
||||
Rota = generate_basic_rota(workers=9, weeks_to_rota=22)
|
||||
def test_locums_basic(self):
|
||||
Rota = generate_basic_rota(workers=2, weeks_to_rota=6)
|
||||
|
||||
Rota.set_rota_constraint("max_shifts_per_week", 2)
|
||||
Rota.set_rota_constraint("max_weekend_frequency", 3)
|
||||
Rota.set_rota_constraint("max_shifts_per_month", 4)
|
||||
|
||||
Rota.terminate_on_warning.remove("Worker/no valid shifts")
|
||||
la = []
|
||||
for date in Rota.get_date_range(end_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||
#for date in Rota.get_date_range():
|
||||
la.append(WorkRequests(date=date, shift="*"))
|
||||
la2 = []
|
||||
for date in Rota.get_date_range(start_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||
#for date in Rota.get_date_range():
|
||||
la2.append(WorkRequests(date=date, shift="*"))
|
||||
|
||||
Rota.add_workers(
|
||||
[
|
||||
Worker(name="worker03", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1),
|
||||
Worker(name="worker04", site="group1", locum=False, locum_availability=la2, locum_max_shifts=40, locum_max_shifts_per_week=2),
|
||||
Worker(name="locum1", site="group1", locum=True),
|
||||
Worker(
|
||||
name="locum2", site="group1", locum=True
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="a",
|
||||
length=12.5,
|
||||
days=days[:4],
|
||||
workers_required=1,
|
||||
|
||||
constraint=[
|
||||
#{"name": "pre", "options": 1},
|
||||
#{"name": "post", "options": 1},
|
||||
#{"name": "max_shifts_per_week", "options": 1},
|
||||
]
|
||||
),
|
||||
)
|
||||
Rota.set_rota_constraint("distribute_locum_shifts", True)
|
||||
Rota.set_rota_constraint("maximum_allowed_shift_diff", 0)
|
||||
Rota.set_rota_constraint("maximum_allowed_locum_shifts_per_worker", 4)
|
||||
|
||||
Rota.build_and_solve()
|
||||
|
||||
Rota.export_rota_to_html("test_locums_basic", timestamp_filename=False)
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
for worker in Rota.get_workers():
|
||||
assert Rota.get_worker_shift_list(worker).count("a") == 4
|
||||
|
||||
def test_locums_nwds(self):
|
||||
Rota = generate_basic_rota(workers=2, weeks_to_rota=6)
|
||||
|
||||
la = []
|
||||
for date in Rota.get_date_range(end_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||
la.append(WorkRequests(date=date, shift="*"))
|
||||
la2 = []
|
||||
for date in Rota.get_date_range(start_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||
la2.append(WorkRequests(date=date, shift="*"))
|
||||
|
||||
Rota.add_workers(
|
||||
[
|
||||
Worker(name="worker03", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1, nwds=[NonWorkingDays(day="Tue")]),
|
||||
Worker(name="worker04", site="group1", locum=False, locum_availability=la2, locum_max_shifts=40, locum_max_shifts_per_week=2, nwds=[NonWorkingDays(day="Wed"),NonWorkingDays(day="Thu")]),
|
||||
#Worker(name="worker03", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1, nwds=[NonWorkingDays(day="Mon"),NonWorkingDays(day="Tue")]),
|
||||
#Worker(name="worker04", site="group1", locum=False, locum_availability=la2, locum_max_shifts=40, locum_max_shifts_per_week=2, nwds=[NonWorkingDays(day="Wed"),NonWorkingDays(day="Thu")]),
|
||||
Worker(name="locum1", site="group1", locum=True),
|
||||
Worker(
|
||||
name="extra1", site="locum"
|
||||
name="locum2", site="group1", locum=True
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="a",
|
||||
length=12.5,
|
||||
days=days[:4],
|
||||
workers_required=1,
|
||||
|
||||
constraint=[
|
||||
#{"name": "pre", "options": 1},
|
||||
#{"name": "post", "options": 1},
|
||||
#{"name": "max_shifts_per_week", "options": 1},
|
||||
]
|
||||
),
|
||||
)
|
||||
#Rota.set_rota_constraint("distribute_locum_shifts", True)
|
||||
Rota.set_rota_constraint("maximum_allowed_shift_diff", 0)
|
||||
Rota.set_rota_constraint("maximum_allowed_locum_shifts_per_worker", 4)
|
||||
#Rota.set_rota_constraint("minimum_allowed_locum_shifts_per_worker", 3)
|
||||
|
||||
Rota.build_and_solve()
|
||||
|
||||
Rota.export_rota_to_html("test_locums_basic", timestamp_filename=False)
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
for worker in Rota.get_workers():
|
||||
print( Rota.get_worker_shift_list(worker))
|
||||
assert Rota.get_worker_shift_list(worker).count("a") == 4
|
||||
|
||||
if worker.name in ("worker03", "worker04"):
|
||||
assert Rota.get_worker_shift_list(worker, include_locums=True).count("a") > 6
|
||||
|
||||
def test_locums_no_availablity(self):
|
||||
Rota = generate_basic_rota(workers=2, weeks_to_rota=5)
|
||||
|
||||
la = []
|
||||
#for date in Rota.get_date_range(end_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||
# la.append(WorkRequests(date=date, shift="*"))
|
||||
la2 = []
|
||||
#for date in Rota.get_date_range(start_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||
# la2.append(WorkRequests(date=date, shift="*"))
|
||||
|
||||
Rota.add_workers(
|
||||
[
|
||||
Worker(name="worker03", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1),
|
||||
Worker(name="worker04", site="group1", locum=False, locum_availability=la2, locum_max_shifts=40, locum_max_shifts_per_week=2),
|
||||
Worker(name="locum1", site="group1", locum=True),
|
||||
Worker(
|
||||
name="extra2", site="locum"
|
||||
name="locum2", site="group1", locum=True
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="a",
|
||||
length=12.5,
|
||||
days=days[:4],
|
||||
workers_required=1,
|
||||
|
||||
constraint=[
|
||||
#{"name": "pre", "options": 1},
|
||||
#{"name": "post", "options": 1},
|
||||
#{"name": "max_shifts_per_week", "options": 1},
|
||||
]
|
||||
),
|
||||
)
|
||||
Rota.set_rota_constraint("distribute_locum_shifts", False)
|
||||
|
||||
with pytest.raises(WarningTermination):
|
||||
Rota.build_and_solve()
|
||||
|
||||
|
||||
|
||||
def test_locums(self):
|
||||
Rota = generate_basic_rota(workers=7, weeks_to_rota=10)
|
||||
|
||||
Rota.set_rota_constraint("max_shifts_per_week", 2)
|
||||
Rota.set_rota_constraint("max_weekend_frequency", 3)
|
||||
Rota.set_rota_constraint("max_shifts_per_month", 4)
|
||||
#Rota.set_rota_constraint("balance_shifts", False)
|
||||
Rota.set_rota_constraint("distribute_locum_shifts", True)
|
||||
Rota.set_rota_constraint("maximum_allowed_shift_diff", 1)
|
||||
Rota.set_rota_constraint("maximum_allowed_locum_shifts_per_worker", 6)
|
||||
|
||||
Rota.terminate_on_warning.remove("Worker/no valid shifts")
|
||||
|
||||
|
||||
la = []
|
||||
for date in Rota.get_date_range(end_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||
la.append(WorkRequests(date=date, shift="*"))
|
||||
la2 = []
|
||||
for date in Rota.get_date_range(start_date=Rota.rota_end_date-datetime.timedelta(weeks=3)):
|
||||
la2.append(WorkRequests(date=date, shift="*"))
|
||||
|
||||
|
||||
Rota.add_workers(
|
||||
[
|
||||
Worker(name="worker08", site="group1", locum=False, locum_availability=la, locum_max_shifts=40, locum_max_shifts_per_week=1),
|
||||
Worker(name="worker09", site="group1", locum=False, locum_availability=la2, locum_max_shifts=40, locum_max_shifts_per_week=2),
|
||||
Worker(name="locum1", site="group1", locum=True),
|
||||
Worker(
|
||||
name="locum2", site="group1", locum=True
|
||||
),
|
||||
#Worker(
|
||||
# name="extra1", site="locum", locum_availability=la,
|
||||
# locum_max_shifts=40
|
||||
#),
|
||||
#Worker(
|
||||
# name="extra2", site="locum", locum_availability=la,
|
||||
# locum_max_shifts=4, locum_max_shifts_per_week=1
|
||||
#),
|
||||
|
||||
]
|
||||
)
|
||||
@@ -710,6 +880,7 @@ class TestLocums:
|
||||
length=12.5,
|
||||
days=days[:4],
|
||||
workers_required=1,
|
||||
|
||||
constraint=[
|
||||
{"name": "pre", "options": 2},
|
||||
{"name": "post", "options": 3},
|
||||
@@ -744,3 +915,5 @@ class TestLocums:
|
||||
Rota.build_and_solve()
|
||||
|
||||
Rota.export_rota_to_html("test_locums", timestamp_filename=False)
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
Reference in New Issue
Block a user