automobile_trip 0.0.9 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +200 -0
- data/LICENSE-PREAMBLE +52 -0
- data/Rakefile +71 -0
- data/VERSION +1 -0
- data/automobile_trip.gemspec +27 -0
- data/dot.rvmrc +9 -0
- data/features/automobile_trip_committees.feature +415 -16
- data/features/automobile_trip_emissions.feature +142 -12
- data/features/step_definitions/automobile_trip_steps.rb +15 -0
- data/features/step_definitions/mapquest_steps.rb +5 -0
- data/features/support/env.rb +7 -1
- data/lib/automobile_trip.rb +1 -0
- data/lib/automobile_trip/carbon_model.rb +570 -13
- data/lib/automobile_trip/characterization.rb +20 -1
- data/lib/automobile_trip/data.rb +21 -4
- data/lib/automobile_trip/fallback.rb +6 -2
- data/lib/automobile_trip/relationships.rb +7 -1
- data/lib/automobile_trip/version.rb +5 -0
- data/lib/test_support/db/fixtures/automobile_fuels.csv +4 -0
- data/lib/test_support/db/fixtures/automobile_make_model_year_variants.csv +2 -0
- data/lib/test_support/db/fixtures/automobile_make_model_years.csv +2 -0
- data/lib/test_support/db/fixtures/automobile_make_models.csv +2 -0
- data/lib/test_support/db/fixtures/automobile_make_years.csv +2 -0
- data/lib/test_support/db/fixtures/automobile_makes.csv +2 -0
- data/lib/test_support/db/fixtures/automobile_size_classes.csv +3 -0
- data/lib/test_support/db/fixtures/automobile_type_fuel_years.csv +5 -0
- data/lib/test_support/db/fixtures/automobile_type_years.csv +3 -0
- data/lib/test_support/db/fixtures/fuel_years.csv +2 -0
- data/lib/test_support/db/fixtures/fuels.csv +4 -0
- data/lib/test_support/db/fixtures/greenhouse_gases.csv +3 -0
- data/vendor/plugin/mapquest/README.textile +70 -0
- data/vendor/plugin/mapquest/Rakefile +15 -0
- data/vendor/plugin/mapquest/init.rb +1 -0
- data/vendor/plugin/mapquest/lib/mapquest_directions.rb +56 -0
- data/vendor/plugin/mapquest/spec/lib/mapquest_directions.xml +2 -0
- data/vendor/plugin/mapquest/spec/lib/mapquest_directions_fail.xml +2 -0
- data/vendor/plugin/mapquest/spec/lib/mapquest_directions_spec.rb +58 -0
- data/vendor/plugin/mapquest/spec/spec_helper.rb +13 -0
- metadata +55 -121
- data/lib/automobile_trip/committee_structure.rb +0 -65
@@ -1,23 +1,153 @@
|
|
1
1
|
Feature: Automobile Trip Emissions Calculations
|
2
2
|
The automobile trip model should generate correct emission calculations
|
3
3
|
|
4
|
-
Scenario: Calculations
|
4
|
+
Scenario: Calculations from nothing
|
5
5
|
Given an automobile_trip has nothing
|
6
6
|
When emissions are calculated
|
7
|
-
Then the emission value should be within "0.
|
7
|
+
Then the emission value should be within "0.01" kgs of "4.62"
|
8
8
|
|
9
|
-
Scenario: Calculations
|
10
|
-
Given an automobile_trip has "
|
9
|
+
Scenario Outline: Calculations from date
|
10
|
+
Given an automobile_trip has "date" of "<date>"
|
11
|
+
And it is the year "2010"
|
11
12
|
When emissions are calculated
|
12
|
-
Then the emission value should be within "0.
|
13
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
14
|
+
Examples:
|
15
|
+
| date | emission |
|
16
|
+
| 2009-06-25 | 0.0 |
|
17
|
+
| 2010-06-25 | 4.62 |
|
18
|
+
| 2011-06-25 | 0.0 |
|
13
19
|
|
14
|
-
Scenario: Calculations
|
15
|
-
Given an automobile_trip has "
|
20
|
+
Scenario Outline: Calculations from date and timeframe
|
21
|
+
Given an automobile_trip has "date" of "<date>"
|
22
|
+
And it has "timeframe" of "<timeframe>"
|
16
23
|
When emissions are calculated
|
17
|
-
Then the emission value should be within "0.
|
24
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
25
|
+
Examples:
|
26
|
+
| date | timeframe | emission |
|
27
|
+
| 2009-06-25 | 2009-01-01/2009-01-31 | 0.0 |
|
28
|
+
| 2009-06-25 | 2009-01-01/2009-12-31 | 4.62 |
|
29
|
+
| 2009-06-25 | 2009-12-01/2009-12-31 | 0.0 |
|
18
30
|
|
19
|
-
Scenario: Calculations
|
20
|
-
Given an automobile_trip has "
|
21
|
-
And it has "fuel_use" of "100"
|
31
|
+
Scenario: Calculations from urbanity estimate
|
32
|
+
Given an automobile_trip has "urbanity_estimate" of "0.5"
|
22
33
|
When emissions are calculated
|
23
|
-
Then the emission value should be within "0.
|
34
|
+
Then the emission value should be within "0.01" kgs of "4.62"
|
35
|
+
|
36
|
+
Scenario Outline: Calculations from hybridity and urbanity estimate
|
37
|
+
Given an automobile_trip has "hybridity" of "<hybridity>"
|
38
|
+
And it has "urbanity_estimate" of "0.5"
|
39
|
+
When emissions are calculated
|
40
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
41
|
+
Examples:
|
42
|
+
| hybridity | emission |
|
43
|
+
| true | 3.30 |
|
44
|
+
| false | 4.66 |
|
45
|
+
|
46
|
+
Scenario: Calculations from make and urbanity estimate
|
47
|
+
Given an automobile_trip has "urbanity_estimate" of "0.5"
|
48
|
+
And it has "make.name" of "Toyota"
|
49
|
+
When emissions are calculated
|
50
|
+
Then the emission value should be within "0.01" kgs of "3.96"
|
51
|
+
|
52
|
+
Scenario Outline: Calculations from make, hybridity and urbanity estimate
|
53
|
+
Given an automobile_trip has "hybridity" of "<hybridity>"
|
54
|
+
And it has "urbanity_estimate" of "0.5"
|
55
|
+
And it has "make.name" of "Toyota"
|
56
|
+
When emissions are calculated
|
57
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
58
|
+
Examples:
|
59
|
+
| hybridity | emission |
|
60
|
+
| true | 2.83 |
|
61
|
+
| false | 4.00 |
|
62
|
+
|
63
|
+
Scenario: Calculations from make year and urbanity estimate
|
64
|
+
Given an automobile_trip has "urbanity_estimate" of "0.5"
|
65
|
+
And it has "make_year.name" of "Toyota 2003"
|
66
|
+
When emissions are calculated
|
67
|
+
Then the emission value should be within "0.01" kgs of "2.64"
|
68
|
+
|
69
|
+
Scenario Outline: Calculations from make year, hybridity and urbanity estimate
|
70
|
+
Given an automobile_trip has "hybridity" of "<hybridity>"
|
71
|
+
And it has "urbanity_estimate" of "0.5"
|
72
|
+
And it has "make_year.name" of "Toyota 2003"
|
73
|
+
When emissions are calculated
|
74
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
75
|
+
Examples:
|
76
|
+
| hybridity | emission |
|
77
|
+
| true | 1.89 |
|
78
|
+
| false | 2.66 |
|
79
|
+
|
80
|
+
Scenario: Calculations from size class and urbanity estimate
|
81
|
+
Given an automobile_trip has "urbanity_estimate" of "0.5"
|
82
|
+
And it has "size_class.name" of "Midsize Car"
|
83
|
+
When emissions are calculated
|
84
|
+
Then the emission value should be within "0.01" kgs of "2.97"
|
85
|
+
|
86
|
+
Scenario Outline: Calculations from size class, hybridity, and urbanity estimate
|
87
|
+
Given an automobile_trip has "hybridity" of "<hybridity>"
|
88
|
+
And it has "urbanity_estimate" of "0.5"
|
89
|
+
And it has "size_class.name" of "Midsize Car"
|
90
|
+
When emissions are calculated
|
91
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
92
|
+
Examples:
|
93
|
+
| hybridity | emission |
|
94
|
+
| true | 1.73 |
|
95
|
+
| false | 3.47 |
|
96
|
+
|
97
|
+
Scenario: Calculations from make model and urbanity estimate
|
98
|
+
Given an automobile_trip has "urbanity_estimate" of "0.5"
|
99
|
+
And it has "make_model.name" of "Toyota Prius"
|
100
|
+
When emissions are calculated
|
101
|
+
Then the emission value should be within "0.01" kgs of "1.65"
|
102
|
+
|
103
|
+
Scenario: Calculations from make model year and urbanity estimate
|
104
|
+
Given an automobile_trip has "urbanity_estimate" of "0.5"
|
105
|
+
And it has "make_model_year.name" of "Toyota Prius 2003"
|
106
|
+
When emissions are calculated
|
107
|
+
Then the emission value should be within "0.01" kgs of "1.16"
|
108
|
+
|
109
|
+
Scenario: Calculations from make model year variant and urbanity estimate
|
110
|
+
Given an automobile_trip has "urbanity_estimate" of "0.5"
|
111
|
+
And it has "make_model_year_variant.row_hash" of "xxx1"
|
112
|
+
When emissions are calculated
|
113
|
+
Then the emission value should be within "0.01" kgs of "0.89"
|
114
|
+
|
115
|
+
Scenario: Calculations from speed and duration
|
116
|
+
Given an automobile_trip has "speed" of "5.0"
|
117
|
+
And it has "duration" of "120.0"
|
118
|
+
When emissions are calculated
|
119
|
+
Then the emission value should be within "0.01" kgs of "2.83"
|
120
|
+
|
121
|
+
Scenario: Calculations from driveable locations
|
122
|
+
Given an automobile_trip has "origin" of "43,-73"
|
123
|
+
And the geocoder will encode the origin as "43,-73"
|
124
|
+
And it has "destination" of "43.1,-73"
|
125
|
+
And the geocoder will encode the destination as "43.1,-73"
|
126
|
+
And mapquest will return a distance of "57.93638" kilometres
|
127
|
+
When emissions are calculated
|
128
|
+
Then the emission value should be within "0.01" kgs of "16.38"
|
129
|
+
|
130
|
+
Scenario: Calculations from non-driveable locations
|
131
|
+
Given an automobile_trip has "origin" of "Lansing, MI"
|
132
|
+
And the geocoder will encode the origin as "42.732535,-84.5555347"
|
133
|
+
And it has "destination" of "Canterbury, Kent, UK"
|
134
|
+
And the geocoder will encode the destination as "51.2772689,1.0805173"
|
135
|
+
When emissions are calculated
|
136
|
+
Then the emission value should be within "0.01" kgs of "4.62"
|
137
|
+
|
138
|
+
Scenario: Calculations from fuel efficiency and distance
|
139
|
+
Given an automobile_trip has "fuel_efficiency" of "10.0"
|
140
|
+
And it has "distance" of "100.0"
|
141
|
+
When emissions are calculated
|
142
|
+
Then the emission value should be within "0.01" kgs of "24.25"
|
143
|
+
|
144
|
+
Scenario Outline: Calculations from fuel use and fuel
|
145
|
+
Given an automobile_trip has "fuel_use" of "20.0"
|
146
|
+
And it has "automobile_fuel.name" of "<fuel>"
|
147
|
+
When emissions are calculated
|
148
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
149
|
+
Examples:
|
150
|
+
| fuel | emission |
|
151
|
+
| regular gasoline | 48.31 |
|
152
|
+
| diesel | 56.52 |
|
153
|
+
| B20 | 45.72 |
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Given /^mapquest determines the distance to be "([^\"]*)"$/ do |distance|
|
2
|
+
mockquest = mock MapQuestDirections, :distance_in_kilometres => distance
|
3
|
+
MapQuestDirections.stub!(:new).and_return mockquest
|
4
|
+
end
|
5
|
+
|
6
|
+
Given /^the geocoder will encode the (.*) as "(.*)"$/ do |component, location|
|
7
|
+
@expectations << lambda do
|
8
|
+
components = @characteristics ? @characteristics : @activity_hash
|
9
|
+
component_value = components[component.to_sym].to_s
|
10
|
+
code = mock Object, :ll => location
|
11
|
+
Geokit::Geocoders::MultiGeocoder.should_receive(:geocode).
|
12
|
+
with(component_value).
|
13
|
+
and_return code
|
14
|
+
end
|
15
|
+
end
|
data/features/support/env.rb
CHANGED
@@ -3,6 +3,12 @@ Bundler.setup
|
|
3
3
|
|
4
4
|
require 'cucumber'
|
5
5
|
require 'cucumber/formatter/unicode'
|
6
|
+
require 'rspec'
|
7
|
+
require 'rspec/expectations'
|
8
|
+
require 'cucumber/rspec/doubles'
|
9
|
+
|
10
|
+
require 'data_miner'
|
11
|
+
DataMiner.logger = Logger.new(nil)
|
6
12
|
|
7
13
|
require 'sniff'
|
8
|
-
Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :
|
14
|
+
Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :cucumber => true, :earth => [:automobile, :fuel]
|
data/lib/automobile_trip.rb
CHANGED
@@ -3,5 +3,6 @@ require 'emitter'
|
|
3
3
|
module BrighterPlanet
|
4
4
|
module AutomobileTrip
|
5
5
|
extend BrighterPlanet::Emitter
|
6
|
+
scope 'The automobile trip emission estimate includes CO2 emissions from non-biogenic fuel use, CH4 and N2O emissions from all fuel use, and fugitive HFC emissions from air conditioning.'
|
6
7
|
end
|
7
8
|
end
|
@@ -2,39 +2,596 @@
|
|
2
2
|
# See LICENSE for details.
|
3
3
|
# Contact Brighter Planet for dual-license arrangements.
|
4
4
|
|
5
|
+
require File.expand_path('../../vendor/plugin/mapquest/lib/mapquest_directions', File.dirname(__FILE__))
|
6
|
+
require 'geokit'
|
5
7
|
|
8
|
+
## Automobile trip carbon model
|
9
|
+
# This model is used by [Brighter Planet](http://brighterplanet.com)'s carbon emission [web service](http://carbon.brighterplanet.com) to estimate the **greenhouse gas emissions of an automobile trip**.
|
10
|
+
#
|
11
|
+
##### Timeframe and activity period
|
12
|
+
# The model estimates the emissions that occur during a particular `timeframe`. To do this it needs to know the `date` on which the trip occurred. For example, if the `timeframe` is January 2010, a trip that occurred on January 5, 2010 will have emissions but a trip that occurred on February 1, 2010 will not.
|
13
|
+
#
|
14
|
+
##### Calculations
|
15
|
+
# The final estimate is the result of the **calculations** detailed below. These calculations are performed in reverse order, starting with the last calculation listed and finishing with the `emission` calculation. Each calculation is named according to the value it returns.
|
16
|
+
#
|
17
|
+
##### Methods
|
18
|
+
# To accomodate varying client input, each calculation may have one or more **methods**. These are listed under each calculation in order from most to least preferred. Each method is named according to the values it requires. If any of these values is not available the method will be ignored. If all the methods for a calculation are ignored, the calculation will not return a value. "Default" methods do not require any values, and so a calculation with a default method will always return a value.
|
19
|
+
#
|
20
|
+
##### Standard compliance
|
21
|
+
# Each method lists any established calculation standards with which it **complies**. When compliance with a standard is requested, all methods that do not comply with that standard are ignored. This means that any values a particular method requires will have been calculated using a compliant method, because those are the only methods available. If any value did not have a compliant method in its calculation then it would be undefined, and the current method would have been ignored.
|
22
|
+
#
|
23
|
+
##### Collaboration
|
24
|
+
# Contributions to this carbon model are actively encouraged and warmly welcomed. This library includes a comprehensive test suite to ensure that your changes do not cause regressions. All changes should include test coverage for new functionality. Please see [sniff](http://github.com/brighterplanet/sniff#readme), our emitter testing framework, for more information.
|
6
25
|
module BrighterPlanet
|
7
26
|
module AutomobileTrip
|
8
27
|
module CarbonModel
|
9
28
|
def self.included(base)
|
10
29
|
base.decide :emission, :with => :characteristics do
|
11
|
-
|
12
|
-
|
13
|
-
|
30
|
+
### Emission calculation
|
31
|
+
# Returns the `emission` estimate (*kg CO<sub>2</sub>e*).
|
32
|
+
committee :emission do
|
33
|
+
#### Emission from co2 emission, ch4 emission, n2o emission, and hfc emission
|
34
|
+
quorum 'from co2 emission, ch4 emission, n2o emission, and hfc emission',
|
35
|
+
:needs => [:co2_emission, :ch4_emission, :n2o_emission, :hfc_emission],
|
36
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
37
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
38
|
+
# Sums the non-biogenic emissions
|
39
|
+
characteristics[:co2_emission] + characteristics[:ch4_emission] + characteristics[:n2o_emission] + characteristics[:hfc_emission]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
### CO<sub>2</sub> emission calculation
|
44
|
+
# Returns the `co2 emission` (*kg CO<sub>2</sub>e*)
|
45
|
+
committee :co2_emission do
|
46
|
+
#### CO<sub>2</sub> emission from fuel use, co2 emission factor, date, and timeframe
|
47
|
+
quorum 'from fuel use, co2 emission factor, date, and timeframe',
|
48
|
+
:needs => [:fuel_use, :co2_emission_factor, :date],
|
49
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
50
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
51
|
+
# - Checks whether the trip `date` falls within the `timeframe`
|
52
|
+
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
53
|
+
if timeframe.include? date
|
54
|
+
# - Multiplies `fuel use` (*l*) by the `co2 emission factor` (*kg CO<sub>2</sub>e / l*) to give *kg CO<sub>2</sub>e*
|
55
|
+
characteristics[:fuel_use] * characteristics[:co2_emission_factor]
|
56
|
+
else
|
57
|
+
# - If the `date` does not fall within the `timeframe`, `co2 emission` is zero
|
58
|
+
0
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
### CO<sub>2</sub> biogenic emission calculation
|
64
|
+
# Returns the `co2 biogenic emission` (*kg CO<sub>2</sub>e*)
|
65
|
+
committee :co2_biogenic_emission do
|
66
|
+
#### CO<sub>2</sub> biogenic emission from fuel use, co2 biogenic emission factor, date, and timeframe
|
67
|
+
quorum 'from fuel use, co2 biogenic emission factor, date, and timeframe',
|
68
|
+
:needs => [:fuel_use, :co2_biogenic_emission_factor, :date],
|
69
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
70
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
71
|
+
# - Checks whether the trip `date` falls within the `timeframe`
|
72
|
+
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
73
|
+
if timeframe.include? date
|
74
|
+
# - Multiplies `fuel use` (*l*) by the `co2 biogenic emission factor` (*kg CO<sub>2</sub>e / l*) to give *kg CO<sub>2</sub>e*
|
75
|
+
characteristics[:fuel_use] * characteristics[:co2_biogenic_emission_factor]
|
76
|
+
else
|
77
|
+
# - If the `date` does not fall within the `timeframe`, `co2 biogenic emission` is zero
|
78
|
+
0
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
### CH<sub>4</sub> emission calculation
|
84
|
+
# Returns the `ch4 emission` (*kg CO<sub>2</sub>e*)
|
85
|
+
committee :ch4_emission do
|
86
|
+
#### CH<sub>4</sub> emission from fuel use, ch4 emission factor, date, and timeframe
|
87
|
+
quorum 'from fuel use, ch4 emission factor, date, and timeframe',
|
88
|
+
:needs => [:fuel_use, :ch4_emission_factor, :date],
|
89
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
90
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
91
|
+
# - Checks whether the trip `date` falls within the `timeframe`
|
92
|
+
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
93
|
+
if timeframe.include? date
|
94
|
+
# - Multiplies `fuel use` (*l*) by the `ch4 emission factor` (*kg CO<sub>2</sub>e / l*) to give *kg CO<sub>2</sub>e*
|
95
|
+
characteristics[:fuel_use] * characteristics[:ch4_emission_factor]
|
96
|
+
else
|
97
|
+
# - If the `date` does not fall within the `timeframe`, `ch4 emission` is zero
|
98
|
+
0
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
### N<sub>2</sub>O emission calculation
|
104
|
+
# Returns the `n2o emission` (*kg CO<sub>2</sub>e*)
|
105
|
+
committee :n2o_emission do
|
106
|
+
#### N<sub>2</sub>O emission from fuel use, n2o emission factor, date, and timeframe
|
107
|
+
quorum 'from fuel use, n2o emission factor, date, and timeframe',
|
108
|
+
:needs => [:fuel_use, :n2o_emission_factor, :date],
|
109
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
110
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
111
|
+
# - Checks whether the trip `date` falls within the `timeframe`
|
112
|
+
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
113
|
+
if timeframe.include? date
|
114
|
+
# - Multiplies `fuel use` (*l*) by the `n2o emission factor` (*kg CO<sub>2</sub>e / l*) to give *kg CO<sub>2</sub>e*
|
115
|
+
characteristics[:fuel_use] * characteristics[:n2o_emission_factor]
|
116
|
+
else
|
117
|
+
# - If the `date` does not fall within the `timeframe`, `n2o emission` is zero
|
118
|
+
0
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
### HFC emission calculation
|
124
|
+
# Returns the `hfc emission` (*kg CO<sub>2</sub>e*)
|
125
|
+
committee :hfc_emission do
|
126
|
+
#### HFC emission from fuel use, hfc emission factor, date, and timeframe
|
127
|
+
quorum 'from fuel use, hfc emission factor, date, and timeframe',
|
128
|
+
:needs => [:fuel_use, :hfc_emission_factor, :date],
|
129
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
130
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
131
|
+
# - Checks whether the trip `date` falls within the `timeframe`
|
132
|
+
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
133
|
+
if timeframe.include? date
|
134
|
+
# - Multiplies `fuel use` (*l*) by the `hfc emission factor` (*kg CO<sub>2</sub>e / l*) to give *kg CO<sub>2</sub>e*
|
135
|
+
characteristics[:fuel_use] * characteristics[:hfc_emission_factor]
|
136
|
+
else
|
137
|
+
# - If the `date` does not fall within the `timeframe`, `hfc emission` is zero
|
138
|
+
0
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
### CO<sub>2</sub> emission factor calculation
|
144
|
+
# Returns the `co2 emission factor` (*kg CO<sub>2</sub>e / l*)
|
145
|
+
committee :co2_emission_factor do
|
146
|
+
#### CO<sub>2</sub> emission factor from automobile fuel
|
147
|
+
quorum 'from automobile fuel',
|
148
|
+
:needs => :automobile_fuel,
|
149
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
150
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
151
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `co2 emission factor` (*kg CO</sub>2</sub>e / l*)
|
152
|
+
characteristics[:automobile_fuel].co2_emission_factor
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
### CO<sub>2</sub> biogenic emission factor calculation
|
157
|
+
# Returns the `co2 biogenic emission factor` (*kg CO<sub>2</sub>e / l*)
|
158
|
+
committee :co2_biogenic_emission_factor do
|
159
|
+
#### CO<sub>2</sub> biogenic emission factor from automobile fuel
|
160
|
+
quorum 'from automobile fuel',
|
161
|
+
:needs => :automobile_fuel,
|
162
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
163
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
164
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `co2 biogenic emission factor` (*kg CO</sub>2</sub>e / l*)
|
165
|
+
characteristics[:automobile_fuel].co2_biogenic_emission_factor
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
### CH<sub>4</sub> emission factor calculation
|
170
|
+
# Returns the `ch4 emission factor` (*kg CO<sub>2</sub>e / l*)
|
171
|
+
committee :ch4_emission_factor do
|
172
|
+
#### CH<sub>4</sub> emission factor from automobile fuel
|
173
|
+
quorum 'from automobile fuel',
|
174
|
+
:needs => :automobile_fuel,
|
175
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
176
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
177
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `ch4 emission factor` (*kg CO</sub>2</sub>e / l*)
|
178
|
+
characteristics[:automobile_fuel].ch4_emission_factor
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
### N<sub>2</sub>O emission factor calculation
|
183
|
+
# Returns the `n2o emission factor` (*kg CO<sub>2</sub>e / l*)
|
184
|
+
committee :n2o_emission_factor do
|
185
|
+
#### N<sub>2</sub>O emission factor from automobile fuel
|
186
|
+
quorum 'from automobile fuel',
|
187
|
+
:needs => :automobile_fuel,
|
188
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
189
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
190
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `n2o emission factor` (*kg CO</sub>2</sub>e / l*)
|
191
|
+
characteristics[:automobile_fuel].n2o_emission_factor
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
### HFC emission factor calculation
|
196
|
+
# Returns the `hfc emission factor` (*kg CO<sub>2</sub>e / l*)
|
197
|
+
committee :hfc_emission_factor do
|
198
|
+
#### HFC emission factor from automobile fuel
|
199
|
+
quorum 'from automobile fuel',
|
200
|
+
:needs => :automobile_fuel,
|
201
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
202
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
203
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `hfc emission factor` (*kg CO</sub>2</sub>e / l*)
|
204
|
+
characteristics[:automobile_fuel].hfc_emission_factor
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
### Fuel calculation
|
209
|
+
# Returns the `fuel` used by the automobile.
|
210
|
+
committee :automobile_fuel do
|
211
|
+
#### Fuel from client input
|
212
|
+
# **Complies:** All
|
213
|
+
#
|
214
|
+
# Uses the client-input [automobile fuel](http://data.brighterplanet.com/automobile_fuels).
|
215
|
+
|
216
|
+
#### Fuel from make model year variant
|
217
|
+
quorum 'from make model year variant',
|
218
|
+
:needs => :make_model_year_variant,
|
219
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
220
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
221
|
+
# Looks up the [variant](http://data.brighterplanet.com/automobile_make_model_year_variants) `automobile fuel`.
|
222
|
+
characteristics[:make_model_year_variant].fuel
|
14
223
|
end
|
15
224
|
|
16
|
-
|
17
|
-
|
225
|
+
#### Default fuel
|
226
|
+
quorum 'default',
|
227
|
+
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
228
|
+
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
229
|
+
# Looks up the default [automobile fuel](http://data.brighterplanet.com/automobile_fuels).
|
230
|
+
AutomobileFuel.fallback
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
### Fuel use calculation
|
235
|
+
# Returns the trip `fuel use` (*l*).
|
236
|
+
committee :fuel_use do
|
237
|
+
#### Fuel use from fuel efficiency and distance
|
238
|
+
quorum 'from fuel efficiency and distance',
|
239
|
+
:needs => [:fuel_efficiency, :distance],
|
240
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
241
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
242
|
+
# Divides the `distance` (*km*) by the `fuel efficiency` (*km / l*) to give *l*.
|
243
|
+
characteristics[:distance] / characteristics[:fuel_efficiency]
|
18
244
|
end
|
19
245
|
end
|
20
246
|
|
21
|
-
|
22
|
-
|
23
|
-
|
247
|
+
### Distance calculation
|
248
|
+
# Returns the trip `distance` (*km*).
|
249
|
+
committee :distance do
|
250
|
+
#### Distance from client input
|
251
|
+
# **Complies:** All
|
252
|
+
#
|
253
|
+
# Uses the client-input `distance` (*km*).
|
254
|
+
|
255
|
+
#### Distance from origin and destination locations
|
256
|
+
quorum 'from origin and destination locations',
|
257
|
+
:needs => [:origin_location, :destination_location, :mapquest_api_key],
|
258
|
+
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
259
|
+
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
260
|
+
# 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.
|
261
|
+
mapquest = MapQuestDirections.new characteristics[:origin_location],
|
262
|
+
characteristics[:destination_location],
|
263
|
+
characteristics[:mapquest_api_key]
|
264
|
+
begin
|
265
|
+
mapquest.distance_in_kilometres
|
266
|
+
rescue
|
267
|
+
nil
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
#### Distance from duration and speed
|
272
|
+
quorum 'from duration and speed',
|
273
|
+
:needs => [:duration, :speed],
|
274
|
+
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
275
|
+
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
276
|
+
# Divides the `duration` (*minutes*) by 60 and multiplies by the `speed` (*km / hour*) to give *km*.
|
277
|
+
(characteristics[:duration] / 60.0) * characteristics[:speed]
|
24
278
|
end
|
25
279
|
|
26
|
-
|
27
|
-
|
280
|
+
#### Default distance
|
281
|
+
quorum 'default',
|
282
|
+
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
283
|
+
:complies => [:ghg_protocol_scope_3, :iso] do
|
284
|
+
# Uses a default `distance` of 16.33 *km*, [calculated from NHTS 2009 data](https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdFhib1FaNVp5VDkxejh4N3FWQmp2VUE&hl=en&output=html).
|
285
|
+
base.fallback.distance
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
### Destination location calculation
|
290
|
+
# Returns the `destination location` (*lat / lng*).
|
291
|
+
committee :destination_location do
|
292
|
+
#### Destination location from destination
|
293
|
+
quorum 'from destination',
|
294
|
+
:needs => :destination,
|
295
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
296
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
297
|
+
# Uses the [Geokit](http://geokit.rubyforge.org/) geocoder to determine the destination location (*lat / lng*).
|
298
|
+
code = Geokit::Geocoders::MultiGeocoder.geocode characteristics[:destination].to_s
|
299
|
+
code.ll == ',' ? nil : code.ll
|
28
300
|
end
|
29
301
|
end
|
30
302
|
|
31
|
-
|
32
|
-
|
33
|
-
|
303
|
+
### Origin location committee
|
304
|
+
# Returns the `origin location` (*lat / lng*).
|
305
|
+
committee :origin_location do
|
306
|
+
#### Destination location from destination
|
307
|
+
quorum 'from origin',
|
308
|
+
:needs => :origin,
|
309
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
310
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
311
|
+
# Uses the [Geokit](http://geokit.rubyforge.org/) geocoder to determine the origin location (*lat / lng*).
|
312
|
+
code = Geokit::Geocoders::MultiGeocoder.geocode characteristics[:origin].to_s
|
313
|
+
code.ll == ',' ? nil : code.ll
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
### Destination calculation
|
318
|
+
# Returns the client-input `destination`.
|
319
|
+
|
320
|
+
### Origin calculation
|
321
|
+
# Returns the client-input `origin`.
|
322
|
+
|
323
|
+
### Duration calculation
|
324
|
+
# Returns the client-input `duration` (*minutes*).
|
325
|
+
|
326
|
+
### Speed calculation
|
327
|
+
# Returns the average `speed` at which the automobile travels (*km / hour*)
|
328
|
+
committee :speed do
|
329
|
+
#### Speed from client input
|
330
|
+
# **Complies:** All
|
331
|
+
#
|
332
|
+
# Uses the client-input `speed` (*km / hour*)
|
333
|
+
|
334
|
+
#### Speed from urbanity
|
335
|
+
quorum 'from urbanity',
|
336
|
+
:needs => :urbanity,
|
337
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
338
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
339
|
+
# * Takes average city and highway driving speeds from [EPA (2006)](http://www.epa.gov/fueleconomy/420r06017.pdf) and converts from *miles / hour* to *km / hour*
|
340
|
+
# * Calculates the harmonic mean of those speeds, weighted by `urbanity`
|
341
|
+
1 / (characteristics[:urbanity] / base.fallback.city_speed + (1 - characteristics[:urbanity]) / base.fallback.highway_speed)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
### Fuel efficiency calculation
|
346
|
+
# Returns the `fuel efficiency` (*km / l*)
|
347
|
+
committee :fuel_efficiency do
|
348
|
+
#### Fuel efficiency from client input
|
349
|
+
# **Complies:** All
|
350
|
+
#
|
351
|
+
# Uses the client-input `fuel efficiency` (*km / l*).
|
352
|
+
|
353
|
+
#### Fuel efficiency from make model year variant and urbanity
|
354
|
+
quorum 'from make model year variant and urbanity',
|
355
|
+
:needs => [:make_model_year_variant, :urbanity],
|
356
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
357
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
358
|
+
# * 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*)
|
359
|
+
fuel_efficiency_city = characteristics[:make_model_year_variant].fuel_efficiency_city
|
360
|
+
fuel_efficiency_highway = characteristics[:make_model_year_variant].fuel_efficiency_highway
|
361
|
+
urbanity = characteristics[:urbanity]
|
362
|
+
if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
|
363
|
+
# * Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`
|
364
|
+
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
#### Fuel efficiency from make model year and urbanity
|
369
|
+
quorum 'from make model year and urbanity',
|
370
|
+
:needs => [:make_model_year, :urbanity],
|
371
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
372
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
373
|
+
# * Looks up the city and highway fuel efficiencies of the automobile [make model year](http://data.brighterplanet.com/automobile_make_model_years) (*km / l*)
|
374
|
+
fuel_efficiency_city = characteristics[:make_model_year].fuel_efficiency_city
|
375
|
+
fuel_efficiency_highway = characteristics[:make_model_year].fuel_efficiency_highway
|
376
|
+
urbanity = characteristics[:urbanity]
|
377
|
+
if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
|
378
|
+
# * Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`
|
379
|
+
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
383
|
+
#### Fuel efficiency from make model and urbanity
|
384
|
+
quorum 'from make model and urbanity',
|
385
|
+
:needs => [:make_model, :urbanity],
|
386
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
387
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
388
|
+
# * Looks up the city and highway fuel efficiencies of the automobile [make model](http://data.brighterplanet.com/automobile_make_models) (*km / l*)
|
389
|
+
fuel_efficiency_city = characteristics[:make_model].fuel_efficiency_city
|
390
|
+
fuel_efficiency_highway = characteristics[:make_model].fuel_efficiency_highway
|
391
|
+
urbanity = characteristics[:urbanity]
|
392
|
+
if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
|
393
|
+
# * Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`
|
394
|
+
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
#### Fuel efficiency from size class, hybridity multiplier, and urbanity
|
399
|
+
quorum 'from size class, hybridity multiplier, and urbanity',
|
400
|
+
:needs => [:size_class, :hybridity_multiplier, :urbanity],
|
401
|
+
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
402
|
+
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
403
|
+
# * Looks up the automobile [size class](http://data.brighterplanet.com/automobile_makes) city and highway fuel efficiency (*km / l*)
|
404
|
+
fuel_efficiency_city = characteristics[:size_class].fuel_efficiency_city
|
405
|
+
fuel_efficiency_highway = characteristics[:size_class].fuel_efficiency_highway
|
406
|
+
urbanity = characteristics[:urbanity]
|
407
|
+
if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
|
408
|
+
# * Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`
|
409
|
+
# * Multiplies the result by the `hybridity multiplier`
|
410
|
+
(1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))) * characteristics[:hybridity_multiplier]
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
#### Fuel efficiency from make year and hybridity multiplier
|
415
|
+
quorum 'from make year and hybridity multiplier',
|
416
|
+
:needs => [:make_year, :hybridity_multiplier],
|
417
|
+
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
418
|
+
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
419
|
+
# * Looks up the automobile [make year](http://data.brighterplanet.com/automobile_make_years) combined fuel efficiency (*km / l*)
|
420
|
+
# * Multiplies the combined fuel efficiency by the `hybridity multiplier`
|
421
|
+
characteristics[:make_year].fuel_efficiency * characteristics[:hybridity_multiplier]
|
422
|
+
end
|
423
|
+
|
424
|
+
#### Fuel efficiency from make and hybridity multiplier
|
425
|
+
quorum 'from make and hybridity multiplier',
|
426
|
+
:needs => [:make, :hybridity_multiplier],
|
427
|
+
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
428
|
+
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
429
|
+
# * Looks up the automobile [make](http://data.brighterplanet.com/automobile_makes) combined fuel efficiency (*km / l*)
|
430
|
+
# * Multiplies the combined fuel efficiency by the `hybridity multiplier`
|
431
|
+
if characteristics[:make].fuel_efficiency.present?
|
432
|
+
characteristics[:make].fuel_efficiency * characteristics[:hybridity_multiplier]
|
433
|
+
else
|
434
|
+
nil
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
#### Fuel efficiency from hybridity multiplier
|
439
|
+
quorum 'from hybridity multiplier',
|
440
|
+
:needs => :hybridity_multiplier,
|
441
|
+
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
442
|
+
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
443
|
+
# * Takes a default `fuel efficiency` of 8.58 *km / l*, calculated from total US automobile vehicle miles travelled and gasoline and diesel consumption.
|
444
|
+
# * Multiplies the `fuel efficiency` by the `hybridity multiplier`
|
445
|
+
base.fallback.fuel_efficiency * characteristics[:hybridity_multiplier]
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
### Hybridity multiplier calculation
|
450
|
+
# Returns the `hybridity multiplier`.
|
451
|
+
# This value may be used to adjust the fuel efficiency based on whether the automobile is a hybrid or conventional vehicle.
|
452
|
+
committee :hybridity_multiplier do
|
453
|
+
#### Hybridity multiplier from size class, hybridity, and urbanity
|
454
|
+
quorum 'from size class, hybridity, and urbanity',
|
455
|
+
:needs => [:size_class, :hybridity, :urbanity],
|
456
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
457
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
458
|
+
# * Looks up the appropriate city and highway hybridity multipliers for the automobile [size class](http://data.brighterplanet.com/automobile_size_classes)
|
459
|
+
drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
|
460
|
+
urbanity = characteristics[:urbanity]
|
461
|
+
size_class = characteristics[:size_class]
|
462
|
+
fuel_efficiency_multipliers = {
|
463
|
+
:city => size_class.send(:"#{drivetrain}_fuel_efficiency_city_multiplier"),
|
464
|
+
:highway => size_class.send(:"#{drivetrain}_fuel_efficiency_highway_multiplier")
|
465
|
+
}
|
466
|
+
if fuel_efficiency_multipliers.values.any?(&:present?)
|
467
|
+
# * Calculates the harmonic mean of those multipliers, weighted by `urbanity`
|
468
|
+
1.0 / ((urbanity / fuel_efficiency_multipliers[:city]) + ((1.0 - urbanity) / fuel_efficiency_multipliers[:highway]))
|
469
|
+
else
|
470
|
+
nil
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
474
|
+
#### Hybridity multiplier from hybridity and urbanity
|
475
|
+
quorum 'from hybridity and urbanity',
|
476
|
+
:needs => [:hybridity, :urbanity],
|
477
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
478
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
479
|
+
# * Looks up the appropriate default city and highway hybridity multipliers
|
480
|
+
drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
|
481
|
+
urbanity = characteristics[:urbanity]
|
482
|
+
fuel_efficiency_multipliers = {
|
483
|
+
:city => AutomobileSizeClass.fallback.send(:"#{drivetrain}_fuel_efficiency_city_multiplier"),
|
484
|
+
:highway => AutomobileSizeClass.fallback.send(:"#{drivetrain}_fuel_efficiency_highway_multiplier")
|
485
|
+
}
|
486
|
+
# * Calculates the harmonic mean of those multipliers, weighted by `urbanity`
|
487
|
+
1.0 / ((urbanity / fuel_efficiency_multipliers[:city]) + ((1.0 - urbanity) / fuel_efficiency_multipliers[:highway]))
|
488
|
+
end
|
489
|
+
|
490
|
+
#### Default hybridity multiplier
|
491
|
+
quorum 'default',
|
492
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
493
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do
|
494
|
+
# Uses a default `hybridity multiplier` of 1.
|
495
|
+
base.fallback.hybridity_multiplier
|
496
|
+
end
|
497
|
+
end
|
498
|
+
|
499
|
+
### Urbanity calculation
|
500
|
+
# Returns the `urbanity`.
|
501
|
+
# 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").
|
502
|
+
committee :urbanity do
|
503
|
+
#### Urbanity from urbanity estimate
|
504
|
+
quorum 'from urbanity estimate',
|
505
|
+
:needs => :urbanity_estimate,
|
506
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
507
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
508
|
+
# Uses the `urbanity estimate` if it is from zero to one
|
509
|
+
if characteristics[:urbanity_estimate] >= 0 and characteristics[:urbanity_estimate] <= 1
|
510
|
+
characteristics[:urbanity_estimate]
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
#### Default urbanity
|
515
|
+
quorum 'default',
|
516
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
517
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do
|
518
|
+
# Uses an `urbanity` of 0.43 after [EPA (2009) Appendix A](http://www.epa.gov/otaq/cert/mpg/fetrends/420r09014-appx-a.pdf)
|
519
|
+
base.fallback.urbanity_estimate
|
520
|
+
end
|
521
|
+
end
|
522
|
+
|
523
|
+
### Urbanity estimate calculation
|
524
|
+
# 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").
|
525
|
+
|
526
|
+
### Hybridity calculation
|
527
|
+
# Returns the client-input `hybridity`. This indicates whether the automobile is a hybrid electric vehicle or a conventional vehicle.
|
528
|
+
|
529
|
+
### Size class calculation
|
530
|
+
# Returns the client-input automobile [size class](http://data.brighterplanet.com/automobile_size_classes).
|
531
|
+
|
532
|
+
### Make model year variant calculation
|
533
|
+
# Returns the client-input automobile [make model year variant](http://data.brighterplanet.com/automobile_make_model_year_variants).
|
534
|
+
|
535
|
+
### Make model year calculation
|
536
|
+
# Returns the client-input automobile [make model year](http://data.brighterplanet.com/automobile_make_model_years).
|
537
|
+
|
538
|
+
### Make model calculation
|
539
|
+
# Returns the client-input automobile [make model](http://data.brighterplanet.com/automobile_make_models).
|
540
|
+
|
541
|
+
### Make year calculation
|
542
|
+
# Returns the client-input automobile [make year](http://data.brighterplanet.com/automobile_make_years).
|
543
|
+
|
544
|
+
### Make calculation
|
545
|
+
# Returns the client-input automobile [make](http://data.brighterplanet.com/automobile_makes).
|
546
|
+
|
547
|
+
### Date calculation
|
548
|
+
# Returns the `date` on which the trip occurred.
|
549
|
+
committee :date do
|
550
|
+
#### Date from client input
|
551
|
+
# **Complies:** All
|
552
|
+
#
|
553
|
+
# Uses the client-input `date`.
|
554
|
+
|
555
|
+
#### Date from timeframe
|
556
|
+
quorum 'from timeframe',
|
557
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO-14064-1, Climate Registry Protocol
|
558
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso, :tcr] do |characteristics, timeframe|
|
559
|
+
# Assumes the trip occurred on the first day of the `timeframe`.
|
560
|
+
timeframe.from
|
561
|
+
end
|
562
|
+
end
|
563
|
+
|
564
|
+
### Timeframe calculation
|
565
|
+
# Returns the `timeframe`.
|
566
|
+
# This is the period during which to calculate emissions.
|
567
|
+
|
568
|
+
#### Timeframe from client input
|
569
|
+
# **Complies:** All
|
570
|
+
#
|
571
|
+
# Uses the client-input `timeframe`.
|
572
|
+
|
573
|
+
#### Default timeframe
|
574
|
+
# **Complies:** All
|
575
|
+
#
|
576
|
+
# Uses the current calendar year.
|
577
|
+
|
578
|
+
### Mapquest API key lookup
|
579
|
+
# Returns Brighter Planet's Mapquest API key
|
580
|
+
committee :mapquest_api_key do
|
581
|
+
#### Default Mapquest API key
|
582
|
+
quorum 'default',
|
583
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
584
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do
|
585
|
+
# Uses Brighter Planet's Mapquest API key.
|
586
|
+
ENV['MAPQUEST_API_KEY']
|
34
587
|
end
|
35
588
|
end
|
36
589
|
end
|
37
590
|
end
|
591
|
+
|
592
|
+
class Mapper
|
593
|
+
include Geokit::Mappable
|
594
|
+
end
|
38
595
|
end
|
39
596
|
end
|
40
597
|
end
|