automobile 0.0.16 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/features/automobile_committees.feature +247 -15
- data/features/automobile_emissions.feature +93 -7
- data/lib/automobile/carbon_model.rb +348 -101
- data/lib/automobile/characterization.rb +12 -14
- data/lib/automobile/data.rb +10 -10
- data/lib/automobile/summarization.rb +2 -2
- data/lib/test_support/automobile_record.rb +7 -10
- metadata +24 -9
@@ -1,36 +1,268 @@
|
|
1
1
|
Feature: Automobile Committee Calculations
|
2
2
|
The automobile model should generate correct committee calculations
|
3
3
|
|
4
|
+
Scenario: Retirement committee from default
|
5
|
+
Given an automobile emitter
|
6
|
+
And a characteristic "timeframe" of "2009-03-04/2009-08-17"
|
7
|
+
When the "retirement" committee is calculated
|
8
|
+
Then the conclusion of the committee should be "2009-08-17"
|
9
|
+
|
4
10
|
Scenario Outline: Retirement committee from acquisition
|
5
11
|
Given an automobile emitter
|
6
12
|
And a characteristic "timeframe" of "<timeframe>"
|
7
13
|
And a characteristic "acquisition" of "<acquisition>"
|
8
14
|
When the "retirement" committee is calculated
|
9
|
-
Then the conclusion of the committee should be "<
|
15
|
+
Then the conclusion of the committee should be "<retirement>"
|
10
16
|
Examples:
|
11
|
-
| timeframe | acquisition |
|
12
|
-
| 2009-03-04/2009-08-17 | 2010-04-21 | 2010-04-21
|
13
|
-
| 2009-03-04/2009-08-17 | 2007-01-30 | 2009-08-17
|
14
|
-
| 2009-03-04/2009-08-17 | | 2009-08-17 |
|
17
|
+
| timeframe | acquisition | retirement |
|
18
|
+
| 2009-03-04/2009-08-17 | 2010-04-21 | 2010-04-21 |
|
19
|
+
| 2009-03-04/2009-08-17 | 2007-01-30 | 2009-08-17 |
|
15
20
|
|
16
|
-
Scenario
|
21
|
+
Scenario: Acquisition committee from make model year variant
|
17
22
|
Given an automobile emitter
|
18
|
-
And a characteristic "
|
19
|
-
And a characteristic "year" of "<year>"
|
23
|
+
And a characteristic "make_model_year_variant.row_hash" of "xxx1"
|
20
24
|
When the "acquisition" committee is calculated
|
21
|
-
Then the
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
Then the committee should have used quorum "from make model year variant"
|
26
|
+
And the conclusion of the committee should be "2003-01-01"
|
27
|
+
|
28
|
+
Scenario: Acquisition committee from make model year
|
29
|
+
Given an automobile emitter
|
30
|
+
And a characteristic "make_model_year.name" of "Acura RSX 2003"
|
31
|
+
When the "acquisition" committee is calculated
|
32
|
+
Then the committee should have used quorum "from make model year"
|
33
|
+
And the conclusion of the committee should be "2003-01-01"
|
34
|
+
|
35
|
+
Scenario: Acquisition committee from make year
|
36
|
+
Given an automobile emitter
|
37
|
+
And a characteristic "make_year.name" of "Acura 2003"
|
38
|
+
When the "acquisition" committee is calculated
|
39
|
+
Then the committee should have used quorum "from make year"
|
40
|
+
And the conclusion of the committee should be "2003-01-01"
|
26
41
|
|
27
42
|
Scenario Outline: Acquisition committee from retirement
|
28
43
|
Given an automobile emitter
|
29
44
|
And a characteristic "timeframe" of "<timeframe>"
|
30
45
|
And a characteristic "retirement" of "<retirement>"
|
31
46
|
When the "acquisition" committee is calculated
|
32
|
-
Then the
|
47
|
+
Then the committee should have used quorum "from retirement"
|
48
|
+
And the conclusion of the committee should be "<acquisition_committee>"
|
33
49
|
Examples:
|
34
50
|
| timeframe | retirement | acquisition_committee |
|
35
51
|
| 2010-08-10/2010-09-16 | 2007-02-03 | 2007-02-03 |
|
36
|
-
| 2010-08-10/2010-09-16 |
|
52
|
+
| 2010-08-10/2010-09-16 | 2010-09-01 | 2010-08-10 |
|
53
|
+
|
54
|
+
Scenario Outline: Active subtimeframe committee from acquisition and retirement
|
55
|
+
Given an automobile emitter
|
56
|
+
And a characteristic "acquisition" of "<acquisition>"
|
57
|
+
And a characteristic "retirement" of "<retirement>"
|
58
|
+
And a characteristic "timeframe" of "<timeframe>"
|
59
|
+
When the "active_subtimeframe" committee is calculated
|
60
|
+
Then the conclusion of the committee should be timeframe "<active_subtimeframe>"
|
61
|
+
Examples:
|
62
|
+
| acquisition | retirement | timeframe | active_subtimeframe |
|
63
|
+
| 2010-04-21 | 2010-09-01 | 2010-01-01/2010-12-31 | 2010-04-21/2010-09-01 |
|
64
|
+
| 2010-04-21 | 2010-09-01 | 2010-05-01/2010-08-01 | 2010-05-01/2010-08-01 |
|
65
|
+
| 2010-04-21 | 2010-09-01 | 2010-05-01/2010-12-31 | 2010-05-01/2010-09-01 |
|
66
|
+
| 2010-04-21 | 2010-09-01 | 2010-01-01/2010-08-01 | 2010-04-21/2010-08-01 |
|
67
|
+
| 2010-04-21 | 2010-09-01 | 2010-01-01/2010-01-31 | 2010-01-01/2010-01-01 |
|
68
|
+
|
69
|
+
Scenario: Fuel type committee from make model year variant
|
70
|
+
Given an automobile emitter
|
71
|
+
And a characteristic "make_model_year_variant.row_hash" of "xxx1"
|
72
|
+
When the "fuel_type" committee is calculated
|
73
|
+
Then the committee should have used quorum "from make model year variant"
|
74
|
+
And the conclusion of the committee should have "name" of "premium gasoline"
|
75
|
+
|
76
|
+
Scenario: Urbanity committee from default
|
77
|
+
Given an automobile emitter
|
78
|
+
When the "urbanity" committee is calculated
|
79
|
+
Then the conclusion of the committee should be "0.43"
|
80
|
+
|
81
|
+
Scenario: Speed committee from urbanity
|
82
|
+
Given an automobile emitter
|
83
|
+
When the "urbanity" committee is calculated
|
84
|
+
And the "speed" committee is calculated
|
85
|
+
Then the conclusion of the committee should be "50.94388"
|
86
|
+
|
87
|
+
Scenario Outline: Hybridity multiplier committee from size class with hybridity multipliers
|
88
|
+
Given an automobile emitter
|
89
|
+
And a characteristic "hybridity" of "<hybridity>"
|
90
|
+
And a characteristic "size_class.name" of "<size_class>"
|
91
|
+
When the "urbanity" committee is calculated
|
92
|
+
And the "hybridity_multiplier" committee is calculated
|
93
|
+
Then the committee should have used quorum "from size class, hybridity, and urbanity"
|
94
|
+
And the conclusion of the committee should be "<multiplier>"
|
95
|
+
Examples:
|
96
|
+
| hybridity | size_class | multiplier |
|
97
|
+
| true | Midsize Car | 1.68067 |
|
98
|
+
| false | Midsize Car | 0.87464 |
|
99
|
+
|
100
|
+
Scenario Outline: Hybridity multiplier committee from size class missing hybridity multipliers
|
101
|
+
Given an automobile emitter
|
102
|
+
And a characteristic "hybridity" of "<hybridity>"
|
103
|
+
And a characteristic "size_class.name" of "<size_class>"
|
104
|
+
When the "urbanity" committee is calculated
|
105
|
+
And the "hybridity_multiplier" committee is calculated
|
106
|
+
Then the committee should have used quorum "from hybridity and urbanity"
|
107
|
+
And the conclusion of the committee should be "<multiplier>"
|
108
|
+
Examples:
|
109
|
+
| hybridity | size_class | multiplier |
|
110
|
+
| true | Midsize Wagon | 1.36919 |
|
111
|
+
| false | Midsize Wagon | 0.99211 |
|
112
|
+
|
113
|
+
Scenario Outline: Hybridity multiplier committee from hybridity and urbanity
|
114
|
+
Given an automobile emitter
|
115
|
+
And a characteristic "hybridity" of "<hybridity>"
|
116
|
+
When the "urbanity" committee is calculated
|
117
|
+
And the "hybridity_multiplier" committee is calculated
|
118
|
+
Then the committee should have used quorum "from hybridity and urbanity"
|
119
|
+
And the conclusion of the committee should be "<multiplier>"
|
120
|
+
Examples:
|
121
|
+
| hybridity | multiplier |
|
122
|
+
| true | 1.36919 |
|
123
|
+
| false | 0.99211 |
|
124
|
+
|
125
|
+
Scenario: Hybridity multiplier committee from default
|
126
|
+
Given an automobile emitter
|
127
|
+
When the "hybridity_multiplier" committee is calculated
|
128
|
+
Then the committee should have used quorum "default"
|
129
|
+
And the conclusion of the committee should be "1.0"
|
130
|
+
|
131
|
+
Scenario: Fuel efficiency committee from make model year variant and urbanity
|
132
|
+
Given an automobile emitter
|
133
|
+
And a characteristic "make_model_year_variant.row_hash" of "xxx1"
|
134
|
+
When the "urbanity" committee is calculated
|
135
|
+
And the "fuel_efficiency" committee is calculated
|
136
|
+
Then the committee should have used quorum "from make model year variant and urbanity"
|
137
|
+
And the conclusion of the committee should be "13.98601"
|
138
|
+
|
139
|
+
Scenario: Fuel efficiency committee from make model year and urbanity
|
140
|
+
Given an automobile emitter
|
141
|
+
And a characteristic "make_model_year.name" of "Acura RSX 2003"
|
142
|
+
When the "urbanity" committee is calculated
|
143
|
+
And the "fuel_efficiency" committee is calculated
|
144
|
+
Then the committee should have used quorum "from make model year and urbanity"
|
145
|
+
And the conclusion of the committee should be "19.43005"
|
146
|
+
|
147
|
+
Scenario: Fuel efficiency committee from make model and urbanity
|
148
|
+
Given an automobile emitter
|
149
|
+
And a characteristic "make_model.name" of "Acura RSX"
|
150
|
+
When the "urbanity" committee is calculated
|
151
|
+
And the "fuel_efficiency" committee is calculated
|
152
|
+
Then the committee should have used quorum "from make model and urbanity"
|
153
|
+
And the conclusion of the committee should be "6.99301"
|
154
|
+
|
155
|
+
Scenario: Fuel efficiency committee from size class, hybridity multiplier, and urbanity
|
156
|
+
Given an automobile emitter
|
157
|
+
And a characteristic "size_class.name" of "Midsize Car"
|
158
|
+
And a characteristic "hybridity_multiplier" of "2"
|
159
|
+
When the "urbanity" committee is calculated
|
160
|
+
And the "fuel_efficiency" committee is calculated
|
161
|
+
Then the committee should have used quorum "from size class, hybridity multiplier, and urbanity"
|
162
|
+
And the conclusion of the committee should be "27.97203"
|
163
|
+
|
164
|
+
Scenario: Fuel efficiency committee from make year and hybridity multiplier
|
165
|
+
Given an automobile emitter
|
166
|
+
And a characteristic "make_year.name" of "Acura 2003"
|
167
|
+
And a characteristic "hybridity_multiplier" of "2"
|
168
|
+
When the "fuel_efficiency" committee is calculated
|
169
|
+
Then the committee should have used quorum "from make year and hybridity multiplier"
|
170
|
+
And the conclusion of the committee should be "30.0"
|
171
|
+
|
172
|
+
Scenario: Fuel efficiency committee from make with fuel efficiency and hybridity multiplier
|
173
|
+
Given an automobile emitter
|
174
|
+
And a characteristic "make.name" of "Acura"
|
175
|
+
And a characteristic "hybridity_multiplier" of "2"
|
176
|
+
When the "fuel_efficiency" committee is calculated
|
177
|
+
Then the committee should have used quorum "from make and hybridity multiplier"
|
178
|
+
And the conclusion of the committee should be "20.0"
|
179
|
+
|
180
|
+
Scenario: Fuel efficiency committee from make missing fuel efficiency and hybridity multiplier
|
181
|
+
Given an automobile emitter
|
182
|
+
And a characteristic "make.name" of "Honda"
|
183
|
+
And a characteristic "hybridity_multiplier" of "2"
|
184
|
+
When the "fuel_efficiency" committee is calculated
|
185
|
+
Then the committee should have used quorum "from hybridity multiplier"
|
186
|
+
And the conclusion of the committee should be "17.1605"
|
187
|
+
|
188
|
+
Scenario: Fuel efficiency committee from hybridity multiplier
|
189
|
+
Given an automobile emitter
|
190
|
+
And a characteristic "hybridity_multiplier" of "1"
|
191
|
+
When the "fuel_efficiency" committee is calculated
|
192
|
+
Then the committee should have used quorum "from hybridity multiplier"
|
193
|
+
And the conclusion of the committee should be "8.58025"
|
194
|
+
|
195
|
+
Scenario: Annual distance committee from weekly distance and timeframe
|
196
|
+
Given an automobile emitter
|
197
|
+
And a characteristic "weekly_distance" of "7"
|
198
|
+
And a characteristic "timeframe" of "2010-05-23/2010-11-24"
|
199
|
+
When the "annual_distance" committee is calculated
|
200
|
+
Then the committee should have used quorum "from weekly distance and timeframe"
|
201
|
+
And the conclusion of the committee should be "365.0"
|
202
|
+
|
203
|
+
Scenario: Annual distance committee from daily distance and timeframe
|
204
|
+
Given an automobile emitter
|
205
|
+
And a characteristic "daily_distance" of "2"
|
206
|
+
And a characteristic "timeframe" of "2010-05-23/2010-11-24"
|
207
|
+
When the "annual_distance" committee is calculated
|
208
|
+
Then the committee should have used quorum "from daily distance and timeframe"
|
209
|
+
And the conclusion of the committee should be "730.0"
|
210
|
+
|
211
|
+
Scenario: Annual distance committee from daily duration, speed and timeframe
|
212
|
+
Given an automobile emitter
|
213
|
+
And a characteristic "daily_duration" of "2"
|
214
|
+
And a characteristic "speed" of "5"
|
215
|
+
And a characteristic "timeframe" of "2010-05-23/2010-11-24"
|
216
|
+
When the "annual_distance" committee is calculated
|
217
|
+
Then the committee should have used quorum "from daily duration, speed, and timeframe"
|
218
|
+
And the conclusion of the committee should be "3650.0"
|
219
|
+
|
220
|
+
Scenario: Annual distance committee from size class
|
221
|
+
Given an automobile emitter
|
222
|
+
And a characteristic "size_class.name" of "Midsize Car"
|
223
|
+
When the "annual_distance" committee is calculated
|
224
|
+
Then the committee should have used quorum "from size class"
|
225
|
+
And the conclusion of the committee should be "10000.0"
|
226
|
+
|
227
|
+
Scenario: Annual distance committee from fuel type
|
228
|
+
Given an automobile emitter
|
229
|
+
And a characteristic "fuel_type.code" of "P"
|
230
|
+
When the "annual_distance" committee is calculated
|
231
|
+
Then the committee should have used quorum "from fuel type"
|
232
|
+
And the conclusion of the committee should be "18161.0"
|
233
|
+
|
234
|
+
Scenario: Annual distance committee from default
|
235
|
+
Given an automobile emitter
|
236
|
+
When the "annual_distance" committee is calculated
|
237
|
+
Then the committee should have used quorum "default"
|
238
|
+
And the conclusion of the committee should be "19020.83674"
|
239
|
+
|
240
|
+
Scenario Outline: Distance committee from annual distance and active subtimeframe
|
241
|
+
Given an automobile emitter
|
242
|
+
And a characteristic "annual_distance" of "<annual_distance>"
|
243
|
+
And a characteristic "active_subtimeframe" of "<active_subtimeframe>"
|
244
|
+
And a characteristic "timeframe" of "<timeframe>"
|
245
|
+
When the "distance" committee is calculated
|
246
|
+
Then the conclusion of the committee should be "<distance>"
|
247
|
+
Examples:
|
248
|
+
| annual_distance | active_subtimeframe | timeframe | distance |
|
249
|
+
| 10000 | 2010-06-01/2010-07-07 | 2010-01-01/2010-12-31 | 986.30137 |
|
250
|
+
| 10000 | 2010-06-01/2010-07-07 | 2010-06-01/2010-06-30 | 986.30137 |
|
251
|
+
|
252
|
+
Scenario: Fuel consumed committee from fuel efficiency and distance
|
253
|
+
Given an automobile emitter
|
254
|
+
And a characteristic "distance" of "100"
|
255
|
+
And a characteristic "fuel_efficiency" of "10"
|
256
|
+
When the "fuel_consumed" committee is calculated
|
257
|
+
Then the conclusion of the committee should be "10.0"
|
258
|
+
|
259
|
+
Scenario: Emission factor committee from fuel type
|
260
|
+
Given an automobile emitter
|
261
|
+
And a characteristic "fuel_type.code" of "P"
|
262
|
+
When the "emission_factor" committee is calculated
|
263
|
+
Then the conclusion of the committee should be "2.48"
|
264
|
+
|
265
|
+
Scenario: Emission factor committee from default
|
266
|
+
Given an automobile emitter
|
267
|
+
When the "emission_factor" committee is calculated
|
268
|
+
Then the conclusion of the committee should be "2.49011"
|
@@ -1,16 +1,38 @@
|
|
1
1
|
Feature: Automobile Emissions Calculations
|
2
2
|
The automobile model should generate correct emission calculations
|
3
3
|
|
4
|
-
Scenario
|
5
|
-
Given an automobile has
|
4
|
+
Scenario: Automobile emission from nothing
|
5
|
+
Given an automobile has nothing
|
6
|
+
When emissions are calculated
|
7
|
+
Then the emission value should be within "0.01" kgs of "5520.12"
|
8
|
+
|
9
|
+
Scenario Outline: Automobile emission from acquisition, retirement, and timeframe
|
10
|
+
Given an automobile has "acquisition" of "<acquisition>"
|
11
|
+
And it has "retirement" of "<retirement>"
|
6
12
|
And it has "timeframe" of "<timeframe>"
|
7
|
-
And it has "model_year.name" of "<make_model_year>"
|
8
13
|
When emissions are calculated
|
9
|
-
Then the emission value should be within "0.
|
14
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
15
|
+
Examples:
|
16
|
+
| acquisition | retirement | timeframe | emission |
|
17
|
+
| 2010-04-21 | 2010-09-01 | 2010-01-01/2010-12-31 | 2011.44 |
|
18
|
+
| 2010-04-21 | 2010-09-01 | 2010-05-01/2010-08-01 | 1391.37 |
|
19
|
+
| 2010-04-21 | 2010-09-01 | 2010-05-01/2010-12-31 | 1860.21 |
|
20
|
+
| 2010-04-21 | 2010-09-01 | 2010-01-01/2010-08-01 | 1542.61 |
|
21
|
+
| 2010-04-21 | 2010-09-01 | 2010-01-01/2010-01-31 | 0.0 |
|
22
|
+
|
23
|
+
Scenario: Automobile emission from fuel type
|
24
|
+
Given an automobile has "fuel_type.code" of "P"
|
25
|
+
When emissions are calculated
|
26
|
+
Then the emission value should be within "0.01" kgs of "5249.18"
|
27
|
+
|
28
|
+
Scenario Outline: Automobile emission from hybridity
|
29
|
+
Given an automobile has "hybridity" of "<hybridity>"
|
30
|
+
When emissions are calculated
|
31
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
10
32
|
Examples:
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
33
|
+
| hybridity | emission |
|
34
|
+
| true | 4031.66 |
|
35
|
+
| false | 5564.02 |
|
14
36
|
|
15
37
|
Scenario: Calculation with multiple distance estimates
|
16
38
|
Given an automobile has "annual_distance_estimate" of "33796.2"
|
@@ -19,3 +41,67 @@ Feature: Automobile Emissions Calculations
|
|
19
41
|
And it has "weekly_distance_estimate" of "804.672"
|
20
42
|
When emissions are calculated
|
21
43
|
Then the emission value should be within "0.1" kgs of "9808.1"
|
44
|
+
|
45
|
+
Scenario: Automobile emission from urbanity
|
46
|
+
Given an automobile has "urbanity" of "0.5"
|
47
|
+
When emissions are calculated
|
48
|
+
Then the emission value should be within "0.01" kgs of "5520.12"
|
49
|
+
|
50
|
+
Scenario Outline: Automobile emission from size class
|
51
|
+
Given an automobile has "size_class.name" of "<size_class>"
|
52
|
+
When emissions are calculated
|
53
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
54
|
+
Examples:
|
55
|
+
| size_class | emission |
|
56
|
+
| Midsize Car | 1780.43 |
|
57
|
+
| Midsize Wagon | 5341.29 |
|
58
|
+
|
59
|
+
Scenario: Automobile emission from fuel efficiency
|
60
|
+
Given an automobile has "fuel_efficiency" of "20"
|
61
|
+
When emissions are calculated
|
62
|
+
Then the emission value should be within "0.01" kgs of "2368.20"
|
63
|
+
|
64
|
+
Scenario: Automobile emission from annual distance
|
65
|
+
Given an automobile has "annual_distance" of "1000"
|
66
|
+
When emissions are calculated
|
67
|
+
Then the emission value should be within "0.01" kgs of "290.21"
|
68
|
+
|
69
|
+
Scenario: Automobile emission from weekly distance
|
70
|
+
Given an automobile has "weekly_distance" of "100"
|
71
|
+
When emissions are calculated
|
72
|
+
Then the emission value should be within "0.01" kgs of "1513.26"
|
73
|
+
|
74
|
+
Scenario: Automobile emission from daily distance
|
75
|
+
Given an automobile has "daily_distance" of "10"
|
76
|
+
When emissions are calculated
|
77
|
+
Then the emission value should be within "0.01" kgs of "1059.28"
|
78
|
+
|
79
|
+
Scenario: Automobile emission from daily duration
|
80
|
+
Given an automobile has "daily_duration" of "5"
|
81
|
+
When emissions are calculated
|
82
|
+
Then the emission value should be within "0.01" kgs of "26981.99"
|
83
|
+
|
84
|
+
Scenario: Automobile emission from make
|
85
|
+
Given an automobile has "make.name" of "Acura"
|
86
|
+
When emissions are calculated
|
87
|
+
Then the emission value should be within "0.01" kgs of "4736.40"
|
88
|
+
|
89
|
+
Scenario: Automobile emission from make year
|
90
|
+
Given an automobile has "make_year.name" of "Acura 2003"
|
91
|
+
When emissions are calculated
|
92
|
+
Then the emission value should be within "0.01" kgs of "3157.60"
|
93
|
+
|
94
|
+
Scenario: Automobile emission from make model
|
95
|
+
Given an automobile has "make_model.name" of "Acura RSX"
|
96
|
+
When emissions are calculated
|
97
|
+
Then the emission value should be within "0.01" kgs of "6773.06"
|
98
|
+
|
99
|
+
Scenario: Automobile emission from make model year
|
100
|
+
Given an automobile has "make_model_year.name" of "Acura RSX 2003"
|
101
|
+
When emissions are calculated
|
102
|
+
Then the emission value should be within "0.01" kgs of "2437.67"
|
103
|
+
|
104
|
+
Scenario: Automobile emission from make model year variant
|
105
|
+
Given an automobile has "make_model_year_variant.row_hash" of "xxx1"
|
106
|
+
When emissions are calculated
|
107
|
+
Then the emission value should be within "0.01" kgs of "3220.31"
|
@@ -4,101 +4,267 @@
|
|
4
4
|
|
5
5
|
require 'conversions'
|
6
6
|
|
7
|
+
## Automobile carbon model
|
8
|
+
# 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**.
|
9
|
+
#
|
10
|
+
##### Timeframe, acquisition, and retirement
|
11
|
+
# The model estimates the emissions that occur during a particular `timeframe`. To do this it needs to know the automobile's `acquisition` (the date it started being used) and `retirement` (the date it stopped being used). For example, if the `timeframe` is January 2010, an automobile with `acquisition` of January 2009 and `retirement` of February 2010 will have emissions, but an automobile with `acquisition` of February 2010 or `retirement` of December 2009 will not.
|
12
|
+
#
|
13
|
+
##### Calculations
|
14
|
+
# 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.
|
15
|
+
#
|
16
|
+
##### Methods
|
17
|
+
# 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.
|
18
|
+
#
|
19
|
+
##### Standard compliance
|
20
|
+
# 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.
|
21
|
+
#
|
22
|
+
##### Collaboration
|
23
|
+
# 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.
|
7
24
|
module BrighterPlanet
|
8
25
|
module Automobile
|
9
26
|
module CarbonModel
|
10
27
|
def self.included(base)
|
11
28
|
base.decide :emission, :with => :characteristics do
|
12
|
-
|
13
|
-
|
29
|
+
### Emission calculation
|
30
|
+
# Returns the `emission` estimate (*kg CO<sub>2</sub>e*).
|
31
|
+
committee :emission do
|
32
|
+
#### Emission from fuel
|
33
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
34
|
+
#
|
35
|
+
# Multiplies `fuel consumed` (*l*) by the `emission factor` (*kg CO<sub>2</sub>e / l*) to give *kg CO<sub>2</sub>e*.
|
36
|
+
quorum 'from fuel', :needs => [:fuel_consumed, :emission_factor], :appreciates => :fuel_type, :complies => [:ghg_protocol, :iso] do |characteristics|
|
14
37
|
if characteristics[:fuel_type].andand.code == AutomobileFuelType::CODES[:electricity]
|
15
|
-
0.0
|
38
|
+
0.0
|
16
39
|
else
|
17
40
|
characteristics[:fuel_consumed] * characteristics[:emission_factor]
|
18
41
|
end
|
19
42
|
end
|
20
43
|
|
44
|
+
#### Emission from default
|
45
|
+
# **Complies:**
|
46
|
+
#
|
47
|
+
# Displays an error message if the previous method fails.
|
21
48
|
quorum 'default' do
|
22
49
|
raise "The emission committee's default quorum should never be called"
|
23
50
|
end
|
24
51
|
end
|
25
|
-
|
26
|
-
|
27
|
-
|
52
|
+
|
53
|
+
### Emission factor calculation
|
54
|
+
# Returns the `emission factor` (*kg CO<sub>2</sub>e / l*)
|
55
|
+
committee :emission_factor do
|
56
|
+
#### Emission factor from fuel type
|
57
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
58
|
+
#
|
59
|
+
# Looks up the automobile [fuel type](http://data.brighterplanet.com/fuel_types) `emission factor` (*kg CO2e / l*)
|
60
|
+
quorum 'from fuel type', :needs => :fuel_type, :complies => [:ghg_protocol, :iso] do |characteristics|
|
28
61
|
characteristics[:fuel_type].emission_factor
|
29
62
|
end
|
30
|
-
|
31
|
-
|
32
|
-
|
63
|
+
|
64
|
+
#### Default emission factor
|
65
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
66
|
+
#
|
67
|
+
# Uses a default `emission factor` of 2.49 *kg CO<sub>2</sub>e / l*, calculated from [EPA (2010)](http://www.epa.gov/climatechange/emissions/usinventoryreport.html)
|
68
|
+
quorum 'default', :complies => [:ghg_protocol, :iso] do
|
69
|
+
20.781.pounds_per_gallon.to(:kilograms_per_litre)
|
33
70
|
end
|
34
71
|
end
|
35
72
|
|
36
|
-
|
37
|
-
|
38
|
-
|
73
|
+
### Fuel consumed calculation
|
74
|
+
# Returns the `fuel consumed` (*l*).
|
75
|
+
committee :fuel_consumed do
|
76
|
+
#### Fuel consumed from fuel efficiency and distance
|
77
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
78
|
+
#
|
79
|
+
# Divides the `distance` (*km*) by the `fuel efficiency` (*km / l*) to give *l*.
|
80
|
+
quorum 'from fuel efficiency and distance', :needs => [:fuel_efficiency, :distance], :complies => [:ghg_protocol, :iso] do |characteristics|
|
81
|
+
characteristics[:distance] / characteristics[:fuel_efficiency]
|
39
82
|
end
|
40
83
|
end
|
41
84
|
|
42
|
-
|
43
|
-
|
85
|
+
### Distance calculation
|
86
|
+
# Returns the `distance` (*km*).
|
87
|
+
# This is the distance the automobile travelled during the `active subtimeframe`.
|
88
|
+
committee :distance do
|
89
|
+
#### Distance from annual distance
|
90
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
91
|
+
#
|
92
|
+
# Multiplies the `annual distance` (*km*) by the fraction of the calendar year in which the `timeframe` falls that overlaps with the `active subtimeframe`.
|
93
|
+
quorum 'from annual distance', :needs => [:annual_distance, :active_subtimeframe], :complies => [:ghg_protocol, :iso] do |characteristics, timeframe|
|
44
94
|
characteristics[:annual_distance] * (characteristics[:active_subtimeframe] / timeframe.year)
|
45
95
|
end
|
46
96
|
end
|
47
97
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
98
|
+
### Annual distance calculation
|
99
|
+
# Returns the `annual distance` (*km*).
|
100
|
+
# This is the distance the automobile would travel if it were in use for the entire calendar year in which the `timeframe` falls.
|
101
|
+
# Note that if either `acquisition` or `retirement` occurs during the calendar year in which the `timeframe` falls then `annual distance` will be MORE THAN the distance the automobile actually travelled during that calendar year.
|
102
|
+
committee :annual_distance do
|
103
|
+
#### Annual distance from client input
|
104
|
+
# **Complies:** All
|
105
|
+
#
|
106
|
+
# Uses the client-input `annual distance` (*km*).
|
107
|
+
|
108
|
+
#### Annual distance from weekly distance
|
109
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
110
|
+
#
|
111
|
+
# Divides the `weekly distance` (*km*) by 7 and multiplies by the number of days in the calendar year in which the `timeframe` falls.
|
112
|
+
quorum 'from weekly distance and timeframe', :needs => :weekly_distance, :complies => [:ghg_protocol, :iso] do |characteristics, timeframe|
|
113
|
+
(characteristics[:weekly_distance] / 7 ) * timeframe.year.days
|
55
114
|
end
|
56
115
|
|
57
|
-
|
116
|
+
#### Annual distance from daily distance
|
117
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
118
|
+
#
|
119
|
+
# Multiplies the `daily distance` (*km*) by the number of days in the calendar year in which the `timeframe` falls.
|
120
|
+
quorum 'from daily distance and timeframe', :needs => :daily_distance, :complies => [:ghg_protocol, :iso] do |characteristics, timeframe|
|
58
121
|
characteristics[:daily_distance] * timeframe.year.days
|
59
122
|
end
|
60
123
|
|
61
|
-
|
124
|
+
#### Annual distance from daily duration and speed
|
125
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
126
|
+
#
|
127
|
+
# * Multiplies the `daily duration` (*hours*) by the `speed` (*km / hour*) to give *km*
|
128
|
+
# * Multiplies the result by the number of days in the calendar year in which the `timeframe` falls.
|
129
|
+
quorum 'from daily duration, speed, and timeframe', :needs => [:daily_duration, :speed], :complies => [:ghg_protocol, :iso] do |characteristics, timeframe|
|
130
|
+
characteristics[:daily_duration] * characteristics[:speed] * timeframe.year.days
|
131
|
+
end
|
132
|
+
|
133
|
+
#### Annual distance from size class
|
134
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
135
|
+
#
|
136
|
+
# Looks up the automobile [size class](http://data.brighterplanet.com/automobile_size_classes) `annual distance` (*km*).
|
137
|
+
quorum 'from size class', :needs => :size_class, :complies => [:ghg_protocol, :iso] do |characteristics|
|
62
138
|
characteristics[:size_class].annual_distance
|
63
139
|
end
|
64
|
-
|
65
|
-
|
140
|
+
|
141
|
+
#### Annual distance from fuel type
|
142
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
143
|
+
#
|
144
|
+
# Looks up the [fuel type](http://data.brighterplanet.com/fuel_types) `annual distance` (*km*).
|
145
|
+
quorum 'from fuel type', :needs => :fuel_type, :complies => [:ghg_protocol, :iso] do |characteristics|
|
66
146
|
characteristics[:fuel_type].annual_distance
|
67
147
|
end
|
68
148
|
|
69
|
-
|
70
|
-
|
149
|
+
#### Default annual distance
|
150
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
151
|
+
#
|
152
|
+
# Uses an `annual distance` of 19,021 *km*, calculated from total US automobile vehicle miles travelled and number of automobiles.
|
153
|
+
quorum 'default', :complies => [:ghg_protocol, :iso] do
|
154
|
+
11819.miles.to(:kilometres)
|
71
155
|
end
|
72
156
|
end
|
73
157
|
|
74
|
-
|
75
|
-
|
76
|
-
|
158
|
+
### Weekly distance calculation
|
159
|
+
# Returns the client-input `weekly distance` (*km*).
|
160
|
+
# This is the average distance the automobile travels each week.
|
161
|
+
|
162
|
+
### Daily distance calculation
|
163
|
+
# Returns the client-input `daily distance` (*km*).
|
164
|
+
# This is the average distance the automobile travels each day.
|
165
|
+
|
166
|
+
### Daily duration calculation
|
167
|
+
# Returns the client-input `daily duration` (*hours*).
|
168
|
+
|
169
|
+
### Fuel efficiency calculation
|
170
|
+
# Returns the `fuel efficiency` (*km / l*)
|
171
|
+
committee :fuel_efficiency do
|
172
|
+
#### Fuel efficiency from client input
|
173
|
+
# **Complies:** All
|
174
|
+
#
|
175
|
+
# Uses the client-input `fuel efficiency` (*km / l*).
|
176
|
+
|
177
|
+
#### Fuel efficiency from make model year variant and urbanity
|
178
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
179
|
+
#
|
180
|
+
# * Looks up the city and highway fuel efficiencies of the automobile [make model year variant](http://data.brighterplanet.com/automobile_variants) (*km / l*)
|
181
|
+
# * Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`
|
182
|
+
quorum 'from make model year variant and urbanity', :needs => [:make_model_year_variant, :urbanity], :complies => [:ghg_protocol, :iso] do |characteristics|
|
183
|
+
fuel_efficiency_city = characteristics[:make_model_year_variant].fuel_efficiency_city
|
184
|
+
fuel_efficiency_highway = characteristics[:make_model_year_variant].fuel_efficiency_highway
|
185
|
+
urbanity = characteristics[:urbanity]
|
186
|
+
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
77
187
|
end
|
78
188
|
|
79
|
-
|
80
|
-
|
189
|
+
#### Fuel efficiency from make model year and urbanity
|
190
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
191
|
+
#
|
192
|
+
# * Looks up the city and highway fuel efficiencies of the automobile [make model year](http://data.brighterplanet.com/automobile_model_years) (*km / l*)
|
193
|
+
# * Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`
|
194
|
+
quorum 'from make model year and urbanity', :needs => [:make_model_year, :urbanity], :complies => [:ghg_protocol, :iso] do |characteristics|
|
195
|
+
fuel_efficiency_city = characteristics[:make_model_year].fuel_efficiency_city
|
196
|
+
fuel_efficiency_highway = characteristics[:make_model_year].fuel_efficiency_highway
|
197
|
+
urbanity = characteristics[:urbanity]
|
198
|
+
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
81
199
|
end
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
200
|
+
|
201
|
+
#### Fuel efficiency from make model and urbanity
|
202
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
203
|
+
#
|
204
|
+
# * Looks up the city and highway fuel efficiencies of the automobile [make model](http://data.brighterplanet.com/automobile_models) (*km / l*)
|
205
|
+
# * Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`
|
206
|
+
quorum 'from make model and urbanity', :needs => [:make_model, :urbanity], :complies => [:ghg_protocol, :iso] do |characteristics|
|
207
|
+
fuel_efficiency_city = characteristics[:make_model].fuel_efficiency_city
|
208
|
+
fuel_efficiency_highway = characteristics[:make_model].fuel_efficiency_highway
|
209
|
+
urbanity = characteristics[:urbanity]
|
210
|
+
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
87
211
|
end
|
88
|
-
|
89
|
-
|
90
|
-
|
212
|
+
|
213
|
+
#### Fuel efficiency from size class, hybridity multiplier, and urbanity
|
214
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
215
|
+
#
|
216
|
+
# * Looks up the automobile [size class](http://data.brighterplanet.com/automobile_makes) city and highway fuel efficiency (*km / l*)
|
217
|
+
# * Calculates the harmonic mean of those fuel efficiencies, weighted by `urbanity`
|
218
|
+
# * Multiplies the result by the `hybridity multiplie`r
|
219
|
+
quorum 'from size class, hybridity multiplier, and urbanity', :needs => [:size_class, :hybridity_multiplier, :urbanity], :complies => [:ghg_protocol, :iso] do |characteristics|
|
220
|
+
fuel_efficiency_city = characteristics[:size_class].fuel_efficiency_city
|
221
|
+
fuel_efficiency_highway = characteristics[:size_class].fuel_efficiency_highway
|
91
222
|
urbanity = characteristics[:urbanity]
|
92
|
-
1.0 / ((urbanity /
|
223
|
+
(1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))) * characteristics[:hybridity_multiplier]
|
224
|
+
end
|
225
|
+
|
226
|
+
#### Fuel efficiency from make year and hybridity multiplier
|
227
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
228
|
+
#
|
229
|
+
# * Looks up the automobile [make year](http://data.brighterplanet.com/automobile_make_years) combined fuel efficiency (*km / l*)
|
230
|
+
# * Multiplies the combined fuel efficiency by the `hybridity multiplier`
|
231
|
+
quorum 'from make year and hybridity multiplier', :needs => [:make_year, :hybridity_multiplier], :complies => [:ghg_protocol, :iso] do |characteristics|
|
232
|
+
characteristics[:make_year].fuel_efficiency * characteristics[:hybridity_multiplier]
|
233
|
+
end
|
234
|
+
|
235
|
+
#### Fuel efficiency from make and hybridity multiplier
|
236
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
237
|
+
#
|
238
|
+
# * Looks up the automobile [make](http://data.brighterplanet.com/automobile_makes) combined fuel efficiency (*km / l*)
|
239
|
+
# * Multiplies the combined fuel efficiency by the `hybridity multiplier`
|
240
|
+
quorum 'from make and hybridity multiplier', :needs => [:make, :hybridity_multiplier], :complies => [:ghg_protocol, :iso] do |characteristics|
|
241
|
+
if characteristics[:make].fuel_efficiency.nil?
|
242
|
+
nil
|
243
|
+
else
|
244
|
+
characteristics[:make].fuel_efficiency * characteristics[:hybridity_multiplier]
|
245
|
+
end
|
93
246
|
end
|
94
247
|
|
95
|
-
|
96
|
-
|
248
|
+
#### Fuel efficiency from hybridity multiplier
|
249
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
250
|
+
#
|
251
|
+
# * Takes a default `fuel efficiency` of 8.58 *km / l*, calculated from total US automobile vehicle miles travelled and gasoline and diesel consumption.
|
252
|
+
# * Multiplies the `fuel efficiency` by the `hybridity multiplier`
|
253
|
+
quorum 'from hybridity multiplier', :needs => :hybridity_multiplier, :complies => [:ghg_protocol, :iso] do |characteristics|
|
254
|
+
20.182.miles_per_gallon.to(:kilometres_per_litre) * characteristics[:hybridity_multiplier]
|
97
255
|
end
|
98
256
|
end
|
99
257
|
|
100
|
-
|
101
|
-
|
258
|
+
### Hybridity multiplier calculation
|
259
|
+
# Returns the `hybridity multiplier`.
|
260
|
+
# This value may be used to adjust the fuel efficiency based on whether the automobile is a hybrid or conventional vehicle.
|
261
|
+
committee :hybridity_multiplier do
|
262
|
+
#### Hybridity multiplier from size class, hybridity, and urbanity
|
263
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
264
|
+
#
|
265
|
+
# * Looks up the appropriate city and highway hybridity multipliers for the automobile [size class](http://data.brighterplanet.com/automobile_size_classes)
|
266
|
+
# * Calculates the harmonic mean of those multipliers, weighted by `urbanity`
|
267
|
+
quorum 'from size class, hybridity, and urbanity', :needs => [:size_class, :hybridity, :urbanity], :complies => [:ghg_protocol, :iso] do |characteristics|
|
102
268
|
drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
|
103
269
|
urbanity = characteristics[:urbanity]
|
104
270
|
size_class = characteristics[:size_class]
|
@@ -113,7 +279,12 @@ module BrighterPlanet
|
|
113
279
|
end
|
114
280
|
end
|
115
281
|
|
116
|
-
|
282
|
+
#### Hybridity multiplier from hybridity and urbanity
|
283
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
284
|
+
#
|
285
|
+
# * Looks up the appropriate default city and highway hybridity multipliers
|
286
|
+
# * Calculates the harmonic mean of those multipliers, weighted by `urbanity`
|
287
|
+
quorum 'from hybridity and urbanity', :needs => [:hybridity, :urbanity], :complies => [:ghg_protocol, :iso] do |characteristics|
|
117
288
|
drivetrain = characteristics[:hybridity] ? :hybrid : :conventional
|
118
289
|
urbanity = characteristics[:urbanity]
|
119
290
|
fuel_efficiency_multipliers = {
|
@@ -123,95 +294,171 @@ module BrighterPlanet
|
|
123
294
|
1.0 / ((urbanity / fuel_efficiency_multipliers[:city]) + ((1.0 - urbanity) / fuel_efficiency_multipliers[:highway]))
|
124
295
|
end
|
125
296
|
|
126
|
-
|
297
|
+
#### Default hybridity multiplier
|
298
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
299
|
+
#
|
300
|
+
# Uses a default `hybridity multiplier` of 1.
|
301
|
+
quorum 'default', :complies => [:ghg_protocol, :iso] do
|
127
302
|
1.0
|
128
303
|
end
|
129
304
|
end
|
130
305
|
|
131
|
-
|
132
|
-
|
133
|
-
fuel_efficiency_city = characteristics[:model].fuel_efficiency_city.to_f
|
134
|
-
fuel_efficiency_highway = characteristics[:model].fuel_efficiency_highway.to_f
|
135
|
-
urbanity = characteristics[:urbanity]
|
136
|
-
1.0 / ((urbanity / fuel_efficiency_city) + ((1.0 - urbanity) / fuel_efficiency_highway))
|
137
|
-
end
|
138
|
-
|
139
|
-
quorum 'from make and model year', :needs => [:model_year] do |characteristics|
|
140
|
-
characteristics[:model_year].make_year.andand.fuel_efficiency
|
141
|
-
end
|
142
|
-
|
143
|
-
quorum 'from size class', :needs => [:size_class, :urbanity] do |characteristics|
|
144
|
-
fuel_efficiencies = characteristics[:size_class].attributes.symbolize_keys.slice(:fuel_efficiency_city, :fuel_efficiency_highway)
|
145
|
-
urbanity = characteristics[:urbanity]
|
146
|
-
1.0 / ((urbanity / fuel_efficiencies[:fuel_efficiency_city].to_f) + ((1.0 - urbanity) / fuel_efficiencies[:fuel_efficiency_highway].to_f))
|
147
|
-
end
|
148
|
-
|
149
|
-
quorum 'from model year', :needs => :model_year do |characteristics|
|
150
|
-
characteristics[:model_year].fuel_efficiency
|
151
|
-
end
|
152
|
-
|
153
|
-
quorum 'from make', :needs => :make do |characteristics|
|
154
|
-
characteristics[:make].fuel_efficiency
|
155
|
-
end
|
156
|
-
|
157
|
-
quorum 'default' do
|
158
|
-
Automobile.automobile_model.fallback.fuel_efficiency
|
159
|
-
end
|
160
|
-
end
|
306
|
+
### Hybridity calculation
|
307
|
+
# Returns the client-input `hybridity`. This indicates whether the automobile is a hybrid electric vehicle or a conventional vehicle.
|
161
308
|
|
162
|
-
|
163
|
-
|
164
|
-
|
309
|
+
### Size class calculation
|
310
|
+
# Returns the client-input automobile [size class](http://data.brighterplanet.com/automobile_size_classes).
|
311
|
+
|
312
|
+
### Speed calculation
|
313
|
+
# Returns the average `speed` at which the automobile travels (*km / hour*)
|
314
|
+
committee :speed do
|
315
|
+
#### Speed from urbanity
|
316
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
317
|
+
#
|
318
|
+
# * 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*
|
319
|
+
# * Calculates the harmonic mean of those speeds, weighted by `urbanity`
|
320
|
+
quorum 'from urbanity', :needs => :urbanity, :complies => [:ghg_protocol, :iso] do |characteristics|
|
321
|
+
1 / (characteristics[:urbanity] / 19.9.miles.to(:kilometres) + (1 - characteristics[:urbanity]) / 57.1.miles.to(:kilometres))
|
165
322
|
end
|
166
323
|
end
|
167
324
|
|
325
|
+
### Urbanity calculation
|
326
|
+
# Returns the `urbanity`.
|
327
|
+
# 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").
|
168
328
|
committee :urbanity do
|
169
|
-
|
170
|
-
|
329
|
+
#### Urbanity from client input
|
330
|
+
# **Complies:** All
|
331
|
+
#
|
332
|
+
# Uses the client-input `urbanity`.
|
333
|
+
|
334
|
+
#### Default urbanity
|
335
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
336
|
+
#
|
337
|
+
# Uses an `urbanity` of 0.43 after [EPA (2009) Appendix A](http://www.epa.gov/otaq/cert/mpg/fetrends/420r09014-appx-a.pdf)
|
338
|
+
quorum 'default', :complies => [:ghg_protocol, :iso] do
|
339
|
+
0.43
|
171
340
|
end
|
172
341
|
end
|
173
342
|
|
343
|
+
### Fuel type calculation
|
344
|
+
# Returns the `fuel type` used by the automobile.
|
174
345
|
committee :fuel_type do
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
346
|
+
#### Fuel type from client input
|
347
|
+
# **Complies:** All
|
348
|
+
#
|
349
|
+
# Uses the client-input [fuel type](http://data.brighterplanet.com/fuel_types).
|
350
|
+
|
351
|
+
#### Fuel type from make model year variant
|
352
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
353
|
+
#
|
354
|
+
# Looks up the [variant](http://data.brighterplanet.com/automobile_variants) `fuel type`.
|
355
|
+
quorum 'from make model year variant', :needs => :make_model_year_variant, :complies => [:ghg_protocol, :iso] do |characteristics|
|
356
|
+
characteristics[:make_model_year_variant].fuel_type
|
181
357
|
end
|
182
358
|
end
|
183
359
|
|
360
|
+
### Active subtimeframe calculation
|
361
|
+
# Returns the portion of the `timeframe` that falls between the `acquisition` and `retirement`.
|
184
362
|
committee :active_subtimeframe do
|
185
|
-
|
363
|
+
#### Active subtimeframe from timeframe, acquisition, and retirement
|
364
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
365
|
+
#
|
366
|
+
# Uses the portion of the `timeframe` that falls between `acquisition` and `retirement`.
|
367
|
+
quorum 'from acquisition and retirement', :needs => [:acquisition, :retirement], :complies => [:ghg_protocol, :iso] do |characteristics, timeframe|
|
186
368
|
Timeframe.constrained_new characteristics[:acquisition].to_date, characteristics[:retirement].to_date, timeframe
|
187
369
|
end
|
188
370
|
end
|
189
371
|
|
372
|
+
### Acquisition calculation
|
373
|
+
# Returns the date of the automobile's `acquisition`.
|
374
|
+
# This is the date the automobile was put into use.
|
190
375
|
committee :acquisition do
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
376
|
+
#### Acquisition from client input
|
377
|
+
# **Complies:** All
|
378
|
+
#
|
379
|
+
# Uses the client-input `acquisition`.
|
380
|
+
|
381
|
+
#### Acquisition from make model year variant
|
382
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
383
|
+
#
|
384
|
+
# Uses the first day of the client-input automobile [make model year variant](http://data.brighterplanet.com/automobile_variants) year.
|
385
|
+
quorum 'from make model year variant', :needs => [:make_model_year_variant], :complies => [:ghg_protocol, :iso] do |characteristics|
|
386
|
+
Date.new characteristics[:make_model_year_variant].year, 1, 1
|
387
|
+
end
|
388
|
+
|
389
|
+
#### Acquisition from make model year
|
390
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
391
|
+
#
|
392
|
+
# Uses the first day of the client-input automobile [make model year](http://data.brighterplanet.com/automobile_model_years) year.
|
393
|
+
quorum 'from make model year', :needs => [:make_model_year], :complies => [:ghg_protocol, :iso] do |characteristics|
|
394
|
+
Date.new characteristics[:make_model_year].year, 1, 1
|
197
395
|
end
|
198
|
-
|
396
|
+
|
397
|
+
#### Acquisition from make year
|
398
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
399
|
+
#
|
400
|
+
# Uses the first day of the client-input automobile [make year](http://data.brighterplanet.com/automobile_make_years) year.
|
401
|
+
quorum 'from make year', :needs => [:make_year], :complies => [:ghg_protocol, :iso] do |characteristics|
|
402
|
+
Date.new characteristics[:make_year].year, 1, 1
|
403
|
+
end
|
404
|
+
|
405
|
+
#### Acquisition from timeframe or retirement
|
406
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
407
|
+
#
|
408
|
+
# Uses the first day of the `timeframe`, or the `retirement`, whichever is earlier.
|
409
|
+
quorum 'from retirement', :appreciates => :retirement, :complies => [:ghg_protocol, :iso] do |characteristics, timeframe|
|
199
410
|
[ timeframe.from, characteristics[:retirement] ].compact.min
|
200
411
|
end
|
201
412
|
end
|
202
413
|
|
414
|
+
### Retirement calculation
|
415
|
+
# Returns the date of the automobile's `retirement`.
|
416
|
+
# This is the date the automobile was taken out of use.
|
203
417
|
committee :retirement do
|
204
|
-
|
418
|
+
#### Retirement from client input
|
419
|
+
# **Complies:** All
|
420
|
+
#
|
421
|
+
# Uses the client-input `retirement`.
|
422
|
+
|
423
|
+
#### Retirement from timeframe or acquisition
|
424
|
+
# **Complies:** GHG Protocol, ISO 14064-1
|
425
|
+
#
|
426
|
+
# Uses the last day of the `timeframe`, or the `acquisition`, whichever is later.
|
427
|
+
quorum 'from acquisition', :appreciates => :acquisition, :complies => [:ghg_protocol, :iso] do |characteristics, timeframe|
|
205
428
|
[ timeframe.to, characteristics[:acquisition] ].compact.max
|
206
429
|
end
|
207
430
|
end
|
208
431
|
|
432
|
+
### Make model year variant calculation
|
433
|
+
# Returns the client-input automobile [make model year variant](http://data.brighterplanet.com/automobile_variants).
|
434
|
+
|
435
|
+
### Make model year calculation
|
436
|
+
# Returns the client-input automobile [make model year](http://data.brighterplanet.com/automobile_model_years).
|
437
|
+
|
438
|
+
### Make model calculation
|
439
|
+
# Returns the client-input automobile [make model](http://data.brighterplanet.com/automobile_models).
|
440
|
+
|
441
|
+
### Make year calculation
|
442
|
+
# Returns the client-input automobile [make year](http://data.brighterplanet.com/automobile_make_years).
|
443
|
+
|
444
|
+
### Make calculation
|
445
|
+
# Returns the client-input automobile [make](http://data.brighterplanet.com/automobile_makes).
|
446
|
+
|
447
|
+
### Timeframe calculation
|
448
|
+
# Returns the `timeframe`.
|
449
|
+
# This is the period during which to calculate emissions.
|
450
|
+
|
451
|
+
#### Timeframe from client input
|
452
|
+
# **Complies:** All
|
453
|
+
#
|
454
|
+
# Uses the client-input `timeframe`.
|
455
|
+
|
456
|
+
#### Default timeframe
|
457
|
+
# **Complies:** All
|
458
|
+
#
|
459
|
+
# Uses the current calendar year.
|
209
460
|
end
|
210
461
|
end
|
211
|
-
SPEEDS = {
|
212
|
-
:highway => 57.1.miles.to(:kilometres), # https://brighterplanet.sifterapp.com/projects/30/issues/428
|
213
|
-
:city => 19.9.miles.to(:kilometres) # https://brighterplanet.sifterapp.com/projects/30/issues/428
|
214
|
-
}
|
215
462
|
end
|
216
463
|
end
|
217
464
|
end
|
@@ -3,13 +3,11 @@ module BrighterPlanet
|
|
3
3
|
module Characterization
|
4
4
|
def self.included(base)
|
5
5
|
base.characterize do
|
6
|
-
has :make
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|
6
|
+
has :make
|
7
|
+
has :make_year
|
8
|
+
has :make_model
|
9
|
+
has :make_model_year
|
10
|
+
has :make_model_year_variant
|
13
11
|
## sabshere 5/27/10: thought exercise... if we wanted people to send in make=ford&model=taurus&model_year=2006 (of course it would be &naked_model=, but you get the point)
|
14
12
|
# has :make do |make|
|
15
13
|
# make.reveals :naked_model_year do |model_year|
|
@@ -18,17 +16,17 @@ module BrighterPlanet
|
|
18
16
|
# end
|
19
17
|
# end
|
20
18
|
# end
|
19
|
+
has :size_class
|
21
20
|
has :fuel_type
|
22
|
-
has :
|
23
|
-
has :urbanity, :measures => :percentage
|
21
|
+
has :urbanity
|
24
22
|
has :hybridity
|
25
|
-
has :
|
26
|
-
has :
|
27
|
-
has :
|
28
|
-
has :
|
23
|
+
has :fuel_efficiency
|
24
|
+
has :annual_distance
|
25
|
+
has :weekly_distance
|
26
|
+
has :daily_distance
|
27
|
+
has :daily_duration
|
29
28
|
has :acquisition
|
30
29
|
has :retirement
|
31
|
-
has :size_class
|
32
30
|
# has :annual_fuel_cost, :trumps => [:annual_distance_estimate, :weekly_distance_estimate, :daily_distance_estimate, :daily_duration, :weekly_fuel_cost], :measures => :cost
|
33
31
|
# has :weekly_fuel_cost, :trumps => [:annual_distance_estimate, :weekly_distance_estimate, :daily_distance_estimate, :daily_duration, :annual_fuel_cost], :measures => :cost
|
34
32
|
end
|
data/lib/automobile/data.rb
CHANGED
@@ -4,20 +4,20 @@ module BrighterPlanet
|
|
4
4
|
def self.included(base)
|
5
5
|
base.data_miner do
|
6
6
|
schema do
|
7
|
-
string '
|
8
|
-
string '
|
9
|
-
string '
|
10
|
-
string '
|
11
|
-
string '
|
12
|
-
string '
|
7
|
+
string 'make_name'
|
8
|
+
string 'make_year_name'
|
9
|
+
string 'make_model_name'
|
10
|
+
string 'make_model_year_name'
|
11
|
+
string 'make_model_year_variant_row_hash'
|
12
|
+
string 'size_class_name'
|
13
|
+
string 'fuel_type_code'
|
13
14
|
boolean 'hybridity'
|
14
15
|
float 'urbanity'
|
15
16
|
float 'fuel_efficiency'
|
16
|
-
float '
|
17
|
-
float '
|
18
|
-
float '
|
17
|
+
float 'annual_distance'
|
18
|
+
float 'weekly_distance'
|
19
|
+
float 'daily_distance'
|
19
20
|
float 'daily_duration'
|
20
|
-
date 'date'
|
21
21
|
date 'acquisition'
|
22
22
|
date 'retirement'
|
23
23
|
end
|
@@ -3,9 +3,9 @@ module BrighterPlanet
|
|
3
3
|
module Summarization
|
4
4
|
def self.included(base)
|
5
5
|
base.summarize do |has|
|
6
|
-
has.adjective :
|
6
|
+
has.adjective :make_model_year
|
7
7
|
has.adjective :make
|
8
|
-
has.adjective :
|
8
|
+
has.adjective :make_model
|
9
9
|
has.identity 'automobile'
|
10
10
|
has.verb :own
|
11
11
|
end
|
@@ -19,14 +19,11 @@ class AutomobileRecord < ActiveRecord::Base
|
|
19
19
|
include BrighterPlanet::Automobile
|
20
20
|
include Sniff::Emitter
|
21
21
|
|
22
|
-
belongs_to :
|
23
|
-
belongs_to :
|
24
|
-
belongs_to :
|
25
|
-
belongs_to :
|
26
|
-
belongs_to :
|
27
|
-
belongs_to :
|
28
|
-
|
29
|
-
falls_back_on :fuel_efficiency => 20.182.miles_per_gallon.to(:kilometres_per_litre), # mpg https://brighterplanet.sifterapp.com/projects/30/issues/428
|
30
|
-
:urbanity => 0.43, # EPA via Ian https://brighterplanet.sifterapp.com/projects/30/issues/428
|
31
|
-
:annual_distance_estimate => 11819.miles.to(:kilometres) # miles https://brighterplanet.sifterapp.com/projects/30/issues/428
|
22
|
+
belongs_to :make, :class_name => 'AutomobileMake', :foreign_key => 'make_name'
|
23
|
+
belongs_to :make_year, :class_name => 'AutomobileMakeYear', :foreign_key => 'make_year_name'
|
24
|
+
belongs_to :make_model, :class_name => 'AutomobileMakeModel', :foreign_key => 'make_model_name'
|
25
|
+
belongs_to :make_model_year, :class_name => 'AutomobileMakeModelYear', :foreign_key => 'make_model_year_name'
|
26
|
+
belongs_to :make_model_year_variant, :class_name => 'AutomobileMakeModelYearVariant', :foreign_key => 'make_model_year_variant_row_hash'
|
27
|
+
belongs_to :fuel_type, :class_name => 'AutomobileFuelType', :foreign_key => 'fuel_type_code'
|
28
|
+
belongs_to :size_class, :class_name => 'AutomobileSizeClass'
|
32
29
|
end
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
|
9
|
-
version: 0.0.16
|
9
|
+
version: 0.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Andy Rossmeissl
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2010-11-
|
21
|
+
date: 2010-11-19 00:00:00 -05:00
|
22
22
|
default_executable:
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
@@ -133,9 +133,9 @@ dependencies:
|
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
segments:
|
135
135
|
- 0
|
136
|
-
-
|
136
|
+
- 3
|
137
137
|
- 0
|
138
|
-
version: 0.
|
138
|
+
version: 0.3.0
|
139
139
|
type: :development
|
140
140
|
prerelease: false
|
141
141
|
version_requirements: *id008
|
@@ -148,12 +148,27 @@ dependencies:
|
|
148
148
|
- !ruby/object:Gem::Version
|
149
149
|
segments:
|
150
150
|
- 0
|
151
|
-
-
|
152
|
-
-
|
153
|
-
version: 0.
|
151
|
+
- 2
|
152
|
+
- 0
|
153
|
+
version: 0.2.0
|
154
154
|
type: :runtime
|
155
155
|
prerelease: false
|
156
156
|
version_requirements: *id009
|
157
|
+
- !ruby/object:Gem::Dependency
|
158
|
+
name: earth
|
159
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ~>
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
segments:
|
165
|
+
- 0
|
166
|
+
- 3
|
167
|
+
- 1
|
168
|
+
version: 0.3.1
|
169
|
+
type: :runtime
|
170
|
+
prerelease: false
|
171
|
+
version_requirements: *id010
|
157
172
|
description: A software model in Ruby for the greenhouse gas emissions of an automobile
|
158
173
|
email: andy@rossmeissl.net
|
159
174
|
executables: []
|
@@ -189,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
189
204
|
requirements:
|
190
205
|
- - ">="
|
191
206
|
- !ruby/object:Gem::Version
|
192
|
-
hash: -
|
207
|
+
hash: -457516079
|
193
208
|
segments:
|
194
209
|
- 0
|
195
210
|
version: "0"
|