Fix bug when no JO comes up for hub in 2018 #409
This commit is contained in:
parent
a2fdb346b3
commit
e13e3c0dd5
2 changed files with 46 additions and 17 deletions
|
|
@ -140,19 +140,28 @@ class AnalyticsController extends Controller
|
|||
// error_log(print_r($scheduler_data, true));
|
||||
unset($chart_all_weekdays['scheduler_data']);
|
||||
|
||||
// run scheduler
|
||||
// send 2018 + month data
|
||||
$sched_res = $this->runScheduler($scheduler_data['2018'][$month]);
|
||||
|
||||
// tally total JOs for the month
|
||||
$total_jos = 0;
|
||||
foreach ($scheduler_data['2018'][$month] as $sday_data)
|
||||
|
||||
// run scheduler
|
||||
// check if 2018 data is available
|
||||
if (isset($scheduler_data['2018'][$month]))
|
||||
{
|
||||
foreach ($sday_data as $shour_data)
|
||||
{
|
||||
$total_jos += $shour_data;
|
||||
}
|
||||
// send 2018 + month data
|
||||
$sched_res = $this->runScheduler($scheduler_data['2018'][$month]);
|
||||
|
||||
// tally total JOs for the month
|
||||
foreach ($scheduler_data['2018'][$month] as $sday_data)
|
||||
foreach ($sday_data as $shour_data)
|
||||
$total_jos += $shour_data;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sched_res = [
|
||||
'weekday_shifts' => $this->initDayData(),
|
||||
'total_riders' => 0,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
$hub_data[$hub_id]['data_weekday'] = $chart_weekday;
|
||||
$hub_data[$hub_id]['data_all_weekdays'] = $chart_all_weekdays;
|
||||
|
|
@ -178,6 +187,23 @@ class AnalyticsController extends Controller
|
|||
return $this->render('analytics/forecast_submit.html.twig', $params);
|
||||
}
|
||||
|
||||
protected function initDayData()
|
||||
{
|
||||
$day_data = [];
|
||||
// each weekday
|
||||
for ($i = 0; $i < 7; $i++)
|
||||
{
|
||||
$day_data[$i] = [
|
||||
'weekday' => $this->weekdays[$i],
|
||||
'total_jos' => 0,
|
||||
'total_riders' => 0,
|
||||
'shifts' => [],
|
||||
];
|
||||
}
|
||||
|
||||
return $day_data;
|
||||
}
|
||||
|
||||
protected function runScheduler($scheduler_data)
|
||||
{
|
||||
// run python script to solve scheduling for riders
|
||||
|
|
@ -208,7 +234,7 @@ class AnalyticsController extends Controller
|
|||
|
||||
|
||||
// segregate into weekdays
|
||||
$day_data = [];
|
||||
$day_data = $this->initDayData();
|
||||
$i = 0;
|
||||
foreach ($scheduler_data as $weekday_data)
|
||||
{
|
||||
|
|
@ -216,12 +242,7 @@ class AnalyticsController extends Controller
|
|||
foreach ($weekday_data as $hourly_jo)
|
||||
$total_jos += $hourly_jo;
|
||||
|
||||
$day_data[$i] = [
|
||||
'weekday' => $this->weekdays[$i],
|
||||
'total_jos' => $total_jos,
|
||||
'total_riders' => 0,
|
||||
'shifts' => [],
|
||||
];
|
||||
$day_data[$i]['total_jos'] = $total_jos;
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,14 +131,22 @@
|
|||
<td>{{ hub.data_shift[i].weekday }}</td>
|
||||
<td>{{ hub.data_shift[i].total_jos }}</td>
|
||||
<td>{{ hub.data_shift[i].total_riders }}</td>
|
||||
{% if hub.data_shift[i].total_riders == 0 %}
|
||||
<td>0</td>
|
||||
{% else %}
|
||||
<td>{{ (hub.data_shift[i].total_jos / hub.data_shift[i].total_riders) | round(1, 'common') }}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
<tr>
|
||||
<td>Overall</td>
|
||||
<td>{{ hub.total_jos }}</td>
|
||||
<td>{{ hub.total_riders }}</td>
|
||||
{% if hub.total_riders == 0 %}
|
||||
<td>0</td>
|
||||
{% else %}
|
||||
<td>{{ (hub.total_jos / hub.total_riders) | round(1, 'common') }}</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
|||
Loading…
Reference in a new issue