diff --git a/.gitignore b/.gitignore index 2a60edd..f23b54e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,8 @@ sample.txt *.csv *.html *.log +current.log +extended proc nights only.log +no nights.log +no twighlights.log +no weekends.log diff --git a/run.py b/run.py index d0c2078..39d5146 100644 --- a/run.py +++ b/run.py @@ -23,7 +23,7 @@ sites = ("truro", "exeter", "torquay", "barnstaple", "plymouth") Rota = RotaBuilder(datetime.date(2020, 9, 7), weeks_to_rota=weeks_to_rota, - balance_offset_modifier=4, + balance_offset_modifier=1, max_weekend_frequency=2, max_night_frequency=2) @@ -259,9 +259,14 @@ rota_collections['nights + proc twighlights + normal weekends'].add_shifts( rota_collections['nights + proc twighlights + proc weekends'].add_shifts( SingleShift((sites), - "proc_twilight_and_weekends", + "proc_twilight", 12.5, - days, + days[:5], + workers_required=3), + SingleShift((sites), + "proc_weekends", + 12.5, + days[5:], workers_required=3), #SingleShift((sites), "night", 12.5, days, balance_weighting=1, workers_required=3, rota_on_nwds=True), SingleShift((sites), diff --git a/s.js b/s.js index a0614f0..a7a5201 100644 --- a/s.js +++ b/s.js @@ -14,86 +14,145 @@ Object.defineProperties(Array.prototype, { } }); -rows = $(".table-div table .worker-row"); -//console.log(trs) +const mean = arr => arr.reduce( ( p, c ) => p + c, 0 ) / arr.length; -workers = {}; +tables = $(".table-div"); -rows.each((n, tr) => { +tables.each((n, table) => { + console.log(table) - //console.log(tr); + rows = $(table).find(".worker-row"); + console.log(rows) - worker_td = $(tr).find("td:first"); + workers = {}; - worker = worker_td.attr("data-worker"); + rows.each((n, tr) => { - shift_tds = $(tr).find(".rota-day"); - shifts = [] + //console.log(tr); - shift_tds.each((n, td) => { - shifts.push($(td).attr("data-shift")); - }) + worker_td = $(tr).find("td:first"); - shifts_unique = new Set(shifts); - shifts_unique.delete(""); - //console.log(shifts_unique); + worker = worker_td.attr("data-worker"); - weekends_worked = 0; + shift_tds = $(tr).find(".rota-day"); + shifts = [] - weeks = shift_tds.length / 7; + shift_tds.each((n, td) => { + shifts.push($(td).attr("data-shift")); + }) - whole_weekends_worked = 0; + shifts_unique = new Set(shifts); + shifts_unique.delete(""); + //console.log(shifts_unique); - for(var i = 1; i <= weeks; i++) { - //console.log($(tr).find(`[data-week='${i}'][data-day='Sat']`)); - if($(tr).find(`[data-week='${i}'][data-day='Sat']`).attr("data-shift") != "" || $(tr).find(`[data-week='${i}'][data-day='Sun']`).attr("data-shift") != "") { weekends_worked = weekends_worked + 1; } - if($(tr).find(`[data-week='${i}'][data-day='Sat']`).attr("data-shift") != "" && $(tr).find(`[data-week='${i}'][data-day='Sun']`).attr("data-shift") != "") { whole_weekends_worked = whole_weekends_worked + 1; } - } + weekends_worked = 0; - shift_counts = {}; + weeks = shift_tds.length / 7; - total_shifts = 0; - days_lost = 0; - shifts_unique.forEach(el => { - //console.log(el); - shift_counts[el] = shifts.count(el); - total_shifts = total_shifts + shifts.count(el); + whole_weekends_worked = 0; - if(el == "night_weekday") { days_lost = days_lost + shifts.count(el) / 4 * 5 } - if(el == "night_weekend") { - days_lost = days_lost + shifts.count(el) / 3 * 4 - whole_weekends_worked = whole_weekends_worked - shifts.count(el) / 3 - } + for(var i = 1; i <= weeks; i++) { + //console.log($(tr).find(`[data-week='${i}'][data-day='Sat']`)); + if($(tr).find(`[data-week='${i}'][data-day='Sat']`).attr("data-shift") != "" || $(tr).find(`[data-week='${i}'][data-day='Sun']`).attr("data-shift") != "") { weekends_worked = weekends_worked + 1; } + if($(tr).find(`[data-week='${i}'][data-day='Sat']`).attr("data-shift") != "" && $(tr).find(`[data-week='${i}'][data-day='Sun']`).attr("data-shift") != "") { whole_weekends_worked = whole_weekends_worked + 1; } + } - }); + shift_counts = {}; - days_lost = days_lost + whole_weekends_worked - console.log(worker, whole_weekends_worked); + total_shifts = 0; + days_lost = 0; + shifts_unique.forEach(el => { + //console.log(el); + shift_counts[el] = shifts.count(el); + total_shifts = total_shifts + shifts.count(el); - //days_lost = days_lost + whole_weekends_worked; - //console.log(shift_counts); + // 5 days for weekday nights + if(el == "night_weekday") { days_lost = days_lost + shifts.count(el) / 4 * 5 } + // 4 days for weekend nights + if(el == "night_weekend") { + days_lost = days_lost + shifts.count(el) / 3 * 4 + whole_weekends_worked = whole_weekends_worked - shifts.count(el) / 3 + } + // 0.5 for twilights + if(el.includes("twilight")) { days_lost = days_lost + shifts.count(el) / 2 } - workers[worker] = { - "site": worker_td.attr("data-site"), - "nwds": worker_td.attr("data-nwds"), - "fte": worker_td.attr("data-fte_adj"), - "end_date": worker_td.attr("data-end_date"), - "shifts": shifts, - "shift_types": shifts_unique, - "weekends_worked": weekends_worked, - "shift_counts": shift_counts, - "days_lost": days_lost, - //"shifts" - } + }); - sc = JSON.stringify(shift_counts); + // Also 1 day for a whole weekend + days_lost = days_lost + whole_weekends_worked + console.log(worker, whole_weekends_worked); - worker_td.after(`