Skip to content

Commit

Permalink
Expose more details in GTFS
Browse files Browse the repository at this point in the history
- Expose route types using Google Transit extension
- Use train number as short name (it should not be longer than 12
  characters, so having the route ends there is not ideal)
  • Loading branch information
jbruechert committed Sep 27, 2024
1 parent 4b3cc2e commit 3b5ce26
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions gtfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def self.trips_data_from_file(file_path)
trip_data = {
'trip_id' => trip_id,
'agency_id' => agency_id,
'trip_short_name' => trip_type,
'trip_short_name' => trip_id,
'train_type_name' => trip_type,
'stops_data' => self::trip_stops_data_for_xml_row(trip_row, trip_id),
'calendar_data' => self::trip_calendar_data_for_xml_row(trip_row),
}
Expand Down Expand Up @@ -352,6 +353,21 @@ def self.gtfs_data_calendar_dates(calendar_rows)
return calendar_dates_rows
end

def self.route_type_to_gtfs(train_type)
case train_type
when "R"
return 106
when "R-E"
return 106
when "R-M"
return 106
when "IR"
return 103
when "IC"
return 102
end
end

def self.gtfs_data_routes_from_trips_data(trips_data)
routes_map = {}
route_id = 1
Expand All @@ -373,10 +389,9 @@ def self.gtfs_data_routes_from_trips_data(trips_data)
route_data = {
'route_id' => route_id,
'agency_id' => trip_data['agency_id'],
'route_short_name' => "#{trip_data['trip_short_name']}: #{first_stop['stop_name']} - #{last_stop['stop_name']}",
'route_long_name' => "#{trip_data['trip_short_name']}: #{stop_names.join(' - ')}",
'route_long_name' => "#{first_stop['stop_name']} - #{last_stop['stop_name']}",
# https://developers.google.com/transit/gtfs/reference#routestxt
'route_type' => '2',
'route_type' => route_type_to_gtfs(trip_data['train_type_name']),
}

routes_map[route_key] = route_data
Expand Down Expand Up @@ -483,3 +498,4 @@ def self.write_gtfs_data(gtfs_data)



p

0 comments on commit 3b5ce26

Please sign in to comment.