From ea2e9b41b3b1eace8e99d6e2672ffffb07665e04 Mon Sep 17 00:00:00 2001 From: Jacek Kowalski <Jacek@jacekk.info> Date: Fri, 21 Jun 2019 11:46:18 +0000 Subject: [PATCH] Add regenerate.php to recreate JSON files in case of manual changes --- lib/mapper.php | 34 ++++++++++++++++------------------ 1 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/mapper.php b/lib/mapper.php index 43dd085..42abecf 100644 --- a/lib/mapper.php +++ b/lib/mapper.php @@ -1,11 +1,10 @@ <?php -require_once(__DIR__.'/../vendor/autoload.php'); -require_once(__DIR__.'/vehicle_types.php'); - use transit_realtime\FeedMessage; class Mapper { + private $ttssDate = NULL; private $ttssTrips = []; + private $gtfsrtDate = NULL; private $gtfsrtTrips = []; private $logger = NULL; @@ -28,6 +27,7 @@ public function loadTTSS($file) { $ttss = json_decode(file_get_contents($file)); + $this->ttssDate = $ttss->lastUpdate; foreach($ttss->vehicles as $vehicle) { if(isset($vehicle->isDeleted) && $vehicle->isDeleted) continue; if(!isset($vehicle->tripId) || !$vehicle->tripId) continue; @@ -39,8 +39,8 @@ continue; } } - $this->ttssTrips[(int)$vehicle->tripId] = [ - 'id' => $vehicle->id, + $this->ttssTrips[(string)$vehicle->tripId] = [ + 'id' => (string)$vehicle->id, 'latitude' => (float)$vehicle->latitude / 3600000.0, 'longitude' => (float)$vehicle->longitude / 3600000.0, ]; @@ -48,10 +48,15 @@ ksort($this->ttssTrips); } + public function getTTSSDate() { + return $this->ttssDate / 1000.0; + } + public function loadGTFSRT($file) { $data = file_get_contents($file); $feed = new FeedMessage(); $feed->parse($data); + $this->gtfsrtDate = $feed->header->timestamp; foreach ($feed->getEntityList() as $entity) { $vehiclePosition = $entity->getVehicle(); $position = $vehiclePosition->getPosition(); @@ -59,7 +64,7 @@ $trip = $vehiclePosition->getTrip(); $tripId = $trip->getTripId(); $this->gtfsrtTrips[self::convertTripId($tripId)] = [ - 'id' => $entity->getId(), + 'id' => (string)$entity->getId(), 'num' => $vehicle->getLicensePlate(), 'tripId' => $tripId, 'latitude' => $position->getLatitude(), @@ -67,6 +72,10 @@ ]; } ksort($this->gtfsrtTrips); + } + + public function getGTFSRTDate() { + return $this->gtfsrtDate; } public function findOffset() { @@ -119,18 +128,7 @@ foreach($this->gtfsrtTrips as $gtfsTripId => $gtfsTrip) { $ttssTripId = $gtfsTripId + $offset; if(isset($this->ttssTrips[$ttssTripId])) { - $data = numToTypeB($gtfsTrip['id']); - $num = $gtfsTrip['num']; - if(!is_array($data) || !isset($data['num'])) { - $data = [ - 'num' => $num, - 'low' => 2, - ]; - } elseif($data['num'] != $num) { - // Ignore due to incorrect depot markings in the data - //$this->logger->warn('Got '.$num.', database has '.$data['num']); - } - $result[$this->ttssTrips[$ttssTripId]['id']] = $data; + $result[$this->ttssTrips[$ttssTripId]['id']] = $gtfsTrip['id']; } } return $result; -- Gitblit v1.9.1