From a3d09166cbbe6f8c62ad56d8432f4bc6dff0ed5b Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sat, 22 Jun 2019 20:16:21 +0000
Subject: [PATCH] Add "Generated at" to tables with vehicle types

---
 lib/mapper.php |   35 ++++++++++++++---------------------
 1 files changed, 14 insertions(+), 21 deletions(-)

diff --git a/lib/mapper.php b/lib/mapper.php
index 3eb7912..a36b4ef 100644
--- a/lib/mapper.php
+++ b/lib/mapper.php
@@ -1,7 +1,4 @@
 <?php
-require_once(__DIR__.'/../vendor/autoload.php');
-require_once(__DIR__.'/vehicle_types.php');
-
 use transit_realtime\FeedMessage;
 
 class Mapper {
@@ -37,13 +34,16 @@
 			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[(int)$vehicle->tripId] = [
-				'id' => $vehicle->id,
+			$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,
 			];
@@ -53,6 +53,10 @@
 	
 	public function getTTSSDate() {
 		return $this->ttssDate / 1000.0;
+	}
+	
+	public function getTTSSTrips() {
+		return $this->ttssTrips;
 	}
 	
 	public function loadGTFSRT($file) {
@@ -67,7 +71,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(),
@@ -126,23 +130,12 @@
 		return $bestOffset;
 	}
 	
-	public function mapUsingOffset($offset, $mapper) {
+	public function mapUsingOffset($offset) {
 		$result = [];
 		foreach($this->gtfsrtTrips as $gtfsTripId => $gtfsTrip) {
 			$ttssTripId = $gtfsTripId + $offset;
 			if(isset($this->ttssTrips[$ttssTripId])) {
-				$data = $mapper($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