Skip to content

Commit

Permalink
Better CSV trip names
Browse files Browse the repository at this point in the history
  • Loading branch information
brendannee committed Nov 26, 2021
1 parent 28a98be commit bb85742
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

### Updated

- Dependency updates
- Better trip names for CSV export

## [2.3.0] - 2021-11-05

### Added
Expand Down
22 changes: 22 additions & 0 deletions lib/template-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,25 @@ export function formatTripName(trip, index, timetable) {

return tripName;
}

/*
* Formats a trip name.
*/
export function formatTripNameForCSV(trip, timetable) {
let tripName = '';
if (timetable.routes.length > 1) {
tripName += `${trip.route_short_name} - `;
}

if (trip.trip_short_name) {
tripName += trip.trip_short_name;
} else {
tripName += trip.trip_id;
}

if (timetableHasDifferentDays(timetable)) {
tripName += ` - ${trip.dayList}`;
}

return tripName;
}
6 changes: 3 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import {
fromGTFSTime,
calendarCodeToCalendar,
} from './time-utils.js';
import { formatTripName } from './template-functions.js';
import { formatTripNameForCSV } from './template-functions.js';

const { version } = JSON.parse(
readFileSync(new URL('../package.json', import.meta.url))
Expand Down Expand Up @@ -1550,8 +1550,8 @@ export async function generateTimetableCSV(timetable) {

lines.push([
'',
...timetable.orderedTrips.map((trip, index) =>
formatTripName(trip, index, timetable)
...timetable.orderedTrips.map((trip) =>
formatTripNameForCSV(trip, timetable)
),
]);

Expand Down

0 comments on commit bb85742

Please sign in to comment.