Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added check for canceled connections #9

Merged
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $ gtfsrt2lc -r /path/to/realtime_rawdata -s /path/to/static_rawdata.zip -u /path
## How does it work?
Providing globally unique identifiers to the different entities that comprise a public transport network is fundamental to lower the adoption cost of public transport data in route-planning appplications. Specifically in the case of live updates about the schedules is important to mantain stable identifiers that remain valid over time. Here we use the Linked Data [principles](https://www.w3.org/DesignIssues/LinkedData.html) to transform schedule updates given in the `GTFS-RT` format to [Linked Connections](http://linkedconnections.org/) and we give the option to serialize them in JSON, CSV or RDF (turtle, N-Triples or JSON-LD) format.

The URI strategy to be used during the conversion process is given following the [RFC 6570](https://tools.ietf.org/html/rfc6570) specification for URI templates. Next we describe how can the URI strategy be defined through an example. A basic understanding of the `GTFS` [specification](https://developers.google.com/tansit/gtfs/reference/) is required.
The URI strategy to be used during the conversion process is given following the [RFC 6570](https://tools.ietf.org/html/rfc6570) specification for URI templates. Next we describe how can the URI strategy be defined through an example. A basic understanding of the `GTFS` [specification](https://developers.google.com/transit/gtfs/reference/) is required.

### URI templates
In order to define the URI of the different entities of a public transport network that are referenced in a Linked Connection, we use a single JSON file that contains the different URI templates. We provide an example of such file [here](https://github.com/linkedconnections/gtfsrt2lc/blob/master/uris_template_example.json) which looks as follows:
Expand Down
15 changes: 12 additions & 3 deletions lib/Connections2JSONLD.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Connections2JSONLD extends Transform {
this.push(this.context);
}

done(null, {
let temp = {
"@id": lc['@id'],
"@type": lc['@type'],
"departureStop": lc['departureStop'],
Expand All @@ -70,7 +70,16 @@ class Connections2JSONLD extends Transform {
"direction": lc['direction'],
"gtfs:trip": lc['trip'],
"gtfs:route": lc['route']
});
}

if(lc['gtfs:pickupType'] != null) {
temp["gtfs:pickupType"] = lc['gtfs:pickupType'];
}

if(lc['gtfs:dropOffType'] != null) {
temp["gtfs:dropOffType"] = lc['gtfs:dropOffType'];
}
done(null, temp);
}

get contextStreamed() {
Expand All @@ -86,4 +95,4 @@ class Connections2JSONLD extends Transform {
}
}

module.exports = Connections2JSONLD;
module.exports = Connections2JSONLD;
23 changes: 20 additions & 3 deletions lib/Gtfsrt2LC.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class Gtfsrt2LC {
let routeURI = this.resolveURI(routeTemplate, trip_id, tripStartTime, raw_connection);
let tripURI = this.resolveURI(tripTemplate, trip_id, tripStartTime, raw_connection);
let connectionURI = this.resolveURI(connectionTemplate, trip_id, tripStartTime, raw_connection);
let pickupType = this.resolveScheduleRelationship(stop_times[j].schedule_relationship);
let dropOffType = this.resolveScheduleRelationship(stop_times[j].schedule_relationship);

let linked_connection = {
"@id": connectionURI,
Expand All @@ -121,7 +123,9 @@ class Gtfsrt2LC {
"arrivalDelay": arrivalDelay,
"direction": this.trips.get(trip_id).trip_headsign,
"trip": tripURI,
"route": routeURI
"route": routeURI,
"gtfs:pickupType": pickupType,
"gtfs:dropOffType": dropOffType
}

readable.push(linked_connection);
Expand Down Expand Up @@ -231,7 +235,7 @@ class Gtfsrt2LC {
}

getConnectionType(entity) {
if (entity.is_deleted) {
if (entity.is_deleted || entity.trip_update.trip.schedule_relationship == 3) {
return 'CanceledConnection';
}
else {
Expand Down Expand Up @@ -303,6 +307,19 @@ class Gtfsrt2LC {
return value;
}

resolveScheduleRelationship(value) {
// SCHEDULED
if(value == 0) {
return 'gtfs:Regular';
}
// SKIPPED
else if(value == 1) {
return 'gtfs:NotAvailable';
}
// NO_DATA
return null;
}

get path() {
return this._path;
}
Expand All @@ -320,4 +337,4 @@ class Gtfsrt2LC {
}
}

module.exports = Gtfsrt2LC;
module.exports = Gtfsrt2LC;