earth 0.2.6 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- earth (0.2.5)
4
+ earth (0.2.6)
5
5
  activerecord (>= 3.0.0.beta4)
6
6
  cohort_scope (>= 0.0.7)
7
7
  conversions (>= 1.4.5)
8
- data_miner (~> 0.5.5)
8
+ data_miner (~> 0.5.6)
9
9
  falls_back_on (>= 0.0.3)
10
10
  geokit (>= 1.5.0)
11
11
  loose_tight_dictionary (>= 0.0.8)
@@ -33,12 +33,12 @@ GEM
33
33
  activesupport (~> 3.0.0)
34
34
  blockenspiel (0.3.2)
35
35
  builder (2.1.2)
36
- cohort_scope (0.1.0)
36
+ cohort_scope (0.1.1)
37
37
  activerecord (>= 3.0.0.beta4)
38
38
  activesupport (>= 3.0.0.beta4)
39
39
  conversions (1.4.5)
40
40
  activesupport (>= 2.3.4)
41
- data_miner (0.5.5)
41
+ data_miner (0.5.6)
42
42
  activerecord (>= 2.3.4)
43
43
  activesupport (>= 2.3.4)
44
44
  andand (>= 1.3.1)
@@ -63,14 +63,14 @@ GEM
63
63
  rake (>= 0.8.7)
64
64
  rubyforge (>= 2.0.4)
65
65
  hpricot (0.8.2)
66
- i18n (0.4.1)
66
+ i18n (0.4.2)
67
67
  jeweler (1.4.0)
68
68
  gemcutter (>= 0.1.0)
69
69
  git (>= 1.2.5)
70
70
  rubyforge (>= 2.0.0)
71
71
  json_pure (1.4.6)
72
72
  libxml-ruby (1.1.4)
73
- log4r (1.1.8)
73
+ log4r (1.1.9)
74
74
  loose_tight_dictionary (0.0.9)
75
75
  activesupport (>= 2.3.4)
76
76
  amatch (>= 0.2.5)
@@ -105,7 +105,7 @@ GEM
105
105
  rspec-mocks (2.0.1)
106
106
  rspec-core (~> 2.0.1)
107
107
  rspec-expectations (~> 2.0.1)
108
- ruby-ole (1.2.11)
108
+ ruby-ole (1.2.11.1)
109
109
  rubyforge (2.0.4)
110
110
  json_pure (>= 1.1.7)
111
111
  rubyzip (0.9.4)
@@ -115,7 +115,7 @@ GEM
115
115
  slither (0.99.4)
116
116
  spreadsheet (0.6.4.1)
117
117
  ruby-ole
118
- sqlite3-ruby (1.3.1)
118
+ sqlite3-ruby (1.3.2)
119
119
  taps (0.3.13)
120
120
  json_pure (>= 1.2.0, < 1.5.0)
121
121
  rack (>= 1.0.1)
@@ -135,7 +135,7 @@ DEPENDENCIES
135
135
  activerecord (>= 3.0.0.beta4)
136
136
  cohort_scope (>= 0.0.7)
137
137
  conversions (>= 1.4.5)
138
- data_miner (~> 0.5.5)
138
+ data_miner (~> 0.5.6)
139
139
  earth!
140
140
  falls_back_on (>= 0.0.3)
141
141
  geokit (>= 1.5.0)
@@ -1,16 +1,16 @@
1
1
  class Aircraft < ActiveRecord::Base
2
- set_primary_key :icao_code
2
+ set_primary_key :bp_code
3
+
4
+ belongs_to :aircraft_class, :foreign_key => 'class_code', :primary_key => 'code'
5
+ has_many :segments, :foreign_key => 'aircraft_bts_code', :primary_key => 'bts_code', :class_name => 'FlightSegment'
6
+ # belongs_to :manufacturer, :foreign_key => 'icao_manufacturer_name', :primary_key => 'name', :class_name => 'AircraftManufacturer'
7
+
8
+ falls_back_on :m3 => lambda { weighted_average(:m3, :weighted_by => [:segments, :passengers]) }, # 9.73423082858437e-08 r7110: 8.6540464368905e-8 r6972: 8.37e-8
9
+ :m2 => lambda { weighted_average(:m2, :weighted_by => [:segments, :passengers]) }, # -0.000134350543484608 r7110: -0.00015337661447817 r6972: -4.09e-5
10
+ :m1 => lambda { weighted_average(:m1, :weighted_by => [:segments, :passengers]) }, # 6.7728101555467 r7110: 4.7781966869412 r6972: 7.85
11
+ :endpoint_fuel => lambda { weighted_average(:endpoint_fuel, :weighted_by => [:segments, :passengers]) }, # 1527.81790006167 r7110: 1065.3476555284 r6972: 1.72e3
12
+ :seats => lambda { weighted_average(:seats, :weighted_by => [:segments, :passengers]) } # 62.1741
3
13
 
4
- belongs_to :aircraft_class, :foreign_key => 'brighter_planet_aircraft_class_code'
5
- belongs_to :manufacturer, :foreign_key => 'manufacturer_name', :class_name => 'AircraftManufacturer'
6
- has_many :segments, :foreign_key => 'bts_aircraft_type_code', :class_name => "FlightSegment", :primary_key => 'bts_aircraft_type_code'
7
-
8
- falls_back_on :m3 => lambda { weighted_average(:m3, :weighted_by => [:segments, :passengers]) }, # 9.73423082858437e-08 r7110: 8.6540464368905e-8 r6972: 8.37e-8
9
- :m2 => lambda { weighted_average(:m2, :weighted_by => [:segments, :passengers]) }, # -0.000134350543484608 r7110: -0.00015337661447817 r6972: -4.09e-5
10
- :m1 => lambda { weighted_average(:m1, :weighted_by => [:segments, :passengers]) }, # 6.7728101555467 r7110: 4.7781966869412 r6972: 7.85
11
- :endpoint_fuel => lambda { weighted_average(:endpoint_fuel, :weighted_by => [:segments, :passengers]) }, # 1527.81790006167 r7110: 1065.3476555284 r6972: 1.72e3
12
- :seats => lambda { weighted_average(:seats, :weighted_by => [:segments, :passengers]) } # 62.1741
13
-
14
14
  data_miner do
15
15
  tap "Brighter Planet's sanitized aircraft data", Earth.taps_server
16
16
 
@@ -1,79 +1,73 @@
1
1
  Aircraft.class_eval do
2
+ # def self.bts_name_dictionary
3
+ # @_bts_dictionary ||= LooseTightDictionary.new RemoteTable.new(:url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_TYPE', :select => lambda { |record| record['Code'].to_i.between?(1, 998) }),
4
+ # :tightenings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=0&output=csv', :headers => false),
5
+ # :identities => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=3&output=csv', :headers => false),
6
+ # :blockings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=4&output=csv', :headers => false),
7
+ # :blocking_only => true,
8
+ # :right_reader => lambda { |record| record['Description'] }
9
+ # end
10
+ #
11
+ # # warning: self-referential, assumes it will be used once first import step is done
12
+ # def self.icao_name_dictionary
13
+ # @_icao_dictionary ||= LooseTightDictionary.new Aircraft.all,
14
+ # :tightenings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=0&output=csv', :headers => false),
15
+ # :identities => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=3&output=csv', :headers => false),
16
+ # :blockings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=4&output=csv', :headers => false),
17
+ # :right_reader => lambda { |record| record.manufacturer_name.to_s + ' ' + record.name.to_s }
18
+ # end
19
+ #
20
+ # class Aircraft::BtsMatcher
21
+ # attr_reader :wants
22
+ # def initialize(wants)
23
+ # @wants = wants
24
+ # end
25
+ # def match(raw_faa_icao_record)
26
+ # @_match ||= Hash.new
27
+ # return @_match[raw_faa_icao_record] if @_match.has_key?(raw_faa_icao_record)
28
+ # faa_icao_record = [ raw_faa_icao_record['Manufacturer'] + ' ' + raw_faa_icao_record['Model'] ]
29
+ # bts_record = Aircraft.bts_name_dictionary.left_to_right faa_icao_record
30
+ # retval = case wants
31
+ # when :bts_aircraft_type_code
32
+ # bts_record['Code']
33
+ # when :bts_name
34
+ # bts_record['Description']
35
+ # end if bts_record
36
+ # @_match[raw_faa_icao_record] = retval
37
+ # end
38
+ # end
39
+ #
40
+ # class Aircraft::FuelUseMatcher
41
+ # def match(raw_fuel_use_record)
42
+ # @_match ||= Hash.new
43
+ # return @_match[raw_fuel_use_record] if @_match.has_key?(raw_fuel_use_record)
44
+ #
45
+ # aircraft_record = if raw_fuel_use_record['ICAO'] =~ /\A[0-9A-Z]+\z/
46
+ # Aircraft.find_by_icao_code raw_fuel_use_record['ICAO']
47
+ # end
48
+ #
49
+ # aircraft_record ||= if raw_fuel_use_record['Aircraft Name'].present?
50
+ # Aircraft.icao_name_dictionary.left_to_right [ raw_fuel_use_record['Aircraft Name'] ]
51
+ # end
52
+ #
53
+ # if aircraft_record
54
+ # @_match[raw_fuel_use_record] = aircraft_record.icao_code
55
+ # else
56
+ # raise "Didn't find a match for #{raw_fuel_use_record['Aircraft Name']} (#{raw_fuel_use_record['ICAO']}), which we found in the fuel use spreadsheet"
57
+ # end
58
+ # end
59
+ # end
2
60
 
3
- # TODO use http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_TYPE
4
- def self.bts_name_dictionary
5
- @_bts_dictionary ||= LooseTightDictionary.new RemoteTable.new(:url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_TYPE', :select => lambda { |record| record['Code'].to_i.between?(1, 998) }),
6
- :tightenings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=0&output=csv', :headers => false),
7
- :identities => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=3&output=csv', :headers => false),
8
- :blockings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=4&output=csv', :headers => false),
9
- :blocking_only => true,
10
- :right_reader => lambda { |record| record['Description'] }
11
- end
12
-
13
- # warning: self-referential, assumes it will be used once first import step is done
14
- def self.icao_name_dictionary
15
- @_icao_dictionary ||= LooseTightDictionary.new Aircraft.all,
16
- :tightenings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=0&output=csv', :headers => false),
17
- :identities => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=3&output=csv', :headers => false),
18
- :blockings => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=tiS_6CCDDM_drNphpYwE_iw&single=true&gid=4&output=csv', :headers => false),
19
- :right_reader => lambda { |record| record.manufacturer_name.to_s + ' ' + record.name.to_s }
20
- end
21
-
22
- class Aircraft::BtsMatcher
23
- attr_reader :wants
24
- def initialize(wants)
25
- @wants = wants
26
- end
27
- def match(raw_faa_icao_record)
28
- @_match ||= Hash.new
29
- return @_match[raw_faa_icao_record] if @_match.has_key?(raw_faa_icao_record)
30
- faa_icao_record = [ raw_faa_icao_record['Manufacturer'] + ' ' + raw_faa_icao_record['Model'] ]
31
- bts_record = Aircraft.bts_name_dictionary.left_to_right faa_icao_record
32
- retval = case wants
33
- when :bts_aircraft_type_code
34
- bts_record['Code']
35
- when :bts_name
36
- bts_record['Description']
37
- end if bts_record
38
- @_match[raw_faa_icao_record] = retval
39
- end
40
- end
41
-
42
- class Aircraft::FuelUseMatcher
43
- def match(raw_fuel_use_record)
44
- @_match ||= Hash.new
45
- return @_match[raw_fuel_use_record] if @_match.has_key?(raw_fuel_use_record)
46
-
47
- aircraft_record = if raw_fuel_use_record['ICAO'] =~ /\A[0-9A-Z]+\z/
48
- Aircraft.find_by_icao_code raw_fuel_use_record['ICAO']
49
- end
50
-
51
- aircraft_record ||= if raw_fuel_use_record['Aircraft Name'].present?
52
- Aircraft.icao_name_dictionary.left_to_right [ raw_fuel_use_record['Aircraft Name'] ]
53
- end
54
-
55
- if aircraft_record
56
- @_match[raw_fuel_use_record] = aircraft_record.icao_code
57
- else
58
- raise "Didn't find a match for #{raw_fuel_use_record['Aircraft Name']} (#{raw_fuel_use_record['ICAO']}), which we found in the fuel use spreadsheet"
59
- end
60
- end
61
- end
62
-
61
+ # for errata
63
62
  class Aircraft::Guru
64
- # for errata
65
63
  def is_a_dc_plane?(row)
66
64
  row['Designator'] =~ /^DC\d/i
67
65
  end
68
66
 
69
- # def is_a_crj_900?(row)
70
- # row['Designator'].downcase == 'crj9'
71
- # end
72
-
73
67
  def is_a_g159?(row)
74
68
  row['Designator'] =~ /^G159$/
75
69
  end
76
-
70
+
77
71
  def is_a_galx?(row)
78
72
  row['Designator'] =~ /^GALX$/
79
73
  end
@@ -89,76 +83,90 @@ Aircraft.class_eval do
89
83
  end
90
84
  end
91
85
  end
92
-
86
+
93
87
  data_miner do
94
88
  schema Earth.database_options do
95
- string 'icao_code'
96
- string 'manufacturer_name'
97
- string 'name'
98
- string 'bts_name'
99
- string 'bts_aircraft_type_code'
100
- string 'brighter_planet_aircraft_class_code'
101
- string 'fuel_use_aircraft_name'
102
- float 'm3'
103
- string 'm3_units'
104
- float 'm2'
105
- string 'm2_units'
106
- float 'm1'
107
- string 'm1_units'
108
- float 'endpoint_fuel'
109
- string 'endpoint_fuel_units'
110
- float 'seats'
111
- float 'distance'
112
- string 'distance_units'
113
- float 'load_factor'
114
- float 'freight_share'
115
- float 'payload'
116
- float 'weighting'
117
- index 'bts_aircraft_type_code'
89
+ string 'bp_code'
90
+ string 'icao_code'
91
+ string 'bts_code'
92
+ string 'class_code'
93
+ string 'fuel_use_code'
94
+ string 'manufacturer_name'
95
+ string 'name'
96
+ string 'fuel_use_aircraft_name'
97
+ float 'm3'
98
+ string 'm3_units'
99
+ float 'm2'
100
+ string 'm2_units'
101
+ float 'm1'
102
+ string 'm1_units'
103
+ float 'endpoint_fuel'
104
+ string 'endpoint_fuel_units'
105
+ float 'seats'
106
+ float 'weighting'
107
+ index 'bts_code'
118
108
  end
119
109
 
120
- ('A'..'Z').each do |letter|
121
- # ('Z'..'Z').each do |letter|
122
- import( "ICAO aircraft codes starting with the letter #{letter} used by the FAA",
123
- :url => "http://www.faa.gov/air_traffic/publications/atpubs/CNT/5-2-#{letter}.htm",
124
- :errata => Errata.new(:url => 'http://spreadsheets.google.com/pub?key=tObVAGyqOkCBtGid0tJUZrw',
125
- :responder => Aircraft::Guru.new),
126
- :encoding => 'windows-1252',
127
- :row_xpath => '//table/tr[2]/td/table/tr',
128
- :column_xpath => 'td' ) do
129
- key 'icao_code', :field_name => 'Designator'
130
- store 'bts_aircraft_type_code', :matcher => Aircraft::BtsMatcher.new(:bts_aircraft_type_code)
131
- store 'bts_name', :matcher => Aircraft::BtsMatcher.new(:bts_name)
132
- store 'manufacturer_name', :field_name => 'Manufacturer'
133
- store 'name', :field_name => 'Model'
134
- end
110
+ import "a curated list of aircraft",
111
+ :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDJFblR4MDE1RGtnLVM1S2JHRGZpT3c&hl=en&single=true&gid=0&output=csv' do
112
+ key 'bp_code'
113
+ store 'icao_code', :nullify => true
114
+ store 'bts_code', :nullify => true
115
+ store 'class_code', :nullify => true
116
+ store 'fuel_use_code', :nullify => true
117
+ store 'manufacturer_name', :nullify => true
118
+ store 'name', :nullify => true
119
+ store 'fuel_use_aircraft_name', :nullify => true
120
+ store 'm3', :nullify => true, :units => :kilograms_per_cubic_nautical_mile
121
+ store 'm2', :nullify => true, :units => :kilograms_per_square_nautical_mile
122
+ store 'm1', :nullify => true, :units => :kilograms_per_nautical_mile
123
+ store 'endpoint_fuel', :nullify => true, :units => :kilograms
135
124
  end
136
125
 
137
- # TODO fixme need to remake aircraft classes dictionary based on ICAO codes
138
- # sabshere 5/17/10 or maybe we can replace this with typ/weight class from FAA (?)
139
- import "Brighter Planet's aircraft class codes",
140
- :url => 'http://static.brighterplanet.com/science/data/transport/air/bts_aircraft_type/bts_aircraft_types-brighter_planet_aircraft_classes.csv' do
141
- key 'bts_aircraft_type_code', :field_name => 'bts_aircraft_type'
142
- store 'brighter_planet_aircraft_class_code'
143
- end
144
-
145
- # EEA
146
- import "pre-calculated fuel use equation coefficients",
147
- :url => 'http://static.brighterplanet.com/science/data/transport/air/fuel_use/aircraft_fuel_use_formulae.ods',
148
- :select => lambda { |row| row['ICAO'].present? or row['Aircraft Name'].present? } do
149
- key 'icao_code', :matcher => Aircraft::FuelUseMatcher.new
150
- store 'fuel_use_aircraft_name', :field_name => 'Aircraft Name'
151
- store 'm3'
152
- store 'm2'
153
- store 'm1'
154
- store 'endpoint_fuel', :field_name => 'b'
155
- end
126
+ # ('A'..'Z').each do |letter|
127
+ # import( "ICAO manufacturers and names for aircraft with an ICAO code starting with the letter #{letter} from the FAA",
128
+ # :url => "http://www.faa.gov/air_traffic/publications/atpubs/CNT/5-2-#{letter}.htm",
129
+ # :errata => Errata.new(:url => 'http://spreadsheets.google.com/pub?key=tObVAGyqOkCBtGid0tJUZrw',
130
+ # :responder => Aircraft::Guru.new),
131
+ # :encoding => 'windows-1252',
132
+ # :row_xpath => '//table/tr[2]/td/table/tr',
133
+ # :column_xpath => 'td' ) do
134
+ # key 'icao_code', :field_name => 'Designator'
135
+ # store 'icao_manufacturer_name', :field_name => 'Manufacturer'
136
+ # store 'icao_name', :field_name => 'Model'
137
+ # end
138
+ # end
139
+
140
+ # import "some hand-picked ICAO manufacturers and names, including some for ICAO codes not used by the FAA",
141
+ # :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHRNaVpSUWw2Z2VhN3RUV25yYWdQX2c&hl=en&single=true&gid=0&output=csv' do
142
+ # key 'icao_code', :field_name => 'icao_code'
143
+ # store 'icao_manufacturer_name', :field_name => 'manufacturer_name'
144
+ # store 'icao_name', :field_name => 'name'
145
+ # end
146
+
147
+ # import "aircraft BTS names",
148
+ # :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_TYPE',
149
+ # :errata => Errata.new(:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdEZ2d3JQMzV5T1o1T3JmVlFyNUZxdEE&hl=en&single=true&gid=0&output=csv') do
150
+ # key 'bts_code', :field_name => 'Code'
151
+ # store 'bts_name', :field_name => 'Description'
152
+ # end
153
+
154
+ # import "the fuel use equations associated with each fuel use code",
155
+ # :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdG9tSC1RczJOdjliWTdjT2ZpdV9RTnc&hl=en&single=true&gid=0&output=csv' do
156
+ # key 'fuel_use_code', :field_name => 'fuel_use_code'
157
+ # store 'fuel_use_aircraft_name', :field_name => 'aircraft_name'
158
+ # store 'm3', :units => :kilograms_per_cubic_nautical_mile
159
+ # store 'm2', :units => :kilograms_per_square_nautical_mile
160
+ # store 'm1', :units => :kilograms_per_nautical_mile
161
+ # store 'endpoint_fuel', :field_name => 'b', :units => :kilograms
162
+ # end
156
163
 
157
164
  process "Derive some average flight characteristics from flight segments" do
158
165
  FlightSegment.run_data_miner!
166
+
159
167
  aircraft = Aircraft.arel_table
160
168
  segments = FlightSegment.arel_table
161
-
169
+
162
170
  # non-working joins method
163
171
  # update_all "aircraft.distance_1 = (SELECT * FROM (#{FlightSegment.joins(:aircraft).weighted_average_relation(:distance, :weighted_by => :passengers ).to_sql}) AS anonymous_1)"
164
172
  # update_all "aircraft.load_factor_1 = (SELECT * FROM (#{FlightSegment.joins(:aircraft).weighted_average_relation(:load_factor, :weighted_by => :passengers ).to_sql}) AS anonymous_1)"
@@ -166,19 +174,34 @@ Aircraft.class_eval do
166
174
  # update aircraft as t1
167
175
  # set t1.distance_1 = (SELECT * FROM (#{FlightSegment.joins(:aircraft).weighted_average_relation(:distance, :weighted_by => :passengers ).where('t1.bts_aircraft_type_code = flight_segments.bts_aircraft_type_code').to_sql}) AS anonymous_1)
168
176
  # }
169
-
170
- conditional_relation = aircraft[:bts_aircraft_type_code].eq(segments[:bts_aircraft_type_code])
171
- update_all "seats = (#{FlightSegment.weighted_average_relation(:seats, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
172
- update_all "distance = (#{FlightSegment.weighted_average_relation(:distance, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
173
- update_all "load_factor = (#{FlightSegment.weighted_average_relation(:load_factor, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
174
- update_all "freight_share = (#{FlightSegment.weighted_average_relation(:freight_share, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
175
- update_all "payload = (#{FlightSegment.weighted_average_relation(:payload, :weighted_by => :passengers, :disaggregate_by => :departures_performed).where(conditional_relation).to_sql})"
176
177
 
177
- update_all "weighting = (#{segments.project(segments[:passengers].sum).where(aircraft[:bts_aircraft_type_code].eq(segments[:bts_aircraft_type_code])).to_sql})"
178
+ # FIXME TODO
179
+ # This should calculate weighted averages from flight segments
180
+ # For example, to calculate seats:
181
+ # SELECT aircraft.icao_code, sum(flight_segments.seats * flight_segments.passengers) / sum(flight_segments.passengers)
182
+ # FROM flight_segments
183
+ # INNER JOIN aircraft_aircraft_types ON flight_segments.aircraft_type_code = aircraft_aircraft_types.aircraft_type_code
184
+ # INNER JOIN aircraft ON aircraft_aircraft_types.icao_code = aircraft.icao_code
185
+ # GROUP BY aircraft.icao_code
186
+
187
+ conditional_relation = segments[:aircraft_bts_code].eq(aircraft[:bts_code])
188
+ update_all "seats = (#{segment.weighted_average_relation(:seats, :weighted_by => :passengers).where(conditional_relation).to_sql})"
189
+ update_all "weighting = (#{segments.project(segments[:passengers].sum).where(conditional_relation).to_sql})"
190
+
191
+ # conditional_relation = aircraft[:aircraft_type_code].eq(segments[:aircraft_type_code])
192
+
193
+ # update_all "seats = (#{FlightSegment.weighted_average_relation(:seats, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
194
+
195
+ # update_all "distance = (#{FlightSegment.weighted_average_relation(:distance, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
196
+ # update_all "load_factor = (#{FlightSegment.weighted_average_relation(:load_factor, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
197
+ # update_all "freight_share = (#{FlightSegment.weighted_average_relation(:freight_share, :weighted_by => :passengers ).where(conditional_relation).to_sql})"
198
+ # update_all "payload = (#{FlightSegment.weighted_average_relation(:payload, :weighted_by => :passengers, :disaggregate_by => :departures_performed).where(conditional_relation).to_sql})"
199
+
200
+ # update_all "weighting = (#{segments.project(segments[:passengers].sum).where(aircraft[:aircraft_type_code].eq(segments[:aircraft_type_code])).to_sql})"
178
201
  end
179
202
 
180
203
  process "Synthesize AircraftManufacturer" do
181
- AircraftManufacturer.run_data_miner!
182
- end
183
- end
204
+ AircraftManufacturer.run_data_miner!
205
+ end
206
+ end
184
207
  end
@@ -1,9 +1,8 @@
1
1
  class AircraftClass < ActiveRecord::Base
2
- set_primary_key :brighter_planet_aircraft_class_code
2
+ set_primary_key :code
3
+
4
+ # has_many :aircraft, :foreign_key => 'class_code', :primary_key => 'code'
3
5
 
4
- has_many :aircraft, :foreign_key => 'brighter_planet_aircraft_class_code'
5
- # has_many :airline_aircraft_seat_classes, :through => :aircraft
6
-
7
6
  data_miner do
8
7
  tap "Brighter Planet's aircraft class data", Earth.taps_server
9
8
  end
@@ -1,42 +1,31 @@
1
1
  AircraftClass.class_eval do
2
2
  data_miner do
3
3
  schema Earth.database_options do
4
- string 'brighter_planet_aircraft_class_code'
4
+ string 'code'
5
5
  string 'name'
6
6
  float 'm1'
7
7
  float 'm2'
8
8
  float 'm3'
9
9
  float 'endpoint_fuel'
10
- integer 'seats'
10
+ float 'seats'
11
11
  end
12
12
 
13
- import "Brighter Planet's aircraft classes", :url => 'http://static.brighterplanet.com/science/data/transport/air/brighter_planet_aircraft_classes.csv' do
14
- key 'brighter_planet_aircraft_class_code'
15
- store 'name', :field_name => 'description'
13
+ import "Brighter Planet's aircraft classes",
14
+ :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGNBbHFibmxJUFprQkUwZHp6VU51Smc&hl=en&single=true&gid=0&output=csv' do
15
+ key 'code', :field_name => 'aircraft_class_code'
16
+ store 'name'
16
17
  end
17
18
 
18
19
  process "Derive some average aircraft chraracteristics from aircraft" do
19
20
  Aircraft.run_data_miner!
20
21
  aircraft = Aircraft.arel_table
21
22
  aircraft_classes = AircraftClass.arel_table
22
- conditional_relation = aircraft_classes[:brighter_planet_aircraft_class_code].eq(aircraft[:brighter_planet_aircraft_class_code])
23
- %w{ m1 m2 m3 endpoint_fuel }.each do |column|
24
- relation = Aircraft.weighted_average_relation(column).
25
- where(conditional_relation)
23
+ conditional_relation = aircraft_classes[:code].eq(aircraft[:class_code])
24
+
25
+ %w{ m1 m2 m3 endpoint_fuel seats }.each do |column|
26
+ relation = Aircraft.weighted_average_relation(column).where(conditional_relation)
26
27
  update_all "#{column} = (#{relation.to_sql})"
27
28
  end
28
29
  end
29
-
30
- process "Derive some average aircraft characteristics from flight segments" do # FIXME TODO why not derive this from aircraft?
31
- FlightSegment.run_data_miner!
32
- aircraft = Aircraft.arel_table
33
- aircraft_classes = AircraftClass.arel_table
34
- segments = FlightSegment.arel_table
35
- relation = FlightSegment.joins(:aircraft). # this requires associations
36
- weighted_average_relation(:seats, :weighted_by => :passengers).
37
- where(aircraft_classes[:brighter_planet_aircraft_class_code].eq(aircraft[:brighter_planet_aircraft_class_code]))
38
- update_all "seats = (#{relation.to_sql})"
39
- end
40
30
  end
41
31
  end
42
-
@@ -1,7 +1,7 @@
1
1
  class AircraftManufacturer < ActiveRecord::Base
2
2
  set_primary_key :name
3
3
 
4
- has_many :aircraft, :foreign_key => 'manufacturer_name'
4
+ # has_many :aircraft, :foreign_key => 'name', :primary_key => 'bp_code'
5
5
 
6
6
  data_miner do
7
7
  tap "Brighter Planet's aircraft manufacturer data", Earth.taps_server
@@ -7,14 +7,13 @@ AircraftManufacturer.class_eval do
7
7
  schema Earth.database_options do
8
8
  string 'name'
9
9
  end
10
-
10
+
11
11
  process "Derive a list of aircraft manufacturers from aircraft" do
12
12
  Aircraft.run_data_miner!
13
13
  connection.execute %{
14
14
  INSERT IGNORE INTO aircraft_manufacturers(name)
15
- SELECT aircraft.manufacturer_name FROM aircraft WHERE LENGTH(aircraft.manufacturer_name) > 0
15
+ SELECT aircraft.icao_manufacturer_name FROM aircraft WHERE aircraft.icao_manufacturer_name IS NOT NULL
16
16
  }
17
17
  end
18
18
  end
19
19
  end
20
-
@@ -3,7 +3,7 @@ class Airline < ActiveRecord::Base
3
3
 
4
4
  # has_many :airline_aircraft, :class_name => 'AirlineAircraft'
5
5
  # has_many :seat_classes, :class_name => 'AirlineSeatClass'
6
- has_many :segments, :class_name => "FlightSegment", :foreign_key => 'airline_iata_code'
6
+ # has_many :segments, :foreign_key => 'airline_iata_code', :primary_key => 'iata_code', :class_name => "FlightSegment"
7
7
  # has_many :airline_aircraft_seat_classes, :class_name => 'AirlineAircraftSeatClass'
8
8
 
9
9
  data_miner do
@@ -17,7 +17,7 @@ class Airport < ActiveRecord::Base
17
17
  end
18
18
  # --------------------------------
19
19
 
20
- belongs_to :country, :foreign_key => 'country_iso_3166_code'
20
+ belongs_to :country, :foreign_key => 'country_iso_3166_code', :primary_key => 'iso_3166_code'
21
21
  acts_as_mappable :default_units => :nms,
22
22
  :lat_column_name => :latitude,
23
23
  :lng_column_name => :longitude
@@ -6,11 +6,10 @@ FlightDistanceClass.class_eval do
6
6
  string 'distance_units'
7
7
  end
8
8
 
9
- import "a list of Brighter Planet-defined distance classes",
10
- :url => 'http://static.brighterplanet.com/science/data/transport/air/distance_classes/distance_classes.csv' do
9
+ import "a list of distance classes taken from the WRI business travel tool and UK DEFRA/DECC GHG Conversion Factors for Company Reporting",
10
+ :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdFBKM0xWaUhKVkxDRmdBVkE3VklxY2c&hl=en&single=true&gid=0&output=csv' do
11
11
  key 'name'
12
- store 'distance', :units_field_name => 'units', :to_units => :kilometres
12
+ store 'distance', :units_field_name => 'distance_units'
13
13
  end
14
14
  end
15
15
  end
16
-
@@ -4,22 +4,22 @@ class FlightSegment < ActiveRecord::Base
4
4
  extend CohortScope
5
5
  self.minimum_cohort_size = 1
6
6
 
7
- belongs_to :airline, :foreign_key => 'airline_iata_code'
8
- belongs_to :origin_airport, :foreign_key => "origin_airport_iata_code", :class_name => 'Airport'
9
- belongs_to :destination_airport, :foreign_key => "dest_airport_iata_code", :class_name => 'Airport'
10
- belongs_to :origin_country, :foreign_key => 'origin_country_iso_3166_code', :class_name => 'Country'
11
- belongs_to :destination_country, :foreign_key => 'dest_country_iso_3166_code', :class_name => 'Country'
12
- belongs_to :aircraft, :foreign_key => 'bts_aircraft_type_code', :primary_key => 'bts_aircraft_type_code'
13
- belongs_to :propulsion, :class_name => 'FlightPropulsion'
14
- belongs_to :configuration, :class_name => 'FlightConfiguration'
15
- belongs_to :service_class, :class_name => 'FlightService'
16
- belongs_to :domesticity, :class_name => 'FlightDomesticity'
7
+ belongs_to :airline, :foreign_key => 'airline_iata_code', :primary_key => 'iata_code'
8
+ belongs_to :origin_airport, :foreign_key => 'origin_airport_iata_code', :primary_key => 'iata_code', :class_name => 'Airport'
9
+ belongs_to :destination_airport, :foreign_key => 'destination_airport_iata_code', :primary_key => 'iata_code', :class_name => 'Airport'
10
+ belongs_to :aircraft, :foreign_key => 'aircraft_bts_code', :primary_key => 'bts_code'
11
+ # belongs_to :origin_country, :foreign_key => 'origin_country_iso_3166_code', :primary_key => 'iso_3166_code', :class_name => 'Country'
12
+ # belongs_to :destination_country, :foreign_key => 'destination_country_iso_3166_code', :primary_key => 'iso_3166_code', :class_name => 'Country'
13
+ # belongs_to :propulsion, :class_name => 'FlightPropulsion'
14
+ # belongs_to :configuration, :class_name => 'FlightConfiguration'
15
+ # belongs_to :service_class, :class_name => 'FlightService'
16
+ # belongs_to :domesticity, :class_name => 'FlightDomesticity'
17
+
18
+ falls_back_on :distance => lambda { weighted_average(:distance, :weighted_by => :passengers) }, # 2077.1205 data1 10-12-2010
19
+ :seats => lambda { weighted_average(:seats, :weighted_by => :passengers) }, # 144.15653537046 data1 10-12-2010
20
+ :load_factor => lambda { weighted_average(:load_factor, :weighted_by => :passengers) }, # 0.78073233770097 data1 10-12-2010
21
+ :freight_share => lambda { weighted_average(:freight_share, :weighted_by => :passengers) } # 0.022567224170157 data1 10-12-2010
17
22
 
18
- falls_back_on :distance => lambda { weighted_average(:distance, :weighted_by => :passengers) }, # 2077.1205 data1 10-12-2010
19
- :seats => lambda { weighted_average(:seats, :weighted_by => :passengers) }, # 144.15653537046 data1 10-12-2010
20
- :load_factor => lambda { weighted_average(:load_factor, :weighted_by => :passengers) }, # 0.78073233770097 data1 10-12-2010
21
- :freight_share => lambda { weighted_average(:freight_share, :weighted_by => :passengers) } # 0.022567224170157 data1 10-12-2010
22
-
23
23
  data_miner do
24
24
  tap "Brighter Planet's sanitized T100 data", Earth.taps_server
25
25
 
@@ -161,69 +161,69 @@ FlightSegment.class_eval do
161
161
  data_miner do
162
162
  schema Earth.database_options do
163
163
  string 'row_hash'
164
- string 'propulsion_id'
165
- integer 'bts_aircraft_group_code'
166
- string 'configuration_id'
167
- integer 'bts_aircraft_configuration_code'
168
- string 'distance_group'
169
- integer 'bts_distance_group_code'
170
- string 'service_class_id'
171
- string 'bts_service_class_code'
172
- string 'domesticity_id'
173
- string 'bts_data_source_code'
174
164
  integer 'departures_performed'
175
- integer 'payload'
176
- integer 'total_seats'
177
165
  integer 'passengers'
178
- integer 'freight'
179
- integer 'mail'
180
- integer 'ramp_to_ramp'
181
- integer 'air_time'
166
+ integer 'total_seats'
167
+ float 'payload' # this needs to be a float because the import includes a units conversion
168
+ string 'payload_units'
169
+ float 'freight' # this needs to be a float because the import includes a units conversion
170
+ string 'freight_units'
171
+ float 'mail' # this needs to be a float because the import includes a units conversion
172
+ string 'mail_units'
182
173
  float 'load_factor'
183
174
  float 'freight_share'
175
+ float 'seats'
184
176
  float 'distance'
185
- integer 'departures_scheduled'
177
+ string 'distance_units'
178
+ string 'aircraft_bts_code'
186
179
  string 'airline_iata_code'
187
- string 'dot_airline_id_code'
188
- string 'unique_carrier_name'
189
- string 'unique_carrier_entity'
190
- string 'region'
191
- string 'current_airline_iata_code'
192
- string 'carrier_name'
193
- integer 'carrier_group'
194
- integer 'carrier_group_new'
195
180
  string 'origin_airport_iata_code'
196
- string 'origin_city_name'
197
- integer 'origin_city_num'
198
- string 'origin_state_abr'
199
- string 'origin_state_fips'
200
- string 'origin_state_nm'
201
181
  string 'origin_country_iso_3166_code'
202
- string 'origin_country_name'
203
- integer 'origin_wac'
204
- string 'dest_airport_iata_code'
205
- string 'dest_city_name'
206
- integer 'dest_city_num'
207
- string 'dest_state_abr'
208
- string 'dest_state_fips'
209
- string 'dest_state_nm'
210
- string 'dest_country_iso_3166_code'
211
- string 'dest_country_name'
212
- integer 'dest_wac'
213
- integer 'bts_aircraft_type_code'
182
+ string 'destination_airport_iata_code'
183
+ string 'destination_country_iso_3166_code'
214
184
  integer 'year'
215
185
  integer 'quarter'
216
186
  integer 'month'
217
- float 'seats'
218
- string 'payload_units'
219
- string 'freight_units'
220
- string 'mail_units'
221
- string 'distance_units'
187
+ # string 'propulsion_id'
188
+ # integer 'bts_aircraft_group_code'
189
+ # string 'configuration_id'
190
+ # integer 'bts_aircraft_configuration_code'
191
+ # string 'distance_group'
192
+ # integer 'bts_distance_group_code'
193
+ # string 'service_class_id'
194
+ # string 'bts_service_class_code'
195
+ # string 'domesticity_id'
196
+ # string 'bts_data_source_code'
197
+ # integer 'ramp_to_ramp'
198
+ # integer 'air_time'
199
+ # integer 'departures_scheduled'
200
+ # string 'dot_airline_id_code'
201
+ # string 'unique_carrier_name'
202
+ # string 'unique_carrier_entity'
203
+ # string 'region'
204
+ # string 'current_airline_iata_code'
205
+ # string 'carrier_name'
206
+ # integer 'carrier_group'
207
+ # integer 'carrier_group_new'
208
+ # string 'origin_city_name'
209
+ # integer 'origin_city_num'
210
+ # string 'origin_state_abr'
211
+ # string 'origin_state_fips'
212
+ # string 'origin_state_nm'
213
+ # string 'origin_country_name'
214
+ # integer 'origin_wac'
215
+ # string 'dest_city_name'
216
+ # integer 'dest_city_num'
217
+ # string 'dest_state_abr'
218
+ # string 'dest_state_fips'
219
+ # string 'dest_state_nm'
220
+ # string 'dest_country_name'
221
+ # integer 'dest_wac'
222
222
  index 'airline_iata_code'
223
- index 'bts_aircraft_type_code'
223
+ index 'aircraft_bts_code'
224
224
  index 'origin_airport_iata_code'
225
- index 'dest_airport_iata_code'
226
- index 'domesticity_id'
225
+ index 'destination_airport_iata_code'
226
+ # index 'domesticity_id'
227
227
  # add_index "flight_segments", ["flight_airline_id", "origin_airport_id", "destination_airport_id", "flight_configuration_id", "flight_aircraft_id", "flight_propulsion_id", "flight_service_id", "origin_country_id", "destination_country_id"], :name => "super_4_index"
228
228
  end
229
229
 
@@ -241,11 +241,11 @@ FlightSegment.class_eval do
241
241
  end
242
242
  end
243
243
  # creating dictionaries by hand so that a new one doesn't get created for every month
244
- propulsion_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_GROUP'
245
- configuration_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_CONFIG'
246
- distance_group_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_DISTANCE_GROUP_500'
247
- service_class_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_SERVICE_CLASS'
248
- domesticity_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_DATA_SOURCE'
244
+ # propulsion_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_GROUP'
245
+ # configuration_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_AIRCRAFT_CONFIG'
246
+ # distance_group_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_DISTANCE_GROUP_500'
247
+ # service_class_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_SERVICE_CLASS'
248
+ # domesticity_dictionary = DataMiner::Dictionary.new :input => 'Code', :output => 'Description', :url => 'http://www.transtats.bts.gov/Download_Lookup.asp?Lookup=L_DATA_SOURCE'
249
249
  months.each do |month, form_data|
250
250
  import "T100 flight segment data from #{month.strftime('%B %Y')}",
251
251
  :url => URL,
@@ -255,71 +255,75 @@ FlightSegment.class_eval do
255
255
 
256
256
  key 'row_hash'
257
257
 
258
- store 'propulsion_id', :field_name => 'AIRCRAFT_GROUP', :dictionary => propulsion_dictionary
259
- store 'bts_aircraft_group_code', :field_name => 'AIRCRAFT_GROUP'
258
+ # store 'propulsion_id', :field_name => 'AIRCRAFT_GROUP', :dictionary => propulsion_dictionary
259
+ # store 'bts_aircraft_group_code', :field_name => 'AIRCRAFT_GROUP'
260
260
 
261
- store 'configuration_id', :field_name => 'AIRCRAFT_CONFIG', :dictionary => configuration_dictionary
262
- store 'bts_aircraft_configuration_code', :field_name => 'AIRCRAFT_CONFIG'
261
+ # store 'configuration_id', :field_name => 'AIRCRAFT_CONFIG', :dictionary => configuration_dictionary
262
+ # store 'bts_aircraft_configuration_code', :field_name => 'AIRCRAFT_CONFIG'
263
263
 
264
- store 'distance_group', :field_name => 'DISTANCE_GROUP', :dictionary => distance_group_dictionary
265
- store 'bts_distance_group_code', :field_name => 'DISTANCE_GROUP'
264
+ # store 'distance_group', :field_name => 'DISTANCE_GROUP', :dictionary => distance_group_dictionary
265
+ # store 'bts_distance_group_code', :field_name => 'DISTANCE_GROUP'
266
266
 
267
- store 'service_class_id', :field_name => 'CLASS', :dictionary => service_class_dictionary
268
- store 'bts_service_class_code', :field_name => 'CLASS'
267
+ # store 'service_class_id', :field_name => 'CLASS', :dictionary => service_class_dictionary
268
+ # store 'bts_service_class_code', :field_name => 'CLASS'
269
269
 
270
- store 'domesticity_id', :field_name => 'DATA_SOURCE', :dictionary => domesticity_dictionary
271
- store 'bts_data_source_code', :field_name => 'DATA_SOURCE'
270
+ # store 'domesticity_id', :field_name => 'DATA_SOURCE', :dictionary => domesticity_dictionary
271
+ # store 'bts_data_source_code', :field_name => 'DATA_SOURCE'
272
272
 
273
- store 'departures_scheduled', :field_name => 'DEPARTURES_SCHEDULED'
274
- store 'departures_performed', :field_name => 'DEPARTURES_PERFORMED'
275
- store 'payload', :field_name => 'PAYLOAD', :from_units => :pounds, :to_units => :kilograms
276
- store 'total_seats', :field_name => 'SEATS'
277
- store 'passengers', :field_name => 'PASSENGERS'
278
- store 'freight', :field_name => 'FREIGHT', :from_units => :pounds, :to_units => :kilograms
279
- store 'mail', :field_name => 'MAIL', :from_units => :pounds, :to_units => :kilograms
280
- store 'distance', :field_name => 'DISTANCE', :from_units => :miles, :to_units => :kilometres
281
- store 'ramp_to_ramp', :field_name => 'RAMP_TO_RAMP'
282
- store 'air_time', :field_name => 'AIR_TIME'
283
- store 'airline_iata_code', :field_name => 'UNIQUE_CARRIER' # adjusted for uniqueness
284
- store 'dot_airline_id_code', :field_name => 'AIRLINE_ID'
285
- store 'unique_carrier_name', :field_name => 'UNIQUE_CARRIER_NAME'
286
- store 'unique_carrier_entity', :field_name => 'UNIQUE_CARRIER_ENTITY'
287
- store 'region', :field_name => 'REGION'
288
- store 'current_airline_iata_code', :field_name => 'CARRIER'
289
- store 'carrier_name', :field_name => 'CARRIER_NAME'
290
- store 'carrier_group', :field_name => 'CARRIER_GROUP'
291
- store 'carrier_group_new', :field_name => 'CARRIER_GROUP_NEW'
292
- store 'origin_airport_iata_code', :field_name => 'ORIGIN'
293
- store 'origin_city_name', :field_name => 'ORIGIN_CITY_NAME'
294
- store 'origin_city_num', :field_name => 'ORIGIN_CITY_NUM'
295
- store 'origin_state_abr', :field_name => 'ORIGIN_STATE_ABR'
296
- store 'origin_state_fips', :field_name => 'ORIGIN_STATE_FIPS'
297
- store 'origin_state_nm', :field_name => 'ORIGIN_STATE_NM'
298
- store 'origin_country_iso_3166_code', :field_name => 'ORIGIN_COUNTRY'
299
- store 'origin_country_name', :field_name => 'ORIGIN_COUNTRY_NAME'
300
- store 'origin_wac', :field_name => 'ORIGIN_WAC'
301
- store 'dest_airport_iata_code', :field_name => 'DEST'
302
- store 'dest_city_name', :field_name => 'DEST_CITY_NAME'
303
- store 'dest_city_num', :field_name => 'DEST_CITY_NUM'
304
- store 'dest_state_abr', :field_name => 'DEST_STATE_ABR'
305
- store 'dest_state_fips', :field_name => 'DEST_STATE_FIPS'
306
- store 'dest_state_nm', :field_name => 'DEST_STATE_NM'
307
- store 'dest_country_iso_3166_code', :field_name => 'DEST_COUNTRY'
308
- store 'dest_country_name', :field_name => 'DEST_COUNTRY_NAME'
309
- store 'dest_wac', :field_name => 'DEST_WAC'
310
- store 'bts_aircraft_type_code', :field_name => 'AIRCRAFT_TYPE' # lol no dictionary please
311
- store 'year', :field_name => 'YEAR'
312
- store 'quarter', :field_name => 'QUARTER'
313
- store 'month', :field_name => 'MONTH'
273
+ # store 'departures_scheduled', :field_name => 'DEPARTURES_SCHEDULED'
274
+ store 'departures_performed', :field_name => 'DEPARTURES_PERFORMED'
275
+ store 'passengers', :field_name => 'PASSENGERS'
276
+ store 'total_seats', :field_name => 'SEATS'
277
+ store 'payload', :field_name => 'PAYLOAD', :from_units => :pounds, :to_units => :kilograms
278
+ store 'freight', :field_name => 'FREIGHT', :from_units => :pounds, :to_units => :kilograms
279
+ store 'mail', :field_name => 'MAIL', :from_units => :pounds, :to_units => :kilograms
280
+ store 'distance', :field_name => 'DISTANCE', :from_units => :miles, :to_units => :kilometres
281
+ store 'aircraft_bts_code', :field_name => 'AIRCRAFT_TYPE'
282
+ store 'airline_iata_code', :field_name => 'UNIQUE_CARRIER'
283
+ store 'origin_airport_iata_code', :field_name => 'ORIGIN'
284
+ store 'origin_country_iso_3166_code', :field_name => 'ORIGIN_COUNTRY'
285
+ store 'destination_airport_iata_code', :field_name => 'DEST'
286
+ store 'destination_country_iso_3166_code', :field_name => 'DEST_COUNTRY'
287
+ store 'year', :field_name => 'YEAR'
288
+ store 'quarter', :field_name => 'QUARTER'
289
+ store 'month', :field_name => 'MONTH'
290
+ # store 'ramp_to_ramp', :field_name => 'RAMP_TO_RAMP'
291
+ # store 'air_time', :field_name => 'AIR_TIME'
292
+ # store 'dot_airline_id_code', :field_name => 'AIRLINE_ID'
293
+ # store 'unique_carrier_name', :field_name => 'UNIQUE_CARRIER_NAME'
294
+ # store 'unique_carrier_entity', :field_name => 'UNIQUE_CARRIER_ENTITY'
295
+ # store 'region', :field_name => 'REGION'
296
+ # store 'current_airline_iata_code', :field_name => 'CARRIER'
297
+ # store 'carrier_name', :field_name => 'CARRIER_NAME'
298
+ # store 'carrier_group', :field_name => 'CARRIER_GROUP'
299
+ # store 'carrier_group_new', :field_name => 'CARRIER_GROUP_NEW'
300
+ # store 'origin_city_name', :field_name => 'ORIGIN_CITY_NAME'
301
+ # store 'origin_city_num', :field_name => 'ORIGIN_CITY_NUM'
302
+ # store 'origin_state_abr', :field_name => 'ORIGIN_STATE_ABR'
303
+ # store 'origin_state_fips', :field_name => 'ORIGIN_STATE_FIPS'
304
+ # store 'origin_state_nm', :field_name => 'ORIGIN_STATE_NM'
305
+ # store 'origin_country_name', :field_name => 'ORIGIN_COUNTRY_NAME'
306
+ # store 'origin_wac', :field_name => 'ORIGIN_WAC'
307
+ # store 'dest_city_name', :field_name => 'DEST_CITY_NAME'
308
+ # store 'dest_city_num', :field_name => 'DEST_CITY_NUM'
309
+ # store 'dest_state_abr', :field_name => 'DEST_STATE_ABR'
310
+ # store 'dest_state_fips', :field_name => 'DEST_STATE_FIPS'
311
+ # store 'dest_state_nm', :field_name => 'DEST_STATE_NM'
312
+ # store 'dest_country_name', :field_name => 'DEST_COUNTRY_NAME'
313
+ # store 'dest_wac', :field_name => 'DEST_WAC'
314
314
  end
315
315
  end
316
316
 
317
317
  process "Derive freight share as a fraction of payload" do
318
318
  update_all 'freight_share = (freight + mail) / payload', 'payload > 0'
319
319
  end
320
-
320
+
321
321
  process "Derive load factor, which is passengers divided by the total seats available" do
322
- update_all 'load_factor = passengers / total_seats', 'passengers <= total_seats'
322
+ update_all 'load_factor = passengers / total_seats', 'total_seats > 0'
323
+ end
324
+
325
+ process "Assume a load factor of 1 where passengers > total seats available" do
326
+ update_all 'load_factor = 1', 'passengers > total_seats AND total_seats > 0'
323
327
  end
324
328
 
325
329
  process "Derive average seats per departure" do
@@ -327,4 +331,3 @@ FlightSegment.class_eval do
327
331
  end
328
332
  end
329
333
  end
330
-
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'earth/air/aircraft'
3
+ require 'earth/air/aircraft/data_miner'
4
+
5
+ describe Aircraft do
6
+ describe 'import' do
7
+ it 'should treat empty cells as null' do
8
+ Aircraft.execute_schema
9
+ Aircraft.run_data_miner!
10
+ Aircraft.count.should > 1
11
+ Aircraft.where(:brighter_planet_aircraft_class_code => nil).should_not be_empty
12
+ end
13
+ end
14
+ end
File without changes
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: earth
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 25
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 2
8
- - 6
9
- version: 0.2.6
9
+ - 7
10
+ version: 0.2.7
10
11
  platform: ruby
11
12
  authors:
12
13
  - Seamus Abshere
@@ -16,7 +17,7 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-10-19 00:00:00 -04:00
20
+ date: 2010-11-01 00:00:00 -07:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
@@ -27,6 +28,7 @@ dependencies:
27
28
  requirements:
28
29
  - - ">="
29
30
  - !ruby/object:Gem::Version
31
+ hash: -1848230024
30
32
  segments:
31
33
  - 3
32
34
  - 0
@@ -43,11 +45,12 @@ dependencies:
43
45
  requirements:
44
46
  - - ~>
45
47
  - !ruby/object:Gem::Version
48
+ hash: 7
46
49
  segments:
47
50
  - 0
48
51
  - 5
49
- - 5
50
- version: 0.5.5
52
+ - 6
53
+ version: 0.5.6
51
54
  type: :runtime
52
55
  version_requirements: *id002
53
56
  - !ruby/object:Gem::Dependency
@@ -58,6 +61,7 @@ dependencies:
58
61
  requirements:
59
62
  - - ">="
60
63
  - !ruby/object:Gem::Version
64
+ hash: 25
61
65
  segments:
62
66
  - 0
63
67
  - 0
@@ -73,6 +77,7 @@ dependencies:
73
77
  requirements:
74
78
  - - ">="
75
79
  - !ruby/object:Gem::Version
80
+ hash: 3
76
81
  segments:
77
82
  - 1
78
83
  - 5
@@ -88,6 +93,7 @@ dependencies:
88
93
  requirements:
89
94
  - - ">="
90
95
  - !ruby/object:Gem::Version
96
+ hash: 17
91
97
  segments:
92
98
  - 0
93
99
  - 0
@@ -103,6 +109,7 @@ dependencies:
103
109
  requirements:
104
110
  - - ">="
105
111
  - !ruby/object:Gem::Version
112
+ hash: 13
106
113
  segments:
107
114
  - 1
108
115
  - 4
@@ -118,6 +125,7 @@ dependencies:
118
125
  requirements:
119
126
  - - ">="
120
127
  - !ruby/object:Gem::Version
128
+ hash: 23
121
129
  segments:
122
130
  - 0
123
131
  - 0
@@ -133,6 +141,7 @@ dependencies:
133
141
  requirements:
134
142
  - - ">="
135
143
  - !ruby/object:Gem::Version
144
+ hash: 15
136
145
  segments:
137
146
  - 0
138
147
  - 0
@@ -148,6 +157,7 @@ dependencies:
148
157
  requirements:
149
158
  - - ">="
150
159
  - !ruby/object:Gem::Version
160
+ hash: 62196417
151
161
  segments:
152
162
  - 2
153
163
  - 0
@@ -165,6 +175,7 @@ dependencies:
165
175
  requirements:
166
176
  - - ">="
167
177
  - !ruby/object:Gem::Version
178
+ hash: 3
168
179
  segments:
169
180
  - 0
170
181
  version: "0"
@@ -178,6 +189,7 @@ dependencies:
178
189
  requirements:
179
190
  - - ">="
180
191
  - !ruby/object:Gem::Version
192
+ hash: 3
181
193
  segments:
182
194
  - 0
183
195
  version: "0"
@@ -191,6 +203,7 @@ dependencies:
191
203
  requirements:
192
204
  - - ">="
193
205
  - !ruby/object:Gem::Version
206
+ hash: 3
194
207
  segments:
195
208
  - 0
196
209
  version: "0"
@@ -204,6 +217,7 @@ dependencies:
204
217
  requirements:
205
218
  - - ">="
206
219
  - !ruby/object:Gem::Version
220
+ hash: 3
207
221
  segments:
208
222
  - 0
209
223
  version: "0"
@@ -217,6 +231,7 @@ dependencies:
217
231
  requirements:
218
232
  - - ">="
219
233
  - !ruby/object:Gem::Version
234
+ hash: 27
220
235
  segments:
221
236
  - 1
222
237
  - 3
@@ -416,7 +431,8 @@ files:
416
431
  - vendor/geokit-rails/test/schema.rb
417
432
  - vendor/geokit-rails/test/tasks.rake
418
433
  - vendor/geokit-rails/test/test_helper.rb
419
- - spec/lib/earth_spec.rb
434
+ - spec/earth/air/aircraft_spec.rb
435
+ - spec/earth_spec.rb
420
436
  - spec/spec_helper.rb
421
437
  - Gemfile
422
438
  - Gemfile.lock
@@ -434,6 +450,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
434
450
  requirements:
435
451
  - - ">="
436
452
  - !ruby/object:Gem::Version
453
+ hash: 3
437
454
  segments:
438
455
  - 0
439
456
  version: "0"
@@ -442,6 +459,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
442
459
  requirements:
443
460
  - - ">="
444
461
  - !ruby/object:Gem::Version
462
+ hash: 3
445
463
  segments:
446
464
  - 0
447
465
  version: "0"
@@ -453,7 +471,8 @@ signing_key:
453
471
  specification_version: 3
454
472
  summary: Land, sky, and sea
455
473
  test_files:
456
- - spec/lib/earth_spec.rb
474
+ - spec/earth/air/aircraft_spec.rb
475
+ - spec/earth_spec.rb
457
476
  - spec/spec_helper.rb
458
477
  - Gemfile
459
478
  - Gemfile.lock