ninoxe 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +49 -0
- data/app/assets/javascripts/ninoxe/application.js +15 -0
- data/app/assets/stylesheets/ninoxe/application.css +13 -0
- data/app/controllers/ninoxe/application_controller.rb +4 -0
- data/app/helpers/ninoxe/application_helper.rb +4 -0
- data/app/models/chouette/access_link.rb +63 -0
- data/app/models/chouette/access_point.rb +145 -0
- data/app/models/chouette/access_point_type.rb +50 -0
- data/app/models/chouette/active_record.rb +66 -0
- data/app/models/chouette/area_type.rb +56 -0
- data/app/models/chouette/chouette_structure.dump +3417 -0
- data/app/models/chouette/command.rb +93 -0
- data/app/models/chouette/command_line_support.rb +35 -0
- data/app/models/chouette/company.rb +19 -0
- data/app/models/chouette/connection_link.rb +43 -0
- data/app/models/chouette/connection_link_type.rb +51 -0
- data/app/models/chouette/direction.rb +60 -0
- data/app/models/chouette/exporter.rb +32 -0
- data/app/models/chouette/file_validator.rb +47 -0
- data/app/models/chouette/group_of_line.rb +30 -0
- data/app/models/chouette/journey_pattern.rb +63 -0
- data/app/models/chouette/line.rb +65 -0
- data/app/models/chouette/link_orientation_type.rb +49 -0
- data/app/models/chouette/loader.rb +110 -0
- data/app/models/chouette/network.rb +33 -0
- data/app/models/chouette/object_id.rb +36 -0
- data/app/models/chouette/pt_link.rb +39 -0
- data/app/models/chouette/route.rb +158 -0
- data/app/models/chouette/stop_area.rb +273 -0
- data/app/models/chouette/stop_point.rb +33 -0
- data/app/models/chouette/time_table.rb +146 -0
- data/app/models/chouette/time_table_date.rb +14 -0
- data/app/models/chouette/time_table_period.rb +26 -0
- data/app/models/chouette/time_table_vehicle_journey.rb +5 -0
- data/app/models/chouette/transport_mode.rb +71 -0
- data/app/models/chouette/trident_active_record.rb +97 -0
- data/app/models/chouette/vehicle_journey.rb +101 -0
- data/app/models/chouette/vehicle_journey_at_stop.rb +45 -0
- data/app/models/chouette/wayback.rb +50 -0
- data/app/views/layouts/ninoxe/application.html.erb +14 -0
- data/config/database.yml +9 -0
- data/config/database.yml.ci +14 -0
- data/config/database.yml.travis +9 -0
- data/config/locales/en.yml +15 -0
- data/config/locales/fr.yml +16 -0
- data/config/routes.rb +2 -0
- data/db/migrate/20120213131553_create_chouette_line.rb +26 -0
- data/db/migrate/20120214101458_create_chouette_company.rb +25 -0
- data/db/migrate/20120214101645_create_chouette_ptnetwork.rb +24 -0
- data/db/migrate/20120406144221_create_chouette_stop_area.rb +33 -0
- data/db/migrate/20120411144209_create_time_table.rb +38 -0
- data/db/migrate/20120425064403_create_chouette_route.rb +22 -0
- data/db/migrate/20120425123944_create_chouette_stop_point.rb +17 -0
- data/db/migrate/20120426114527_create_chouette_connection_link.rb +28 -0
- data/db/migrate/20120521073709_create_chouette_journey_pattern.rb +26 -0
- data/db/migrate/20120521073723_create_chouette_journey_pattern_stop_point.rb +14 -0
- data/db/migrate/20120521073740_create_chouette_time_slot.rb +22 -0
- data/db/migrate/20120521073746_create_chouette_vehicle_journey.rb +34 -0
- data/db/migrate/20120521073758_create_chouette_vehicle_journey_at_stop.rb +25 -0
- data/db/migrate/20120521073900_create_chouette_time_table_vehicle_journey.rb +16 -0
- data/db/migrate/20120521132304_create_chouette_access_point.rb +34 -0
- data/db/migrate/20120521132313_create_chouette_access_link.rb +33 -0
- data/db/migrate/20120521132429_create_chouette_facility.rb +34 -0
- data/db/migrate/20120521132502_create_chouette_facility_feature.rb +12 -0
- data/db/migrate/20120521132551_create_chouette_group_of_line.rb +18 -0
- data/db/migrate/20120521132600_create_chouette_group_of_line_line.rb +12 -0
- data/db/migrate/20120521132656_create_chouette_routing_constrains_line.rb +12 -0
- data/db/migrate/20120521132724_create_chouette_stoparea_stoparea.rb +12 -0
- data/db/migrate/20120531091529_create_chouette_pt_link.rb +21 -0
- data/db/migrate/20120926141405_add_id_to_time_table_date.rb +12 -0
- data/db/migrate/20120926141415_add_id_to_time_table_period.rb +12 -0
- data/db/migrate/20121024072219_add_fields_to_access_points.rb +12 -0
- data/lib/chouette_factories.rb +1 -0
- data/lib/factories/chouette_access_links.rb +11 -0
- data/lib/factories/chouette_access_points.rb +8 -0
- data/lib/factories/chouette_companies.rb +5 -0
- data/lib/factories/chouette_connection_links.rb +11 -0
- data/lib/factories/chouette_group_of_lines.rb +4 -0
- data/lib/factories/chouette_journey_pattern.rb +32 -0
- data/lib/factories/chouette_lines.rb +20 -0
- data/lib/factories/chouette_networks.rb +5 -0
- data/lib/factories/chouette_routes.rb +18 -0
- data/lib/factories/chouette_stop_areas.rb +8 -0
- data/lib/factories/chouette_stop_points.rb +7 -0
- data/lib/factories/chouette_time_table.rb +21 -0
- data/lib/factories/chouette_vehicle_journey.rb +50 -0
- data/lib/factories/chouette_vehicle_journey_at_stop.rb +5 -0
- data/lib/ninoxe/engine.rb +15 -0
- data/lib/ninoxe/version.rb +3 -0
- data/lib/ninoxe.rb +7 -0
- metadata +251 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'tmpdir'
|
2
|
+
|
3
|
+
#if RUBY_PLATFORM == "java"
|
4
|
+
# FIXME disable remove_entry_secure because incompatible with jruby ?!
|
5
|
+
# See http://jira.codehaus.org/browse/JRUBY-4082
|
6
|
+
module FileUtils
|
7
|
+
def self.remove_entry_secure(*args)
|
8
|
+
self.remove_entry *args
|
9
|
+
end
|
10
|
+
end
|
11
|
+
#end
|
12
|
+
|
13
|
+
class Chouette::Command
|
14
|
+
|
15
|
+
include Chouette::CommandLineSupport
|
16
|
+
|
17
|
+
@@command = "chouette"
|
18
|
+
cattr_accessor :command
|
19
|
+
|
20
|
+
attr_accessor :database, :schema, :host, :user, :password
|
21
|
+
|
22
|
+
def initialize(options = {})
|
23
|
+
database_options_from_active_record.merge(options).each do |k,v|
|
24
|
+
send "#{k}=", v
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def database_options_from_active_record
|
29
|
+
config = Chouette::ActiveRecord.connection_pool.spec.config
|
30
|
+
{
|
31
|
+
:database => config[:database],
|
32
|
+
:user => config[:username],
|
33
|
+
:password => config[:password],
|
34
|
+
:host => (config[:host] or "localhost")
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def run!(options = {})
|
40
|
+
Dir.mktmpdir do |config_dir|
|
41
|
+
chouette_properties = File.join(config_dir, "chouette.properties")
|
42
|
+
open(chouette_properties, "w") do |f|
|
43
|
+
f.puts "database.name = #{database}"
|
44
|
+
f.puts "database.schema = #{schema}"
|
45
|
+
#f.puts "database.showsql = true"
|
46
|
+
f.puts "hibernate.username = #{user}"
|
47
|
+
f.puts "hibernate.password = #{password}"
|
48
|
+
f.puts "jdbc.url=jdbc:postgresql://#{host}:5432/#{database}"
|
49
|
+
f.puts "jdbc.username = #{user}"
|
50
|
+
f.puts "jdbc.password = #{password}"
|
51
|
+
f.puts "database.hbm2ddl.auto=update"
|
52
|
+
end
|
53
|
+
|
54
|
+
logger.debug "Chouette properties: #{File.readlines(chouette_properties).collect(&:strip).join(', ')}"
|
55
|
+
|
56
|
+
command_line = "#{command} -classpath #{config_dir} #{command_options(options)}"
|
57
|
+
logger.debug "Execute '#{command_line}'"
|
58
|
+
|
59
|
+
execute! command_line
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class Option
|
64
|
+
|
65
|
+
attr_accessor :key, :value
|
66
|
+
|
67
|
+
def initialize(key, value)
|
68
|
+
@key, @value = key.to_s, value
|
69
|
+
end
|
70
|
+
|
71
|
+
def command_key
|
72
|
+
key.camelize(:lower)
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_s
|
76
|
+
unless value == true
|
77
|
+
"-#{command_key} #{value}"
|
78
|
+
else
|
79
|
+
"-#{command_key}"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def command_options(options)
|
86
|
+
options.collect do |key, value|
|
87
|
+
Option.new(key, value)
|
88
|
+
end.sort_by(&:key).join(' ')
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Chouette::CommandLineSupport
|
2
|
+
|
3
|
+
class ExecutionError < StandardError; end
|
4
|
+
|
5
|
+
def available_loggers
|
6
|
+
[].tap do |logger|
|
7
|
+
logger << Chouette::ActiveRecord.logger
|
8
|
+
logger << Rails.logger if defined?(Rails)
|
9
|
+
logger << Logger.new($stdout)
|
10
|
+
end.compact
|
11
|
+
end
|
12
|
+
|
13
|
+
def logger
|
14
|
+
@logger ||= available_loggers.first
|
15
|
+
end
|
16
|
+
|
17
|
+
def max_output_length
|
18
|
+
2000
|
19
|
+
end
|
20
|
+
|
21
|
+
def execute!(command)
|
22
|
+
logger.debug "execute '#{command}'"
|
23
|
+
|
24
|
+
output = `#{command} 2>&1`
|
25
|
+
output = "[...] #{output[-max_output_length,max_output_length]}" if output.length > max_output_length
|
26
|
+
logger.info output unless output.empty?
|
27
|
+
|
28
|
+
if $? != 0
|
29
|
+
raise ExecutionError.new("Command failed: #{command} (error code #{$?})")
|
30
|
+
end
|
31
|
+
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Chouette::Company < Chouette::TridentActiveRecord
|
2
|
+
has_many :lines
|
3
|
+
|
4
|
+
validates_presence_of :registration_number
|
5
|
+
validates_uniqueness_of :registration_number
|
6
|
+
validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}
|
7
|
+
|
8
|
+
validates_presence_of :name
|
9
|
+
|
10
|
+
attr_accessible :objectid, :object_version, :creation_time, :creator_id, :name, :short_name
|
11
|
+
attr_accessible :organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :registration_number
|
12
|
+
|
13
|
+
def self.nullable_attributes
|
14
|
+
[:organizational_unit, :operating_department_name, :code, :phone, :fax, :email]
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
19
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Chouette::ConnectionLink < Chouette::TridentActiveRecord
|
2
|
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
|
3
|
+
set_primary_key :id
|
4
|
+
|
5
|
+
attr_accessor :connection_link_type
|
6
|
+
|
7
|
+
attr_accessible :connection_link_type,:departure_id, :arrival_id, :objectid, :object_version, :creation_time, :creator_id, :name, :comment
|
8
|
+
attr_accessible :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration
|
9
|
+
attr_accessible :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs
|
10
|
+
|
11
|
+
belongs_to :departure, :class_name => 'Chouette::StopArea'
|
12
|
+
belongs_to :arrival, :class_name => 'Chouette::StopArea'
|
13
|
+
|
14
|
+
validates_presence_of :name
|
15
|
+
validates_presence_of :link_type
|
16
|
+
|
17
|
+
def connection_link_type
|
18
|
+
link_type && Chouette::ConnectionLinkType.new( link_type.underscore)
|
19
|
+
end
|
20
|
+
|
21
|
+
def connection_link_type=(connection_link_type)
|
22
|
+
self.link_type = (connection_link_type ? connection_link_type.camelcase : nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
@@connection_link_types = nil
|
26
|
+
def self.connection_link_types
|
27
|
+
@@connection_link_types ||= Chouette::ConnectionLinkType.all
|
28
|
+
end
|
29
|
+
|
30
|
+
def possible_areas
|
31
|
+
Chouette::StopArea.where("area_type != 'ITL'")
|
32
|
+
end
|
33
|
+
|
34
|
+
def stop_areas
|
35
|
+
Chouette::StopArea.where(:id => [self.departure_id,self.arrival_id])
|
36
|
+
end
|
37
|
+
|
38
|
+
def geometry
|
39
|
+
GeoRuby::SimpleFeatures::LineString.from_points( [ departure.geometry, arrival.geometry], 4326) if departure.geometry and arrival.geometry
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class Chouette::ConnectionLinkType < ActiveSupport::StringInquirer
|
2
|
+
|
3
|
+
def initialize(text_code, numerical_code)
|
4
|
+
super text_code.to_s
|
5
|
+
@numerical_code = numerical_code
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.new(text_code, numerical_code = nil)
|
9
|
+
if text_code and numerical_code
|
10
|
+
super
|
11
|
+
elsif self === text_code
|
12
|
+
text_code
|
13
|
+
else
|
14
|
+
if Fixnum === text_code
|
15
|
+
text_code, numerical_code = definitions.rassoc(text_code)
|
16
|
+
else
|
17
|
+
text_code, numerical_code = definitions.assoc(text_code.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
super text_code, numerical_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_i
|
25
|
+
@numerical_code
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
"#{to_s}/#{to_i}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
camelize
|
34
|
+
end
|
35
|
+
|
36
|
+
@@definitions = [
|
37
|
+
["underground", 0],
|
38
|
+
["mixed", 1],
|
39
|
+
["overground", 2]
|
40
|
+
]
|
41
|
+
cattr_reader :definitions
|
42
|
+
|
43
|
+
@@all = nil
|
44
|
+
def self.all
|
45
|
+
@@all ||= definitions.collect do |text_code, numerical_code|
|
46
|
+
new(text_code, numerical_code)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class Chouette::Direction < ActiveSupport::StringInquirer
|
2
|
+
|
3
|
+
def initialize(text_code, numerical_code)
|
4
|
+
super text_code.to_s
|
5
|
+
@numerical_code = numerical_code
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.new(text_code, numerical_code = nil)
|
9
|
+
if text_code and numerical_code
|
10
|
+
super
|
11
|
+
elsif self === text_code
|
12
|
+
text_code
|
13
|
+
else
|
14
|
+
if Fixnum === text_code
|
15
|
+
text_code, numerical_code = definitions.rassoc(text_code)
|
16
|
+
else
|
17
|
+
text_code, numerical_code = definitions.assoc(text_code.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
super text_code, numerical_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_i
|
25
|
+
@numerical_code
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
"#{to_s}/#{to_i}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
@@definitions = [
|
37
|
+
["straight_forward", 0],
|
38
|
+
["backward", 1],
|
39
|
+
["clock_wise", 2],
|
40
|
+
["counter_clock_wise", 3],
|
41
|
+
["north", 4],
|
42
|
+
["north_west", 5],
|
43
|
+
["west", 6],
|
44
|
+
["south_west", 7],
|
45
|
+
["south", 8],
|
46
|
+
["south_east", 9],
|
47
|
+
["east", 10],
|
48
|
+
["north_east", 11]
|
49
|
+
]
|
50
|
+
cattr_reader :definitions
|
51
|
+
|
52
|
+
@@all = nil
|
53
|
+
def self.all
|
54
|
+
@@all ||= definitions.collect do |text_code, numerical_code|
|
55
|
+
new(text_code, numerical_code)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Chouette::Exporter
|
2
|
+
|
3
|
+
attr_reader :schema
|
4
|
+
|
5
|
+
def initialize(schema)
|
6
|
+
@schema = schema
|
7
|
+
end
|
8
|
+
|
9
|
+
def chouette_command
|
10
|
+
@chouette_command ||= Chouette::Command.new(:schema => schema)
|
11
|
+
end
|
12
|
+
|
13
|
+
def export(file, options = {})
|
14
|
+
options = {
|
15
|
+
:format => :neptune
|
16
|
+
}.merge(options)
|
17
|
+
|
18
|
+
command_options = {
|
19
|
+
:c => "export",
|
20
|
+
:o => "line",
|
21
|
+
:format => options.delete(:format).to_s.upcase,
|
22
|
+
:output_file => File.expand_path(file),
|
23
|
+
:optimize_memory => true
|
24
|
+
}.merge(options)
|
25
|
+
|
26
|
+
logger.info "Export #{file} in schema #{schema}"
|
27
|
+
chouette_command.run! command_options
|
28
|
+
end
|
29
|
+
|
30
|
+
include Chouette::CommandLineSupport
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Chouette::FileValidator
|
2
|
+
|
3
|
+
attr_reader :schema, :database, :user, :password, :host
|
4
|
+
|
5
|
+
def initialize(schema)
|
6
|
+
@schema = schema
|
7
|
+
|
8
|
+
Chouette::ActiveRecord.connection_pool.spec.config.tap do |config|
|
9
|
+
@database = config[:database]
|
10
|
+
@user = config[:username]
|
11
|
+
@password = config[:password]
|
12
|
+
@host = (config[:host] or "localhost")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.chouette_command=(command)
|
17
|
+
Chouette::Command.command = command
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
deprecate :chouette_command= => "Use Chouette::Command.command ="
|
22
|
+
end
|
23
|
+
|
24
|
+
def chouette_command
|
25
|
+
@chouette_command ||= Chouette::Command.new(:schema => schema)
|
26
|
+
end
|
27
|
+
|
28
|
+
def validate(file, options = {})
|
29
|
+
options = {
|
30
|
+
:format => :neptune
|
31
|
+
}.merge(options)
|
32
|
+
|
33
|
+
command_options = {
|
34
|
+
:c => "validate",
|
35
|
+
:o => "line",
|
36
|
+
:input_file => File.expand_path(file),
|
37
|
+
:optimize_memory => true
|
38
|
+
}.merge(options)
|
39
|
+
|
40
|
+
logger.info "Validate #{file}"
|
41
|
+
chouette_command.run! command_options
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
include Chouette::CommandLineSupport
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
class Chouette::GroupOfLine < Chouette::TridentActiveRecord
|
2
|
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
|
3
|
+
set_primary_key :id
|
4
|
+
|
5
|
+
has_and_belongs_to_many :lines, :class_name => 'Chouette::Line', :order => 'lines.name'
|
6
|
+
|
7
|
+
validates_presence_of :name
|
8
|
+
|
9
|
+
attr_accessible :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :lines
|
10
|
+
attr_accessible :line_tokens
|
11
|
+
attr_reader :line_tokens
|
12
|
+
|
13
|
+
def self.nullable_attributes
|
14
|
+
[:comment]
|
15
|
+
end
|
16
|
+
|
17
|
+
def commercial_stop_areas
|
18
|
+
Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :group_of_lines] ] ]).where(:group_of_lines => {:id => self.id}).uniq
|
19
|
+
end
|
20
|
+
|
21
|
+
def stop_areas
|
22
|
+
Chouette::StopArea.joins(:stop_points => [:route => [:line => :group_of_lines] ]).where(:group_of_lines => {:id => self.id})
|
23
|
+
end
|
24
|
+
|
25
|
+
def line_tokens=(ids)
|
26
|
+
self.line_ids = ids.split(",")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class Chouette::JourneyPattern < Chouette::TridentActiveRecord
|
2
|
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
|
3
|
+
set_primary_key :id
|
4
|
+
|
5
|
+
belongs_to :route
|
6
|
+
has_many :vehicle_journeys, :dependent => :destroy
|
7
|
+
has_many :vehicle_journey_at_stops, :through => :vehicle_journeys
|
8
|
+
has_and_belongs_to_many :stop_points, :class_name => 'Chouette::StopPoint', :order => 'stop_points.position', :before_add => :vjas_add, :before_remove => :vjas_remove, :after_add => :shortcuts_update_for_add, :after_remove => :shortcuts_update_for_remove
|
9
|
+
|
10
|
+
attr_accessible :route_id, :objectid, :object_version, :creation_time, :creator_id, :name, :comment, :registration_number, :published_name, :departure_stop_point_id, :arrival_stop_point_id, :stop_point_ids, :stop_points
|
11
|
+
|
12
|
+
# TODO: this a workarround
|
13
|
+
# otherwise, we loose the first stop_point
|
14
|
+
# when creating a new journey_pattern
|
15
|
+
def special_update
|
16
|
+
bck_sp = self.stop_points.map {|s| s}
|
17
|
+
self.update_attributes :stop_points => []
|
18
|
+
self.update_attributes :stop_points => bck_sp
|
19
|
+
end
|
20
|
+
|
21
|
+
def departure_stop_point
|
22
|
+
return unless departure_stop_point_id
|
23
|
+
Chouette::StopPoint.find( departure_stop_point_id)
|
24
|
+
end
|
25
|
+
def arrival_stop_point
|
26
|
+
return unless arrival_stop_point_id
|
27
|
+
Chouette::StopPoint.find( arrival_stop_point_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
def shortcuts_update_for_add( stop_point)
|
31
|
+
stop_points << stop_point unless stop_points.include?( stop_point)
|
32
|
+
|
33
|
+
ordered_stop_points = stop_points
|
34
|
+
ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty?
|
35
|
+
|
36
|
+
self.update_attributes!( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id),
|
37
|
+
:arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id))
|
38
|
+
end
|
39
|
+
def shortcuts_update_for_remove( stop_point)
|
40
|
+
stop_points.delete( stop_point) if stop_points.include?( stop_point)
|
41
|
+
|
42
|
+
ordered_stop_points = stop_points
|
43
|
+
ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty?
|
44
|
+
|
45
|
+
self.update_attributes!( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id),
|
46
|
+
:arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id))
|
47
|
+
end
|
48
|
+
def vjas_add( stop_point)
|
49
|
+
return if new_record?
|
50
|
+
|
51
|
+
vehicle_journeys.each do |vj|
|
52
|
+
vjas = vj.vehicle_journey_at_stops.create :stop_point_id => stop_point.id
|
53
|
+
end
|
54
|
+
end
|
55
|
+
def vjas_remove( stop_point)
|
56
|
+
return if new_record?
|
57
|
+
|
58
|
+
vehicle_journey_at_stops.where( :stop_point_id => stop_point.id).each do |vjas|
|
59
|
+
vjas.destroy
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Chouette::Line < Chouette::TridentActiveRecord
|
2
|
+
# FIXME http://jira.codehaus.org/browse/JRUBY-6358
|
3
|
+
set_primary_key :id
|
4
|
+
|
5
|
+
attr_accessor :transport_mode
|
6
|
+
attr_accessible :transport_mode, :network_id, :company_id, :objectid, :object_version
|
7
|
+
attr_accessible :creation_time, :creator_id, :name, :number, :published_name, :transport_mode_name
|
8
|
+
attr_accessible :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs
|
9
|
+
|
10
|
+
belongs_to :company
|
11
|
+
belongs_to :network
|
12
|
+
has_many :routes, :dependent => :destroy
|
13
|
+
has_many :journey_patterns, :through => :routes
|
14
|
+
|
15
|
+
has_and_belongs_to_many :group_of_lines, :class_name => 'Chouette::GroupOfLine', :order => 'group_of_lines.name'
|
16
|
+
attr_accessible :group_of_lines, :group_of_line_ids, :group_of_line_tokens
|
17
|
+
attr_reader :group_of_line_tokens
|
18
|
+
|
19
|
+
validates_presence_of :network
|
20
|
+
validates_presence_of :company
|
21
|
+
|
22
|
+
validates_presence_of :registration_number
|
23
|
+
validates_uniqueness_of :registration_number
|
24
|
+
validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}
|
25
|
+
|
26
|
+
validates_presence_of :name
|
27
|
+
|
28
|
+
def self.nullable_attributes
|
29
|
+
[:published_name, :number, :comment]
|
30
|
+
end
|
31
|
+
|
32
|
+
def transport_mode
|
33
|
+
# return nil if transport_mode_name is nil
|
34
|
+
transport_mode_name && Chouette::TransportMode.new( transport_mode_name.underscore)
|
35
|
+
end
|
36
|
+
|
37
|
+
def transport_mode=(transport_mode)
|
38
|
+
self.transport_mode_name = (transport_mode ? transport_mode.camelcase : nil)
|
39
|
+
end
|
40
|
+
|
41
|
+
@@transport_modes = nil
|
42
|
+
def self.transport_modes
|
43
|
+
@@transport_modes ||= Chouette::TransportMode.all.select do |transport_mode|
|
44
|
+
transport_mode.to_i > 0
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def commercial_stop_areas
|
49
|
+
Chouette::StopArea.joins(:children => [:stop_points => [:route => :line] ]).where(:lines => {:id => self.id}).uniq
|
50
|
+
end
|
51
|
+
|
52
|
+
def stop_areas
|
53
|
+
Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id})
|
54
|
+
end
|
55
|
+
|
56
|
+
def stop_areas_last_parents
|
57
|
+
Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id}).collect(&:root).flatten.uniq
|
58
|
+
end
|
59
|
+
|
60
|
+
def group_of_line_tokens=(ids)
|
61
|
+
self.group_of_line_ids = ids.split(",")
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class Chouette::LinkOrientationType < ActiveSupport::StringInquirer
|
2
|
+
|
3
|
+
def initialize(text_code, numerical_code)
|
4
|
+
super text_code.to_s
|
5
|
+
@numerical_code = numerical_code
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.new(text_code, numerical_code = nil)
|
9
|
+
if text_code and numerical_code
|
10
|
+
super
|
11
|
+
elsif self === text_code
|
12
|
+
text_code
|
13
|
+
else
|
14
|
+
if Fixnum === text_code
|
15
|
+
text_code, numerical_code = definitions.rassoc(text_code)
|
16
|
+
else
|
17
|
+
text_code, numerical_code = definitions.assoc(text_code.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
super text_code, numerical_code
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_i
|
25
|
+
@numerical_code
|
26
|
+
end
|
27
|
+
|
28
|
+
def inspect
|
29
|
+
"#{to_s}/#{to_i}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
camelize
|
34
|
+
end
|
35
|
+
|
36
|
+
@@definitions = [
|
37
|
+
["access_point_to_stop_area", 0],
|
38
|
+
["stop_area_to_access_point", 1]
|
39
|
+
]
|
40
|
+
cattr_reader :definitions
|
41
|
+
|
42
|
+
@@all = nil
|
43
|
+
def self.all
|
44
|
+
@@all ||= definitions.collect do |text_code, numerical_code|
|
45
|
+
new(text_code, numerical_code)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|