automobile_trip 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Rakefile +8 -66
- data/automobile_trip.gemspec +13 -11
- data/features/automobile_trip_committees.feature +94 -48
- data/features/automobile_trip_emissions.feature +29 -24
- data/features/support/env.rb +1 -1
- data/lib/automobile_trip.rb +1 -1
- data/lib/automobile_trip/carbon_model.rb +99 -85
- data/lib/automobile_trip/characterization.rb +2 -1
- data/lib/automobile_trip/data.rb +1 -0
- data/lib/automobile_trip/fallback.rb +1 -6
- data/lib/automobile_trip/relationships.rb +1 -0
- data/lib/automobile_trip/version.rb +1 -1
- data/lib/test_support/db/fixtures/automobile_fuels.csv +4 -4
- data/lib/test_support/db/fixtures/automobile_make_model_year_variants.csv +1 -1
- data/lib/test_support/db/fixtures/automobile_type_fuel_year_ages.csv +3 -0
- data/lib/test_support/db/fixtures/countries.csv +2 -0
- data/lib/test_support/db/fixtures/fuels.csv +0 -1
- metadata +19 -39
- data/Gemfile.lock +0 -200
data/features/support/env.rb
CHANGED
@@ -11,4 +11,4 @@ require 'data_miner'
|
|
11
11
|
DataMiner.logger = Logger.new(nil)
|
12
12
|
|
13
13
|
require 'sniff'
|
14
|
-
Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :cucumber => true, :earth => [:automobile, :fuel]
|
14
|
+
Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :cucumber => true, :earth => [:automobile, :fuel, :locality]
|
data/lib/automobile_trip.rb
CHANGED
@@ -3,6 +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
|
6
|
+
scope 'The automobile trip emission estimate is the total anthropogenic emissions from fuel and air conditioning used by the automobile during the trip. It includes CO2 emissions from combustion of non-biogenic fuel, CH4 and N2O emissions from combustion of all fuel, and fugitive HFC emissions from air conditioning.'
|
7
7
|
end
|
8
8
|
end
|
@@ -30,71 +30,71 @@ module BrighterPlanet
|
|
30
30
|
### Emission calculation
|
31
31
|
# Returns the `emission` estimate (*kg CO<sub>2</sub>e*).
|
32
32
|
committee :emission do
|
33
|
-
#### Emission from
|
33
|
+
#### Emission from CO<sub>2</sub> emission, CH<sub>4</sub> emission, N<sub>2</sub>O emission, and HFC emission
|
34
34
|
quorum 'from co2 emission, ch4 emission, n2o emission, and hfc emission',
|
35
35
|
:needs => [:co2_emission, :ch4_emission, :n2o_emission, :hfc_emission],
|
36
36
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
37
37
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
38
|
-
# Sums the non-biogenic emissions
|
38
|
+
# Sums the non-biogenic emissions to give *kg CO<sub>2</sub>e*.
|
39
39
|
characteristics[:co2_emission] + characteristics[:ch4_emission] + characteristics[:n2o_emission] + characteristics[:hfc_emission]
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
### CO<sub>2</sub> emission calculation
|
44
|
-
# Returns the `co2 emission` (*kg
|
44
|
+
# Returns the `co2 emission` (*kg*).
|
45
45
|
committee :co2_emission do
|
46
|
-
#### CO<sub>2</sub> emission from fuel use,
|
46
|
+
#### CO<sub>2</sub> emission from fuel use, CO<sub>2</sub> emission factor, date, and timeframe
|
47
47
|
quorum 'from fuel use, co2 emission factor, date, and timeframe',
|
48
48
|
:needs => [:fuel_use, :co2_emission_factor, :date],
|
49
49
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
50
50
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
51
|
-
#
|
51
|
+
# Checks whether the trip `date` falls within the `timeframe`.
|
52
52
|
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
53
53
|
if timeframe.include? date
|
54
|
-
#
|
54
|
+
# Multiplies `fuel use` (*l*) by the `co2 emission factor` (*kg / l*) to give *kg*.
|
55
55
|
characteristics[:fuel_use] * characteristics[:co2_emission_factor]
|
56
56
|
else
|
57
|
-
#
|
57
|
+
# If the `date` does not fall within the `timeframe`, `co2 emission` is zero.
|
58
58
|
0
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
63
|
### CO<sub>2</sub> biogenic emission calculation
|
64
|
-
# Returns the `co2 biogenic emission` (*kg
|
64
|
+
# Returns the `co2 biogenic emission` (*kg*).
|
65
65
|
committee :co2_biogenic_emission do
|
66
|
-
#### CO<sub>2</sub> biogenic emission from fuel use,
|
66
|
+
#### CO<sub>2</sub> biogenic emission from fuel use, CO<sub>2</sub> biogenic emission factor, date, and timeframe
|
67
67
|
quorum 'from fuel use, co2 biogenic emission factor, date, and timeframe',
|
68
68
|
:needs => [:fuel_use, :co2_biogenic_emission_factor, :date],
|
69
69
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
70
70
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
71
|
-
#
|
71
|
+
# Checks whether the trip `date` falls within the `timeframe`.
|
72
72
|
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
73
73
|
if timeframe.include? date
|
74
|
-
#
|
74
|
+
# Multiplies `fuel use` (*l*) by the `co2 biogenic emission factor` (*kg / l*) to give *kg*.
|
75
75
|
characteristics[:fuel_use] * characteristics[:co2_biogenic_emission_factor]
|
76
76
|
else
|
77
|
-
#
|
77
|
+
# If the `date` does not fall within the `timeframe`, `co2 biogenic emission` is zero.
|
78
78
|
0
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
83
|
### CH<sub>4</sub> emission calculation
|
84
|
-
# Returns the `ch4 emission` (*kg CO<sub>2</sub>e*)
|
84
|
+
# Returns the `ch4 emission` (*kg CO<sub>2</sub>e*).
|
85
85
|
committee :ch4_emission do
|
86
|
-
#### CH<sub>4</sub> emission from fuel use,
|
86
|
+
#### CH<sub>4</sub> emission from fuel use, CH<sub>4</sub> emission factor, date, and timeframe
|
87
87
|
quorum 'from fuel use, ch4 emission factor, date, and timeframe',
|
88
88
|
:needs => [:fuel_use, :ch4_emission_factor, :date],
|
89
89
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
90
90
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
91
|
-
#
|
91
|
+
# Checks whether the trip `date` falls within the `timeframe`.
|
92
92
|
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
93
93
|
if timeframe.include? date
|
94
|
-
#
|
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
95
|
characteristics[:fuel_use] * characteristics[:ch4_emission_factor]
|
96
96
|
else
|
97
|
-
#
|
97
|
+
# If the `date` does not fall within the `timeframe`, `ch4 emission` is zero.
|
98
98
|
0
|
99
99
|
end
|
100
100
|
end
|
@@ -103,117 +103,117 @@ module BrighterPlanet
|
|
103
103
|
### N<sub>2</sub>O emission calculation
|
104
104
|
# Returns the `n2o emission` (*kg CO<sub>2</sub>e*)
|
105
105
|
committee :n2o_emission do
|
106
|
-
#### N<sub>2</sub>O emission from fuel use,
|
106
|
+
#### N<sub>2</sub>O emission from fuel use, N<sub>2</sub>O emission factor, date, and timeframe
|
107
107
|
quorum 'from fuel use, n2o emission factor, date, and timeframe',
|
108
108
|
:needs => [:fuel_use, :n2o_emission_factor, :date],
|
109
109
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
110
110
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
111
|
-
#
|
111
|
+
# Checks whether the trip `date` falls within the `timeframe`.
|
112
112
|
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
113
113
|
if timeframe.include? date
|
114
|
-
#
|
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
115
|
characteristics[:fuel_use] * characteristics[:n2o_emission_factor]
|
116
116
|
else
|
117
|
-
#
|
117
|
+
# If the `date` does not fall within the `timeframe`, `n2o emission` is zero.
|
118
118
|
0
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
123
123
|
### HFC emission calculation
|
124
|
-
# Returns the `hfc emission` (*kg CO<sub>2</sub>e*)
|
124
|
+
# Returns the `hfc emission` (*kg CO<sub>2</sub>e*).
|
125
125
|
committee :hfc_emission do
|
126
|
-
#### HFC emission from fuel use,
|
126
|
+
#### HFC emission from fuel use, HFC emission factor, date, and timeframe
|
127
127
|
quorum 'from fuel use, hfc emission factor, date, and timeframe',
|
128
128
|
:needs => [:fuel_use, :hfc_emission_factor, :date],
|
129
129
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
130
130
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics, timeframe|
|
131
|
-
#
|
131
|
+
# Checks whether the trip `date` falls within the `timeframe`.
|
132
132
|
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
133
133
|
if timeframe.include? date
|
134
|
-
#
|
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
135
|
characteristics[:fuel_use] * characteristics[:hfc_emission_factor]
|
136
136
|
else
|
137
|
-
#
|
137
|
+
# If the `date` does not fall within the `timeframe`, `hfc emission` is zero.
|
138
138
|
0
|
139
139
|
end
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
143
|
### CO<sub>2</sub> emission factor calculation
|
144
|
-
# Returns the `co2 emission factor` (*kg
|
144
|
+
# Returns the `co2 emission factor` (*kg / l*).
|
145
145
|
committee :co2_emission_factor do
|
146
146
|
#### CO<sub>2</sub> emission factor from automobile fuel
|
147
147
|
quorum 'from automobile fuel',
|
148
148
|
:needs => :automobile_fuel,
|
149
149
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
150
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
|
151
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `co2 emission factor` (*kg / l*).
|
152
152
|
characteristics[:automobile_fuel].co2_emission_factor
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
156
|
### CO<sub>2</sub> biogenic emission factor calculation
|
157
|
-
# Returns the `co2 biogenic emission factor` (*kg
|
157
|
+
# Returns the `co2 biogenic emission factor` (*kg / l*).
|
158
158
|
committee :co2_biogenic_emission_factor do
|
159
159
|
#### CO<sub>2</sub> biogenic emission factor from automobile fuel
|
160
160
|
quorum 'from automobile fuel',
|
161
161
|
:needs => :automobile_fuel,
|
162
162
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
163
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
|
164
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `co2 biogenic emission factor` (*kg / l*).
|
165
165
|
characteristics[:automobile_fuel].co2_biogenic_emission_factor
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
169
169
|
### CH<sub>4</sub> emission factor calculation
|
170
|
-
# Returns the `ch4 emission factor` (*kg CO<sub>2</sub>e / l*)
|
170
|
+
# Returns the `ch4 emission factor` (*kg CO<sub>2</sub>e / l*).
|
171
171
|
committee :ch4_emission_factor do
|
172
172
|
#### CH<sub>4</sub> emission factor from automobile fuel
|
173
173
|
quorum 'from automobile fuel',
|
174
174
|
:needs => :automobile_fuel,
|
175
175
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
176
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*)
|
177
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `ch4 emission factor` (*kg CO</sub>2</sub>e / l*).
|
178
178
|
characteristics[:automobile_fuel].ch4_emission_factor
|
179
179
|
end
|
180
180
|
end
|
181
181
|
|
182
182
|
### N<sub>2</sub>O emission factor calculation
|
183
|
-
# Returns the `n2o emission factor` (*kg CO<sub>2</sub>e / l*)
|
183
|
+
# Returns the `n2o emission factor` (*kg CO<sub>2</sub>e / l*).
|
184
184
|
committee :n2o_emission_factor do
|
185
185
|
#### N<sub>2</sub>O emission factor from automobile fuel
|
186
186
|
quorum 'from automobile fuel',
|
187
187
|
:needs => :automobile_fuel,
|
188
188
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
189
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*)
|
190
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `n2o emission factor` (*kg CO</sub>2</sub>e / l*).
|
191
191
|
characteristics[:automobile_fuel].n2o_emission_factor
|
192
192
|
end
|
193
193
|
end
|
194
194
|
|
195
195
|
### HFC emission factor calculation
|
196
|
-
# Returns the `hfc emission factor` (*kg CO<sub>2</sub>e / l*)
|
196
|
+
# Returns the `hfc emission factor` (*kg CO<sub>2</sub>e / l*).
|
197
197
|
committee :hfc_emission_factor do
|
198
198
|
#### HFC emission factor from automobile fuel
|
199
199
|
quorum 'from automobile fuel',
|
200
200
|
:needs => :automobile_fuel,
|
201
201
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
202
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*)
|
203
|
+
# Looks up the [fuel](http://data.brighterplanet.com/fuels) `hfc emission factor` (*kg CO</sub>2</sub>e / l*).
|
204
204
|
characteristics[:automobile_fuel].hfc_emission_factor
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
|
-
###
|
209
|
-
# Returns the `fuel` used
|
208
|
+
### Automobile fuel calculation
|
209
|
+
# Returns the type of `automobile fuel` used.
|
210
210
|
committee :automobile_fuel do
|
211
|
-
####
|
211
|
+
#### Automobile fuel from client input
|
212
212
|
# **Complies:** All
|
213
213
|
#
|
214
214
|
# Uses the client-input [automobile fuel](http://data.brighterplanet.com/automobile_fuels).
|
215
215
|
|
216
|
-
####
|
216
|
+
#### Automobile fuel from make model year variant
|
217
217
|
quorum 'from make model year variant',
|
218
218
|
:needs => :make_model_year_variant,
|
219
219
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
@@ -222,10 +222,10 @@ module BrighterPlanet
|
|
222
222
|
characteristics[:make_model_year_variant].fuel
|
223
223
|
end
|
224
224
|
|
225
|
-
#### Default fuel
|
225
|
+
#### Default automobile fuel
|
226
226
|
quorum 'default',
|
227
227
|
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
228
|
-
:complies => [:ghg_protocol_scope_3, :iso] do
|
228
|
+
:complies => [:ghg_protocol_scope_3, :iso] do
|
229
229
|
# Looks up the default [automobile fuel](http://data.brighterplanet.com/automobile_fuels).
|
230
230
|
AutomobileFuel.fallback
|
231
231
|
end
|
@@ -277,12 +277,13 @@ module BrighterPlanet
|
|
277
277
|
(characteristics[:duration] / 60.0) * characteristics[:speed]
|
278
278
|
end
|
279
279
|
|
280
|
-
####
|
281
|
-
quorum '
|
280
|
+
#### Distance from country
|
281
|
+
quorum 'from country',
|
282
|
+
:needs => :country,
|
282
283
|
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
283
|
-
:complies => [:ghg_protocol_scope_3, :iso] do
|
284
|
-
#
|
285
|
-
|
284
|
+
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
285
|
+
# Looks up the [country](http://data.brighterplanet.com/countries) `automobile trip distance`.
|
286
|
+
characteristics[:country].automobile_trip_distance
|
286
287
|
end
|
287
288
|
end
|
288
289
|
|
@@ -324,26 +325,25 @@ module BrighterPlanet
|
|
324
325
|
# Returns the client-input `duration` (*minutes*).
|
325
326
|
|
326
327
|
### Speed calculation
|
327
|
-
# Returns the average `speed` at which the automobile travels (*km / hour*)
|
328
|
+
# Returns the average `speed` at which the automobile travels (*km / hour*).
|
328
329
|
committee :speed do
|
329
330
|
#### Speed from client input
|
330
331
|
# **Complies:** All
|
331
332
|
#
|
332
|
-
# Uses the client-input `speed` (*km / hour*)
|
333
|
+
# Uses the client-input `speed` (*km / hour*).
|
333
334
|
|
334
|
-
#### Speed from urbanity
|
335
|
-
quorum 'from urbanity',
|
336
|
-
:needs => :urbanity,
|
335
|
+
#### Speed from urbanity and country
|
336
|
+
quorum 'from urbanity and country',
|
337
|
+
:needs => [:urbanity, :country],
|
337
338
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
338
339
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
339
|
-
#
|
340
|
-
|
341
|
-
1 / (characteristics[:urbanity] / base.fallback.city_speed + (1 - characteristics[:urbanity]) / base.fallback.highway_speed)
|
340
|
+
# 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`.
|
341
|
+
1 / (characteristics[:urbanity] / characteristics[:country].automobile_city_speed + (1 - characteristics[:urbanity]) / characteristics[:country].automobile_highway_speed)
|
342
342
|
end
|
343
343
|
end
|
344
344
|
|
345
345
|
### Fuel efficiency calculation
|
346
|
-
# Returns the `fuel efficiency` (*km / l*)
|
346
|
+
# Returns the `fuel efficiency` (*km / l*).
|
347
347
|
committee :fuel_efficiency do
|
348
348
|
#### Fuel efficiency from client input
|
349
349
|
# **Complies:** All
|
@@ -355,12 +355,12 @@ module BrighterPlanet
|
|
355
355
|
:needs => [:make_model_year_variant, :urbanity],
|
356
356
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
357
357
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
358
|
-
#
|
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
359
|
fuel_efficiency_city = characteristics[:make_model_year_variant].fuel_efficiency_city
|
360
360
|
fuel_efficiency_highway = characteristics[:make_model_year_variant].fuel_efficiency_highway
|
361
361
|
urbanity = characteristics[:urbanity]
|
362
362
|
if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
|
363
|
-
#
|
363
|
+
# Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`.
|
364
364
|
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
365
365
|
end
|
366
366
|
end
|
@@ -370,12 +370,12 @@ module BrighterPlanet
|
|
370
370
|
:needs => [:make_model_year, :urbanity],
|
371
371
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
372
372
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
373
|
-
#
|
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
374
|
fuel_efficiency_city = characteristics[:make_model_year].fuel_efficiency_city
|
375
375
|
fuel_efficiency_highway = characteristics[:make_model_year].fuel_efficiency_highway
|
376
376
|
urbanity = characteristics[:urbanity]
|
377
377
|
if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
|
378
|
-
#
|
378
|
+
# Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`.
|
379
379
|
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
380
380
|
end
|
381
381
|
end
|
@@ -385,12 +385,12 @@ module BrighterPlanet
|
|
385
385
|
:needs => [:make_model, :urbanity],
|
386
386
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
387
387
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
388
|
-
#
|
388
|
+
# Looks up the city and highway fuel efficiencies of the automobile [make model](http://data.brighterplanet.com/automobile_make_models) (*km / l*).
|
389
389
|
fuel_efficiency_city = characteristics[:make_model].fuel_efficiency_city
|
390
390
|
fuel_efficiency_highway = characteristics[:make_model].fuel_efficiency_highway
|
391
391
|
urbanity = characteristics[:urbanity]
|
392
392
|
if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
|
393
|
-
#
|
393
|
+
# Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`.
|
394
394
|
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
395
395
|
end
|
396
396
|
end
|
@@ -400,13 +400,12 @@ module BrighterPlanet
|
|
400
400
|
:needs => [:size_class, :hybridity_multiplier, :urbanity],
|
401
401
|
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
402
402
|
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
403
|
-
#
|
403
|
+
# Looks up the automobile [size class](http://data.brighterplanet.com/automobile_makes) city and highway fuel efficiency (*km / l*).
|
404
404
|
fuel_efficiency_city = characteristics[:size_class].fuel_efficiency_city
|
405
405
|
fuel_efficiency_highway = characteristics[:size_class].fuel_efficiency_highway
|
406
406
|
urbanity = characteristics[:urbanity]
|
407
407
|
if fuel_efficiency_city.present? and fuel_efficiency_highway.present?
|
408
|
-
#
|
409
|
-
# * Multiplies the result by the `hybridity multiplier`
|
408
|
+
# Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`, and multiplies the result by the `hybridity multiplier`.
|
410
409
|
(1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))) * characteristics[:hybridity_multiplier]
|
411
410
|
end
|
412
411
|
end
|
@@ -416,8 +415,7 @@ module BrighterPlanet
|
|
416
415
|
:needs => [:make_year, :hybridity_multiplier],
|
417
416
|
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
418
417
|
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
419
|
-
#
|
420
|
-
# * Multiplies the combined fuel efficiency by the `hybridity multiplier`
|
418
|
+
# 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`.
|
421
419
|
characteristics[:make_year].fuel_efficiency * characteristics[:hybridity_multiplier]
|
422
420
|
end
|
423
421
|
|
@@ -426,8 +424,7 @@ module BrighterPlanet
|
|
426
424
|
:needs => [:make, :hybridity_multiplier],
|
427
425
|
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
428
426
|
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
429
|
-
#
|
430
|
-
# * Multiplies the combined fuel efficiency by the `hybridity multiplier`
|
427
|
+
# Looks up the automobile [make](http://data.brighterplanet.com/automobile_makes) combined fuel efficiency (*km / l*) and multiplies it by the `hybridity multiplier`.
|
431
428
|
if characteristics[:make].fuel_efficiency.present?
|
432
429
|
characteristics[:make].fuel_efficiency * characteristics[:hybridity_multiplier]
|
433
430
|
else
|
@@ -435,14 +432,13 @@ module BrighterPlanet
|
|
435
432
|
end
|
436
433
|
end
|
437
434
|
|
438
|
-
#### Fuel efficiency from hybridity multiplier
|
439
|
-
quorum 'from hybridity multiplier',
|
440
|
-
:needs => :hybridity_multiplier,
|
435
|
+
#### Fuel efficiency from hybridity multiplier and country
|
436
|
+
quorum 'from hybridity multiplier and country',
|
437
|
+
:needs => [:hybridity_multiplier, :country],
|
441
438
|
# **Complies:** GHG Protocol Scope 3, ISO 14064-1
|
442
439
|
:complies => [:ghg_protocol_scope_3, :iso] do |characteristics|
|
443
|
-
#
|
444
|
-
|
445
|
-
base.fallback.fuel_efficiency * characteristics[:hybridity_multiplier]
|
440
|
+
# Looks up the [country](http://data.brighterplanet.com/countries) `automobile fuel efficiency` and multiplies it by the `hybridity multiplier`.
|
441
|
+
characteristics[:country].automobile_fuel_efficiency * characteristics[:hybridity_multiplier]
|
446
442
|
end
|
447
443
|
end
|
448
444
|
|
@@ -455,7 +451,7 @@ module BrighterPlanet
|
|
455
451
|
:needs => [:size_class, :hybridity, :urbanity],
|
456
452
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
457
453
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
458
|
-
#
|
454
|
+
# Looks up the appropriate city and highway hybridity multipliers for the automobile [size class](http://data.brighterplanet.com/automobile_size_classes).
|
459
455
|
drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
|
460
456
|
urbanity = characteristics[:urbanity]
|
461
457
|
size_class = characteristics[:size_class]
|
@@ -464,7 +460,7 @@ module BrighterPlanet
|
|
464
460
|
:highway => size_class.send(:"#{drivetrain}_fuel_efficiency_highway_multiplier")
|
465
461
|
}
|
466
462
|
if fuel_efficiency_multipliers.values.any?(&:present?)
|
467
|
-
#
|
463
|
+
# Calculates the harmonic mean of those multipliers, weighted by `urbanity`.
|
468
464
|
1.0 / ((urbanity / fuel_efficiency_multipliers[:city]) + ((1.0 - urbanity) / fuel_efficiency_multipliers[:highway]))
|
469
465
|
else
|
470
466
|
nil
|
@@ -476,14 +472,14 @@ module BrighterPlanet
|
|
476
472
|
:needs => [:hybridity, :urbanity],
|
477
473
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
478
474
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
479
|
-
#
|
475
|
+
# Looks up the appropriate default city and highway hybridity multipliers.
|
480
476
|
drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
|
481
477
|
urbanity = characteristics[:urbanity]
|
482
478
|
fuel_efficiency_multipliers = {
|
483
479
|
:city => AutomobileSizeClass.fallback.send(:"#{drivetrain}_fuel_efficiency_city_multiplier"),
|
484
480
|
:highway => AutomobileSizeClass.fallback.send(:"#{drivetrain}_fuel_efficiency_highway_multiplier")
|
485
481
|
}
|
486
|
-
#
|
482
|
+
# Calculates the harmonic mean of those multipliers, weighted by `urbanity`.
|
487
483
|
1.0 / ((urbanity / fuel_efficiency_multipliers[:city]) + ((1.0 - urbanity) / fuel_efficiency_multipliers[:highway]))
|
488
484
|
end
|
489
485
|
|
@@ -505,18 +501,19 @@ module BrighterPlanet
|
|
505
501
|
:needs => :urbanity_estimate,
|
506
502
|
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
507
503
|
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
508
|
-
# Uses the `urbanity estimate` if it is from zero to one
|
504
|
+
# Uses the `urbanity estimate` if it is from zero to one.
|
509
505
|
if characteristics[:urbanity_estimate] >= 0 and characteristics[:urbanity_estimate] <= 1
|
510
506
|
characteristics[:urbanity_estimate]
|
511
507
|
end
|
512
508
|
end
|
513
509
|
|
514
|
-
####
|
515
|
-
quorum '
|
510
|
+
#### Urbanity from country
|
511
|
+
quorum 'from country',
|
512
|
+
:needs => :country,
|
516
513
|
# **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
|
-
#
|
519
|
-
|
514
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do |characteristics|
|
515
|
+
# Looks up the [country](http://data.brighterplanet.com/countries) `automobile urbanity`.
|
516
|
+
characteristics[:country].automobile_urbanity
|
520
517
|
end
|
521
518
|
end
|
522
519
|
|
@@ -544,6 +541,23 @@ module BrighterPlanet
|
|
544
541
|
### Make calculation
|
545
542
|
# Returns the client-input automobile [make](http://data.brighterplanet.com/automobile_makes).
|
546
543
|
|
544
|
+
### Country calculation
|
545
|
+
# Returns the `country` in which the trip occurred.
|
546
|
+
committee :country do
|
547
|
+
#### Country from client input
|
548
|
+
# **Complies:** All
|
549
|
+
#
|
550
|
+
# Uses the client-input `country`.
|
551
|
+
|
552
|
+
#### Default country
|
553
|
+
quorum 'default',
|
554
|
+
# **Complies:** GHG Protocol Scope 1, GHG Protocol Scope 3, ISO 14064-1
|
555
|
+
:complies => [:ghg_protocol_scope_1, :ghg_protocol_scope_3, :iso] do
|
556
|
+
# Uses an artificial country that contains global averages.
|
557
|
+
Country.fallback
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
547
561
|
### Date calculation
|
548
562
|
# Returns the `date` on which the trip occurred.
|
549
563
|
committee :date do
|