Output tables of vehicles on lines
5 files modified
2 files added
| | |
| | | { |
| | | "require": { |
| | | "google/gtfs-realtime-bindings": "^0.0.2", |
| | | "monolog/monolog": "^1.24" |
| | | "monolog/monolog": "^1.24", |
| | | "twig/twig": "^2.0" |
| | | } |
| | | } |
| | |
| | | 'ttss_file' => 'vehicles_A.json', |
| | | 'database' => 'mapping_A.sqlite3', |
| | | 'result' => 'mapping_A.json', |
| | | 'result_vehicles' => 'vehicles_A.html', |
| | | 'mapper' => 'numToTypeB', |
| | | 'prefix' => 'b', |
| | | ], |
| | | 'tram' => [ |
| | | 'gtfsrt' => 'ftp://ztp.krakow.pl/VehiclePositions_T.pb', |
| | |
| | | 'ttss_file' => 'vehicles_T.json', |
| | | 'database' => 'mapping_T.sqlite3', |
| | | 'result' => 'mapping_T.json', |
| | | 'result_vehicles' => 'vehicles_T.html', |
| | | 'mapper' => 'numToTypeT', |
| | | 'prefix' => 't', |
| | | ], |
| | | 'tram2' => [ |
| | | 'gtfsrt' => 'ftp://ztp.krakow.pl/VehiclePositions.pb', |
| | |
| | | 'ttss_file' => 'vehicles_T.json', |
| | | 'database' => 'mapping_T.sqlite3', |
| | | 'result' => 'mapping_T.json', |
| | | 'result_vehicles' => 'vehicles_T.html', |
| | | 'mapper' => 'numToTypeT', |
| | | 'prefix' => 't', |
| | | ], |
| | | ]; |
| | | |
| | | foreach($sources as $name => &$source) { |
| | | foreach(['gtfsrt_file', 'ttss_file', 'database', 'result'] as $field) { |
| | | foreach(['gtfsrt_file', 'ttss_file', 'database', 'result', 'result_vehicles'] as $field) { |
| | | $source[$field] = __DIR__.'/data/'.$source[$field]; |
| | | } |
| | | |
| | | $source['result_temp'] = $source['result'].'.tmp'; |
| | | $source['result_vehicles_temp'] = $source['result_vehicles'].'.tmp'; |
| | | } |
| | | unset($source); |
| | |
| | | if(!isset($vehicle->name) || !$vehicle->name) continue; |
| | | if(!isset($vehicle->latitude) || !$vehicle->latitude) continue; |
| | | if(!isset($vehicle->longitude) || !$vehicle->longitude) continue; |
| | | foreach($this->specialNames as $name) { |
| | | if(substr($vehicle->name, -strlen($name)) == $name) { |
| | | list($line, $direction) = explode(' ', $vehicle->name, 2); |
| | | foreach($this->specialNames as $specialName) { |
| | | if(substr($vehicle->name, -strlen($specialName)) == $specialName) { |
| | | continue; |
| | | } |
| | | } |
| | | $this->ttssTrips[(string)$vehicle->tripId] = [ |
| | | 'id' => (string)$vehicle->id, |
| | | 'line' => $line, |
| | | 'direction' => $direction, |
| | | 'latitude' => (float)$vehicle->latitude / 3600000.0, |
| | | 'longitude' => (float)$vehicle->longitude / 3600000.0, |
| | | ]; |
| | |
| | | return $this->ttssDate / 1000.0; |
| | | } |
| | | |
| | | public function getTTSSTrips() { |
| | | return $this->ttssTrips; |
| | | } |
| | | |
| | | public function loadGTFSRT($file) { |
| | | $data = file_get_contents($file); |
| | | $feed = new FeedMessage(); |
New file |
| | |
| | | <?php |
| | | function createVehiclesList($trips, $mapping, $saveConfig = FALSE) { |
| | | $lines = []; |
| | | foreach($trips as $trip) { |
| | | $lines[$trip['line']][] = [ |
| | | 'trip' => $trip, |
| | | 'vehicle' => $mapping[$trip['id']] ?? [], |
| | | ]; |
| | | } |
| | | foreach($lines as &$line) { |
| | | usort($line, function($a, $b) { |
| | | return (substr($a['vehicle']['num'] ?? '', 2) <=> substr($b['vehicle']['num'] ?? '', 2)); |
| | | }); |
| | | } |
| | | unset($line); |
| | | ksort($lines); |
| | | |
| | | if($saveConfig) { |
| | | $twigLoader = new \Twig\Loader\FilesystemLoader(__DIR__.'/../templates'); |
| | | $twig = new \Twig\Environment($twigLoader); |
| | | |
| | | $vehiclesHtml = $twig->render('vehicles.html', [ |
| | | 'lines' => $lines, |
| | | 'prefix' => $saveConfig['prefix'], |
| | | ]); |
| | | if(!file_put_contents($saveConfig['result_vehicles_temp'], $vehiclesHtml)) { |
| | | throw new Exception('Vehicles save failed'); |
| | | } |
| | | rename($saveConfig['result_vehicles_temp'], $saveConfig['result_vehicles']); |
| | | } |
| | | |
| | | return $lines; |
| | | } |
| | |
| | | require_once(__DIR__.'/lib/database.php'); |
| | | require_once(__DIR__.'/lib/fetch.php'); |
| | | require_once(__DIR__.'/lib/mapper.php'); |
| | | require_once(__DIR__.'/lib/output.php'); |
| | | require_once(__DIR__.'/lib/vehicle_types.php'); |
| | | require_once(__DIR__.'/config.php'); |
| | | |
| | |
| | | throw new Exception('Ignoring result due to better data already present'); |
| | | } |
| | | |
| | | |
| | | $logger->info('Creating mapping...'); |
| | | |
| | | $db->addMapping($mapping); |
| | | |
| | | $jsonContent = []; |
| | |
| | | throw new Exception('Result save failed'); |
| | | } |
| | | rename($source['result_temp'], $source['result']); |
| | | |
| | | |
| | | $logger->info('Creating vehicle list...'); |
| | | |
| | | createVehiclesList($mapper->getTTSSTrips(), $jsonContent, $source); |
| | | |
| | | $logger->info('Finished'); |
| | | } catch(Throwable $e) { |
| | | $logger->error($e->getMessage(), ['exception' => $e, 'exception_string' => (string)$e]); |
New file |
| | |
| | | <!DOCTYPE html> |
| | | <title>Vehicles on lines (TTSS-based)</title> |
| | | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| | | |
| | | <style type="text/css"> |
| | | table { |
| | | border-collapse: collapse; |
| | | border-spacing: 0; |
| | | } |
| | | th, td { |
| | | border: 1px solid black; |
| | | padding: 5px; |
| | | } |
| | | td { |
| | | vertical-align: top; |
| | | text-align: center; |
| | | } |
| | | a { |
| | | text-decoration: none; |
| | | } |
| | | a:hover { |
| | | text-decoration: underline; |
| | | } |
| | | .low { |
| | | color: #000; |
| | | } |
| | | .low0 { |
| | | color: #C70; |
| | | } |
| | | .low1, .low2 { |
| | | color: #070; |
| | | } |
| | | </style> |
| | | |
| | | <table> |
| | | |
| | | <thead> |
| | | <tr> |
| | | {% for line in lines|keys %} |
| | | <th>{{ line | e }}</th> |
| | | {% endfor %} |
| | | </tr> |
| | | </thead> |
| | | |
| | | <tbody> |
| | | <tr> |
| | | {% for trips in lines %} |
| | | <td> |
| | | {% for trip in trips %} |
| | | <a href="https://mpk.jacekk.net/map.html#!{{ prefix }}{{ trip.trip.id | e }}" class="low{{ trip.vehicle.low | default }}"> |
| | | {{ trip.vehicle.num | default('<?>') | e }}<br /> |
| | | </a> |
| | | {% endfor %} |
| | | </td> |
| | | {% endfor %} |
| | | </tr> |
| | | </tbody> |
| | | |
| | | </table> |