<commit_before>class SubRoute < ActiveRecord::Base
  has_many :route_sub_routes
  has_many :routes, :through => :route_sub_routes
  belongs_to :from_station, :class_name => 'StopArea'
  belongs_to :to_station, :class_name => 'StopArea'
  belongs_to :transport_mode
  has_many :campaigns, :as => :location, :order => 'created_at desc'
  has_many :problems, :as => :location, :order => 'created_at desc'
  
  attr_accessor :show_as_point
  is_route_or_sub_route
  
  def points
    [from_station, to_station]
  end
  
  def transport_modes
    [TransportMode.find_by_name('Train')]
  end
  
  def terminuses
    points
  end
  
  def operators_responsible?
    true
  end
  
  def pte_responsible? 
    false
  end
  
  def councils_responsible? 
    false
  end
  
  def operators
    route_operators = routes.map{ |route| route.operators }.flatten.uniq
    if route_operators.empty?
      mode = TransportMode.find_by_name('Train')
      route_operators = Operator.find(:all, :conditions => ['transport_mode_id = ?', mode.id], 
                                            :order => 'name asc')
    end
    route_operators
  end
  
  def responsible_organization_type
    :company
  end
  
  def responsible_organizations
    operators
  end
  
  def name
    name_by_terminuses(transport_mode)
  end
  
  def description
    name
  end
  
  def self.make_sub_route(from_station, to_station, transport_mode)
    exists = find(:first, :conditions => ['from_station_id = ? 
                                          AND to_station_id = ? 
                                          AND transport_mode_id = ?', 
                          from_station, to_station, transport_mode])
    return exists if exists
    created = create!({:from_station => from_station, 
                       :to_station => to_station, 
                       :transport_mode => transport_mode})
    return created
  end
end<commit_msg>Add method for making route_sub_routes for a sub_route.<commit_after>class SubRoute < ActiveRecord::Base
  has_many :route_sub_routes
  has_many :routes, :through => :route_sub_routes
  belongs_to :from_station, :class_name => 'StopArea'
  belongs_to :to_station, :class_name => 'StopArea'
  belongs_to :transport_mode
  has_many :campaigns, :as => :location, :order => 'created_at desc'
  has_many :problems, :as => :location, :order => 'created_at desc'
  
  attr_accessor :show_as_point
  is_route_or_sub_route
  
  def points
    [from_station, to_station]
  end
  
  def transport_modes
    [TransportMode.find_by_name('Train')]
  end
  
  def terminuses
    points
  end
  
  def operators_responsible?
    true
  end
  
  def pte_responsible? 
    false
  end
  
  def councils_responsible? 
    false
  end
  
  def operators
    route_operators = routes.map{ |route| route.operators }.flatten.uniq
    if route_operators.empty?
      mode = TransportMode.find_by_name('Train')
      route_operators = Operator.find(:all, :conditions => ['transport_mode_id = ?', mode.id], 
                                            :order => 'name asc')
    end
    route_operators
  end
  
  def responsible_organization_type
    :company
  end
  
  def responsible_organizations
    operators
  end
  
  def name
    name_by_terminuses(transport_mode)
  end
  
  def description
    name
  end
  
  def make_routes
    find_options = { :transport_modes => [TransportMode.find_by_name('Train').id],
                     :as_terminus => false }
    found_routes = Route.find_all_by_locations([from_station, to_station], find_options)  
    found_routes.each do |route|
      self.route_sub_routes.create!(:route => route)
    end
  end
  
  def self.make_sub_route(from_station, to_station, transport_mode)
    exists = find(:first, :conditions => ['from_station_id = ? 
                                          AND to_station_id = ? 
                                          AND transport_mode_id = ?', 
                          from_station, to_station, transport_mode])
    return exists if exists
    created = create!({:from_station => from_station, 
                       :to_station => to_station, 
                       :transport_mode => transport_mode})
    return created
  end
end
{'fraction_non_alphanumeric': 0.08142857142857143, 'fraction_numerical': 0.0, 'mean_word_length': 2.4547697368421053, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7212502', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1280, 'n_words': 282}