Skip to content

Commit

Permalink
Merge pull request #1163 from transitland/ssp-interpolation-error-ski…
Browse files Browse the repository at this point in the history
…p-trip

SSP: Skip trip if interpolation issues
  • Loading branch information
irees committed Aug 11, 2017
2 parents a856068 + d5f9987 commit 762f174
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/models/schedule_stop_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ def self.interpolate(ssps, method=:linear)
def self.interpolate_linear(group)
window_start = GTFS::WideTime.parse(group.first.origin_departure_time)
window_end = GTFS::WideTime.parse(group.last.destination_arrival_time)
fail StandardError.new("First stop in trip must have a departure time") unless window_start
fail StandardError.new("Last stop in trip must have an arrival time") unless window_end
duration = window_end.to_seconds - window_start.to_seconds
step = duration / group.size.to_f
current = window_start.to_seconds
Expand Down
7 changes: 6 additions & 1 deletion app/services/gtfs_schedule_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,12 @@ def make_ssp_trip(gtfs_trip, gtfs_stop_times, gtfs_frequency: nil)
end

# Interpolate stop_times
ScheduleStopPair.interpolate(ssp_trip)
begin
ScheduleStopPair.interpolate(ssp_trip)
rescue StandardError => e
info("Trip #{gtfs_trip.trip_id}: Could not process arrival/departure times, skipping: #{e.message}")
return []
end

# Skip trip if validation errors
unless ssp_trip.map(&:valid?).all?
Expand Down

0 comments on commit 762f174

Please sign in to comment.