diff --git a/src/Controller/AnalyticsController.php b/src/Controller/AnalyticsController.php
index dbbdbf29..017333e5 100644
--- a/src/Controller/AnalyticsController.php
+++ b/src/Controller/AnalyticsController.php
@@ -128,6 +128,17 @@ class AnalyticsController extends Controller
];
}
+ // init aggregate information
+ $agg_data = [];
+ for ($i = 0; $i < 7; $i++)
+ {
+ $agg_data[] = [
+ 'label' => $this->weekdays[$i],
+ 'total_jos' => 0,
+ 'total_riders' => 0,
+ ];
+ }
+
// reprocess weekday data to account for overlap
foreach ($hub_data as $hub_id => $one_hub)
{
@@ -140,19 +151,37 @@ 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,
+ ];
+ }
+
+ // agggregate weekday data
+ $i = 0;
+ foreach ($sched_res['weekday_shifts'] as $day_data)
+ {
+ $agg_data[$i]['total_jos'] += $day_data['total_jos'];
+ $agg_data[$i]['total_riders'] += $day_data['total_riders'];
+ $i++;
+ }
+
$hub_data[$hub_id]['data_weekday'] = $chart_weekday;
$hub_data[$hub_id]['data_all_weekdays'] = $chart_all_weekdays;
@@ -168,16 +197,36 @@ class AnalyticsController extends Controller
// get job orders not covered by hubs
$not_covered = $this->generateNotCoveredData($em, $hub_coverage, $today);
+ // error_log(print_r($agg_data, true));
+
$params = [
'date' => $today,
'hub_list' => $hub_data,
'hub_coverage' => $hub_coverage,
'not_covered' => $not_covered,
+ 'agg_data' => $agg_data,
];
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
@@ -193,7 +242,7 @@ class AnalyticsController extends Controller
foreach ($scheduler_data as $weekday_data)
$args[] = implode('-', $weekday_data);
- error_log(print_r($args, true));
+ // error_log(print_r($args, true));
// error_log('running...' . $sched_script);
@@ -204,11 +253,11 @@ class AnalyticsController extends Controller
error_log('SCHEDULER DID NOT RUN PROPERLY');
$res = $proc->getOutput();
- error_log($res);
+ // error_log($res);
// segregate into weekdays
- $day_data = [];
+ $day_data = $this->initDayData();
$i = 0;
foreach ($scheduler_data as $weekday_data)
{
@@ -216,12 +265,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++;
}
@@ -251,7 +295,7 @@ class AnalyticsController extends Controller
for ($i = 1; $i < count($this->hour_shifts[$hour_shift_index]); $i++)
$rider_hours[$this->hour_shifts[$hour_shift_index][$i]] = 1;
- error_log('allocating ' . $rider_count . ' for ' . $label);
+ // error_log('allocating ' . $rider_count . ' for ' . $label);
// add shifts to the weekday
for ($i = 1; $i < count($this->day_shifts[$day_shift_index]); $i++)
diff --git a/templates/analytics/forecast_submit.html.twig b/templates/analytics/forecast_submit.html.twig
index 2fafd57f..d884bc15 100644
--- a/templates/analytics/forecast_submit.html.twig
+++ b/templates/analytics/forecast_submit.html.twig
@@ -39,6 +39,37 @@
+
+
+
+
+
+
+ | Day |
+ # JO |
+ # Rider |
+ JO per Rider |
+
+
+
+ {% for i in 0..6 %}
+
+ | {{ agg_data[i].label }} |
+ {{ agg_data[i].total_jos }} |
+ {{ agg_data[i].total_riders }} |
+ {% if agg_data[i].total_riders == 0 %}
+ 0 |
+ {% else %}
+ {{ (agg_data[i].total_jos / agg_data[i].total_riders) | round(1, 'common') }} |
+ {% endif %}
+
+ {% endfor %}
+
+
+
+
+
+
{% for hub in hub_list %}
@@ -65,6 +96,41 @@
+
+
+
+ | Day |
+ # JO |
+ # Rider |
+ JO per Rider |
+
+
+
+ {% for i in 0..6 %}
+
+ | {{ hub.data_shift[i].weekday }} |
+ {{ hub.data_shift[i].total_jos }} |
+ {{ hub.data_shift[i].total_riders }} |
+ {% if hub.data_shift[i].total_riders == 0 %}
+ 0 |
+ {% else %}
+ {{ (hub.data_shift[i].total_jos / hub.data_shift[i].total_riders) | round(1, 'common') }} |
+ {% endif %}
+
+ {% endfor %}
+
+ | Overall |
+ {{ hub.total_jos }} |
+ {{ hub.total_riders }} |
+ {% if hub.total_riders == 0 %}
+ 0 |
+ {% else %}
+ {{ (hub.total_jos / hub.total_riders) | round(1, 'common') }} |
+ {% endif %}
+
+
+
+
{% for day_data in hub.data_shift %}
{% endfor %}
-
-
-
- | Day |
- # JO |
- # Rider |
- JO per Rider |
-
-
-
- {% for i in 0..6 %}
-
- | {{ hub.data_shift[i].weekday }} |
- {{ hub.data_shift[i].total_jos }} |
- {{ hub.data_shift[i].total_riders }} |
- {{ (hub.data_shift[i].total_jos / hub.data_shift[i].total_riders) | round(1, 'common') }} |
-
- {% endfor %}
-
- | Overall |
- {{ hub.total_jos }} |
- {{ hub.total_riders }} |
- {{ (hub.total_jos / hub.total_riders) | round(1, 'common') }} |
-
-
-