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

Expose more details in GTFS #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 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,25 @@ 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 "IR-N"
return 105
when "IC"
return 102
else
return 2
end
end

def self.gtfs_data_routes_from_trips_data(trips_data)
routes_map = {}
route_id = 1
Expand All @@ -373,10 +393,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 @@ -480,6 +499,3 @@ def self.write_gtfs_data(gtfs_data)
end

end