From c51c837850b5c21b870ac5c001167ea9bb669efa Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Fri, 01 Feb 2019 00:30:21 +0000
Subject: [PATCH] Use database to find out bus type by vehicle number

---
 parse.php |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/parse.php b/parse.php
index 6e5b4e9..afa57b0 100644
--- a/parse.php
+++ b/parse.php
@@ -1,5 +1,6 @@
 <?php
-require_once 'vendor/autoload.php';
+require('vendor/autoload.php');
+require('common.php');
 
 use transit_realtime\FeedMessage;
 
@@ -53,6 +54,7 @@
 			$trip = $vehiclePosition->getTrip();
 			$tripId = $trip->getTripId();
 			$this->gtfsTrips[self::convertTripId($tripId)] = [
+				'id' => $entity->getId(),
 				'num' => $vehicle->getLicensePlate(),
 				'tripId' => $tripId,
 				'latitude' => $position->getLatitude(),
@@ -102,6 +104,7 @@
 		}
 		
 		if($options != 1) {
+			fwrite(STDERR, 'Found '.$options.' possible mappings!'."\n");
 			return FALSE;
 		}
 		return $bestOffset;
@@ -112,9 +115,12 @@
 		foreach($this->gtfsTrips as $gtfsTripId => $gtfsTrip) {
 			$jsonTripId = $gtfsTripId + $offset;
 			if(isset($this->jsonTrips[$jsonTripId])) {
-				$result[$jsonTripId] = [
-					'num' => $gtfsTrip['num'],
-				];
+				$data = numToTypeB($gtfsTrip['id']);
+				$num = $gtfsTrip['num'];
+				if($data['num'] != $num) {
+					fwrite(STDERR, 'Got '.$num.', database has '.$data['num']."\n");
+				}
+				$result[$jsonTripId] = $data;
 			}
 		}
 		return $result;

--
Gitblit v1.9.1