Skip to content

Commit

Permalink
Merge pull request #64 from linkedconnections/development
Browse files Browse the repository at this point in the history
v2.0.3
  • Loading branch information
julianrojas87 authored Jul 7, 2022
2 parents 00544ca + b41c51e commit 8379e40
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
19 changes: 12 additions & 7 deletions lib/Gtfsrt2LC.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ 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,
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,
Expand Down Expand Up @@ -626,7 +626,7 @@ class Gtfsrt2LC {
return update;
}

async differentiaUpdate(params) {
async differentialUpdate(params) {
const {
route,
trip,
Expand All @@ -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'],
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
15 changes: 15 additions & 0 deletions test/gtfsrt2lc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

0 comments on commit 8379e40

Please sign in to comment.