flight 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ class FlightConfiguration < ActiveRecord::Base
2
+ set_primary_key :name
3
+ end
@@ -0,0 +1,3 @@
1
+ class FlightDistanceClass < ActiveRecord::Base
2
+ set_primary_key :name
3
+ end
@@ -0,0 +1,3 @@
1
+ class FlightDomesticity < ActiveRecord::Base
2
+ set_primary_key :name
3
+ end
@@ -0,0 +1,6 @@
1
+ class FlightFuelType < ActiveRecord::Base
2
+ # this fallback is jet fuel
3
+ falls_back_on :emission_factor => (21.09.pounds.to(:kilograms) / 1.gallons.to(:litres)), # in pounds CO2/gallon fuel: http://www.eia.doe.gov/oiaf/1605/excel/Fuel%20Emission%20Factors.xls
4
+ :radiative_forcing_index => 2, # from Matt
5
+ :density => 3.057 # kg / gal
6
+ end
@@ -0,0 +1,3 @@
1
+ class FlightPropulsion < ActiveRecord::Base
2
+ set_primary_key :name
3
+ end
@@ -0,0 +1,8 @@
1
+ class FlightSeatClass < ActiveRecord::Base
2
+ set_primary_key :name
3
+ # has_many :airline_seat_classes, :class_name => 'AirlineSeatClass'
4
+ # has_many :aircraft_seat_classes, :class_name => 'AircraftSeatClass'
5
+ # has_many :airline_aircraft_seat_classes, :class_name => 'AirlineAircraftSeatClass'
6
+
7
+ falls_back_on :multiplier => 1
8
+ end
@@ -0,0 +1,30 @@
1
+ class FlightSegment < ActiveRecord::Base
2
+ set_primary_key :row_hash
3
+
4
+ extend CohortScope
5
+ self.minimum_cohort_size = 5 #FIXME ??
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'
17
+
18
+ falls_back_on :load_factor => lambda { weighted_average(:load_factor, :weighted_by => :passengers) }, # 0.78222911236768
19
+ :freight_share => lambda { weighted_average(:freight_share, :weighted_by => :passengers) }, # 0.024017329363736
20
+ :seats => lambda { weighted_average :seats, :weighted_by => :passengers }
21
+
22
+ INPUT_CHARACTERISTICS = [
23
+ :origin_airport,
24
+ :destination_airport,
25
+ :aircraft,
26
+ :airline,
27
+ :propulsion,
28
+ :domesticity
29
+ ]
30
+ end
@@ -0,0 +1,3 @@
1
+ class FlightService < ActiveRecord::Base
2
+ set_primary_key :name
3
+ end
@@ -0,0 +1,337 @@
1
+ require 'sniff/database'
2
+
3
+ Sniff::Database.define_schema do
4
+ create_table "aircraft", :primary_key => "icao_code", :id => false, :force => true do |t|
5
+ t.string 'icao_code'
6
+ t.string "manufacturer_name"
7
+ t.string "name"
8
+ t.string "bts_name"
9
+ t.string "bts_aircraft_type_code"
10
+ t.string "brighter_planet_aircraft_class_code"
11
+ t.string "fuel_use_aircraft_name"
12
+ t.float "m3"
13
+ t.float "m2"
14
+ t.float "m1"
15
+ t.float "endpoint_fuel"
16
+ t.float "seats"
17
+ t.float "distance"
18
+ t.float "load_factor"
19
+ t.float "freight_share"
20
+ t.float "payload"
21
+ t.float "weighting"
22
+ t.datetime "created_at"
23
+ t.datetime "updated_at"
24
+ end
25
+
26
+ create_table "aircraft_classes", :primary_key => "brighter_planet_aircraft_class_code", :id => false, :force => true do |t|
27
+ t.string 'brighter_planet_aircraft_class_code'
28
+ t.string "name"
29
+ t.float "m1"
30
+ t.float "m2"
31
+ t.float "m3"
32
+ t.float "endpoint_fuel"
33
+ t.integer "seats"
34
+ t.datetime "created_at"
35
+ t.datetime "updated_at"
36
+ end
37
+
38
+ create_table "aircraft_manufacturers", :primary_key => "name", :id => false, :force => true do |t|
39
+ t.string 'name'
40
+ t.datetime "created_at"
41
+ t.datetime "updated_at"
42
+ end
43
+
44
+ create_table "airlines", :primary_key => "iata_code", :id => false, :force => true do |t|
45
+ t.string 'iata_code'
46
+ t.string "name"
47
+ t.string "dot_airline_id_code"
48
+ t.boolean "international"
49
+ t.float "distance"
50
+ t.float "load_factor"
51
+ t.float "freight_share"
52
+ t.float "payload"
53
+ t.datetime "created_at"
54
+ t.datetime "updated_at"
55
+ t.float "seats"
56
+ end
57
+
58
+ create_table "airports", :primary_key => "iata_code", :id => false, :force => true do |t|
59
+ t.string 'iata_code'
60
+ t.string "name"
61
+ t.string "city"
62
+ t.string "country_name"
63
+ t.string "country_iso_3166_code"
64
+ t.float "latitude"
65
+ t.float "longitude"
66
+ t.float "seats"
67
+ t.float "distance"
68
+ t.float "load_factor"
69
+ t.float "freight_share"
70
+ t.float "payload"
71
+ t.boolean "international_origin"
72
+ t.boolean "international_destination"
73
+ t.datetime "created_at"
74
+ t.datetime "updated_at"
75
+ end
76
+
77
+ create_table "flight_aircraft", :force => true do |t|
78
+ t.string "name"
79
+ t.integer "seats"
80
+ t.integer "flight_fuel_type_id"
81
+ t.float "endpoint_fuel"
82
+ t.integer "flight_manufacturer_id"
83
+ t.datetime "updated_at"
84
+ t.datetime "created_at"
85
+ t.date "bts_begin_date"
86
+ t.date "bts_end_date"
87
+ t.float "load_factor"
88
+ t.float "freight_share"
89
+ t.float "m3"
90
+ t.float "m2"
91
+ t.float "m1"
92
+ t.float "distance"
93
+ t.float "payload"
94
+ t.integer "flight_aircraft_class_id"
95
+ t.float "multiplier"
96
+ t.string "manufacturer_name"
97
+ t.string "brighter_planet_aircraft_class_code"
98
+ t.integer "weighting"
99
+ t.integer "bts_aircraft_type"
100
+ end
101
+
102
+ create_table "flight_aircraft_classes", :force => true do |t|
103
+ t.string "name"
104
+ t.integer "seats"
105
+ t.integer "flight_fuel_type_id"
106
+ t.float "endpoint_fuel"
107
+ t.string "brighter_planet_aircraft_class_code"
108
+ t.float "m1"
109
+ t.float "m2"
110
+ t.float "m3"
111
+ end
112
+
113
+ create_table "flight_aircraft_seat_classes", :force => true do |t|
114
+ t.integer "flight_aircraft_id"
115
+ t.integer "flight_seat_class_id"
116
+ t.integer "seats"
117
+ t.datetime "created_at"
118
+ t.datetime "updated_at"
119
+ t.float "multiplier"
120
+ t.boolean "fresh"
121
+ end
122
+
123
+ create_table "flight_airline_aircraft", :force => true do |t|
124
+ t.integer "flight_airline_id"
125
+ t.integer "flight_aircraft_id"
126
+ t.integer "seats"
127
+ t.datetime "updated_at"
128
+ t.datetime "created_at"
129
+ t.float "total_seat_area"
130
+ t.float "average_seat_area"
131
+ t.boolean "fresh"
132
+ t.float "multiplier"
133
+ end
134
+
135
+ create_table "flight_airline_aircraft_seat_classes", :force => true do |t|
136
+ t.integer "seats"
137
+ t.float "pitch"
138
+ t.float "width"
139
+ t.float "multiplier"
140
+ t.datetime "created_at"
141
+ t.datetime "updated_at"
142
+ t.float "seat_area"
143
+ t.string "name"
144
+ t.integer "flight_airline_id"
145
+ t.integer "flight_aircraft_id"
146
+ t.integer "flight_seat_class_id"
147
+ t.integer "weighting"
148
+ t.integer "peers"
149
+ end
150
+
151
+ create_table "flight_airline_seat_classes", :force => true do |t|
152
+ t.integer "flight_seat_class_id"
153
+ t.integer "flight_airline_id"
154
+ t.float "multiplier"
155
+ t.datetime "created_at"
156
+ t.datetime "updated_at"
157
+ t.integer "seats"
158
+ t.boolean "fresh"
159
+ end
160
+
161
+ create_table "flight_airlines", :force => true do |t|
162
+ t.string "name"
163
+ t.string "iata"
164
+ t.string "us_dot_airline_id"
165
+ t.float "load_factor"
166
+ t.float "freight_share"
167
+ t.float "distance"
168
+ t.float "multiplier"
169
+ t.integer "seats"
170
+ t.float "payload"
171
+ t.boolean "international"
172
+ end
173
+
174
+ create_table "flight_configurations", :primary_key => "name", :id => false, :force => true do |t|
175
+ t.string 'name'
176
+ t.string "bts_aircraft_configuration_code"
177
+ t.datetime "created_at"
178
+ t.datetime "updated_at"
179
+ end
180
+
181
+ create_table "flight_distance_classes", :primary_key => "name", :id => false, :force => true do |t|
182
+ t.string 'name'
183
+ t.float "distance"
184
+ t.string "distance_units"
185
+ t.datetime "updated_at"
186
+ t.datetime "created_at"
187
+ end
188
+
189
+ create_table "flight_domesticities", :primary_key => "name", :id => false, :force => true do |t|
190
+ t.string 'name'
191
+ t.string "bts_data_source_code"
192
+ t.float "distance"
193
+ t.string "distance_units"
194
+ t.float "freight_share"
195
+ t.float "load_factor"
196
+ t.float "seats"
197
+ t.float "payload"
198
+ t.string "payload_units"
199
+ t.datetime "created_at"
200
+ t.datetime "updated_at"
201
+ end
202
+
203
+ create_table "flight_fuel_types", :force => true do |t|
204
+ t.string "name"
205
+ t.float "emission_factor"
206
+ t.float "radiative_forcing_index"
207
+ t.float "density"
208
+ t.datetime "created_at"
209
+ t.datetime "updated_at"
210
+ end
211
+
212
+ create_table "flight_manufacturers", :force => true do |t|
213
+ t.string "name"
214
+ t.datetime "created_at"
215
+ t.datetime "updated_at"
216
+ end
217
+
218
+ create_table "flight_patterns", :force => true do |t|
219
+ t.string "name"
220
+ t.integer "flight_id"
221
+ t.date "start_date"
222
+ t.date "end_date"
223
+ t.datetime "created_at"
224
+ t.datetime "updated_at"
225
+ t.float "monthly_flights"
226
+ t.integer "profile_id"
227
+ end
228
+
229
+ create_table "flight_propulsions", :primary_key => "name", :id => false, :force => true do |t|
230
+ t.string 'name'
231
+ t.string "bts_aircraft_group_code"
232
+ t.datetime "created_at"
233
+ t.datetime "updated_at"
234
+ end
235
+
236
+ create_table "flight_seat_classes", :primary_key => "name", :id => false, :force => true do |t|
237
+ t.string 'name'
238
+ t.float "multiplier"
239
+ t.integer "seats"
240
+ t.datetime "updated_at"
241
+ t.datetime "created_at"
242
+ end
243
+
244
+ create_table "flight_segments", :primary_key => "row_hash", :id => false, :force => true do |t|
245
+ t.string 'row_hash'
246
+ t.string "propulsion_id"
247
+ t.integer "bts_aircraft_group_code"
248
+ t.string "configuration_id"
249
+ t.integer "bts_aircraft_configuration_code"
250
+ t.string "distance_group"
251
+ t.integer "bts_distance_group_code"
252
+ t.string "service_class_id"
253
+ t.string "bts_service_class_code"
254
+ t.string "domesticity_id"
255
+ t.string "bts_data_source_code"
256
+ t.integer "departures_performed"
257
+ t.integer "payload"
258
+ t.integer "total_seats"
259
+ t.integer "passengers"
260
+ t.integer "freight"
261
+ t.integer "mail"
262
+ t.integer "ramp_to_ramp"
263
+ t.integer "air_time"
264
+ t.float "load_factor"
265
+ t.float "freight_share"
266
+ t.integer "distance"
267
+ t.integer "departures_scheduled"
268
+ t.string "airline_iata_code"
269
+ t.string "dot_airline_id_code"
270
+ t.string "unique_carrier_name"
271
+ t.string "unique_carrier_entity"
272
+ t.string "region"
273
+ t.string "current_airline_iata_code"
274
+ t.string "carrier_name"
275
+ t.integer "carrier_group"
276
+ t.integer "carrier_group_new"
277
+ t.string "origin_airport_iata_code"
278
+ t.string "origin_city_name"
279
+ t.integer "origin_city_num"
280
+ t.string "origin_state_abr"
281
+ t.string "origin_state_fips"
282
+ t.string "origin_state_nm"
283
+ t.string "origin_country_iso_3166_code"
284
+ t.string "origin_country_name"
285
+ t.integer "origin_wac"
286
+ t.string "dest_airport_iata_code"
287
+ t.string "dest_city_name"
288
+ t.integer "dest_city_num"
289
+ t.string "dest_state_abr"
290
+ t.string "dest_state_fips"
291
+ t.string "dest_state_nm"
292
+ t.string "dest_country_iso_3166_code"
293
+ t.string "dest_country_name"
294
+ t.integer "dest_wac"
295
+ t.integer "bts_aircraft_type_code"
296
+ t.integer "year"
297
+ t.integer "quarter"
298
+ t.integer "month"
299
+ t.float "seats"
300
+ t.string "payload_units"
301
+ t.string "freight_units"
302
+ t.string "mail_units"
303
+ t.string "distance_units"
304
+ t.datetime "created_at"
305
+ t.datetime "updated_at"
306
+ end
307
+
308
+ create_table "flight_services", :primary_key => "name", :id => false, :force => true do |t|
309
+ t.string 'name'
310
+ t.string "bts_service_class_code"
311
+ t.datetime "created_at"
312
+ t.datetime "updated_at"
313
+ end
314
+
315
+ create_table "flight_records", :force => true do |t|
316
+ t.date "date"
317
+ t.datetime "created_at"
318
+ t.datetime "updated_at"
319
+ t.float "distance_estimate"
320
+ t.integer "seats_estimate"
321
+ t.float "load_factor"
322
+ t.time "time_of_day"
323
+ t.integer "year"
324
+ t.integer "emplanements_per_trip"
325
+ t.integer "trips"
326
+ t.string "origin_airport_id"
327
+ t.string "destination_airport_id"
328
+ t.string "distance_class_id"
329
+ t.string "aircraft_id"
330
+ t.string "aircraft_class_id"
331
+ t.string "propulsion_id"
332
+ t.string "fuel_type_id"
333
+ t.string "airline_id"
334
+ t.string "seat_class_id"
335
+ t.string "domesticity_id"
336
+ end
337
+ end
@@ -0,0 +1,34 @@
1
+ require 'flight'
2
+
3
+ class FlightRecord < ActiveRecord::Base
4
+ include Sniff::Emitter
5
+ include BrighterPlanet::Flight
6
+ set_table_name 'flight_records'
7
+
8
+ belongs_to :origin_airport, :class_name => 'Airport'
9
+ belongs_to :destination_airport, :class_name => 'Airport'
10
+ belongs_to :distance_class, :class_name => 'FlightDistanceClass'
11
+ belongs_to :fuel_type, :class_name => 'FlightFuelType'
12
+ belongs_to :propulsion, :class_name => 'FlightPropulsion'
13
+ belongs_to :aircraft_class
14
+ belongs_to :aircraft
15
+ belongs_to :seat_class, :class_name => 'FlightSeatClass'
16
+ belongs_to :airline
17
+ belongs_to :domesticity, :class_name => 'FlightDomesticity'
18
+
19
+ falls_back_on :trips => 1.941, # http://www.bts.gov/publications/america_on_the_go/long_distance_transportation_patterns/html/table_07.html
20
+ :emplanements_per_trip => 1.67,
21
+ :distance_estimate => 2077.4455,
22
+ :load_factor => lambda { FlightSegment.fallback.load_factor }
23
+
24
+ class << self
25
+ def research(key)
26
+ case key
27
+ when :route_inefficiency_factor
28
+ 1.07
29
+ when :dogleg_factor
30
+ 1.25
31
+ end
32
+ end
33
+ end
34
+ end