aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorZog2018-04-18 16:14:54 +0200
committercedricnjanga2018-04-19 23:12:34 -0700
commite6567cbfc987d8488492e2b1ce66a03db3a3d37d (patch)
treedbace69e87473783624c89e3351be153ba7f9bed /app/models
parent7c0ce4a2f39f6d7386734016452c594ee7ee8797 (diff)
downloadchouette-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')
-rw-r--r--app/models/chouette/journey_pattern.rb37
-rw-r--r--app/models/chouette/stop_point.rb4
2 files changed, 30 insertions, 11 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
diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb
index 1df1a664a..6f2d89578 100644
--- a/app/models/chouette/stop_point.rb
+++ b/app/models/chouette/stop_point.rb
@@ -9,7 +9,6 @@ module Chouette
include ForAlightingEnumerations
include ObjectidSupport
-
belongs_to :stop_area
belongs_to :route, inverse_of: :stop_points
has_many :vehicle_journey_at_stops, :dependent => :destroy
@@ -17,7 +16,6 @@ module Chouette
acts_as_list :scope => :route, top_of_list: 0
-
validates_presence_of :stop_area
validate :stop_area_id_validation
def stop_area_id_validation
@@ -28,7 +26,7 @@ module Chouette
scope :default_order, -> { order("position") }
- delegate :name, to: :stop_area
+ delegate :name, :kind, :area_type, to: :stop_area
before_destroy :remove_dependent_journey_pattern_stop_points
def remove_dependent_journey_pattern_stop_points