This commit is contained in:
Ross
2023-06-22 20:56:19 +01:00
parent beda17c7e8
commit cbbdc8d318
2 changed files with 63 additions and 47 deletions
+48 -40
View File
@@ -27,23 +27,25 @@ from rota.workers import (
suspend_on_finish = False
solve = True
#time_to_run = 508500
#time_to_run = 2660000
# time_to_run = 508500
# time_to_run = 2660000
time_to_run = 100
#allow = 5000
# allow = 5000
ratio = 0.41
#ratio = 0.9
# ratio = 0.9
start_date = datetime.date(2023, 9, 4)
#start_date = datetime.date(2023, 5, 1)
#start_date = start_date + datetime.timedelta(weeks=13)
# start_date = datetime.date(2023, 5, 1)
# start_date = start_date + datetime.timedelta(weeks=13)
# start_date = datetime.date(2022, 10, 10)
Rota = RotaBuilder(start_date, weeks_to_rota=10, balance_offset_modifier=1)
#Rota = RotaBuilder(start_date, weeks_to_rota=20, balance_offset_modifier=1)
Rota = RotaBuilder(
start_date, weeks_to_rota=10, balance_offset_modifier=1, name="proc rota"
)
# Rota = RotaBuilder(start_date, weeks_to_rota=20, balance_offset_modifier=1)
Rota.constraint_options["balance_weekends"] = True
Rota.constraint_options["max_night_frequency"] = 3 # 3
Rota.constraint_options["max_night_frequency"] = 3 # 3
Rota.constraint_options["max_night_frequency_week_exclusions"] = []
Rota.constraint_options["max_weekend_frequency"] = 2
Rota.constraint_options["hard_constrain_pair_separation"] = True
@@ -132,7 +134,7 @@ Rota.add_shifts(
constraint=[{"name": "pre", "options": 2}, {"name": "post", "options": 2}],
),
SingleShift(
sites=("plymouth","plymouth twilights and weekends"),
sites=("plymouth", "plymouth twilights and weekends"),
name="weekend_plymouth2",
length=8,
days=days[5:],
@@ -143,7 +145,7 @@ Rota.add_shifts(
constraint=[{"name": "pre", "options": 2}, {"name": "post", "options": 2}],
),
SingleShift(
sites=("plymouth", "plymouth twilights","plymouth twilights and weekends"),
sites=("plymouth", "plymouth twilights", "plymouth twilights and weekends"),
name="plymouth_bank_holidays",
length=8,
days=days[5:],
@@ -195,11 +197,11 @@ Rota.add_shifts(
),
)
#Rota.add_grade_constraint_by_week([2], [1, 2], ["night_weekday", "night_weekend"])
# Rota.add_grade_constraint_by_week([2], [1, 2], ["night_weekday", "night_weekend"])
load_leave = True
Rota.build_shifts()
#Rota.add_grade_constraint_by_week([2], [1], Rota.get_shift_names())
# Rota.add_grade_constraint_by_week([2], [1], Rota.get_shift_names())
if load_leave:
import leave
@@ -254,13 +256,19 @@ if load_leave:
# nwds = [i.strip()[:3].capitalize() for i in nwd.split("/")] if nwd else None
end_date = end_date if end_date else None
if oop:
formatted_oops = []
for dates in oop.split(","):
s, e = dates.split("-")
formatted_oops.append(
{"start_date": datetime.datetime.strptime(s.strip(), "%d/%m/%y").date(), "end_date": datetime.datetime.strptime(e.strip(), "%d/%m/%y").date()}
{
"start_date": datetime.datetime.strptime(
s.strip(), "%d/%m/%y"
).date(),
"end_date": datetime.datetime.strptime(
e.strip(), "%d/%m/%y"
).date(),
}
)
oop = formatted_oops
@@ -300,42 +308,42 @@ if load_leave:
site_pref = w["site_pref"]
w = Worker(
name=worker_name,
site=site.lower(),
grade=int(grade[2]),
id=n,
fte=int(fte),
nwds=nwds,
start_date=start_date,
end_date=end_date,
oop=oop,
not_available_to_work=leave_requests,
work_requests=work_requests,
remote_site=site_pref,
previous_shifts=previous_shifts,
pair=pair,
shift_balance_extra=w["shift_balance_extra"],
bank_holiday_extra=w["bank_holiday_extra"],
)
name=worker_name,
site=site.lower(),
grade=int(grade[2]),
id=n,
fte=int(fte),
nwds=nwds,
start_date=start_date,
end_date=end_date,
oop=oop,
not_available_to_work=leave_requests,
work_requests=work_requests,
remote_site=site_pref,
previous_shifts=previous_shifts,
pair=pair,
shift_balance_extra=w["shift_balance_extra"],
bank_holiday_extra=w["bank_holiday_extra"],
)
print(w)
Rota.add_worker(w)
# Rota.build_workers()
# Rota.build_model()
solver_options = {"ratio": ratio, "seconds": time_to_run, "threads": 10}
start_time = time.time()
Rota.build_and_solve(solver_options)
#Rota.solve_shifts_by_block(solver_options, block_length=13)
#Rota.solve_shifts_individually(solver_options)
#start_time = time.time()
Rota.build_and_solve(solver_options, export=True)
# Rota.solve_shifts_by_block(solver_options, block_length=13)
# Rota.solve_shifts_individually(solver_options)
# Rota.solve_model(options=solver_options)
end_time = time.time()
#end_time = time.time()
print(f"Time taken {end_time-start_time}")
#print(f"Time taken {end_time-start_time}")
# print(Rota.get_worker_details())
@@ -353,7 +361,7 @@ print(f"Time taken {end_time-start_time}")
# print(worker_timetable_brief)
Rota.export_rota_to_html("proc_rota")
#Rota.export_rota_to_html("proc_rota")
# Rota.export_rota_to_csv("rota")
if suspend_on_finish: