Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Fix crash in transfer validation when a stop has missing coordinates #514

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions transitfeed/transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
# limitations under the License.

from __future__ import absolute_import
from .gtfsobjectbase import GtfsObjectBase
from . import problems as problems_module
from . import util
from .gtfsobjectbase import GtfsObjectBase


class Transfer(GtfsObjectBase):
"""Represents a transfer in a schedule"""
Expand Down Expand Up @@ -154,12 +155,16 @@ def ValidateTransferWalkingTime(self, problems):
return

distance = self.GetTransferDistance()
if distance is None:
# If the distance cannot be determined because of missing coordinates on a stop, return
# The stops.txt validation will report the missing coordinates.
return
# If min_transfer_time + 120s isn't enough for someone walking very fast
# (2m/s) then issue a warning.
#
# Stops that are close together (less than 240m appart) never trigger this
# warning, regardless of min_transfer_time.
FAST_WALKING_SPEED= 2 # 2m/s
FAST_WALKING_SPEED = 2 # 2m/s
if self.min_transfer_time + 120 < distance / FAST_WALKING_SPEED:
problems.TransferWalkingSpeedTooFast(from_stop_id=self.from_stop_id,
to_stop_id=self.to_stop_id,
Expand Down
4 changes: 3 additions & 1 deletion transitfeed/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def _MaxVersion(versions):
if len(versions) == 0:
return None

version_tuple = lambda x: tuple(int(item) for item in x.split('.'))
version_tuple = lambda x: tuple(int(item) for item in x.split('.'))
return max(versions, key=version_tuple)

OUTPUT_ENCODING = 'utf-8'
Expand Down Expand Up @@ -534,6 +534,8 @@ def ApproximateDistanceBetweenStops(stop1, stop2):
Earth is a sphere."""
if (stop1.stop_lat is None or stop1.stop_lon is None or
stop2.stop_lat is None or stop2.stop_lon is None):
print('Cannot determine distance between stops %s and %s due to missing coordinates'
% (stop1.stop_id, stop2.stop_id))
return None
return ApproximateDistance(stop1.stop_lat, stop1.stop_lon,
stop2.stop_lat, stop2.stop_lon)
Expand Down