Add prior adjustments summary to worker display and enhance data attributes
This commit is contained in:
@@ -4898,10 +4898,35 @@ class RotaBuilder(object):
|
||||
sun_count += 1
|
||||
break
|
||||
# Small HTML summary to be inserted inside the worker td (friendly display)
|
||||
# Build a small adjustments summary from prior allocations (if any)
|
||||
prior_map = {}
|
||||
adjustments_list = []
|
||||
for shift in self.get_shifts():
|
||||
prev = getattr(worker, "previous_shifts", {}) or {}
|
||||
if shift.name in prev:
|
||||
worked, allocated = prev[shift.name]
|
||||
try:
|
||||
adj = float(allocated) - float(worked)
|
||||
except Exception:
|
||||
adj = 0.0
|
||||
prior_map[shift.name] = {"worked": worked, "allocated": allocated, "adjustment": adj}
|
||||
if adj != 0:
|
||||
adjustments_list.append(f"{shift.name}:{adj:+g}")
|
||||
|
||||
adjustments_html = ""
|
||||
if adjustments_list:
|
||||
adjustments_html = (
|
||||
"<div class='worker-adjustments auto-generated' style='margin-top:3px; font-size:0.85em; color:#666;'>"
|
||||
+ "Adjust: "
|
||||
+ ", ".join(adjustments_list)
|
||||
+ "</div>"
|
||||
)
|
||||
|
||||
worker_summary_html = (
|
||||
f"<div class='worker-summary auto-generated' style='margin-top:4px; font-size:0.9em; color:#333;'>"
|
||||
f"<span class=\'weekend-sat\'>Sat: <strong>{sat_count}</strong></span>"
|
||||
f" <span class=\'weekend-sun\'>Sun: <strong>{sun_count}</strong></span>"
|
||||
f"{adjustments_html}"
|
||||
f"</div>"
|
||||
)
|
||||
|
||||
@@ -4922,6 +4947,7 @@ class RotaBuilder(object):
|
||||
data-bank-holiday-extra='{bank_holiday_extra}'
|
||||
data-weekend-sat='{weekend_sat}'
|
||||
data-weekend-sun='{weekend_sun}'
|
||||
data-previous-shifts='{previous_shifts}'
|
||||
data-shift-diff='{shift_diff}'
|
||||
data-shift-diff-summed='{shift_diff_summed}'
|
||||
>
|
||||
@@ -4944,6 +4970,7 @@ class RotaBuilder(object):
|
||||
weekend_sat=sat_count,
|
||||
weekend_sun=sun_count,
|
||||
worker_summary_html=worker_summary_html,
|
||||
previous_shifts=json.dumps(prior_map),
|
||||
pair=worker.pair,
|
||||
shift_balance_extra=json.dumps(worker.shift_balance_extra),
|
||||
shift_diff=json.dumps(shift_diff_dict),
|
||||
|
||||
Reference in New Issue
Block a user