.
This commit is contained in:
@@ -15,6 +15,9 @@ import csv
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
from io import StringIO
|
||||
import sys
|
||||
|
||||
ShiftName = str
|
||||
DayStr = str
|
||||
WeekInt = int
|
||||
@@ -100,7 +103,7 @@ class RotaBuilder(object):
|
||||
start_date,
|
||||
weeks_to_rota=26,
|
||||
balance_offset_modifier=1,
|
||||
ltft_balance_offset=4,
|
||||
ltft_balance_offset=2,
|
||||
max_night_frequency=2,
|
||||
max_weekend_frequency=2,
|
||||
use_previous_shifts=False,
|
||||
@@ -161,7 +164,8 @@ class RotaBuilder(object):
|
||||
"balance_shifts": True,
|
||||
"balance_weekends": True,
|
||||
"max_weekends": False,
|
||||
"max_shifts_per_week": 5,
|
||||
"max_shifts_per_week": 4,
|
||||
"max_shifts_per_month": 12,
|
||||
"prevent_monday_after_full_weekends": [],
|
||||
"prevent_monday_and_tuesday_after_full_weekends": [],
|
||||
"prevent_fridays_before_full_weekends": [],
|
||||
@@ -682,6 +686,15 @@ class RotaBuilder(object):
|
||||
# Most of our constraints apply per worker
|
||||
for worker in self.workers:
|
||||
|
||||
|
||||
for week_blocks in self.get_week_block_iterator(4):
|
||||
# Prevent weekend shifts more than once every n weeks
|
||||
self.model.constraints.add(
|
||||
self.constraint_options["max_shifts_per_month"] >= sum(
|
||||
self.model.works[worker.id, week, day, shift.name] for week in week_blocks
|
||||
for day in self.days for shift in self.get_shifts()))
|
||||
|
||||
|
||||
if self.constraint_options[
|
||||
"avoid_st2_first_month"] and worker.grade == 2:
|
||||
# Avoid ST1s on the first month
|
||||
@@ -1577,6 +1590,7 @@ class RotaBuilder(object):
|
||||
class RotaResults(object):
|
||||
def __init__(self, rota, results):
|
||||
self.rota = rota
|
||||
self.results = results
|
||||
|
||||
def export_rota_to_csv(self, filename="rota"):
|
||||
works = self.rota.model.works
|
||||
@@ -1845,6 +1859,13 @@ class RotaResults(object):
|
||||
# w.append("U")
|
||||
# timetable.append("".join(w))
|
||||
|
||||
|
||||
result_stream = StringIO()
|
||||
|
||||
self.results.write(ostream=result_stream)
|
||||
self.results.write_json(ostream=result_stream)
|
||||
result_string = result_stream.getvalue()
|
||||
|
||||
html = """
|
||||
<body>
|
||||
<div class="table-div" id="{}">
|
||||
@@ -1864,8 +1885,14 @@ class RotaResults(object):
|
||||
{}
|
||||
</div>
|
||||
</details>
|
||||
<details>
|
||||
<summary><h2>Output</h2></summary>
|
||||
<pre>
|
||||
{}
|
||||
</pre>
|
||||
<div>
|
||||
</body>
|
||||
""".format(table_name, "\n".join(timetable), json.dumps(self.rota.constraint_options, indent=4), "<br/>".join(str(i) for i in self.rota.shifts))
|
||||
""".format(table_name, "\n".join(timetable), json.dumps(self.rota.constraint_options, indent=4), "<br/>".join(str(i) for i in self.rota.shifts), result_string)
|
||||
|
||||
if include_html_tag:
|
||||
html = """<html>
|
||||
|
||||
Reference in New Issue
Block a user