diff options
| author | Zog | 2018-04-18 16:14:54 +0200 | 
|---|---|---|
| committer | cedricnjanga | 2018-04-19 23:12:34 -0700 | 
| commit | e6567cbfc987d8488492e2b1ce66a03db3a3d37d (patch) | |
| tree | dbace69e87473783624c89e3351be153ba7f9bed /app/models/chouette/journey_pattern.rb | |
| parent | 7c0ce4a2f39f6d7386734016452c594ee7ee8797 (diff) | |
| download | chouette-core-e6567cbfc987d8488492e2b1ce66a03db3a3d37d.tar.bz2 | |
Refs #6193; Show journey length in VJs editor
If `journey_length_in_vehicle_journeys` feature is enabled
Diffstat (limited to 'app/models/chouette/journey_pattern.rb')
| -rw-r--r-- | app/models/chouette/journey_pattern.rb | 37 | 
1 files changed, 29 insertions, 8 deletions
| diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb index 1e4041798..4b4cc2c73 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -86,10 +86,8 @@ module Chouette      def state_stop_points_update item        item['stop_points'].each do |sp| -        exist = stop_area_ids.include?(sp['id']) -        next if exist && sp['checked'] - -        stop_point = route.stop_points.find_by(stop_area_id: sp['id']) +        stop_point = route.stop_points.find_by(stop_area_id: sp['id'], position: sp['position']) +        exist = stop_points.include?(stop_point)          if !exist && sp['checked']            stop_points << stop_point          end @@ -175,11 +173,12 @@ module Chouette        full      end -    def distance_to stop +    def distance_between start, stop +      return 0 unless start.position < stop.position        val = 0 -      i = 0 -      _end = stop_points.first -      while _end != stop +      i = stop_points.index(start) +      _end = start +      while _end && _end != stop          i += 1          _start = _end          _end = stop_points[i] @@ -188,6 +187,28 @@ module Chouette        val      end +    def distance_to stop +      distance_between stop_points.first, stop +    end + +    def journey_length +      i = 0 +      j = stop_points.length - 1 +      start = stop_points[i] +      stop = stop_points[j] +      while i < j && start.kind == "non_commercial" +        i+= 1 +        start = stop_points[i] +      end + +      while i < j && stop.kind == "non_commercial" +        j-= 1 +        stop = stop_points[j] +      end +      return 0 unless start && stop +      distance_between start, stop +    end +      def set_distances distances        raise "inconsistent data: #{distances.count} values for #{stop_points.count} stops" unless distances.count == stop_points.count        prev = distances[0].to_i | 
