.
This commit is contained in:
+24
-12
@@ -26,6 +26,8 @@ from io import StringIO
|
||||
import sys
|
||||
|
||||
from rich.pretty import pprint
|
||||
from rich.progress import track
|
||||
from rich.panel import Panel
|
||||
|
||||
import logging
|
||||
|
||||
@@ -177,9 +179,9 @@ class RotaBuilder(object):
|
||||
SHIFT_BOUNDS=SHIFT_BOUNDS,
|
||||
):
|
||||
|
||||
print(f"Start time: {datetime.datetime.now()}")
|
||||
print(f"Use previous shifts {use_previous_shifts}")
|
||||
print(f"Use previous shifts (balance_extra) {use_shift_balance_extra}")
|
||||
console.print(Panel(f"""[white]
|
||||
{locals()}
|
||||
""", style="green", title="Generating Rota"), justify="left")
|
||||
|
||||
self.SHIFT_BOUNDS = SHIFT_BOUNDS
|
||||
self.shifts: List[SingleShift] = [] # type List[SingleShift]
|
||||
@@ -203,7 +205,7 @@ class RotaBuilder(object):
|
||||
self.rota_days_length = len(self.weeks) * 7
|
||||
self.rota_end_date = self.start_date + datetime.timedelta(self.rota_days_length)
|
||||
|
||||
print(
|
||||
console.print(
|
||||
f"Weeks to rota: {weeks_to_rota} ({self.start_date} - {self.rota_end_date})"
|
||||
)
|
||||
|
||||
@@ -961,7 +963,7 @@ class RotaBuilder(object):
|
||||
# - self.model.night_per_site_t2[week, block, site]
|
||||
# == self.model.night_per_site[week, block, site] - 1
|
||||
# )
|
||||
for site in self.sites:
|
||||
for site in track(self.sites, description="Generating site balance constraints..."):
|
||||
for shift in self.get_shifts_with_constraint("balance_across_groups"):
|
||||
if site in shift.sites:
|
||||
block = shift.name
|
||||
@@ -985,7 +987,7 @@ class RotaBuilder(object):
|
||||
|
||||
weeks_days = self.get_week_day_combinations()
|
||||
|
||||
for week in self.weeks:
|
||||
for week in track(self.weeks, description="Generating week constraints..."):
|
||||
for shift_name in self.shifts_to_assign_or_force_as_blocks():
|
||||
shift = self.get_shift_by_name(shift_name)
|
||||
for worker in self.get_workers_for_shift(shift):
|
||||
@@ -1073,6 +1075,8 @@ class RotaBuilder(object):
|
||||
|
||||
# Most of our constraints apply per worker
|
||||
for worker in self.workers:
|
||||
console.rule(f"Generate worker constraints: [bold blue]{worker.name}[/bold blue]")
|
||||
logging.debug(f"Generate worker constraints: {worker.name}")
|
||||
|
||||
if self.constraint_options["minimise_shift_diffs"]:
|
||||
self.model.constraints.add(
|
||||
@@ -1097,6 +1101,7 @@ class RotaBuilder(object):
|
||||
except ValueError:
|
||||
# Occurs if there are no shifts within a defined block
|
||||
# TODO: test if this breaks (and we should check rathar than except)
|
||||
logging.debug(f"Failed to constrain max_shifts_per_month for worker: {worker.name}")
|
||||
pass
|
||||
|
||||
for constraint_dict in self.constraint_options["avoid_shifts_by_grades"]:
|
||||
@@ -1161,7 +1166,7 @@ class RotaBuilder(object):
|
||||
# Balance shifts within required limits (set by balance_offset)
|
||||
# If balance_offset is too restrictive (for the rota length)
|
||||
# no solution will be possible
|
||||
for shift in self.get_shifts():
|
||||
for shift in track(self.get_shifts(), description="Generate shift balance constraints"):
|
||||
if (
|
||||
worker.site in shift.sites
|
||||
): # Each site specfies which sites self.workers can fullfill it
|
||||
@@ -1777,7 +1782,7 @@ class RotaBuilder(object):
|
||||
|
||||
# def get_pre_may(week_days, max_pre)
|
||||
|
||||
for n in range(len(weeks_days)):
|
||||
for n in track(range(len(weeks_days)), description="Generate week/day constraints"):
|
||||
|
||||
week, day = weeks_days[n]
|
||||
|
||||
@@ -2358,7 +2363,7 @@ class RotaBuilder(object):
|
||||
self.workers_id_map = {}
|
||||
self.workers_name_map = {}
|
||||
|
||||
for worker in self.workers:
|
||||
for worker in track(self.workers, description="Building workers"):
|
||||
worker.load_rota(self)
|
||||
wid = worker.id
|
||||
if wid in self.workers_id_map:
|
||||
@@ -2377,7 +2382,7 @@ class RotaBuilder(object):
|
||||
self.full_time_equivalent_sites = {}
|
||||
self.workers_at_sites = {}
|
||||
|
||||
for site in self.sites:
|
||||
for site in track(self.sites, description="Generating site workers"):
|
||||
self.workers_at_sites[site] = [w for w in self.workers if w.site == site]
|
||||
self.full_time_equivalent_sites[site] = sum(
|
||||
w.fte_adj for w in self.workers if w.site == site
|
||||
@@ -2920,9 +2925,9 @@ class RotaBuilder(object):
|
||||
for week, day in self.get_week_day_combinations():
|
||||
d = self.start_date + datetime.timedelta(n)
|
||||
|
||||
th_class = ""
|
||||
th_class = "date"
|
||||
if d in bank_holiday_map:
|
||||
th_class = "bank-holiday"
|
||||
th_class = th_class + " bank-holiday"
|
||||
|
||||
date_row.append(
|
||||
f"<th title='{d}' class='{th_class}' data-date='{d}'>Week {week}: {day}</th>"
|
||||
@@ -3140,6 +3145,13 @@ class RotaBuilder(object):
|
||||
<div id="export-div">
|
||||
<div>
|
||||
</details>
|
||||
<details>
|
||||
<summary><h2>Shift timetables</h2></summary>
|
||||
<div id="shift-timetable-options">
|
||||
</div>
|
||||
<div id="shift-timetable-div">
|
||||
<div>
|
||||
</details>
|
||||
</div
|
||||
</body>
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user