diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/chouette/journey_pattern.rb | 7 | ||||
| -rw-r--r-- | app/models/chouette/route.rb | 31 | ||||
| -rw-r--r-- | app/models/compliance_check_set.rb | 36 | ||||
| -rw-r--r-- | app/models/referential.rb | 4 | ||||
| -rw-r--r-- | app/models/route_section_search.rb | 33 | ||||
| -rw-r--r-- | app/models/route_sections_selector.rb | 101 |
6 files changed, 59 insertions, 153 deletions
diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb index fb30ab69e..5058c95dc 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -148,6 +148,7 @@ module Chouette vjas.destroy end end +<<<<<<< HEAD def control_route_sections stop_area_ids = self.stop_points.map(&:stop_area_id) @@ -183,4 +184,8 @@ module Chouette end end end -end
\ No newline at end of file +end +======= + end +end +>>>>>>> master diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 6794ba3e4..be86b5b04 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -76,20 +76,19 @@ module Chouette validates :wayback, inclusion: { in: self.wayback.values } - after_commit :journey_patterns_control_route_sections - - def duplicate - overrides = { - 'opposite_route_id' => nil - } - keys_for_create = attributes.keys - %w{id objectid created_at updated_at} - atts_for_create = attributes - .slice(*keys_for_create) - .merge(overrides) - new_route = self.class.create!(atts_for_create) - duplicate_stop_points(for_route: new_route) - new_route - end + def duplicate + overrides = { + 'opposite_route_id' => nil, + 'name' => I18n.t('activerecord.copy', name: self.name) + } + keys_for_create = attributes.keys - %w{id objectid created_at updated_at} + atts_for_create = attributes + .slice(*keys_for_create) + .merge(overrides) + new_route = self.class.create!(atts_for_create) + duplicate_stop_points(for_route: new_route) + new_route + end def duplicate_stop_points(for_route:) stop_points.each(&duplicate_stop_point(for_route: for_route)) @@ -192,9 +191,13 @@ module Chouette protected +<<<<<<< HEAD def self.vehicle_journeys_timeless(stop_point_id) all( :conditions => ['vehicle_journeys.id NOT IN (?)', Chouette::VehicleJourneyAtStop.where(stop_point_id: stop_point_id).pluck(:vehicle_journey_id)] ) end +======= + protected +>>>>>>> master end end
\ No newline at end of file diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 536afc705..80e499b74 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -18,4 +18,40 @@ class ComplianceCheckSet < ActiveRecord::Base where('created_at BETWEEN :begin AND :end', begin: period_range.begin, end: period_range.end) end + def update_status + statuses = compliance_check_resources.map do |resource| + case resource.status + when 'ERROR' + return update(status: 'failed') + when 'WARNING' + return update(status: 'warning') + else + resource.status + end + end + + if statuses_ok_or_ignored?(statuses) + return update(status: 'successful') + end + + true + end + + private + + def statuses_ok_or_ignored?(statuses) + uniform_statuses = statuses.uniq + + ( + # All statuses OK + uniform_statuses.length == 1 && + uniform_statuses.first == 'OK' + ) || + ( + # Statuses OK or IGNORED + uniform_statuses.length == 2 && + uniform_statuses.include?('OK') && + uniform_statuses.include?('IGNORED') + ) + end end diff --git a/app/models/referential.rb b/app/models/referential.rb index 8003d342f..fa6bcbcf1 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -126,10 +126,6 @@ class Referential < ActiveRecord::Base Chouette::VehicleJourneyFrequency.all end - def route_sections - Chouette::RouteSection.all - end - def routing_constraint_zones Chouette::RoutingConstraintZone.all end diff --git a/app/models/route_section_search.rb b/app/models/route_section_search.rb deleted file mode 100644 index bf53cdf05..000000000 --- a/app/models/route_section_search.rb +++ /dev/null @@ -1,33 +0,0 @@ -class RouteSectionSearch - include ActiveModel::Conversion - extend ActiveModel::Naming - - attr_accessor :departure_name, :arrival_name, :line_id - attr_accessor :scope - - def scope - scope ||= Chouette::RouteSection - end - - def initialize(attributes = {}) - attributes.each { |k,v| send "#{k}=", v } if attributes - end - - def collection - collection = scope - - [:departure, :arrival].each do |endpoint| - endpoint_name = send "#{endpoint}_name" - collection = collection.by_endpoint_name(endpoint, endpoint_name) if endpoint_name.present? - end - - collection = collection.by_line_id(line_id) if line_id.present? - - collection - end - - def persisted? - false - end - -end diff --git a/app/models/route_sections_selector.rb b/app/models/route_sections_selector.rb deleted file mode 100644 index 0db09ed25..000000000 --- a/app/models/route_sections_selector.rb +++ /dev/null @@ -1,101 +0,0 @@ -class RouteSectionsSelector - extend ActiveModel::Naming - include ActiveModel::Conversion - - include ActiveModel::Validations - - attr_reader :itinerary - - def initialize(journey_pattern, attributes = {}) - @itinerary = journey_pattern - - self.attributes = attributes - end - - def attributes=(attributes) - attributes.each { |k,v| send "#{k}=", v } - end - - def update_attributes(attributes) - self.attributes = attributes - save - end - - delegate :stop_points, to: :itinerary - - def sections - @sections ||= create_sections - end - - def create_sections - [].tap do |sections| - stop_points.each_cons(2).each_with_index do |(departure, arrival), index| - journey_pattern_section = Chouette::JourneyPatternSection.find_by(journey_pattern: @itinerary, rank: index) - - if journey_pattern_section - route_section = journey_pattern_section ? journey_pattern_section.route_section : nil - else - route_section = Chouette::RouteSection.find_by(departure: departure.stop_area, arrival: arrival.stop_area) - end - - sections << Section.new(departure.stop_area, arrival.stop_area, index, route_section) - end - end - end - - def sections_attributes=(attributes) - # Process the attributes hash - attributes.each do |index, section_attributes| - sections[index.to_i].attributes = section_attributes - end - end - - def save - sections.each do |s| - Chouette::JourneyPatternSection.update_by_journey_pattern_rank(itinerary.id, s.route_section_id, s.rank) - end - end - - class Section - extend ActiveModel::Translation - - attr_accessor :departure, :arrival, :rank, :route_section_id - - def initialize(departure, arrival, rank, route_section = nil) - @departure, @arrival, @rank = departure, arrival, rank - - self.route_section = route_section - end - - def route_section=(route_section) - @route_section = route_section - @route_section_id = route_section.respond_to?(:id) ? route_section.id : nil - end - - def route_section - @route_section ||= candidates.find_by id: route_section_id - end - - def persisted? - false - end - - def candidates - @candidates ||= Chouette::RouteSection.where(departure: departure, arrival: arrival) - end - - def create_candidate - Chouette::RouteSection.create(departure: departure, arrival: arrival) - end - - def attributes=(attributes) - attributes.each { |k,v| send "#{k}=", v } - end - - def valid? - route_section.present? - end - - end - -end |
