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

Add support for required via tag (if given inside OSM data) #129

Merged
merged 1 commit into from
Aug 4, 2018
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions osm2gtfs/core/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class Itinerary(Element):

line = attr.ib(default=None)
fr = attr.ib(default=None)
via = attr.ib(default=None)
to = attr.ib(default=None)
duration = attr.ib(default=None)

Expand All @@ -109,6 +110,10 @@ def __attrs_post_init__(self):
if 'from' in self.tags:
self.fr = self.tags['from']

# pylint: disable=unsupported-membership-test,unsubscriptable-object
if 'via' in self.tags:
self.via = self.tags['via']

# pylint: disable=unsupported-membership-test,unsubscriptable-object
if 'to' in self.tags:
self.to = self.tags['to']
Expand Down
20 changes: 15 additions & 5 deletions osm2gtfs/creators/trips_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,16 @@ def _prepare_trips(self, feed, schedule, itinerary):
for trip in schedule['lines'][itinerary.route_id]:
input_fr = trip["from"]
input_to = trip["to"]
if input_fr == itinerary.fr and input_to == itinerary.to:
input_via = trip["via"] if "via" in trip else None
if (input_fr == itinerary.fr and
input_to == itinerary.to and
input_via == itinerary.via):
trip_services = trip["services"]
for service in trip_services:
services.append(service)

if not services:
print(" Warning: From and to values didn't match with schedule.")
print(" Warning: From, to and via values didn't match with schedule.")

# Loop through all service days
trips = []
Expand Down Expand Up @@ -299,8 +302,11 @@ def _load_itinerary_schedule(self, schedule, itinerary, service):
times = None
for trip in schedule['lines'][itinerary.route_id]:
trip_services = trip["services"]
if "via" not in trip:
trip["via"] = None
if (trip["from"] == itinerary.fr and
trip["to"] == itinerary.to and
trip["via"] == itinerary.via and
service in trip_services):
times = trip["times"]
if times is None:
Expand All @@ -317,9 +323,13 @@ def _load_scheduled_stops(self, schedule, itinerary, service):
stops = []
for trip in schedule['lines'][itinerary.route_id]:
trip_services = trip["services"]
if (trip[
"from"] == itinerary.fr and trip[
"to"] == itinerary.to and service in trip_services):
trip_fr = trip["from"]
trip_to = trip["to"]
trip_via = trip["via"] if "via" in trip else None
if (trip_fr == itinerary.fr and
trip_to == itinerary.to and
trip_via == itinerary.via and
service in trip_services):
for stop in trip["stations"]:
stops.append(stop)
return stops