aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/chouette
diff options
context:
space:
mode:
authorZog2018-02-20 08:31:43 +0100
committerJohan Van Ryseghem2018-02-20 09:50:28 +0100
commiteb428adf7d5fedf947c00f30bf1f04462f2291e3 (patch)
tree16d041c335842623fe8fddaebfbd34263eebe3e7 /app/models/chouette
parent5fe1e8762051ef567191210ab65e6916cf12b932 (diff)
downloadchouette-core-eb428adf7d5fedf947c00f30bf1f04462f2291e3.tar.bz2
Refs #5924; Fix some bugs revealed during imports
- The checksum computing for VehicleJourneyAtStops - Offsets calculation in VehicleJourneys
Diffstat (limited to 'app/models/chouette')
-rw-r--r--app/models/chouette/vehicle_journey.rb2
-rw-r--r--app/models/chouette/vehicle_journey_at_stop.rb8
-rw-r--r--app/models/chouette/vehicle_journey_at_stops_day_offset.rb16
3 files changed, 16 insertions, 10 deletions
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 028cd18dd..1a79db823 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -105,7 +105,7 @@ module Chouette
attrs << self.try(:company).try(:get_objectid).try(:local_id)
attrs << self.footnotes.map(&:checksum).sort
vjas = self.vehicle_journey_at_stops
- vjas += VehicleJourneyAtStop.where(vehicle_journey_id: self.id)
+ vjas += VehicleJourneyAtStop.where(vehicle_journey_id: self.id) unless self.new_record?
attrs << vjas.uniq.sort_by { |s| s.stop_point&.position }.map(&:checksum).sort
end
end
diff --git a/app/models/chouette/vehicle_journey_at_stop.rb b/app/models/chouette/vehicle_journey_at_stop.rb
index eda711ade..3b4f35f13 100644
--- a/app/models/chouette/vehicle_journey_at_stop.rb
+++ b/app/models/chouette/vehicle_journey_at_stop.rb
@@ -41,7 +41,7 @@ module Chouette
:arrival_day_offset,
I18n.t(
'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max',
- short_id: vehicle_journey.get_objectid.short_id,
+ short_id: vehicle_journey&.get_objectid&.short_id,
max: DAY_OFFSET_MAX + 1
)
)
@@ -52,7 +52,7 @@ module Chouette
:departure_day_offset,
I18n.t(
'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max',
- short_id: vehicle_journey.get_objectid.short_id,
+ short_id: vehicle_journey&.get_objectid&.short_id,
max: DAY_OFFSET_MAX + 1
)
)
@@ -69,8 +69,8 @@ module Chouette
def checksum_attributes
[].tap do |attrs|
- attrs << self.departure_time.try(:to_s, :time)
- attrs << self.arrival_time.try(:to_s, :time)
+ attrs << self.departure_time&.utc.try(:to_s, :time)
+ attrs << self.arrival_time&.utc.try(:to_s, :time)
attrs << self.departure_day_offset.to_s
attrs << self.arrival_day_offset.to_s
end
diff --git a/app/models/chouette/vehicle_journey_at_stops_day_offset.rb b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb
index b2cb90d11..7497cd72c 100644
--- a/app/models/chouette/vehicle_journey_at_stops_day_offset.rb
+++ b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb
@@ -11,13 +11,19 @@ module Chouette
@at_stops.inject(nil) do |prior_stop, stop|
next stop if prior_stop.nil?
- if stop.arrival_time < prior_stop.departure_time ||
- stop.arrival_time < prior_stop.arrival_time
+ # we only compare time of the day, not actual times
+ stop_arrival_time = stop.arrival_time - stop.arrival_time.to_date.to_time
+ stop_departure_time = stop.departure_time - stop.departure_time.to_date.to_time
+ prior_stop_arrival_time = prior_stop.arrival_time - prior_stop.arrival_time.to_date.to_time
+ prior_stop_departure_time = prior_stop.departure_time - prior_stop.departure_time.to_date.to_time
+
+ if stop_arrival_time < prior_stop_departure_time ||
+ stop_arrival_time < prior_stop_arrival_time
arrival_offset += 1
end
- if stop.departure_time < stop.arrival_time ||
- stop.departure_time < prior_stop.departure_time
+ if stop_departure_time < stop_arrival_time ||
+ stop_departure_time < prior_stop_departure_time
departure_offset += 1
end
@@ -39,4 +45,4 @@ module Chouette
save
end
end
-end \ No newline at end of file
+end