From 70ddd4b2dfbbc9621f4aae28853de3da6a94cc26 Mon Sep 17 00:00:00 2001 From: Julian Rojas Date: Thu, 7 Jul 2022 17:52:20 +0200 Subject: [PATCH 1/4] Fix unique ID building for checking historic records --- lib/Gtfsrt2LC.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Gtfsrt2LC.js b/lib/Gtfsrt2LC.js index 30225ed..ee9a46a 100644 --- a/lib/Gtfsrt2LC.js +++ b/lib/Gtfsrt2LC.js @@ -154,10 +154,10 @@ class Gtfsrt2LC { route: r, trip: t, stopTimes: st, - cu, - ncu: completedUpdates[j + 1], + cu: await this.getStop(cu.stopId), + ncu: await this.getStop(completedUpdates[j + 1].stopId), pdIndex, - startTime: tripUpdate.trip.startTime, + startTime: format(tripStartTime, 'H:mm:ss'), startDate, departureDelay, arrivalDelay, @@ -642,11 +642,16 @@ class Gtfsrt2LC { } = params; // Build Connection's original rule as in gtfs2lc + const depStopId = cu['stop_code'] && cu['stop_code'] !== '' ? + cu['stop_code'] : cu['stop_id']; + const arrStopId = ncu['stop_code'] && ncu['stop_code'] !== '' ? + ncu['stop_code'] : ncu['stop_id']; + const uniqueId = [ route['route_long_name'].replace(/\s/g, ''), trip['trip_short_name'], - cu['stopId'], - ncu['stopId'], + depStopId, + arrStopId, startTime, stopTimes[pdIndex]['departure_time'], stopTimes[pdIndex + 1]['arrival_time'], From c440b9f5c8149928a26d7fb59fb36bb2c415873a Mon Sep 17 00:00:00 2001 From: Julian Rojas Date: Thu, 7 Jul 2022 17:52:39 +0200 Subject: [PATCH 2/4] 2.0.3 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index a58921f..cebcfb9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gtfsrt2lc", - "version": "2.0.2", + "version": "2.0.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "gtfsrt2lc", - "version": "2.0.2", + "version": "2.0.3", "license": "MIT", "dependencies": { "commander": "^5.0.0", diff --git a/package.json b/package.json index effb649..b5e22d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gtfsrt2lc", - "version": "2.0.2", + "version": "2.0.3", "description": "Converts the GTFS-RT to Linked Connections", "main": "./Gtfsrt2LC.js", "bin": { From d28286117828b693c214a315f3756c5f03ed1b71 Mon Sep 17 00:00:00 2001 From: Julian Rojas Date: Thu, 7 Jul 2022 18:30:40 +0200 Subject: [PATCH 3/4] Extend test coverage --- lib/Gtfsrt2LC.js | 4 ++-- test/gtfsrt2lc.test.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Gtfsrt2LC.js b/lib/Gtfsrt2LC.js index ee9a46a..552af8e 100644 --- a/lib/Gtfsrt2LC.js +++ b/lib/Gtfsrt2LC.js @@ -150,7 +150,7 @@ class Gtfsrt2LC { // Check if this is a new update based on recorded Connections history (if any) // and skip it if is not new. - if (this.historyDB && !(await this.differentiaUpdate({ + if (this.historyDB && !(await this.differentialUpdate({ route: r, trip: t, stopTimes: st, @@ -626,7 +626,7 @@ class Gtfsrt2LC { return update; } - async differentiaUpdate(params) { + async differentialUpdate(params) { const { route, trip, diff --git a/test/gtfsrt2lc.test.js b/test/gtfsrt2lc.test.js index 3c13c90..99c5c27 100644 --- a/test/gtfsrt2lc.test.js +++ b/test/gtfsrt2lc.test.js @@ -582,4 +582,19 @@ test('Cover GtfsIndex functions', async () => { try { await gti.getIndexes(); } catch (err) { } +}); + +test('Cover Gtfsrt2LC functions', async () => { + grt = new Gtfsrt2lc({ path: rt_path, uris: mock_uris, headers: {} }); + // Test for resolveScheduleRelationship + const notAvailable = grt.resolveScheduleRelationship(1, 1); + const mustPhone = grt.resolveScheduleRelationship(0, 2); + const mustCoordinate = grt.resolveScheduleRelationship(0, 3); + // Test for getting headers + const headers = grt.headers(); + + expect(notAvailable).toBe('gtfs:NotAvailable'); + expect(mustPhone).toBe('gtfs:MustPhone'); + expect(mustCoordinate).toBe('gtfs:MustCoordinateWithDriver'); + expect(headers).toBeDefined(); }); \ No newline at end of file From b41c51e77f0bacef4a493006303d7d0828e57cf5 Mon Sep 17 00:00:00 2001 From: Julian Rojas Date: Thu, 7 Jul 2022 18:35:14 +0200 Subject: [PATCH 4/4] Fix tests --- test/gtfsrt2lc.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/gtfsrt2lc.test.js b/test/gtfsrt2lc.test.js index 99c5c27..b8d63cc 100644 --- a/test/gtfsrt2lc.test.js +++ b/test/gtfsrt2lc.test.js @@ -591,7 +591,7 @@ test('Cover Gtfsrt2LC functions', async () => { const mustPhone = grt.resolveScheduleRelationship(0, 2); const mustCoordinate = grt.resolveScheduleRelationship(0, 3); // Test for getting headers - const headers = grt.headers(); + const headers = grt.headers; expect(notAvailable).toBe('gtfs:NotAvailable'); expect(mustPhone).toBe('gtfs:MustPhone');