Rewrite the schedule generation script #31

Merged
user890104 merged 19 commits from schedule-rewrite into master 2016-10-24 00:52:04 +03:00
1 changed files with 42 additions and 15 deletions
Showing only changes of commit 46d9f93ac3 - Show all commits

View File

@ -99,6 +99,7 @@ function parseData($config, $data) {
$found = true; $found = true;
$hall_data[] = [ $hall_data[] = [
'event_id' => $slot['event_id'], 'event_id' => $slot['event_id'],
'hall_id' => $slot['hall_id'],
'edge' => $slot['starts_at'] === $timestamps[0] || $slot['ends_at'] === $timestamps[1], 'edge' => $slot['starts_at'] === $timestamps[0] || $slot['ends_at'] === $timestamps[1],
]; ];
break; break;
@ -113,6 +114,21 @@ function parseData($config, $data) {
$events[] = $hall_data; $events[] = $hall_data;
} }
// Remove halls with no events after filtering
$count = count($events);
for ($i = 0; $i < $count; ++$i) {
$hasEvents = false;
foreach ($events[$i] as $event_info) {
if (!is_null($event_info)) {
$hasEvents = true;
break;
}
}
if (!$hasEvents) {
unset($events[$i]);
}
}
// Transpose the matrix // Transpose the matrix
// rows->halls, cols->timeslots ===> rows->timeslots, cols->halls // rows->halls, cols->timeslots ===> rows->timeslots, cols->halls
$events = array_map(null, ...$events); $events = array_map(null, ...$events);
@ -192,28 +208,23 @@ function parseData($config, $data) {
unset($events_data); unset($events_data);
// Build the HTML // Build the HTML
$schedule = '<table border="1"><thead><tr><th></th>'; $schedule_body = '';
foreach ($data['halls'] as $hall_id => $hall) {
$schedule .= '<th>' . $hall['bg'] . '</th>';
}
$schedule .= '</tr></thead><tbody>';
$lastTs = 0; $lastTs = 0;
$fulltalks = ''; $fulltalks = '';
$hall_ids = [];
foreach ($events as $slot_index => $events_data) { foreach ($events as $slot_index => $events_data) {
$columns = []; $columns = [];
if (date('d.m', $microslots[$slot_index][0]) !== date('d.m', $lastTs)) { if (date('d.m', $microslots[$slot_index][0]) !== date('d.m', $lastTs)) {
$schedule .= '<tr><th colspan="' . (count($events_data) + 1) . '">' . strftime('%d %B - %A', $microslots[$slot_index][0]) . '</th></tr>'; $schedule_body .= '<tr><th colspan="' . (count($events_data) + 1) . '">' . strftime('%d %B - %A', $microslots[$slot_index][0]) . '</th></tr>';
} }
$lastTs = $microslots[$slot_index][0]; $lastTs = $microslots[$slot_index][0];
$lastEventId = 0; $lastEventId = 0;
$colspan = 1; $colspan = 1;
foreach ($events_data as $hall_index => $event_info) { foreach ($events_data as $event_info) {
if ($event_info === false) { if ($event_info === false) {
continue; continue;
} }
@ -223,6 +234,10 @@ function parseData($config, $data) {
continue; continue;
} }
if (!in_array($event_info['hall_id'], $hall_ids)) {
$hall_ids[] = $event_info['hall_id'];
}
$eid = &$event_info['event_id']; $eid = &$event_info['event_id'];
$event = &$data['events'][$eid]; $event = &$data['events'][$eid];
@ -288,13 +303,25 @@ function parseData($config, $data) {
unset($eid, $event); unset($eid, $event);
} }
$schedule .= '<tr><td>'; $schedule_body .= '<tr><td>';
$schedule .= strftime('%H:%M', $microslots[$slot_index][0]) . ' - ' . strftime('%H:%M', $microslots[$slot_index][1]); $schedule_body .= strftime('%H:%M', $microslots[$slot_index][0]) . ' - ' . strftime('%H:%M', $microslots[$slot_index][1]);
$schedule .= '</td>'; $schedule_body .= '</td>';
$schedule .= implode('', $columns); $schedule_body .= implode('', $columns);
$schedule .= '</tr>'; $schedule_body .= '</tr>';
} }
$schedule = '<table border="1"><thead><tr><th></th>';
foreach ($data['halls'] as $hall_id => $hall) {
if (!in_array($hall_id, $hall_ids)) {
continue;
}
$schedule .= '<th>' . $hall['bg'] . '</th>';
}
$schedule .= '</tr></thead><tbody>';
$schedule .= $schedule_body;
$schedule .= '</tbody></table>'; $schedule .= '</tbody></table>';
// Create the legend // Create the legend