Module: BrighterPlanet::AutomobileTrip::CarbonModel

Defined in:
lib/automobile_trip/carbon_model.rb

Defined Under Namespace

Classes: Mapper

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



28
29
30
31
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
# File 'lib/automobile_trip/carbon_model.rb', line 28

def self.included(base)
  base.decide :emission, :with => :characteristics do
    ### Emission calculation
    # Returns the `emission` estimate (*kg CO<sub>2</sub>e*).
    committee :emission do
      #### Emission from CO<sub>2</sub> emission, CH<sub>4</sub> emission, N<sub>2</sub>O emission, and HFC emission
      quorum 'from co2 emission, ch4 emission, n2o emission, and hfc emission',
        :needs => [:co2_emission, :ch4_emission, :n2o_emission, :hfc_emission],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Sums the non-biogenic emissions to give *kg CO<sub>2</sub>e*.
          characteristics[:co2_emission] + characteristics[:ch4_emission] + characteristics[:n2o_emission] + characteristics[:hfc_emission]
      end
    end
    
    ### CO<sub>2</sub> emission calculation
    # Returns the `co2 emission` (*kg*).
    committee :co2_emission do
      #### CO<sub>2</sub> emission from fuel use, CO<sub>2</sub> emission factor, date, and timeframe
      quorum 'from fuel use, co2 emission factor, date, and timeframe',
        :needs => [:fuel_use, :co2_emission_factor, :date],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
          # Checks whether the trip `date` falls within the `timeframe`.
          date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
          if timeframe.include? date
            # Multiplies `fuel use` (*l*) by the `co2 emission factor` (*kg / l*) to give *kg*.
            characteristics[:fuel_use] * characteristics[:co2_emission_factor]
          else
            # If the `date` does not fall within the `timeframe`, `co2 emission` is zero.
            0
          end
      end
    end
    
    ### CO<sub>2</sub> biogenic emission calculation
    # Returns the `co2 biogenic emission` (*kg*).
    committee :co2_biogenic_emission do
      #### CO<sub>2</sub> biogenic emission from fuel use, CO<sub>2</sub> biogenic emission factor, date, and timeframe
      quorum 'from fuel use, co2 biogenic emission factor, date, and timeframe',
        :needs => [:fuel_use, :co2_biogenic_emission_factor, :date],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
          # Checks whether the trip `date` falls within the `timeframe`.
          date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
          if timeframe.include? date
            # Multiplies `fuel use` (*l*) by the `co2 biogenic emission factor` (*kg / l*) to give *kg*.
            characteristics[:fuel_use] * characteristics[:co2_biogenic_emission_factor]
          else
            # If the `date` does not fall within the `timeframe`, `co2 biogenic emission` is zero.
            0
          end
      end
    end
    
    ### CH<sub>4</sub> emission calculation
    # Returns the `ch4 emission` (*kg CO<sub>2</sub>e*).
    committee :ch4_emission do
      #### CH<sub>4</sub> emission from fuel use, CH<sub>4</sub> emission factor, date, and timeframe
      quorum 'from fuel use, ch4 emission factor, date, and timeframe',
        :needs => [:fuel_use, :ch4_emission_factor, :date],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
          # Checks whether the trip `date` falls within the `timeframe`.
          date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
          if timeframe.include? date
            # Multiplies `fuel use` (*l*) by the `ch4 emission factor` (*kg CO<sub>2</sub>e / l*) to give *kg CO<sub>2</sub>e*.
            characteristics[:fuel_use] * characteristics[:ch4_emission_factor]
          else
            # If the `date` does not fall within the `timeframe`, `ch4 emission` is zero.
            0
          end
      end
    end
    
    ### N<sub>2</sub>O emission calculation
    # Returns the `n2o emission` (*kg CO<sub>2</sub>e*)
    committee :n2o_emission do
      #### N<sub>2</sub>O emission from fuel use, N<sub>2</sub>O emission factor, date, and timeframe
      quorum 'from fuel use, n2o emission factor, date, and timeframe',
        :needs => [:fuel_use, :n2o_emission_factor, :date],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
          # Checks whether the trip `date` falls within the `timeframe`.
          date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
          if timeframe.include? date
            # Multiplies `fuel use` (*l*) by the `n2o emission factor` (*kg CO<sub>2</sub>e / l*) to give *kg CO<sub>2</sub>e*.
            characteristics[:fuel_use] * characteristics[:n2o_emission_factor]
          else
            # If the `date` does not fall within the `timeframe`, `n2o emission` is zero.
            0
          end
      end
    end
    
    ### HFC emission calculation
    # Returns the `hfc emission` (*kg CO<sub>2</sub>e*).
    committee :hfc_emission do
      #### HFC emission from fuel use, HFC emission factor, date, and timeframe
      quorum 'from fuel use, hfc emission factor, date, and timeframe',
        :needs => [:fuel_use, :hfc_emission_factor, :date],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
          # Checks whether the trip `date` falls within the `timeframe`.
          date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
          if timeframe.include? date
            # Multiplies `fuel use` (*l*) by the `hfc emission factor` (*kg CO<sub>2</sub>e / l*) to give *kg CO<sub>2</sub>e*.
            characteristics[:fuel_use] * characteristics[:hfc_emission_factor]
          else
            # If the `date` does not fall within the `timeframe`, `hfc emission` is zero.
            0
          end
      end
    end
    
    ### CO<sub>2</sub> emission factor calculation
    # Returns the `co2 emission factor` (*kg / l*).
    committee :co2_emission_factor do
      #### CO<sub>2</sub> emission factor from automobile fuel
      quorum 'from automobile fuel',
        :needs => :automobile_fuel,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [fuel](http://data.brighterplanet.com/fuels) `co2 emission factor` (*kg / l*).
          characteristics[:automobile_fuel].co2_emission_factor
      end
    end
    
    ### CO<sub>2</sub> biogenic emission factor calculation
    # Returns the `co2 biogenic emission factor` (*kg / l*).
    committee :co2_biogenic_emission_factor do
      #### CO<sub>2</sub> biogenic emission factor from automobile fuel
      quorum 'from automobile fuel',
        :needs => :automobile_fuel,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [fuel](http://data.brighterplanet.com/fuels) `co2 biogenic emission factor` (*kg / l*).
          characteristics[:automobile_fuel].co2_biogenic_emission_factor
      end
    end
    
    ### CH<sub>4</sub> emission factor calculation
    # Returns the `ch4 emission factor` (*kg CO<sub>2</sub>e / l*).
    committee :ch4_emission_factor do
      #### CH<sub>4</sub> emission factor from automobile fuel
      quorum 'from automobile fuel',
        :needs => :automobile_fuel,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [fuel](http://data.brighterplanet.com/fuels) `ch4 emission factor` (*kg CO</sub>2</sub>e / l*).
          characteristics[:automobile_fuel].ch4_emission_factor
      end
    end
    
    ### N<sub>2</sub>O emission factor calculation
    # Returns the `n2o emission factor` (*kg CO<sub>2</sub>e / l*).
    committee :n2o_emission_factor do
      #### N<sub>2</sub>O emission factor from automobile fuel
      quorum 'from automobile fuel',
        :needs => :automobile_fuel,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [fuel](http://data.brighterplanet.com/fuels) `n2o emission factor` (*kg CO</sub>2</sub>e / l*).
          characteristics[:automobile_fuel].n2o_emission_factor
      end
    end
    
    ### HFC emission factor calculation
    # Returns the `hfc emission factor` (*kg CO<sub>2</sub>e / l*).
    committee :hfc_emission_factor do
      #### HFC emission factor from automobile fuel
      quorum 'from automobile fuel',
        :needs => :automobile_fuel,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [fuel](http://data.brighterplanet.com/fuels) `hfc emission factor` (*kg CO</sub>2</sub>e / l*).
          characteristics[:automobile_fuel].hfc_emission_factor
      end
    end
    
    ### Automobile fuel calculation
    # Returns the type of `automobile fuel` used.
    committee :automobile_fuel do
      #### Automobile fuel from client input
      # **Complies:** All
      #
      # Uses the client-input [automobile fuel](http://data.brighterplanet.com/automobile_fuels).
      
      #### Automobile fuel from make model year variant
      quorum 'from make model year variant',
        :needs => :make_model_year_variant,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [variant](http://data.brighterplanet.com/automobile_make_model_year_variants) `automobile fuel`.
          characteristics[:make_model_year_variant].fuel
      end
      
      #### Default automobile fuel
      quorum 'default',
        # **Complies:** GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_3, :iso] do
          # Looks up the default [automobile fuel](http://data.brighterplanet.com/automobile_fuels).
          AutomobileFuel.fallback
      end
    end
    
    ### Fuel use calculation
    # Returns the trip `fuel use` (*l*).
    committee :fuel_use do
      #### Fuel use from fuel efficiency and distance
      quorum 'from fuel efficiency and distance',
        :needs => [:fuel_efficiency, :distance],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Divides the `distance` (*km*) by the `fuel efficiency` (*km / l*) to give *l*.
          characteristics[:distance] / characteristics[:fuel_efficiency]
      end
    end
    
    ### Distance calculation
    # Returns the trip `distance` (*km*).
    committee :distance do
      #### Distance from client input
      # **Complies:** All
      #
      # Uses the client-input `distance` (*km*).
      
      #### Distance from origin and destination locations
      quorum 'from origin and destination locations',
        :needs => [:origin_location, :destination_location, :mapquest_api_key],
        # **Complies:** GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
          # Uses the [Mapquest directions API](http://developer.mapquest.com/web/products/dev-services/directions-ws) to calculate distance by road between the origin and destination locations.
          mapquest = MapQuestDirections.new characteristics[:origin_location],
                                            characteristics[:destination_location],
                                            characteristics[:mapquest_api_key]
          begin
            mapquest.distance_in_kilometres
          rescue
            nil
          end
      end
      
      #### Distance from duration and speed
      quorum 'from duration and speed',
        :needs => [:duration, :speed],
        # **Complies:** GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
          # Divides the `duration` (*minutes*) by 60 and multiplies by the `speed` (*km / hour*) to give *km*.
          (characteristics[:duration] / 60.0) * characteristics[:speed]
      end
      
      #### Distance from country
      quorum 'from country',
        :needs => :country,
        # **Complies:** GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [country](http://data.brighterplanet.com/countries) `automobile trip distance`.
          characteristics[:country].automobile_trip_distance
      end
    end
    
    ### Destination location calculation
    # Returns the `destination location` (*lat / lng*).
    committee :destination_location do
      #### Destination location from destination
      quorum 'from destination',
        :needs => :destination,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Uses the [Geokit](http://geokit.rubyforge.org/) geocoder to determine the destination location (*lat / lng*).
          code = Geokit::Geocoders::MultiGeocoder.geocode characteristics[:destination].to_s
          code.ll == ',' ? nil : code.ll
      end
    end
    
    ### Origin location committee
    # Returns the `origin location` (*lat / lng*).
    committee :origin_location do
      #### Destination location from destination
      quorum 'from origin',
        :needs => :origin,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Uses the [Geokit](http://geokit.rubyforge.org/) geocoder to determine the origin location (*lat / lng*).
          code = Geokit::Geocoders::MultiGeocoder.geocode characteristics[:origin].to_s
          code.ll == ',' ? nil : code.ll
      end
    end
    
    ### Destination calculation
    # Returns the client-input `destination`.
    
    ### Origin calculation
    # Returns the client-input `origin`.
    
    ### Duration calculation
    # Returns the client-input `duration` (*minutes*).
    
    ### Speed calculation
    # Returns the average `speed` at which the automobile travels (*km / hour*).
    committee :speed do
      #### Speed from client input
      # **Complies:** All
      #
      # Uses the client-input `speed` (*km / hour*).
      
      #### Speed from urbanity and country
      quorum 'from urbanity and country',
        :needs => [:urbanity, :country],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [country](http://data.brighterplanet.com/countries) average city and highway driving speeds and calculates the harmonic mean of those speeds weighted by `urbanity`.
          1 / (characteristics[:urbanity] / characteristics[:country].automobile_city_speed + (1 - characteristics[:urbanity]) / characteristics[:country].automobile_highway_speed)
      end
    end
    
    ### Fuel efficiency calculation
    # Returns the `fuel efficiency` (*km / l*).
    committee :fuel_efficiency do
      #### Fuel efficiency from client input
      # **Complies:** All
      #
      # Uses the client-input `fuel efficiency` (*km / l*).
      
      #### Fuel efficiency from make model year variant and urbanity
      quorum 'from make model year variant and urbanity',
        :needs => [:make_model_year_variant, :urbanity],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the city and highway fuel efficiencies of the automobile [make model year variant](http://data.brighterplanet.com/automobile_make_model_year_variants) (*km / l*).
          fuel_efficiency_city = characteristics[:make_model_year_variant].fuel_efficiency_city
          fuel_efficiency_highway = characteristics[:make_model_year_variant].fuel_efficiency_highway
          urbanity = characteristics[:urbanity]
          if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
            # Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`.
            1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
          end
      end
      
      #### Fuel efficiency from make model year and urbanity
      quorum 'from make model year and urbanity',
        :needs => [:make_model_year, :urbanity],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the city and highway fuel efficiencies of the automobile [make model year](http://data.brighterplanet.com/automobile_make_model_years) (*km / l*).
          fuel_efficiency_city = characteristics[:make_model_year].fuel_efficiency_city
          fuel_efficiency_highway = characteristics[:make_model_year].fuel_efficiency_highway
          urbanity = characteristics[:urbanity]
          if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
            # Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`.
            1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
          end
      end
      
      #### Fuel efficiency from make model and urbanity
      quorum 'from make model and urbanity',
        :needs => [:make_model, :urbanity],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the city and highway fuel efficiencies of the automobile [make model](http://data.brighterplanet.com/automobile_make_models) (*km / l*).
          fuel_efficiency_city = characteristics[:make_model].fuel_efficiency_city
          fuel_efficiency_highway = characteristics[:make_model].fuel_efficiency_highway
          urbanity = characteristics[:urbanity]
          if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
            # Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`.
            1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
          end
      end
      
      #### Fuel efficiency from size class, hybridity multiplier, and urbanity
      quorum 'from size class, hybridity multiplier, and urbanity',
        :needs => [:size_class, :hybridity_multiplier, :urbanity],
        # **Complies:** GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the automobile [size class](http://data.brighterplanet.com/automobile_makes) city and highway fuel efficiency (*km / l*).
          fuel_efficiency_city = characteristics[:size_class].fuel_efficiency_city
          fuel_efficiency_highway = characteristics[:size_class].fuel_efficiency_highway
          urbanity = characteristics[:urbanity]
          if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
            # Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`, and multiplies the result by the `hybridity multiplier`.
            (1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))) * characteristics[:hybridity_multiplier]
          end
      end
      
      #### Fuel efficiency from make year and hybridity multiplier
      quorum 'from make year and hybridity multiplier',
        :needs => [:make_year, :hybridity_multiplier],
        # **Complies:** GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the automobile [make year](http://data.brighterplanet.com/automobile_make_years) combined fuel efficiency (*km / l*) and multiplies it by the `hybridity multiplier`.
          characteristics[:make_year].fuel_efficiency * characteristics[:hybridity_multiplier]
      end
      
      #### Fuel efficiency from make and hybridity multiplier
      quorum 'from make and hybridity multiplier',
        :needs => [:make, :hybridity_multiplier],
        # **Complies:** GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the automobile [make](http://data.brighterplanet.com/automobile_makes) combined fuel efficiency (*km / l*) and multiplies it by the `hybridity multiplier`.
          if characteristics[:make].fuel_efficiency.present?
            characteristics[:make].fuel_efficiency * characteristics[:hybridity_multiplier]
          else
            nil
          end
      end
      
      #### Fuel efficiency from hybridity multiplier and country
      quorum 'from hybridity multiplier and country',
        :needs => [:hybridity_multiplier, :country],
        # **Complies:** GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [country](http://data.brighterplanet.com/countries) `automobile fuel efficiency` and multiplies it by the `hybridity multiplier`.
          characteristics[:country].automobile_fuel_efficiency * characteristics[:hybridity_multiplier]
      end
    end
    
    ### Hybridity multiplier calculation
    # Returns the `hybridity multiplier`.
    # This value may be used to adjust the fuel efficiency based on whether the automobile is a hybrid or conventional vehicle.
    committee :hybridity_multiplier do
      #### Hybridity multiplier from size class, hybridity, and urbanity
      quorum 'from size class, hybridity, and urbanity', 
        :needs => [:size_class, :hybridity, :urbanity],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the appropriate city and highway hybridity multipliers for the automobile [size class](http://data.brighterplanet.com/automobile_size_classes).
          drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
          urbanity = characteristics[:urbanity]
          size_class = characteristics[:size_class]
          fuel_efficiency_multipliers = {
            :city => size_class.send(:"#{drivetrain}_fuel_efficiency_city_multiplier"),
            :highway => size_class.send(:"#{drivetrain}_fuel_efficiency_highway_multiplier")
          }
          if fuel_efficiency_multipliers.values.any?(&:present?)
            # Calculates the harmonic mean of those multipliers, weighted by `urbanity`.
            1.0 / ((urbanity / fuel_efficiency_multipliers[:city]) + ((1.0 - urbanity) / fuel_efficiency_multipliers[:highway]))
          else
            nil
          end
      end
      
      #### Hybridity multiplier from hybridity and urbanity
      quorum 'from hybridity and urbanity',
        :needs => [:hybridity, :urbanity],
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the appropriate default city and highway hybridity multipliers.
          drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
          urbanity = characteristics[:urbanity]
          fuel_efficiency_multipliers = {
            :city => AutomobileSizeClass.fallback.send(:"#{drivetrain}_fuel_efficiency_city_multiplier"),
            :highway => AutomobileSizeClass.fallback.send(:"#{drivetrain}_fuel_efficiency_highway_multiplier")
          }
          # Calculates the harmonic mean of those multipliers, weighted by `urbanity`.
          1.0 / ((urbanity / fuel_efficiency_multipliers[:city]) + ((1.0 - urbanity) / fuel_efficiency_multipliers[:highway]))
      end
      
      #### Default hybridity multiplier
      quorum 'default',
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do
          # Uses a default `hybridity multiplier` of 1.
          base.fallback.hybridity_multiplier
      end
    end
    
    ### Urbanity calculation
    # Returns the `urbanity`.
    # This is the fraction of the total distance driven that occurs on towns and city streets as opposed to highways (defined using a 45 miles per hour "speed cutpoint").
    committee :urbanity do
      #### Urbanity from urbanity estimate
      quorum 'from urbanity estimate',
        :needs => :urbanity_estimate,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Uses the `urbanity estimate` if it is from zero to one.
          if characteristics[:urbanity_estimate] >= 0 and characteristics[:urbanity_estimate] <= 1
            characteristics[:urbanity_estimate]
          end
      end
      
      #### Urbanity from country
      quorum 'from country',
        :needs => :country,
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
          # Looks up the [country](http://data.brighterplanet.com/countries) `automobile urbanity`.
          characteristics[:country].automobile_urbanity
      end
    end
    
    ### Urbanity estimate calculation
    # Returns the client-input `urbanity estimate`. This is the fraction of the total distance driven that occurs on towns and city streets as opposed to highways (defined using a 45 miles per hour "speed cutpoint").
    
    ### Hybridity calculation
    # Returns the client-input `hybridity`. This indicates whether the automobile is a hybrid electric vehicle or a conventional vehicle.
    
    ### Size class calculation
    # Returns the client-input automobile [size class](http://data.brighterplanet.com/automobile_size_classes).
    
    ### Make model year variant calculation
    # Returns the client-input automobile [make model year variant](http://data.brighterplanet.com/automobile_make_model_year_variants).
    
    ### Make model year calculation
    # Returns the client-input automobile [make model year](http://data.brighterplanet.com/automobile_make_model_years).
    
    ### Make model calculation
    # Returns the client-input automobile [make model](http://data.brighterplanet.com/automobile_make_models).
    
    ### Make year calculation
    # Returns the client-input automobile [make year](http://data.brighterplanet.com/automobile_make_years).
    
    ### Make calculation
    # Returns the client-input automobile [make](http://data.brighterplanet.com/automobile_makes).
    
    ### Country calculation
    # Returns the `country` in which the trip occurred.
    committee :country do
      #### Country from client input
      # **Complies:** All
      #
      # Uses the client-input `country`.
      
      #### Default country
      quorum 'default',
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do
          # Uses an artificial country that contains global averages.
          Country.fallback
      end
    end
    
    ### Date calculation
    # Returns the `date` on which the trip occurred.
    committee :date do
      #### Date from client input
      # **Complies:** All
      #
      # Uses the client-input `date`.
      
      #### Date from timeframe
      quorum 'from timeframe',
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO-14064-1, Climate Registry Protocol
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso, :tcr] do |characteristics, timeframe|
          # Assumes the trip occurred on the first day of the `timeframe`.
          timeframe.from
      end
    end
    
    ### Timeframe calculation
    # Returns the `timeframe`.
    # This is the period during which to calculate emissions.
      
      #### Timeframe from client input
      # **Complies:** All
      #
      # Uses the client-input `timeframe`.
      
      #### Default timeframe
      # **Complies:** All
      #
      # Uses the current calendar year.
    
    ### Mapquest API key lookup
    # Returns Brighter Planet's Mapquest API key
    committee :mapquest_api_key do
      #### Default Mapquest API key
      quorum 'default',
        # **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
        :complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do
          # Uses Brighter Planet's Mapquest API key.
          ENV['MAPQUEST_API_KEY']
      end
    end
  end
end