Module: BrighterPlanet::Flight::CarbonModel

Defined in:
lib/flight/carbon_model.rb,
lib/flight/carbon_model/fuel_use_equation.rb

Defined Under Namespace

Classes: FuelUseEquation

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
# File 'lib/flight/carbon_model.rb', line 32

def self.included(base)
  base.decide :emission, :with => :characteristics do
    ### Emission calculation
    # Returns the `emission` estimate in *kg CO<sub>2</sub>e*.
    # This is the passenger's share of the total flight emissions that occurred during the `timeframe`.
    committee :emission do
      #### Emission from fuel, emission factor, freight share, passengers, multipliers, and date
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # - Checks whether the flight occurred during the `timeframe`
      # - Multiplies `fuel use` (*kg fuel*) by an `emission factor` (*kg CO<sub>2</sub>e / kg fuel*) and an `aviation multiplier` to give total flight emissions in *kg CO<sub>2</sub>e*
      # - Multiplies by (1 - `freight share`) to take out emissions attributed to freight cargo and mail, leaving emissions attributed to passengers and their baggage
      # - Divides by the number of `passengers` and multiplies by a `seat class multiplier` to give `emission` for the passenger
      # - If the flight did not occur during the `timeframe`, `emission` is zero
      quorum 'from fuel, emission factor, freight share, passengers, multipliers, and date',
        :needs => [:fuel, :emission_factor, :freight_share, :passengers, :seat_class_multiplier, :aviation_multiplier, :date], :complies => [:ghg_protocol, :iso, :tcr] do |characteristics, timeframe|
        date = characteristics[:date].is_a?(Date) ?
          characteristics[:date] :
          Date.parse(characteristics[:date].to_s)
        if timeframe.include? date
          characteristics[:fuel] * characteristics[:emission_factor] * characteristics[:aviation_multiplier] * (1 - characteristics[:freight_share]) / characteristics[:passengers] * characteristics[:seat_class_multiplier]
        else
          0
        end
      end
    end
    
    ### Emission factor calculation
    # Returns the `emission factor` in *kg CO<sub>2</sub>e / kg fuel*.
    committee :emission_factor do
      #### Emission factor from fuel type
      # Complies: GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Looks up the [fuel type](http://data.brighterplanet.com/fuel_types) and divides its `emission factor` (*kg CO<sub>2</sub> / litre fuel*) by its `density` (*kg fuel / litre fuel*) to give *kg CO<sub>2</sub>e / kg fuel*.
      quorum 'from fuel type', :needs => :fuel_type, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:fuel_type].emission_factor.to_f / characteristics[:fuel_type].density.to_f
      end
    end
    
    ### Aviation multiplier calculation
    # Returns the `aviation multiplier`. This approximates the extra climate impact of emissions high in the atmosphere.
    committee :aviation_multiplier do
      #### Aviation multiplier from client input
      # **Complies:** All
      #
      # Uses the client-input `aviation multiplier`.
      
      #### Default aviation multiplier
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Uses an `aviation multiplier` of **2.0** after [Kolmuss and Crimmins (2009)](http://sei-us.org/publications/id/13).
      quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
        2.0
      end
    end
    
    ### Fuel calculation
    # Returns the flight's total `fuel` use in *kg fuel*.
    committee :fuel do
      #### Fuel from fuel per segment and segments per trip and trips
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Multiplies the `fuel per segment` (*kg fuel*) by the `segments per trip` and the number of `trips` to give *kg fuel*.
      quorum 'from fuel per segment and segments per trip and trips', :needs => [:fuel_per_segment, :segments_per_trip, :trips], :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:fuel_per_segment] * characteristics[:segments_per_trip].to_f * characteristics[:trips].to_f
      end
    end
    
    ### Fuel per segment calculation
    # Returns the `fuel per segment` in *kg fuel*.
    committee :fuel_per_segment do
      #### Fuel per segment from adjusted distance per segment and fuel use coefficients
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Uses a third-order polynomial equation to calculate the fuel used per segment:
      #
      # (m<sub>3</sub> * d^3 ) + (m<sub>2</sub> * d^2 ) + (m<sub>1</sub> * d) + endpoint fuel
      #
      # Where d is the `adjusted distance per segment` and m<sub>3</sub>, m<sub>2</sub>, m<sub>2</sub>, and endpoint fuel are the `fuel use coefficients`.
      quorum 'from adjusted distance per segment and fuel use coefficients', :needs => [:adjusted_distance_per_segment, :fuel_use_coefficients], :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:fuel_use_coefficients].m3.to_f * characteristics[:adjusted_distance_per_segment].to_f ** 3 +
          characteristics[:fuel_use_coefficients].m2.to_f * characteristics[:adjusted_distance_per_segment].to_f ** 2 +
          characteristics[:fuel_use_coefficients].m1.to_f * characteristics[:adjusted_distance_per_segment].to_f +
          characteristics[:fuel_use_coefficients].endpoint_fuel.to_f
      end
    end
    
    ### Adjusted distance per segment calculation
    # Returns the `adjusted distance per segment` in *nautical miles*.
    committee :adjusted_distance_per_segment do
      #### Adjusted distance per segment from adjusted distance and segments per trip
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Divides the `adjusted distance` (*nautical miles*) by `segments per trip` to give *nautical miles*.
      quorum 'from adjusted distance and segments per trip', :needs => [:adjusted_distance, :segments_per_trip], :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:adjusted_distance] / characteristics[:segments_per_trip]
      end
    end
    
    ### Adjusted distance calculation
    # Returns the `adjusted distance` in *nautical miles*.
    # The `adjusted distance` accounts for factors that increase the actual distance traveled by real world flights.
    committee :adjusted_distance do
      #### Adjusted distance from distance, route inefficiency factor, and dogleg factor
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Multiplies `distance` (*nautical miles*) by a `route inefficiency factor` and a `dogleg factor` to give *nautical miles*.
      quorum 'from distance, route inefficiency factor, and dogleg factor', :needs => [:distance, :route_inefficiency_factor, :dogleg_factor], :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:distance] * characteristics[:route_inefficiency_factor] * characteristics[:dogleg_factor]
      end
    end
    
    ### Distance calculation
    # Returns the flight's base `distance` in *nautical miles*.
    committee :distance do
      #### Distance from airports
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Calculates the great circle distance between the `origin airport` and `destination airport` and converts from *km* to *nautical miles*.
      quorum 'from airports', :needs => [:origin_airport, :destination_airport], :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        if  characteristics[:origin_airport].latitude and
            characteristics[:origin_airport].longitude and
            characteristics[:destination_airport].latitude and
            characteristics[:destination_airport].longitude
          characteristics[:origin_airport].distance_to(characteristics[:destination_airport], :units => :kms).kilometres.to :nautical_miles
        end
      end
      
      #### Distance from distance estimate
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Converts the `distance_estimate` in *km* to *nautical miles*.
      quorum 'from distance estimate', :needs => :distance_estimate, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:distance_estimate].kilometres.to :nautical_miles
      end
      
      #### Distance from distance class
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Looks up the [distance class](http://data.brighterplanet.com/flight_distance_classes)' `distance` and converts from *km* to *nautical miles*.
      quorum 'from distance class', :needs => :distance_class, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:distance_class].distance.kilometres.to :nautical_miles
      end
      
      #### Distance from cohort
      # **Complies:**
      #
      # Calculates the average `distance` of the `cohort` segments, weighted by their passengers, and converts from *km* to *nautical miles*.
      quorum 'from cohort', :needs => :cohort do |characteristics| # cohort here will be some combo of origin, airline, and aircraft
        distance = characteristics[:cohort].weighted_average(:distance, :weighted_by => :passengers).kilometres.to(:nautical_miles)
        distance > 0 ? distance : nil
      end
      
      #### Default distance
      # **Complies:**
      #
      # Calculates the average `distance` of [all segments in the T-100 database](http://data.brighterplanet.com/flight_segments), weighted by their passengers, and converts from *km* to *nautical miles*.
      quorum 'default' do
        FlightSegment.fallback.distance.kilometres.to :nautical_miles
      end
    end
    
    ### Route inefficiency factor calculation
    # This calculation returns the `route inefficiency factor`.
    # This is a measure of how much farther real world flights travel than the great circle distance between their origin and destination.
    # It accounts for factors like flight path routing around controlled airspace and circling while waiting for clearance to land.
    committee :route_inefficiency_factor do
      #### Route inefficiency factor from country
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Looks up the `route inefficiency factor` for the [country](http://data.brighterplanet.com/countries) in which the flight occurs.
      quorum 'from country', :needs => :country, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:country].andand.flight_route_inefficiency_factor
      end
      
      #### Default route inefficiency factor
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Uses a `route inefficiency factor` of **10%** based on [Kettunen et al. (2005)](http://www.atmseminar.org/seminarContent/seminar6/papers/p_055_MPM.pdf)
      quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
        Country.fallback.flight_route_inefficiency_factor
      end
    end
    
    ### Dogleg factor calculation
    # Returns the `dogleg factor`.
    # This is a measure of how far out of the way the average layover is compared to a direct flight.
    committee :dogleg_factor do
      #### Dogleg factor from segments per trip
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Assumes that each layover increases the total flight distance by **25%**.
      quorum 'from segments per trip', :needs => :segments_per_trip, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        1.25 ** (characteristics[:segments_per_trip] - 1)
      end
    end
    
    ### Distance estimate calculation
    # Returns the client-input `distance estimate` in *km*.
    
    ### Distance class calculation
    # Returns the client-input [distance class](http://data.brighterplanet.com/distance_classes).
    
    ### Fuel use coefficients calculation
    # Returns the `fuel use coefficients`. These are the coefficients of the third-order polynomial equation that describes aircraft fuel use.
    committee :fuel_use_coefficients do
      #### Fuel use coefficients from aircraft
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Looks up the [aircraft](http://data.brighterplanet.com/aircraft)'s `fuel use coefficients`.
      quorum 'from aircraft', :needs => :aircraft, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        aircraft = characteristics[:aircraft]
        fuel_use = FuelUseEquation.new aircraft.m3, aircraft.m2, aircraft.m1, aircraft.endpoint_fuel
        if fuel_use.empty?
          nil
        else
          fuel_use
        end
      end
      
      #### Fuel use coefficients from aircraft class
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Looks up the [aircraft class](http://data.brighterplanet.com/aircraft_classes)' `fuel use coefficients`.
      quorum 'from aircraft class', :needs => :aircraft_class, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        aircraft_class = characteristics[:aircraft_class]
        FuelUseEquation.new aircraft_class.m3, aircraft_class.m2, aircraft_class.m1, aircraft_class.endpoint_fuel
      end
      
      #### Fuel use coefficients from cohort
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Calculates the average `fuel use coefficients` of the aircraft used by the `cohort` segments, weighted by the segment passengers.
      # If an aircraft does not have `fuel use coefficients`, it takes the `fuel use coefficients` for the aircraft's [aircraft class](http://data.brighterplanet.com/aircraft_classes).
      quorum 'from cohort', :needs => :cohort, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        flight_segments = characteristics[:cohort]
        
        passengers = flight_segments.inject(0) do |passengers, flight_segment|
          passengers + flight_segment.passengers
        end
        puts "passengers: #{passengers.inspect}"
        
        bts_codes = flight_segments.map(&:aircraft_bts_code).uniq
        relevant_aircraft = Aircraft.find_all_by_bts_code(bts_codes).inject({}) do |hsh, aircraft|
          hsh[aircraft.bts_code] = aircraft
          hsh
        end

        sum_coefficients = lambda do |name|
          flight_segments.inject(0) do |coefficient, flight_segment|
            bts_code = flight_segment.aircraft_bts_code.to_s
            aircraft = relevant_aircraft[bts_code]
            if aircraft.nil?
              puts "aircraft is nil, bts_code is #{bts_code}"
              puts "flight segment: #{flight_segment.inspect}"
            end
            aircraft_coefficient = aircraft.send(name)
            if aircraft.aircraft_class.nil?
              puts "aircraft #{aircraft.inspect} has nil class"
              puts "flight segment: #{flight_segment.inspect}"
            end
            if aircraft_coefficient.nil?
              aircraft_coefficient = aircraft.aircraft_class.send(name)
            end
#                  puts "coeff = #{coefficient} + (#{aircraft_coefficient} * #{flight_segment.passengers}) = #{coefficient + (aircraft_coefficient * flight_segment.passengers)}"
            coefficient + (aircraft_coefficient * flight_segment.passengers)
          end
        end

        puts "m3 coeff = #{sum_coefficients.call(:m3).inspect}"
        puts "m2 coeff = #{sum_coefficients.call(:m2).inspect}"
        puts "m1 coeff = #{sum_coefficients.call(:m1).inspect}"
        puts "endpoint_fuel coeff = #{sum_coefficients.call(:endpoint_fuel).inspect}"
        m3 = sum_coefficients.call(:m3) / passengers
        m2 = sum_coefficients.call(:m2) / passengers
        m1 = sum_coefficients.call(:m1) / passengers
        endpoint_fuel = sum_coefficients.call(:endpoint_fuel) / passengers
        
        FuelUseEquation.new m3, m2, m1, endpoint_fuel
      end
      
      #### Default fuel use coefficients
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Calculates the average `fuel use coefficients` of the aircraft used by [all segments in the T-100 database](http://data.brighterplanet.com/flight_segments), weighted by the segment passengers.
      # If an aircraft does not have `fuel use coefficients`, it takes the `fuel use coefficients` for the aircraft's [aircraft class](http://data.brighterplanet.com/aircraft_classes).
      quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
        FuelUseEquation.new Aircraft.fallback.m3, Aircraft.fallback.m2, Aircraft.fallback.m1, Aircraft.fallback.endpoint_fuel
      end
    end
    
    ### Fuel type calculation
    # Returns the `fuel type`.
    committee :fuel_type do
      #### Fuel type from client input
      # **Complies:** All
      #
      # Uses the client-input [fuel type](http://data.brighterplanet.com/fuel_types).
      
      #### Default fuel type
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Assumes the flight uses **Jet Fuel**.
      quorum 'default', :complies => [:ghg_protocol, :ico, :tcr] do
        FuelType.find_by_name 'Jet Fuel'
      end
    end
    
    ### Passengers calculation
    # Returns the number of `passengers`.
    committee :passengers do
      #### Passengers from seats and load factor
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Multiplies the number of `seats` by the `load factor`.
      quorum 'from seats and load factor', :needs => [:seats, :load_factor], :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        (characteristics[:seats] * characteristics[:load_factor]).round
      end
    end
    
    ### Seats calculation
    # Returns the number of `seats`.
    committee :seats do
      #### Seats from seats estimate
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Uses the client-input estimate of the number of `seats`.
      quorum 'from seats estimate', :needs => :seats_estimate, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:seats_estimate]
      end
      
      #### Seats from aircraft
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Looks up the [aircraft](http://data.brighterplanet.com/aircraft)'s average number of `seats`.
      quorum 'from aircraft', :needs => :aircraft, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:aircraft].seats
      end
      
      #### Seats from aircraft class
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Looks up the [aircraft class](http://data.brighterplanet.com/aircraft_classes)' average number of `seats`.
      quorum 'from aircraft class', :needs => :aircraft_class, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:aircraft_class].seats
      end
      
      #### Seats from cohort
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Calculates the average number of `seats` of the `cohort` segments, weighted by their passengers.
      quorum 'from cohort', :needs => :cohort, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        seats = characteristics[:cohort].weighted_average :seats, :weighted_by => :passengers
        if seats.nil? or seats.zero?
          nil
        else
          seats
        end
      end
      
      #### Default seats
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Calculates the average number of `seats` of [all segments in the T-100 database](http://data.brighterplanet.com/flight_segments), weighted by their passengers.
      quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
        FlightSegment.fallback.seats
      end
    end
    
    ### Seats estimate calculation
    # Returns the client-input `seats estimate`.
    
    ### Load factor calculation
    # Returns the `load factor`.
    # This is the portion of available seats that are occupied.
    committee :load_factor do
      #### Load factor from client input
      # **Complies:** All
      #
      # Uses the client-input `load factor`.
      
      #### Load factor from cohort
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Calculates the average `load factor` of the `cohort` segments, weighted by their passengers.
      quorum 'from cohort', :needs => :cohort, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:cohort].weighted_average(:load_factor, :weighted_by => :passengers)
      end
      
      #### Default load factor
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Calculates the average `load factor` of [all segments in the T-100 database](http://data.brighterplanet.com/flight_segments), weighted by their passengers.
      quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
        FlightSegment.fallback.load_factor
      end
    end
    
    ### Freight share calculation
    # Returns the `freight share`.
    # This is the percent of the total aircraft weight that is freight cargo and mail (as opposed to passengers and their baggage).
    committee :freight_share do
      #### Freight share from cohort
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Calculates the average `freight share` of the `cohort` segments, weighted by their passengers.
      quorum 'from cohort', :needs => :cohort, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:cohort].weighted_average(:freight_share, :weighted_by => :passengers)
      end
      
      #### Default freight share
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Calculates the average `freight share` of [all segments in the T-100 database](http://data.brighterplanet.com/flight_segments), weighted by their passengers.
      quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
        FlightSegment.fallback.freight_share
      end
    end
    
    ### Trips calculation
    # Returns the number of `trips`.
    # A one-way flight has one trip; a round-trip flight has two trips.
    committee :trips do
      #### Trips from client input
      # **Complies:** All
      #
      # Uses the client-input number of `trips`.
      
      #### Default trips
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Uses an average number of `trips` of **1.941**, taken from the [U.S. National Household Travel Survey](http://www.bts.gov/publications/america_on_the_go/long_distance_transportation_patterns/html/table_07.html).
      quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
        1.941
      end
    end
    
    ### Seat class multiplier calculation
    # Returns the `seat class multiplier`. This reflects the amount of cabin space occupied by the passenger's seat.
    committee :seat_class_multiplier do
      #### Seat class multiplier from seat class
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Looks up the [seat class](http://data.brighterplanet.com/flight_seat_classes)' `seat class multiplier`.
      quorum 'from seat class', :needs => :seat_class, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:seat_class].multiplier
      end
      
      #### Default seat class multiplier
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Uses a `seat class multiplier` of **1**.
      quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
        FlightSeatClass.fallback.multiplier
      end
    end
    
    ### Seat class calculation
    # Returns the client-input [seat class](http://data.brighterplanet.com/seat_classes).
    
    ### Country calculation
    # Returns the [country](http://data.brighterplanet.com/countries) in which a flight occurs.
    committee :country do
      #### Country from client input
      # **Complies:** All
      #
      # Uses the client-input [country](http://data.brighterplanet.com/countries).
      
      #### Country from origin airport and destination airport
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Checks whether the flight's `origin airport` and `destination airport` are within the same country.
      # If so, that country is the `country`.
      quorum 'from origin airport and destination airport', :needs => [:origin_airport, :destination_airport], :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        if characteristics[:origin_airport].country == characteristics[:destination_airport].country
          characteristics[:origin_airport].country
        end
      end
    end
    
    ### Aircraft Class calculation
    # This calculation returns the [aircraft class](http://data.brighterplanet.com/aircraft_classes).
    committee :aircraft_class do
      #### Aircraft class from client input
      # **Complies:** All
      #
      # Uses the client-input [aircraft_class](http://data.brighterplanet.com/aircraft_classes).
      
      #### Aircraft class from aircraft
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Looks up the [aircraft](http://data.brighterplanet.com/aircraft)'s [aircraft_class](http://data.brighterplanet.com/aircraft_classes).
      quorum 'from aircraft', :needs => :aircraft, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        characteristics[:aircraft].aircraft_class
      end
    end
    
    ### Cohort calculation
    # Returns the `cohort`.
    # This is a set of flight segment records in the [T-100 database](http://data.brighterplanet.com/flight_segments) that match certain client-input values.
    committee :cohort do
      #### Cohort from segments per trip and input
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # - Checks whether the flight is direct
      # - Takes the input values for `origin airport`, `destination airport`, `aircraft`, and `airline`
      # - Selects all the records in the T-100 database that match the available input values
      # - Drops the last input value (initially `airline`, then `aircraft`, etc.) if no records match all of the available input values
      # - Repeats steps 3 and 4 until some records match or no input values remain
      # - If no records match any of the input values, or if the flight is indirect, then `cohort` is undefined.
      quorum 'from segments per trip and input', :needs => :segments_per_trip, :appreciates => [:origin_airport, :destination_airport, :aircraft, :airline], :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
        cohort = {}
        if characteristics[:segments_per_trip] == 1
          provided_characteristics = [:origin_airport, :destination_airport, :aircraft, :airline].
            inject(ActiveSupport::OrderedHash.new) do |memo, characteristic_name|
              memo[characteristic_name] = characteristics[characteristic_name]
              memo
            end
          cohort = FlightSegment.strict_cohort provided_characteristics
        end
        if cohort.any? && !cohort.all? { |fs| fs.passengers.zero? }
          cohort
        else
          nil
        end
      end
    end
    
    ### Origin airport calculation
    # Returns the client-input [origin airport](http://data.brighterplanet.com/airports).
    
    ### Destination airport calculation
    # Returns the client-input [destination airport](http://data.brighterplanet.com/airports).
    
    ### Aircraft calculation
    # Returns the client-input type of [aircraft](http://data.brighterplanet.com/aircraft).
    
    ### Airline calculation
    # Returns the client-input [airline](http://data.brighterplanet.com/airlines) operating the flight.
    
    ### Segments per trip calculation
    # Returns the `segments per trip`.
    # Direct flights have a single segment per trip. Indirect flights with one or more layovers have two or more segments per trip.
    committee :segments_per_trip do
      #### Segments per trip from client input
      # **Complies:** All
      #
      # Uses the client-input `segments per trip`.
      
      #### Default segments per trip
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Uses an average `segments per trip` of **1.67**, calculated from the [U.S. National Household Travel Survey](http://nhts.ornl.gov/).
      quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
        1.67
      end
    end
    
    ### Date calculation
    # Returns the `date` on which the flight occurred.
    committee :date do
      #### Date from client input
      # **Complies:** All
      #
      # Uses the client-input `date`.
      
      #### Date from timeframe
      # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
      #
      # Assumes the flight occurred on the first day of the `timeframe`.
      quorum 'from timeframe', :complies => [:ghg_protocol, :iso, :tcr] do |characteristics, timeframe|
        timeframe.from
      end
    end
  end
end