From f31891393d7551f4f39200a41b4e2a4fda5745c9 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 21 Jan 2021 08:44:56 +0000 Subject: [PATCH 1/4] Add shift schedule dropdown. #531 --- src/Controller/AnalyticsController.php | 12 ++++++++++++ src/Ramcar/ShiftSchedule.php | 14 ++++++++++++++ templates/analytics/forecast_form.html.twig | 11 +++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/Ramcar/ShiftSchedule.php diff --git a/src/Controller/AnalyticsController.php b/src/Controller/AnalyticsController.php index 4d589899..45effd17 100644 --- a/src/Controller/AnalyticsController.php +++ b/src/Controller/AnalyticsController.php @@ -22,6 +22,8 @@ use DateInterval; use App\Entity\JobOrder; use App\Entity\Hub; +use App\Ramcar\ShiftSchedule; + class AnalyticsController extends Controller { protected $weekdays = [ @@ -94,6 +96,7 @@ class AnalyticsController extends Controller $params = [ 'hub_list' => $hub_list, 'default_hubs' => $hub_ids, + 'shift_schedules' => ShiftSchedule::getCollection(), ]; return $this->render('analytics/forecast_form.html.twig', $params); @@ -117,6 +120,11 @@ class AnalyticsController extends Controller $date_from = DateTime::createFromFormat('d M Y', $req->request->get('date_from')); $date_to = DateTime::createFromFormat('d M Y', $req->request->get('date_to')); + $shift = $req->request->get('shift_schedule'); + + // TODO: populate the hour_shift array, depending on the shift selected + $hour_shift = $this->populateHourShift($shift); + // error_log(print_r($hub_list, true)); // $hub_list = [ 6, 4, 36, 7, 8, 126, 127, 18, 12, 9, 60, 10, 21, 135 ]; @@ -661,4 +669,8 @@ class AnalyticsController extends Controller protected function solveRiderSchedule() { } + + protected function populateHourShift($shift) + { + } } diff --git a/src/Ramcar/ShiftSchedule.php b/src/Ramcar/ShiftSchedule.php new file mode 100644 index 00000000..85e733b4 --- /dev/null +++ b/src/Ramcar/ShiftSchedule.php @@ -0,0 +1,14 @@ + '24/7 Schedule', + '8_5' => '8-5 Schedule', + ]; +} diff --git a/templates/analytics/forecast_form.html.twig b/templates/analytics/forecast_form.html.twig index d2c6108a..b43d6d6f 100644 --- a/templates/analytics/forecast_form.html.twig +++ b/templates/analytics/forecast_form.html.twig @@ -30,6 +30,17 @@
+
+
+ + + +
+
From f5759c8ceaf040394577f1b6b8fc6f9143703d43 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 21 Jan 2021 09:55:16 +0000 Subject: [PATCH 2/4] Add population of hour shift, depending on selected shift schedule. #531 --- src/Controller/AnalyticsController.php | 38 ++++++++++++++++++++++++++ src/Ramcar/ShiftSchedule.php | 4 +-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Controller/AnalyticsController.php b/src/Controller/AnalyticsController.php index 45effd17..6efd2eae 100644 --- a/src/Controller/AnalyticsController.php +++ b/src/Controller/AnalyticsController.php @@ -672,5 +672,43 @@ class AnalyticsController extends Controller protected function populateHourShift($shift) { + $hour_shift = []; + + if ($shift == '24_7') { + $hour_shift = [ + ['00:00 - 09:00', 0, 1, 2, 3, 4, 5, 6, 7, 8], + ['01:00 - 10:00', 1, 2, 3, 4, 5, 6, 7, 8, 9], + ['02:00 - 11:00', 2, 3, 4, 5, 6, 7, 8, 9, 10], + ['03:00 - 12:00', 3, 4, 5, 6, 7, 8, 9, 10, 11], + ['04:00 - 13:00', 4, 5, 6, 7, 8, 9, 10, 11, 12], + ['05:00 - 14:00', 5, 6, 7, 8, 9, 10, 11, 12, 13], + ['06:00 - 15:00', 6, 7, 8, 9, 10, 11, 12, 13, 14], + ['07:00 - 16:00', 7, 8, 9, 10, 11, 12, 13, 14, 15], + ['08:00 - 17:00', 8, 9, 10, 11, 12, 13, 14, 15, 16], + ['09:00 - 18:00', 9, 10, 11, 12, 13, 14, 15, 16, 17], + ['10:00 - 19:00', 10, 11, 12, 13, 14, 15, 16, 17, 18], + ['11:00 - 20:00', 11, 12, 13, 14, 15, 16, 17, 18, 19], + ['12:00 - 21:00', 12, 13, 14, 15, 16, 17, 18, 19, 20], + ['13:00 - 22:00', 13, 14, 15, 16, 17, 18, 19, 20, 21], + ['14:00 - 23:00', 14, 15, 16, 17, 18, 19, 20, 21, 22], + ['15:00 - 00:00', 15, 16, 17, 18, 19, 20, 21, 22, 23], + ['16:00 - 01:00', 16, 17, 18, 19, 20, 21, 22, 23, 0], + ['17:00 - 02:00', 17, 18, 19, 20, 21, 22, 23, 0, 1], + ['18:00 - 03:00', 18, 19, 20, 21, 22, 23, 0, 1, 2], + ['19:00 - 04:00', 19, 20, 21, 22, 23, 0, 1, 2, 3], + ['20:00 - 05:00', 20, 21, 22, 23, 0, 1, 2, 3, 4], + ['21:00 - 06:00', 21, 22, 23, 0, 1, 2, 3, 4, 5], + ['22:00 - 07:00', 22, 23, 0, 1, 2, 3, 4, 5, 6], + ['23:00 - 08:00', 23, 0, 1, 2, 3, 4, 5, 6, 7], + ]; + } + if ($shift == '8AM_5PM') { + $hour_shift = [ + ['07:00 - 16:00', 7, 8, 9, 10, 11, 12, 13, 14, 15], + ['08:00 - 17:00', 8, 9, 10, 11, 12, 13, 14, 15, 16], + ]; + } + + return $hour_shift; } } diff --git a/src/Ramcar/ShiftSchedule.php b/src/Ramcar/ShiftSchedule.php index 85e733b4..a59f3134 100644 --- a/src/Ramcar/ShiftSchedule.php +++ b/src/Ramcar/ShiftSchedule.php @@ -5,10 +5,10 @@ namespace App\Ramcar; class ShiftSchedule extends NameValue { const SCHED_24_7 = '24_7'; - const SCHED_8_5 = '8_5'; + const SCHED_8_5 = '8AM_5PM'; const COLLECTION = [ '24_7' => '24/7 Schedule', - '8_5' => '8-5 Schedule', + '8AM_5PM' => '8AM-5PM Schedule', ]; } From 44afc498c1c70c6126562e2a9b206f83245e65cc Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 22 Jan 2021 10:35:38 +0000 Subject: [PATCH 3/4] Add population of hours based on shift selected. #531 --- src/Controller/AnalyticsController.php | 28 ++++++++----- utils/schedule_solver/solver.py | 58 ++++++++++++++------------ 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/Controller/AnalyticsController.php b/src/Controller/AnalyticsController.php index 6efd2eae..ccd654ae 100644 --- a/src/Controller/AnalyticsController.php +++ b/src/Controller/AnalyticsController.php @@ -46,7 +46,7 @@ class AnalyticsController extends Controller ['Sun - Fri', 6, 0, 1, 2, 3, 4], // Sun - Fri ]; - protected $hour_shifts = [ + //protected $hour_shifts = [ /* ['00:00 - 09:00', 0, 1, 2, 3, 4, 5, 6, 7, 8], ['01:00 - 10:00', 1, 2, 3, 4, 5, 6, 7, 8, 9], @@ -56,8 +56,8 @@ class AnalyticsController extends Controller ['05:00 - 14:00', 5, 6, 7, 8, 9, 10, 11, 12, 13], ['06:00 - 15:00', 6, 7, 8, 9, 10, 11, 12, 13, 14], */ - ['07:00 - 16:00', 7, 8, 9, 10, 11, 12, 13, 14, 15], - ['08:00 - 17:00', 8, 9, 10, 11, 12, 13, 14, 15, 16], + //['07:00 - 16:00', 7, 8, 9, 10, 11, 12, 13, 14, 15], + //['08:00 - 17:00', 8, 9, 10, 11, 12, 13, 14, 15, 16], /* ['09:00 - 18:00', 9, 10, 11, 12, 13, 14, 15, 16, 17], ['10:00 - 19:00', 10, 11, 12, 13, 14, 15, 16, 17, 18], @@ -75,7 +75,7 @@ class AnalyticsController extends Controller ['22:00 - 07:00', 22, 23, 0, 1, 2, 3, 4, 5, 6], ['23:00 - 08:00', 23, 0, 1, 2, 3, 4, 5, 6, 7], */ - ]; + //]; /** * @Menu(selected="analytics_forecast") @@ -123,8 +123,9 @@ class AnalyticsController extends Controller $shift = $req->request->get('shift_schedule'); // TODO: populate the hour_shift array, depending on the shift selected - $hour_shift = $this->populateHourShift($shift); + $hour_shifts = $this->populateHourShift($shift); + error_log(print_r($hour_shifts, true)); // error_log(print_r($hub_list, true)); // $hub_list = [ 6, 4, 36, 7, 8, 126, 127, 18, 12, 9, 60, 10, 21, 135 ]; @@ -176,7 +177,7 @@ class AnalyticsController extends Controller // error_log(print_r($scheduler_data, true)); // run scheduler - $sched_res = $this->runScheduler($scheduler_data); + $sched_res = $this->runScheduler($scheduler_data, $hour_shifts, $shift); // tally total JOs for the month foreach ($scheduler_data as $sday_data) @@ -251,7 +252,7 @@ class AnalyticsController extends Controller return $day_data; } - protected function runScheduler($scheduler_data) + protected function runScheduler($scheduler_data, $hour_shifts, $shift) { // run python script to solve scheduling for riders @@ -266,13 +267,18 @@ class AnalyticsController extends Controller foreach ($scheduler_data as $weekday_data) $args[] = implode('-', $weekday_data); - // error_log(print_r($args, true)); + // add shift + $args[] = $shift; + + //error_log(print_r($args, true)); error_log('running...' . $sched_script); $proc = new Process($args); $proc->run(); + //error_log('getErrorOutput() ' . $proc->getErrorOutput()); + if (!$proc->isSuccessful()) error_log('SCHEDULER DID NOT RUN PROPERLY'); @@ -311,7 +317,7 @@ class AnalyticsController extends Controller $total_riders += $rider_count; - $label = $this->day_shifts[$day_shift_index][0] . ' ' . $this->hour_shifts[$hour_shift_index][0]; + $label = $this->day_shifts[$day_shift_index][0] . ' ' . $hour_shifts[$hour_shift_index][0]; $shifts[] = [ 'label' => $label, @@ -322,8 +328,8 @@ class AnalyticsController extends Controller $rider_hours = []; for ($i = 0; $i < 24; $i++) $rider_hours[$i] = 0; - for ($i = 1; $i < count($this->hour_shifts[$hour_shift_index]); $i++) - $rider_hours[$this->hour_shifts[$hour_shift_index][$i]] = 1; + for ($i = 1; $i < count($hour_shifts[$hour_shift_index]); $i++) + $rider_hours[$hour_shifts[$hour_shift_index][$i]] = 1; // error_log('allocating ' . $rider_count . ' for ' . $label); diff --git a/utils/schedule_solver/solver.py b/utils/schedule_solver/solver.py index da4f960e..98a87974 100644 --- a/utils/schedule_solver/solver.py +++ b/utils/schedule_solver/solver.py @@ -45,32 +45,38 @@ def main(): for hour_index in range(0, len(hours)): req_hours[day_index][hour_index] = int(hours_data[hour_index]) - # all hour shifts available - hour_shifts = [ - #['00 - 09', 0, 1, 2, 3, 4, 5, 6, 7, 8], - #['01 - 10', 1, 2, 3, 4, 5, 6, 7, 8, 9], - #['02 - 11', 2, 3, 4, 5, 6, 7, 8, 9, 10], - #['03 - 12', 3, 4, 5, 6, 7, 8, 9, 10, 11], - #['04 - 13', 4, 5, 6, 7, 8, 9, 10, 11, 12], - #['05 - 14', 5, 6, 7, 8, 9, 10, 11, 12, 13], - #['06 - 15', 6, 7, 8, 9, 10, 11, 12, 13, 14], - ['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15], - ['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16]] - #['09 - 18', 9, 10, 11, 12, 13, 14, 15, 16, 17], - #['10 - 19', 10, 11, 12, 13, 14, 15, 16, 17, 18], - #['11 - 20', 11, 12, 13, 14, 15, 16, 17, 18, 19], - #['12 - 21', 12, 13, 14, 15, 16, 17, 18, 19, 20], - #['13 - 22', 13, 14, 15, 16, 17, 18, 19, 20, 21], - #['14 - 23', 14, 15, 16, 17, 18, 19, 20, 21, 22], - #['15 - 00', 15, 16, 17, 18, 19, 20, 21, 22, 23], - #['16 - 01', 16, 17, 18, 19, 20, 21, 22, 23, 0], - #['17 - 02', 17, 18, 19, 20, 21, 22, 23, 0, 1], - #['18 - 03', 18, 19, 20, 21, 22, 23, 0, 1, 2], - #['19 - 04', 19, 20, 21, 22, 23, 0, 1, 2, 3], - #['20 - 05', 20, 21, 22, 23, 0, 1, 2, 3, 4], - #['21 - 06', 21, 22, 23, 0, 1, 2, 3, 4, 5], - #['22 - 07', 22, 23, 0, 1, 2, 3, 4, 5, 6], - #['23 - 08', 23, 0, 1, 2, 3, 4, 5, 6, 7]] + shift = sys.argv[8] + hour_shifts = [] + if shift == "24_7": + hour_shifts = [ + ['00 - 09', 0, 1, 2, 3, 4, 5, 6, 7, 8], + ['01 - 10', 1, 2, 3, 4, 5, 6, 7, 8, 9], + ['02 - 11', 2, 3, 4, 5, 6, 7, 8, 9, 10], + ['03 - 12', 3, 4, 5, 6, 7, 8, 9, 10, 11], + ['04 - 13', 4, 5, 6, 7, 8, 9, 10, 11, 12], + ['05 - 14', 5, 6, 7, 8, 9, 10, 11, 12, 13], + ['06 - 15', 6, 7, 8, 9, 10, 11, 12, 13, 14], + ['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15], + ['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16], + ['09 - 18', 9, 10, 11, 12, 13, 14, 15, 16, 17], + ['10 - 19', 10, 11, 12, 13, 14, 15, 16, 17, 18], + ['11 - 20', 11, 12, 13, 14, 15, 16, 17, 18, 19], + ['12 - 21', 12, 13, 14, 15, 16, 17, 18, 19, 20], + ['13 - 22', 13, 14, 15, 16, 17, 18, 19, 20, 21], + ['14 - 23', 14, 15, 16, 17, 18, 19, 20, 21, 22], + ['15 - 00', 15, 16, 17, 18, 19, 20, 21, 22, 23], + ['16 - 01', 16, 17, 18, 19, 20, 21, 22, 23, 0], + ['17 - 02', 17, 18, 19, 20, 21, 22, 23, 0, 1], + ['18 - 03', 18, 19, 20, 21, 22, 23, 0, 1, 2], + ['19 - 04', 19, 20, 21, 22, 23, 0, 1, 2, 3], + ['20 - 05', 20, 21, 22, 23, 0, 1, 2, 3, 4], + ['21 - 06', 21, 22, 23, 0, 1, 2, 3, 4, 5], + ['22 - 07', 22, 23, 0, 1, 2, 3, 4, 5, 6], + ['23 - 08', 23, 0, 1, 2, 3, 4, 5, 6, 7]] + if shift == "8AM_5PM": + hour_shifts = [ + ['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15], + ['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16]] # all possible days riders come in day_shifts = [ From cdcdbe72b22c71a0cf29b6929496bcdba517fbb3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 25 Jan 2021 02:29:09 +0000 Subject: [PATCH 4/4] Added comments for the arguments for the solver script. #531 --- utils/schedule_solver/solver.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/schedule_solver/solver.py b/utils/schedule_solver/solver.py index 98a87974..f7d5c03b 100644 --- a/utils/schedule_solver/solver.py +++ b/utils/schedule_solver/solver.py @@ -38,13 +38,16 @@ def main(): req_hours = [[0 for x in range(len(hours))] for y in range(len(days))] # get arguments - # there will be 7 arguments, monday to sunday schedule + # there will be 8 arguments, monday to sunday schedule and the shift selected + # sample argument: + # 0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0 0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0 0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0 0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0 0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0 0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0 0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0 24_7 for day_index in range(0, len(days)): hours_string = sys.argv[day_index + 1] hours_data = hours_string.split('-') for hour_index in range(0, len(hours)): req_hours[day_index][hour_index] = int(hours_data[hour_index]) + # index of shift selected is 8 shift = sys.argv[8] hour_shifts = [] if shift == "24_7":