Add weekend shift adjustment calculations and update worker summary display
This commit is contained in:
@@ -4997,10 +4997,66 @@ class RotaBuilder(object):
|
||||
+ "</div>"
|
||||
)
|
||||
|
||||
# Compute per-day (Sat/Sun) adjustments for the 'weekend' shift if provided
|
||||
sat_adj = None
|
||||
sun_adj = None
|
||||
prev_all = getattr(worker, "previous_shifts", {}) or {}
|
||||
weekend_entry = prev_all.get("weekend")
|
||||
if weekend_entry is not None:
|
||||
try:
|
||||
if isinstance(weekend_entry, dict):
|
||||
if "Sat" in weekend_entry:
|
||||
w_worked, w_alloc = weekend_entry["Sat"]
|
||||
sat_adj = float(w_alloc) - float(w_worked)
|
||||
if "Sun" in weekend_entry:
|
||||
w_worked, w_alloc = weekend_entry["Sun"]
|
||||
sun_adj = float(w_alloc) - float(w_worked)
|
||||
if sat_adj is None and sun_adj is None and "__all__" in weekend_entry:
|
||||
w_worked, w_alloc = weekend_entry["__all__"]
|
||||
total = float(w_alloc) - float(w_worked)
|
||||
sat_adj = sun_adj = total / 2.0
|
||||
if sat_adj is None and sun_adj is None:
|
||||
# fallback: sum any tuple values and split
|
||||
worked_sum = sum(v[0] for v in weekend_entry.values() if isinstance(v, (list, tuple)))
|
||||
alloc_sum = sum(v[1] for v in weekend_entry.values() if isinstance(v, (list, tuple)))
|
||||
total = float(alloc_sum) - float(worked_sum)
|
||||
sat_adj = sun_adj = total / 2.0
|
||||
else:
|
||||
# tuple-style entry, split evenly across Sat/Sun
|
||||
w_worked, w_alloc = weekend_entry
|
||||
total = float(w_alloc) - float(w_worked)
|
||||
sat_adj = sun_adj = total / 2.0
|
||||
except Exception:
|
||||
sat_adj = sun_adj = None
|
||||
|
||||
def _adj_html(adj):
|
||||
if adj is None:
|
||||
return ""
|
||||
try:
|
||||
adjf = float(adj)
|
||||
except Exception:
|
||||
return ""
|
||||
sign_text = f"{adjf:+.2f}"
|
||||
# colour intensity scaled by magnitude (cap divisor at 3.0 to avoid overpowering)
|
||||
mag = min(1.0, abs(adjf) / 3.0)
|
||||
if adjf > 0:
|
||||
bg = f"rgba(0,128,0,{mag:.2f})"
|
||||
color = "#fff"
|
||||
elif adjf < 0:
|
||||
bg = f"rgba(196,0,0,{mag:.2f})"
|
||||
color = "#fff"
|
||||
else:
|
||||
bg = "rgba(128,128,128,0.15)"
|
||||
color = "#000"
|
||||
return f" <span class='weekend-day-adjust' style='margin-left:6px; padding:1px 6px; border-radius:4px; background:{bg}; color:{color}; font-weight:600; font-size:0.85em;'>({sign_text})</span>"
|
||||
|
||||
sat_adj_html = _adj_html(sat_adj)
|
||||
sun_adj_html = _adj_html(sun_adj)
|
||||
|
||||
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"<span class='weekend-sat'>Sat: <strong>{sat_count}</strong>{sat_adj_html}</span>"
|
||||
f" <span class='weekend-sun'>Sun: <strong>{sun_count}</strong>{sun_adj_html}</span>"
|
||||
f"{adjustments_html}"
|
||||
f"</div>"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user