Resolve "Add 24/7 and current configuration for rider scheduling" #1427
4 changed files with 127 additions and 37 deletions
|
|
@ -22,6 +22,8 @@ use DateInterval;
|
||||||
use App\Entity\JobOrder;
|
use App\Entity\JobOrder;
|
||||||
use App\Entity\Hub;
|
use App\Entity\Hub;
|
||||||
|
|
||||||
|
use App\Ramcar\ShiftSchedule;
|
||||||
|
|
||||||
class AnalyticsController extends Controller
|
class AnalyticsController extends Controller
|
||||||
{
|
{
|
||||||
protected $weekdays = [
|
protected $weekdays = [
|
||||||
|
|
@ -44,7 +46,7 @@ class AnalyticsController extends Controller
|
||||||
['Sun - Fri', 6, 0, 1, 2, 3, 4], // Sun - Fri
|
['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],
|
['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],
|
['01:00 - 10:00', 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
|
|
@ -54,8 +56,8 @@ class AnalyticsController extends Controller
|
||||||
['05:00 - 14:00', 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
['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],
|
['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],
|
//['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],
|
//['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],
|
['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],
|
['10:00 - 19:00', 10, 11, 12, 13, 14, 15, 16, 17, 18],
|
||||||
|
|
@ -73,7 +75,7 @@ class AnalyticsController extends Controller
|
||||||
['22:00 - 07:00', 22, 23, 0, 1, 2, 3, 4, 5, 6],
|
['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],
|
['23:00 - 08:00', 23, 0, 1, 2, 3, 4, 5, 6, 7],
|
||||||
*/
|
*/
|
||||||
];
|
//];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Menu(selected="analytics_forecast")
|
* @Menu(selected="analytics_forecast")
|
||||||
|
|
@ -94,6 +96,7 @@ class AnalyticsController extends Controller
|
||||||
$params = [
|
$params = [
|
||||||
'hub_list' => $hub_list,
|
'hub_list' => $hub_list,
|
||||||
'default_hubs' => $hub_ids,
|
'default_hubs' => $hub_ids,
|
||||||
|
'shift_schedules' => ShiftSchedule::getCollection(),
|
||||||
];
|
];
|
||||||
|
|
||||||
return $this->render('analytics/forecast_form.html.twig', $params);
|
return $this->render('analytics/forecast_form.html.twig', $params);
|
||||||
|
|
@ -117,6 +120,12 @@ class AnalyticsController extends Controller
|
||||||
$date_from = DateTime::createFromFormat('d M Y', $req->request->get('date_from'));
|
$date_from = DateTime::createFromFormat('d M Y', $req->request->get('date_from'));
|
||||||
$date_to = DateTime::createFromFormat('d M Y', $req->request->get('date_to'));
|
$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_shifts = $this->populateHourShift($shift);
|
||||||
|
|
||||||
|
error_log(print_r($hour_shifts, true));
|
||||||
// error_log(print_r($hub_list, true));
|
// error_log(print_r($hub_list, true));
|
||||||
|
|
||||||
// $hub_list = [ 6, 4, 36, 7, 8, 126, 127, 18, 12, 9, 60, 10, 21, 135 ];
|
// $hub_list = [ 6, 4, 36, 7, 8, 126, 127, 18, 12, 9, 60, 10, 21, 135 ];
|
||||||
|
|
@ -168,7 +177,7 @@ class AnalyticsController extends Controller
|
||||||
// error_log(print_r($scheduler_data, true));
|
// error_log(print_r($scheduler_data, true));
|
||||||
|
|
||||||
// run scheduler
|
// run scheduler
|
||||||
$sched_res = $this->runScheduler($scheduler_data);
|
$sched_res = $this->runScheduler($scheduler_data, $hour_shifts, $shift);
|
||||||
|
|
||||||
// tally total JOs for the month
|
// tally total JOs for the month
|
||||||
foreach ($scheduler_data as $sday_data)
|
foreach ($scheduler_data as $sday_data)
|
||||||
|
|
@ -243,7 +252,7 @@ class AnalyticsController extends Controller
|
||||||
return $day_data;
|
return $day_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function runScheduler($scheduler_data)
|
protected function runScheduler($scheduler_data, $hour_shifts, $shift)
|
||||||
{
|
{
|
||||||
// run python script to solve scheduling for riders
|
// run python script to solve scheduling for riders
|
||||||
|
|
||||||
|
|
@ -258,13 +267,18 @@ class AnalyticsController extends Controller
|
||||||
foreach ($scheduler_data as $weekday_data)
|
foreach ($scheduler_data as $weekday_data)
|
||||||
$args[] = implode('-', $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);
|
error_log('running...' . $sched_script);
|
||||||
|
|
||||||
$proc = new Process($args);
|
$proc = new Process($args);
|
||||||
$proc->run();
|
$proc->run();
|
||||||
|
|
||||||
|
//error_log('getErrorOutput() ' . $proc->getErrorOutput());
|
||||||
|
|
||||||
if (!$proc->isSuccessful())
|
if (!$proc->isSuccessful())
|
||||||
error_log('SCHEDULER DID NOT RUN PROPERLY');
|
error_log('SCHEDULER DID NOT RUN PROPERLY');
|
||||||
|
|
||||||
|
|
@ -303,7 +317,7 @@ class AnalyticsController extends Controller
|
||||||
|
|
||||||
$total_riders += $rider_count;
|
$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[] = [
|
$shifts[] = [
|
||||||
'label' => $label,
|
'label' => $label,
|
||||||
|
|
@ -314,8 +328,8 @@ class AnalyticsController extends Controller
|
||||||
$rider_hours = [];
|
$rider_hours = [];
|
||||||
for ($i = 0; $i < 24; $i++)
|
for ($i = 0; $i < 24; $i++)
|
||||||
$rider_hours[$i] = 0;
|
$rider_hours[$i] = 0;
|
||||||
for ($i = 1; $i < count($this->hour_shifts[$hour_shift_index]); $i++)
|
for ($i = 1; $i < count($hour_shifts[$hour_shift_index]); $i++)
|
||||||
$rider_hours[$this->hour_shifts[$hour_shift_index][$i]] = 1;
|
$rider_hours[$hour_shifts[$hour_shift_index][$i]] = 1;
|
||||||
|
|
||||||
// error_log('allocating ' . $rider_count . ' for ' . $label);
|
// error_log('allocating ' . $rider_count . ' for ' . $label);
|
||||||
|
|
||||||
|
|
@ -661,4 +675,46 @@ class AnalyticsController extends Controller
|
||||||
protected function solveRiderSchedule()
|
protected function solveRiderSchedule()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
src/Ramcar/ShiftSchedule.php
Normal file
14
src/Ramcar/ShiftSchedule.php
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Ramcar;
|
||||||
|
|
||||||
|
class ShiftSchedule extends NameValue
|
||||||
|
{
|
||||||
|
const SCHED_24_7 = '24_7';
|
||||||
|
const SCHED_8_5 = '8AM_5PM';
|
||||||
|
|
||||||
|
const COLLECTION = [
|
||||||
|
'24_7' => '24/7 Schedule',
|
||||||
|
'8AM_5PM' => '8AM-5PM Schedule',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,17 @@
|
||||||
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ url('analytics_forecast_submit') }}">
|
<form id="row-form" class="m-form m-form--fit m-form--label-align-right m-form--group-seperator-dashed" method="post" action="{{ url('analytics_forecast_submit') }}">
|
||||||
|
|
||||||
<div class="m-portlet__body">
|
<div class="m-portlet__body">
|
||||||
|
<div class="form-group m-form__group row no-border">
|
||||||
|
<div class="col-lg-6">
|
||||||
|
<label data-field="shift_schedule">Shift Schedule</label>
|
||||||
|
<select id="shift_schedule" class="form-control m-input" name="shift_schedule">
|
||||||
|
{% for key, schedule in shift_schedules %}
|
||||||
|
<option value="{{ key }}">{{ schedule }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<div class="form-control-feedback hide" data-field="shift_schedule"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="form-group m-form__group row no-border">
|
<div class="form-group m-form__group row no-border">
|
||||||
<div class="col-lg-6">
|
<div class="col-lg-6">
|
||||||
<label data-field="time_from">Restrict Time From</label>
|
<label data-field="time_from">Restrict Time From</label>
|
||||||
|
|
|
||||||
|
|
@ -38,39 +38,48 @@ def main():
|
||||||
req_hours = [[0 for x in range(len(hours))] for y in range(len(days))]
|
req_hours = [[0 for x in range(len(hours))] for y in range(len(days))]
|
||||||
|
|
||||||
# get arguments
|
# 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)):
|
for day_index in range(0, len(days)):
|
||||||
hours_string = sys.argv[day_index + 1]
|
hours_string = sys.argv[day_index + 1]
|
||||||
hours_data = hours_string.split('-')
|
hours_data = hours_string.split('-')
|
||||||
for hour_index in range(0, len(hours)):
|
for hour_index in range(0, len(hours)):
|
||||||
req_hours[day_index][hour_index] = int(hours_data[hour_index])
|
req_hours[day_index][hour_index] = int(hours_data[hour_index])
|
||||||
|
|
||||||
# all hour shifts available
|
# index of shift selected is 8
|
||||||
hour_shifts = [
|
shift = sys.argv[8]
|
||||||
#['00 - 09', 0, 1, 2, 3, 4, 5, 6, 7, 8],
|
hour_shifts = []
|
||||||
#['01 - 10', 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
if shift == "24_7":
|
||||||
#['02 - 11', 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
hour_shifts = [
|
||||||
#['03 - 12', 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
['00 - 09', 0, 1, 2, 3, 4, 5, 6, 7, 8],
|
||||||
#['04 - 13', 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
['01 - 10', 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||||
#['05 - 14', 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
['02 - 11', 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||||
#['06 - 15', 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
['03 - 12', 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
||||||
['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
['04 - 13', 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
||||||
['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16]]
|
['05 - 14', 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
||||||
#['09 - 18', 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
['06 - 15', 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
||||||
#['10 - 19', 10, 11, 12, 13, 14, 15, 16, 17, 18],
|
['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||||
#['11 - 20', 11, 12, 13, 14, 15, 16, 17, 18, 19],
|
['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||||
#['12 - 21', 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
['09 - 18', 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
||||||
#['13 - 22', 13, 14, 15, 16, 17, 18, 19, 20, 21],
|
['10 - 19', 10, 11, 12, 13, 14, 15, 16, 17, 18],
|
||||||
#['14 - 23', 14, 15, 16, 17, 18, 19, 20, 21, 22],
|
['11 - 20', 11, 12, 13, 14, 15, 16, 17, 18, 19],
|
||||||
#['15 - 00', 15, 16, 17, 18, 19, 20, 21, 22, 23],
|
['12 - 21', 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
||||||
#['16 - 01', 16, 17, 18, 19, 20, 21, 22, 23, 0],
|
['13 - 22', 13, 14, 15, 16, 17, 18, 19, 20, 21],
|
||||||
#['17 - 02', 17, 18, 19, 20, 21, 22, 23, 0, 1],
|
['14 - 23', 14, 15, 16, 17, 18, 19, 20, 21, 22],
|
||||||
#['18 - 03', 18, 19, 20, 21, 22, 23, 0, 1, 2],
|
['15 - 00', 15, 16, 17, 18, 19, 20, 21, 22, 23],
|
||||||
#['19 - 04', 19, 20, 21, 22, 23, 0, 1, 2, 3],
|
['16 - 01', 16, 17, 18, 19, 20, 21, 22, 23, 0],
|
||||||
#['20 - 05', 20, 21, 22, 23, 0, 1, 2, 3, 4],
|
['17 - 02', 17, 18, 19, 20, 21, 22, 23, 0, 1],
|
||||||
#['21 - 06', 21, 22, 23, 0, 1, 2, 3, 4, 5],
|
['18 - 03', 18, 19, 20, 21, 22, 23, 0, 1, 2],
|
||||||
#['22 - 07', 22, 23, 0, 1, 2, 3, 4, 5, 6],
|
['19 - 04', 19, 20, 21, 22, 23, 0, 1, 2, 3],
|
||||||
#['23 - 08', 23, 0, 1, 2, 3, 4, 5, 6, 7]]
|
['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
|
# all possible days riders come in
|
||||||
day_shifts = [
|
day_shifts = [
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue