e
This commit is contained in:
+274
-4
@@ -197,8 +197,10 @@ class TestNightShifts:
|
||||
length=12.5,
|
||||
days=days[:2],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"},
|
||||
{"name": "pre", "options": 5},{"name": "post", "options": 5},
|
||||
constraint=[
|
||||
{"name": "night"},
|
||||
{"name": "pre", "options": 5},
|
||||
{"name": "post", "options": 5},
|
||||
],
|
||||
workers_required=3,
|
||||
),
|
||||
@@ -227,10 +229,10 @@ class TestNightShifts:
|
||||
"date": Rota.rota_end_date - datetime.timedelta(days=1),
|
||||
"reason": "no wanna",
|
||||
},
|
||||
#{
|
||||
# {
|
||||
# "date": Rota.rota_end_date - datetime.timedelta(days=5),
|
||||
# "reason": "no wanna",
|
||||
#},
|
||||
# },
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -240,3 +242,271 @@ class TestNightShifts:
|
||||
Rota.export_rota_to_html("night")
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
def test_nights_max_frequency(self):
|
||||
Rota = generate_basic_rota()
|
||||
|
||||
Rota.constraint_options["max_night_frequency"] = 1
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="n",
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
workers_required=2,
|
||||
),
|
||||
# SingleShift(
|
||||
# sites=("group1", "group2"),
|
||||
# name="m",
|
||||
# length=12.5,
|
||||
# days=days[:5],
|
||||
# force_as_block=True,
|
||||
# # constraint=[{"name": "night"}, {"name": "pre", "options": 3}],
|
||||
# # constraint=[{"name": "night"}],
|
||||
# workers_required=2,
|
||||
# ),
|
||||
# SingleShift(
|
||||
# sites=("group1", "group2"), name="b", length= 12.5, days=days[:3],
|
||||
# force_as_block=False,
|
||||
# #constraint=[{"name": "night"}],
|
||||
# ),
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
Rota.export_rota_to_html("night")
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
def test_nights_max_frequency_fail(self):
|
||||
Rota = generate_basic_rota()
|
||||
|
||||
Rota.constraint_options["max_night_frequency"] = 2
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="n",
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
workers_required=2,
|
||||
),
|
||||
# SingleShift(
|
||||
# sites=("group1", "group2"),
|
||||
# name="m",
|
||||
# length=12.5,
|
||||
# days=days[:5],
|
||||
# force_as_block=True,
|
||||
# # constraint=[{"name": "night"}, {"name": "pre", "options": 3}],
|
||||
# # constraint=[{"name": "night"}],
|
||||
# workers_required=2,
|
||||
# ),
|
||||
# SingleShift(
|
||||
# sites=("group1", "group2"), name="b", length= 12.5, days=days[:3],
|
||||
# force_as_block=False,
|
||||
# #constraint=[{"name": "night"}],
|
||||
# ),
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
Rota.export_rota_to_html("night")
|
||||
|
||||
assert Rota.results.solver.status == "warning"
|
||||
|
||||
def test_nights_max_frequency3(self):
|
||||
Rota = generate_basic_rota()
|
||||
|
||||
Rota.constraint_options["max_night_frequency"] = 2
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="n",
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
workers_required=1,
|
||||
),
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="m",
|
||||
length=12.5,
|
||||
days=days[:5],
|
||||
force_as_block=True,
|
||||
# constraint=[{"name": "night"}, {"name": "pre", "options": 3}],
|
||||
constraint=[{"name": "night"}],
|
||||
workers_required=1,
|
||||
),
|
||||
# SingleShift(
|
||||
# sites=("group1", "group2"), name="b", length= 12.5, days=days[:3],
|
||||
# force_as_block=False,
|
||||
# #constraint=[{"name": "night"}],
|
||||
# ),
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
Rota.export_rota_to_html("night")
|
||||
|
||||
assert Rota.results.solver.status == "warning"
|
||||
|
||||
def test_nights_max_frequency4(self):
|
||||
Rota = generate_basic_rota()
|
||||
|
||||
Rota.constraint_options["max_night_frequency"] = 2
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="n",
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
workers_required=1,
|
||||
),
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="m",
|
||||
length=12.5,
|
||||
days=days[:5],
|
||||
force_as_block=True,
|
||||
# constraint=[{"name": "night"}, {"name": "pre", "options": 3}],
|
||||
constraint=[{"name": "night"}],
|
||||
workers_required=1,
|
||||
),
|
||||
# SingleShift(
|
||||
# sites=("group1", "group2"), name="b", length= 12.5, days=days[:3],
|
||||
# force_as_block=False,
|
||||
# #constraint=[{"name": "night"}],
|
||||
# ),
|
||||
)
|
||||
|
||||
Rota.add_workers(
|
||||
[
|
||||
Worker(
|
||||
name="worker3",
|
||||
site="group1",
|
||||
grade=1,
|
||||
),
|
||||
Worker(
|
||||
name="worker4",
|
||||
site="group1",
|
||||
grade=1,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
Rota.export_rota_to_html("night")
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
def test_nights_max_frequency_exclusions(self):
|
||||
Rota = generate_basic_rota()
|
||||
|
||||
Rota.constraint_options["max_night_frequency"] = 2
|
||||
Rota.constraint_options["max_night_frequency_week_exclusions"] = list(range(10))
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="n",
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
workers_required=2,
|
||||
),
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
Rota.export_rota_to_html("night")
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
def test_nights_max_frequency_exclusions2(self):
|
||||
Rota = generate_basic_rota(weeks_to_rota=8)
|
||||
|
||||
Rota.constraint_options["max_night_frequency"] = 2
|
||||
Rota.constraint_options["max_night_frequency_week_exclusions"] = list(range(1,4))
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="n",
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
constraint=[{"name": "night"}],
|
||||
workers_required=2,
|
||||
),
|
||||
)
|
||||
|
||||
Rota.add_workers(
|
||||
[
|
||||
Worker(
|
||||
name="worker3",
|
||||
site="group1",
|
||||
grade=1,
|
||||
start_date=Rota.start_date + datetime.timedelta(weeks=4)
|
||||
),
|
||||
Worker(
|
||||
name="worker4",
|
||||
site="group1",
|
||||
grade=1,
|
||||
start_date=Rota.start_date + datetime.timedelta(weeks=4)
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
Rota.export_rota_to_html("night")
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
def test_nights_max_frequency_exclusions3(self):
|
||||
# TODO: find out the issues with odd rotas and exclusions
|
||||
Rota = generate_basic_rota(weeks_to_rota=9)
|
||||
|
||||
Rota.constraint_options["max_night_frequency"] = 2
|
||||
Rota.constraint_options["max_night_frequency_week_exclusions"] = list(range(1,5))
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1", "group2"),
|
||||
name="n",
|
||||
length=12.5,
|
||||
days=days[5:],
|
||||
force_as_block=True,
|
||||
balance_offset=10,
|
||||
constraint=[{"name": "night"}],
|
||||
workers_required=2,
|
||||
),
|
||||
)
|
||||
|
||||
Rota.add_workers(
|
||||
[
|
||||
Worker(
|
||||
name="worker3",
|
||||
site="group1",
|
||||
grade=1,
|
||||
start_date=Rota.start_date + datetime.timedelta(weeks=4)
|
||||
),
|
||||
Worker(
|
||||
name="worker4",
|
||||
site="group1",
|
||||
grade=1,
|
||||
start_date=Rota.start_date + datetime.timedelta(weeks=4)
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
Rota.build_and_solve(options={"ratio": 0.000})
|
||||
Rota.export_rota_to_html("night")
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
@@ -318,3 +318,76 @@ class TestWorkers:
|
||||
assert Rota.results.solver.termination_condition == "optimal"
|
||||
|
||||
Rota.export_rota_to_html("worker_oops")
|
||||
|
||||
def test_worker_pairs(self):
|
||||
Rota = setup_basic_rota()
|
||||
|
||||
Rota.add_shifts(
|
||||
SingleShift(
|
||||
sites=("group1",),
|
||||
name="a",
|
||||
length=12.5,
|
||||
days=days[:5],
|
||||
balance_offset=20,
|
||||
workers_required=1,
|
||||
),
|
||||
SingleShift(
|
||||
sites=("group1",),
|
||||
name="b",
|
||||
length=12.5,
|
||||
days=days[:5],
|
||||
balance_offset=20,
|
||||
workers_required=1,
|
||||
),
|
||||
)
|
||||
|
||||
Rota.add_workers(
|
||||
[
|
||||
Worker(name="worker1", site="group1", grade=1, fte=100, pair="1"),
|
||||
Worker(name="worker2", site="group1", grade=1, fte=100, pair="1"),
|
||||
]
|
||||
)
|
||||
|
||||
Rota.constraint_options["hard_constrain_pair_separation"] = True
|
||||
|
||||
Rota.build_and_solve()
|
||||
|
||||
# With two paired workers we shouldn't be able to solve
|
||||
assert Rota.results.solver.status == "warning"
|
||||
|
||||
worker3 = Worker(name="worker3", site="group1", grade=1, fte=100)
|
||||
Rota.add_worker(worker3)
|
||||
|
||||
# An additional worker can take half the shifts
|
||||
Rota.build_and_solve()
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
assert Rota.get_workers_total_shifts()["worker3"] == 50
|
||||
assert (
|
||||
Rota.get_workers_total_shifts()["worker1"]
|
||||
+ Rota.get_workers_total_shifts()["worker2"]
|
||||
== 50
|
||||
)
|
||||
|
||||
worker3.pair = "1"
|
||||
|
||||
Rota.build_and_solve()
|
||||
|
||||
assert Rota.results.solver.status == "warning"
|
||||
|
||||
worker3.pair = 0
|
||||
|
||||
Rota.build_and_solve()
|
||||
Rota.export_rota_to_html("worker_pairs")
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
|
||||
worker4 = Worker(name="worker4", site="group1", grade=1, fte=100, pair="1")
|
||||
Rota.add_worker(worker4)
|
||||
|
||||
Rota.build_and_solve()
|
||||
Rota.export_rota_to_html("worker_pairs")
|
||||
|
||||
assert Rota.results.solver.status == "ok"
|
||||
assert Rota.get_workers_total_shifts()["worker3"] == 50
|
||||
Reference in New Issue
Block a user