Skip to content

Commit 095361a

Browse files
committed
version bump
Use gtfs 0.10.0
1 parent 92d4d77 commit 095361a

File tree

5 files changed

+1076
-984
lines changed

5 files changed

+1076
-984
lines changed

lib/formatters.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ function parseTime(timeStr) {
1212
return moment(timeStr, 'HH:mm:ss');
1313
}
1414

15+
exports.msToSeconds = ms => {
16+
return Math.round(ms / 1000);
17+
};
18+
1519
exports.formatDate = date => {
1620
if (date.holiday_name) {
1721
return date.holiday_name;
@@ -31,8 +35,7 @@ exports.formatStopTime = (stoptime, timetable, config) => {
3135
stoptime = {
3236
classes: ['skipped'],
3337
arrival_formatted_time: config.noServiceSymbol,
34-
departure_formatted_time: config.noServiceSymbol,
35-
38+
departure_formatted_time: config.noServiceSymbol
3639
};
3740
timetable.noServiceSymbolUsed = true;
3841
}

lib/gtfs-to-html.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ const sanitize = require('sanitize-filename');
77
const Table = require('cli-table');
88
const Timer = require('timer-machine');
99

10-
const fileUtils = require('../lib/file-utils');
11-
const utils = require('../lib/utils');
10+
const fileUtils = require('./file-utils');
11+
const formatters = require('./formatters');
12+
const utils = require('./utils');
1213

1314
module.exports = selectedConfig => {
1415
const config = utils.setDefaultConfig(selectedConfig);
15-
1616
const log = (config.verbose === false) ? _.noop : console.log;
1717

18+
if (!config.agencies || config.agencies.length === 0) {
19+
throw new Error('No agencies defined in `config.json`');
20+
}
21+
1822
return Promise.all(config.agencies.map(agency => {
1923
const timer = new Timer();
2024
const agencyKey = agency.agency_key;
@@ -33,20 +37,17 @@ module.exports = selectedConfig => {
3337

3438
log(`Generating HTML schedules for ${agencyKey}`);
3539

36-
return new Promise((resolve, reject) => {
40+
return new Promise(resolve => {
3741
if (config.skipImport) {
3842
return resolve();
3943
}
4044

4145
// Import GTFS
4246
const agencyConfig = _.clone(_.omit(config, 'agencies'));
4347
agencyConfig.agencies = [agency];
44-
gtfs.import(agencyConfig, err => {
45-
if (err) {
46-
return reject(err);
47-
}
48-
resolve();
49-
});
48+
49+
gtfs.import(agencyConfig)
50+
.then(resolve);
5051
})
5152
.then(() => fileUtils.prepDirectory(exportPath, assetPath))
5253
.then(() => utils.getTimetablePages(agencyKey))
@@ -104,7 +105,7 @@ module.exports = selectedConfig => {
104105
);
105106

106107
log(table.toString());
107-
log(`Timetable generation required ${Math.round(timer.time() / 1000)} seconds`);
108+
log(`Timetable generation required ${formatters.msToSeconds(timer.time())} seconds`);
108109
});
109110
}));
110111
};

lib/utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function sortTrips(trips) {
4747
return _.sortBy(trips, trip => {
4848
let selectedStoptime;
4949
if (commonStoptime) {
50-
selectedStoptime = _.find(trip.stoptimes, {stop_id: commonStoptime.stop_id});
50+
selectedStoptime = _.find(trip.stoptimes, {stop_id: commonStoptime.stop_id});
5151
} else {
5252
selectedStoptime = trip.stoptimes[0];
5353
}
@@ -96,7 +96,7 @@ function processStops(agencyKey, timetable, config) {
9696

9797
let stopSequence = 0;
9898
timetable.stops.forEach(stop => {
99-
// find a stoptime for the matching stop_id greater than the last stop_sequence
99+
// Find a stoptime for the matching stop_id greater than the last stop_sequence
100100
const stoptime = _.find(trip.stoptimes, st => st.stop_id === stop.stop_id && st.stop_sequence >= stopSequence);
101101
if (stoptime) {
102102
stopSequence = stoptime.stop_sequence;
@@ -248,7 +248,7 @@ function getStops(timetableStopOrders, stoptimes) {
248248

249249
// Convert stops to array of object
250250
const stops = stopIds.map((stopId, idx) => {
251-
let stop = {
251+
const stop = {
252252
stop_id: stopId,
253253
trips: []
254254
};
@@ -303,7 +303,7 @@ function formatTimetablePage(agencyKey, timetablePage) {
303303
return gtfs.getRoutesById(agencyKey, timetablePage.timetables[0].route_id)
304304
.then(route => {
305305
if (!route) {
306-
throw new Error(`No route found for route_id=${timetable.route_id}, timetable_id=${timetable.timetable_id}`);
306+
throw new Error(`No route found for route_id=${timetablePage.timetables[0].route_id}, timetable_id=${timetablePage.timetables[0].timetable_id}`);
307307
}
308308

309309
timetablePage.timetable_page_label = `${route.route_short_name} ${route.route_long_name}`;
@@ -544,7 +544,7 @@ exports.getTimetablePages = agencyKey => {
544544
} else if (!timetablePages || timetablePages.length === 0) {
545545
// If no timetablepages, use timetables
546546
return Promise.all(timetables.map(timetable => {
547-
return convertTimetableToTimetablePage(agencyKey, timetable)
547+
return convertTimetableToTimetablePage(agencyKey, timetable);
548548
}));
549549
}
550550

0 commit comments

Comments
 (0)