Skip to content

Commit

Permalink
First working version
Browse files Browse the repository at this point in the history
  • Loading branch information
Pieter Colpaert committed Nov 4, 2015
1 parent e6d8c2b commit dbc49c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
28 changes: 25 additions & 3 deletions lib/ConnectionsBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,31 @@ var ConnectionsBuilder = function (tripsdb, servicesdb) {
util.inherits(ConnectionsBuilder, Transform);

ConnectionsBuilder.prototype._transform = function (connectionRule, encoding, done) {
//{"trip_id":"STBA","arrival_dfm":"6:20:00","departure_dfm":"6:00:00","departure_stop":"STAGECOACH","arrival_stop":"BEATTY_AIRPORT","departure_stop_headsign":"","arrival_stop_headsign":"","pickup_type":""}
//TODO
connectionRule["trip_id"];
//Examples of
// * a connectionRule: {"trip_id":"STBA","arrival_dfm":"6:20:00","departure_dfm":"6:00:00","departure_stop":"STAGECOACH","arrival_stop":"BEATTY_AIRPORT","departure_stop_headsign":"","arrival_stop_headsign":"","pickup_type":""}
// * a trip: { route_id: 'AAMV',service_id: 'WE',trip_id: 'AAMV4',trip_headsign: 'to Airport',direction_id: '1', block_id: '', shape_id: '' }
var departureDFM = moment.duration(connectionRule['departure_dfm']);
var arrivalDFM = moment.duration(connectionRule['arrival_dfm']);
var self = this;
this._tripsdb.get(connectionRule['trip_id'], function (error, trip) {
trip = JSON.parse(trip);
self._servicesdb.get(trip['service_id'], function (error, service) {
service = JSON.parse(service);
for (var i in service) {
var serviceDay = service[i];
var departureTime = moment(serviceDay, 'YYYYMMDD').add(departureDFM);
var arrivalTime = moment(serviceDay, 'YYYYMMDD').add(arrivalDFM);
self.push({
departureTime: departureTime,
arrivalTime: arrivalTime,
arrivalStop: connectionRule['arrival_stop'],
departureStop: connectionRule['departure_stop'],
trip: connectionRule['trip_id']
});
}
done();
});
});
};

module.exports = ConnectionsBuilder;
2 changes: 1 addition & 1 deletion lib/gtfs2lc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Mapper.prototype.resultStream = function (path, done) {
count ++;
//wait for the 2 streams to finish (services and trips) to write to the stores
if (count === 2) {
console.error("Indexing services and trips succesful!");
console.error("Indexing services and trips succesful!");
//Step 4 and 5: let's create our connections!
done(connectionRules.pipe(new ConnectionsBuilder(tripsdb, servicesdb)));
}
Expand Down

0 comments on commit dbc49c8

Please sign in to comment.