From 4bb4f5b97a5c9beb8a864bf4185b2b4604a25d15 Mon Sep 17 00:00:00 2001 From: Ross Date: Tue, 19 May 2026 15:33:37 +0100 Subject: [PATCH] Refactor total shifts calculation in generateExtra and worker row processing for improved clarity and error handling --- output/timetable.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/output/timetable.js b/output/timetable.js index 9437a36..28ebb21 100644 --- a/output/timetable.js +++ b/output/timetable.js @@ -78,11 +78,11 @@ function generateExtra() { shift_counts = {}; - total_shifts = 0; + //total_shifts = 0; days_lost = 0; shifts_unique.forEach(el => { shift_counts[el] = shifts.count(el); - total_shifts = total_shifts + shifts.count(el); + //total_shifts = total_shifts + shifts.count(el); // why like this? if (el == "night_weekend") { @@ -518,6 +518,16 @@ $(".table-div .worker-row .worker").each((n, tr) => { locum_shift_counts = jtr.data("locum-shift-counts") shift_targets = jtr.data("worker-targets") + // Compute total shifts from shift_counts (sum of assigned counts) + let total_shifts = 0; + try { + if (shift_counts && typeof shift_counts === 'object') { + total_shifts = Object.values(shift_counts).reduce((a, b) => a + (parseFloat(b) || 0), 0); + } + } catch (e) { + total_shifts = 0; + } + oshifts.forEach((s) => { if (s in shift_targets && shift_targets[s] > 0) {