further tests and fixes

This commit is contained in:
Ross
2022-05-18 17:20:28 +01:00
parent f887257a55
commit a8cf3e3460
7 changed files with 953 additions and 102 deletions
+43 -47
View File
@@ -227,7 +227,6 @@ class TestDemoRotaNights:
"night_weekday",
12.5,
days[:4],
balance_offset=10,
workers_required=1,
constraints=["preclear2", "postclear2"],
# constraints=["night"],
@@ -241,7 +240,6 @@ class TestDemoRotaNights:
"night_weekend",
12.5,
days[4:],
balance_offset=40,
# balance_weighting=0.5
constraints=["preclear2", "postclear2"],
# constraints=["night"],
@@ -252,7 +250,6 @@ class TestDemoRotaNights:
"twilight",
12.5,
days[:5],
balance_offset=40,
# balance_weighting=0.5
workers_required=2,
# constraints=["preclear2", "postclear2"],
@@ -268,37 +265,36 @@ class TestDemoRotaNights:
Rota.build_workers()
Rota.build_model()
print(Rota.get_worker_details())
for w in Rota.get_workers():
print(w)
print(w.get_shift_targets())
solver_options = {"ratio": 0.1, "seconds": 1000, "threads": 10}
solver_options = {"ratio": 0.00, "seconds": 1000, "threads": 10}
Rota.solve_model(options=solver_options)
# print(Rota.get_worker_details())
# optimizer = SolverFactory('cbc')
# result = optimizer.solve(prob,tee=True)
# result.Solver.Status = SolverStatus.warning
# prob.solutions.load_from(result)
worker_timetable_brief = Rota.get_worker_timetable_brief(
show_prefs=False, show_unavailable=False
)
print(worker_timetable_brief)
print(Rota.get_shift_summary_dict())
Rota.export_rota_to_html("test3")
print(Rota.get_worker_shift_list(worker1))
def test_start_date(self):
assert self.Rota.start_date == self.start_date
def test_night_assignment(self):
shift_summary = self.Rota.get_shift_summary_dict()
for worker_name in shift_summary:
worker_shifts = shift_summary[worker_name]
worker = self.Rota.get_worker_by_name(worker_name)
if worker.fte == 40:
assert worker_shifts["night_weekday"] in (0,4)
assert worker_shifts["night_weekend"] in (0,3)
elif worker.fte == 60:
assert worker_shifts["night_weekday"] in (0,4,8)
assert worker_shifts["night_weekend"] in (0,3,6)
else:
assert worker_shifts["night_weekday"] in (4,8)
assert worker_shifts["night_weekend"] in (3,6)
class TestDemoRotaClear:
weeks_to_rota = 10
start_date = datetime.date(2022, 3, 7)
@@ -946,10 +942,10 @@ class TestNightUnavailable:
# Add a few workers
worker1 = Worker(
Rota, "worker1", "group1", 1, not_available_to_work=(("15/03/22", "****"),)
Rota, "worker1", "group1", 1, not_available_to_work=((datetime.datetime.strptime("15/03/22", "%d/%m/%y").date(), "****"),)
)
worker2 = Worker(
Rota, "worker2", "group1", 1, not_available_to_work=(("14/03/22", "****"),)
Rota, "worker2", "group1", 1, not_available_to_work=((datetime.datetime.strptime("14/03/22", "%d/%m/%y").date(), "****"),)
)
Rota.add_workers((worker1, worker2))
@@ -1011,10 +1007,10 @@ class TestNightUnavailable:
def test_assign_split(self):
self.Rota.shifts = []
worker3 = Worker(
self.Rota, "worker3", "group1", 1, not_available_to_work=(("13/03/22", "****"),)
self.Rota, "worker3", "group1", 1, not_available_to_work=((datetime.datetime.strptime("13/03/22", "%d/%m/%y").date(), "****"),)
)
worker4 = Worker(
self.Rota, "worker4", "group1", 1, not_available_to_work=(("12/03/22", "****"),)
self.Rota, "worker4", "group1", 1, not_available_to_work=((datetime.datetime.strptime("12/03/22", "%d/%m/%y").date(), "****"),)
)
self.Rota.add_workers((worker3, worker4))
@@ -1034,25 +1030,25 @@ class TestNightUnavailable:
for worker in summary:
assert summary[worker]["night_weekend"] == 15
def test_assign_split_night_constraint(self):
self.Rota.shifts = []
worker3 = Worker(
self.Rota, "worker3", "group1", 1, not_available_to_work=(("13/03/22", "****"),)
)
worker4 = Worker(
self.Rota, "worker4", "group1", 1, not_available_to_work=(("12/03/22", "****"),)
)
self.Rota.add_workers((worker3, worker4))
self.Rota.add_shifts(
SingleShift(
("group1",), "night_weekend", 12.5, days[5:], workers_required=3, constraints=["night"]
),
)
self.Rota.build_and_solve(options={"ratio": 0.00})
assert self.Rota.results.solver.status == "warning"
# def test_assign_split_night_constraint(self):
# self.Rota.shifts = []
# worker3 = Worker(
# self.Rota, "worker3", "group1", 1, not_available_to_work=((datetime.datetime.strptime("13/03/22", "%d/%m/%y").date(), "****"),)
# )
# worker4 = Worker(
# self.Rota, "worker4", "group1", 1, not_available_to_work=((datetime.datetime.strptime("12/03/22", "%d/%m/%y").date(), "****"),)
# )
# self.Rota.add_workers((worker3, worker4))
#
# self.Rota.add_shifts(
# SingleShift(
# ("group1",), "night_weekend", 12.5, days[5:], workers_required=3, constraints=["night"]
# ),
# )
#
# self.Rota.build_and_solve(options={"ratio": 0.00})
#
# assert self.Rota.results.solver.status == "warning"
if __name__ == "__main__":
t = TestLimitConstraints()