purchase 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/features/purchase_committees.feature +119 -33
- data/features/purchase_emissions.feature +6 -6
- data/lib/purchase/carbon_model.rb +32 -28
- metadata +183 -63
- data/features/step_definitions/matrix.rb +0 -24
@@ -19,8 +19,16 @@ Feature: Purchase Committee Calculations
|
|
19
19
|
Scenario: Cost committee from default
|
20
20
|
Given a purchase emitter
|
21
21
|
When the "cost" committee is calculated
|
22
|
+
Then the committee should have used quorum "default"
|
22
23
|
Then the conclusion of the committee should be "100"
|
23
24
|
|
25
|
+
Scenario: Adjusted cost committee starting from nothing
|
26
|
+
Given a purchase emitter
|
27
|
+
When the "date" committee is calculated
|
28
|
+
And the "cost" committee is calculated
|
29
|
+
And the "adjusted_cost" committee is calculated
|
30
|
+
Then the conclusion of the committee should be "82.85004"
|
31
|
+
|
24
32
|
Scenario Outline: Adjusted cost committee from cost and date
|
25
33
|
Given a purchase emitter
|
26
34
|
And a characteristic "cost" of "<cost>"
|
@@ -32,17 +40,24 @@ Feature: Purchase Committee Calculations
|
|
32
40
|
| 831.23 | 2010-08-01 | 688.67439 |
|
33
41
|
| 11.00 | 2005-07-14 | 9.11350 |
|
34
42
|
|
43
|
+
Scenario: Merchant category committee from default
|
44
|
+
Given a purchase emitter
|
45
|
+
When the "merchant_category" committee is calculated
|
46
|
+
Then the committee should have used quorum "default"
|
47
|
+
And the conclusion of the committee should have "mcc" of "5111"
|
48
|
+
|
35
49
|
Scenario Outline: Merchant category committee from merchant
|
36
50
|
Given a purchase emitter
|
37
51
|
And a characteristic "merchant.id" of "<id>"
|
38
52
|
When the "merchant_category" committee is calculated
|
39
|
-
Then the
|
53
|
+
Then the committee should have used quorum "from merchant"
|
54
|
+
And the conclusion of the committee should have "mcc" of "<mcc>"
|
40
55
|
Examples:
|
41
56
|
| id | mcc |
|
42
57
|
| 1 | 1111 |
|
43
58
|
| 2 | 2222 |
|
44
59
|
|
45
|
-
Scenario Outline: Merchant category industries committee from merchant category
|
60
|
+
Scenario Outline: Merchant category industries committee starting from merchant category
|
46
61
|
Given a purchase emitter
|
47
62
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
48
63
|
When the "merchant_category_industries" committee is calculated
|
@@ -68,12 +83,21 @@ Feature: Purchase Committee Calculations
|
|
68
83
|
Given a purchase emitter
|
69
84
|
And a characteristic "industry.naics_code" of "<naics>"
|
70
85
|
When the "trade_industry_ratios" committee is calculated
|
71
|
-
Then the committee should have used quorum "from
|
86
|
+
Then the committee should have used quorum "from industry"
|
72
87
|
And the conclusion of the committee should include a key of "<naics>" and value "1"
|
73
88
|
Examples:
|
74
89
|
| naics |
|
75
90
|
| 459000 |
|
76
91
|
|
92
|
+
Scenario: Trade industry ratios from merchant category industries and industry
|
93
|
+
Given a purchase emitter
|
94
|
+
And a characteristic "merchant_category.mcc" of "1111"
|
95
|
+
And a characteristic "industry.naics_code" of "459000"
|
96
|
+
When the "merchant_category_industries" committee is calculated
|
97
|
+
And the "trade_industry_ratios" committee is calculated
|
98
|
+
Then the committee should have used quorum "from industry"
|
99
|
+
And the conclusion of the committee should include a key of "459000" and value "1"
|
100
|
+
|
77
101
|
Scenario Outline: Non-trade industry ratios from merchant category industries
|
78
102
|
Given a purchase emitter
|
79
103
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
@@ -90,16 +114,20 @@ Feature: Purchase Committee Calculations
|
|
90
114
|
Given a purchase emitter
|
91
115
|
And a characteristic "industry.naics_code" of "<naics>"
|
92
116
|
When the "non_trade_industry_ratios" committee is calculated
|
93
|
-
Then the
|
117
|
+
Then the committee should have used quorum "from industry"
|
118
|
+
And the conclusion of the committee should include a key of "<naics>" and value "1"
|
94
119
|
Examples:
|
95
120
|
| naics |
|
96
121
|
| 111111 |
|
97
122
|
| 399900 |
|
98
123
|
|
99
|
-
Scenario
|
124
|
+
Scenario: Non-trade industry ratios from merchant category industries and industry
|
100
125
|
Given a purchase emitter
|
101
|
-
|
102
|
-
|
126
|
+
And a characteristic "merchant_category.mcc" of "2222"
|
127
|
+
And a characteristic "industry.naics_code" of "111111"
|
128
|
+
When the "merchant_category_industries" committee is calculated
|
129
|
+
And the "non_trade_industry_ratios" committee is calculated
|
130
|
+
Then the committee should have used quorum "from industry"
|
103
131
|
And the conclusion of the committee should include a key of "111111" and value "1"
|
104
132
|
|
105
133
|
Scenario Outline: Product line ratios from trade industry ratios
|
@@ -140,10 +168,10 @@ Feature: Purchase Committee Calculations
|
|
140
168
|
Then the conclusion of the committee should include a key of "<naics>" and value "<ratio>"
|
141
169
|
Examples:
|
142
170
|
| mcc | naics | ratio |
|
143
|
-
| 2222 | 399100 | 0.
|
144
|
-
| 2222 | 399200 | 0.
|
171
|
+
| 2222 | 399100 | 0.375 |
|
172
|
+
| 2222 | 399200 | 0.125 |
|
145
173
|
|
146
|
-
Scenario Outline: Industry ratios committee from
|
174
|
+
Scenario Outline: Industry ratios committee starting from merchant category
|
147
175
|
Given a purchase emitter
|
148
176
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
149
177
|
When the "merchant_category_industries" committee is calculated
|
@@ -157,11 +185,11 @@ Feature: Purchase Committee Calculations
|
|
157
185
|
Examples:
|
158
186
|
| mcc | naics | ratio |
|
159
187
|
| 1111 | 111111 | 1.0 |
|
160
|
-
| 2222 | 399100 | 0.
|
161
|
-
| 2222 | 399200 | 0.
|
188
|
+
| 2222 | 399100 | 0.375 |
|
189
|
+
| 2222 | 399200 | 0.125 |
|
162
190
|
| 2222 | 399900 | 0.5 |
|
163
191
|
|
164
|
-
Scenario Outline: Industry ratios committee from industry
|
192
|
+
Scenario Outline: Industry ratios committee starting from industry
|
165
193
|
Given a purchase emitter
|
166
194
|
And a characteristic "industry.naics_code" of "<naics>"
|
167
195
|
When the "non_trade_industry_ratios" committee is calculated
|
@@ -174,15 +202,14 @@ Feature: Purchase Committee Calculations
|
|
174
202
|
Examples:
|
175
203
|
| naics | new_naics | ratio |
|
176
204
|
| 111111 | 111111 | 1.0 |
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
205
|
+
| 399100 | 399100 | 1.0 |
|
206
|
+
| 399200 | 399200 | 1.0 |
|
207
|
+
| 459000 | 399100 | 0.75 |
|
208
|
+
| 459000 | 399200 | 0.25 |
|
180
209
|
|
181
|
-
Scenario Outline: Industry sector ratios committee from merchant category
|
182
|
-
Given a purchase emitter
|
210
|
+
Scenario Outline: Industry sector ratios committee starting from merchant category
|
211
|
+
Given a purchase emitter
|
183
212
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
184
|
-
And a characteristic "cost" of "100"
|
185
|
-
And a characteristic "date" of "2010-08-01"
|
186
213
|
When the "merchant_category_industries" committee is calculated
|
187
214
|
And the "non_trade_industry_ratios" committee is calculated
|
188
215
|
And the "trade_industry_ratios" committee is calculated
|
@@ -195,12 +222,29 @@ Feature: Purchase Committee Calculations
|
|
195
222
|
Examples:
|
196
223
|
| mcc | io_code | ratio |
|
197
224
|
| 1111 | 111000 | 1.0 |
|
198
|
-
| 2222 | 3991A0 | 0.
|
199
|
-
| 2222 | 3991B0 | 0.
|
200
|
-
| 2222 | 399200 | 0.
|
225
|
+
| 2222 | 3991A0 | 0.28125 |
|
226
|
+
| 2222 | 3991B0 | 0.09375 |
|
227
|
+
| 2222 | 399200 | 0.125 |
|
201
228
|
| 2222 | 399900 | 0.5 |
|
202
229
|
|
203
|
-
Scenario Outline: Industry sector ratios
|
230
|
+
Scenario Outline: Industry sector ratios sum check starting from merchant category
|
231
|
+
Given a purchase emitter
|
232
|
+
And a characteristic "merchant_category.mcc" of "<mcc>"
|
233
|
+
When the "merchant_category_industries" committee is calculated
|
234
|
+
And the "non_trade_industry_ratios" committee is calculated
|
235
|
+
And the "trade_industry_ratios" committee is calculated
|
236
|
+
And the "product_line_ratios" committee is calculated
|
237
|
+
And the "product_line_industry_product_ratios" committee is calculated
|
238
|
+
And the "industry_product_ratios" committee is calculated
|
239
|
+
And the "industry_ratios" committee is calculated
|
240
|
+
And the "industry_sector_ratios" committee is calculated
|
241
|
+
Then the conclusion of the committee should have ratios summing to "1.0"
|
242
|
+
Examples:
|
243
|
+
| mcc |
|
244
|
+
| 1111 |
|
245
|
+
| 2222 |
|
246
|
+
|
247
|
+
Scenario Outline: Industry sector ratios committee starting from industry
|
204
248
|
Given a purchase emitter
|
205
249
|
And a characteristic "industry.naics_code" of "<naics>"
|
206
250
|
When the "non_trade_industry_ratios" committee is calculated
|
@@ -216,11 +260,29 @@ Feature: Purchase Committee Calculations
|
|
216
260
|
| 111111 | 111000 | 1.0 |
|
217
261
|
| 399100 | 3991A0 | 0.75 |
|
218
262
|
| 399100 | 3991B0 | 0.25 |
|
219
|
-
|
|
220
|
-
|
|
263
|
+
| 459000 | 3991A0 | 0.5625|
|
264
|
+
| 459000 | 3991B0 | 0.1875|
|
265
|
+
| 459000 | 399200 | 0.25 |
|
266
|
+
|
267
|
+
Scenario Outline: Industry sector ratios sum check starting from industry
|
268
|
+
Given a purchase emitter
|
269
|
+
And a characteristic "industry.naics_code" of "<naics>"
|
270
|
+
When the "non_trade_industry_ratios" committee is calculated
|
271
|
+
And the "trade_industry_ratios" committee is calculated
|
272
|
+
And the "product_line_ratios" committee is calculated
|
273
|
+
And the "product_line_industry_product_ratios" committee is calculated
|
274
|
+
And the "industry_product_ratios" committee is calculated
|
275
|
+
And the "industry_ratios" committee is calculated
|
276
|
+
And the "industry_sector_ratios" committee is calculated
|
277
|
+
Then the conclusion of the committee should have ratios summing to "1.0"
|
278
|
+
Examples:
|
279
|
+
| naics |
|
280
|
+
| 111111 |
|
281
|
+
| 399100 |
|
282
|
+
| 459000 |
|
221
283
|
|
222
|
-
Scenario Outline: Industry sector shares committee from merchant category
|
223
|
-
Given a purchase emitter
|
284
|
+
Scenario Outline: Industry sector shares committee starting from merchant category
|
285
|
+
Given a purchase emitter
|
224
286
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
225
287
|
And a characteristic "adjusted_cost" of "100.00"
|
226
288
|
When the "merchant_category_industries" committee is calculated
|
@@ -236,11 +298,35 @@ Feature: Purchase Committee Calculations
|
|
236
298
|
Examples:
|
237
299
|
| mcc | io_code | share |
|
238
300
|
| 1111 | 111000 | 100.0 |
|
239
|
-
| 2222 | 3991A0 |
|
240
|
-
| 2222 | 3991B0 |
|
241
|
-
| 2222 | 399200 |
|
301
|
+
| 2222 | 3991A0 | 28.125 |
|
302
|
+
| 2222 | 3991B0 | 9.375 |
|
303
|
+
| 2222 | 399200 | 12.5 |
|
242
304
|
| 2222 | 399900 | 50.0 |
|
243
305
|
|
306
|
+
Scenario Outline: Industry sector shares committee starting from industry
|
307
|
+
Given a purchase emitter
|
308
|
+
And a characteristic "industry.naics_code" of "<naics>"
|
309
|
+
And a characteristic "adjusted_cost" of "100.00"
|
310
|
+
When the "non_trade_industry_ratios" committee is calculated
|
311
|
+
And the "trade_industry_ratios" committee is calculated
|
312
|
+
And the "product_line_ratios" committee is calculated
|
313
|
+
And the "product_line_industry_product_ratios" committee is calculated
|
314
|
+
And the "industry_product_ratios" committee is calculated
|
315
|
+
And the "industry_ratios" committee is calculated
|
316
|
+
And the "industry_sector_ratios" committee is calculated
|
317
|
+
And the "industry_sector_shares" committee is calculated
|
318
|
+
Then the conclusion of the committee should include a key of "<io_code>" and value "<share>"
|
319
|
+
Examples:
|
320
|
+
| naics | io_code | share |
|
321
|
+
| 111111 | 111000 | 100.0 |
|
322
|
+
| 399100 | 3991A0 | 75.0 |
|
323
|
+
| 399100 | 3991B0 | 25.0 |
|
324
|
+
| 399200 | 399200 | 100.0 |
|
325
|
+
| 399900 | 399900 | 100.0 |
|
326
|
+
| 459000 | 3991A0 | 56.25 |
|
327
|
+
| 459000 | 3991B0 | 18.75 |
|
328
|
+
| 459000 | 399200 | 25.0 |
|
329
|
+
|
244
330
|
Scenario Outline: Sector shares committee from industry and product line shares
|
245
331
|
Given a purchase emitter
|
246
332
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
@@ -259,7 +345,7 @@ Feature: Purchase Committee Calculations
|
|
259
345
|
Examples:
|
260
346
|
| mcc|111000|3991A0 |3991B0|399200|399900|4A0000|
|
261
347
|
|1111|100.00| 0| 0| 0| 0| 0|
|
262
|
-
|2222| 0|
|
348
|
+
|2222| 0| 28.125| 9.375| 12.5| 50.0| 0|
|
263
349
|
|
264
350
|
Scenario: Sector direct requirements committee
|
265
351
|
Given a purchase emitter
|
@@ -311,4 +397,4 @@ Feature: Purchase Committee Calculations
|
|
311
397
|
Examples:
|
312
398
|
|mcc |111000 |3991A0 |3991B0 |399200 |399900 |4A0000 |
|
313
399
|
|1111|90.44460| 6.83919| 5.58981| 18.5568|19.91952 |11.38220|
|
314
|
-
|2222|
|
400
|
+
|2222|34.95823|38.38879|22.27460|77.55067|119.05953|38.64496|
|
@@ -23,7 +23,7 @@ Feature: Purchase Emissions Calculations
|
|
23
23
|
Examples:
|
24
24
|
| id | emission |
|
25
25
|
| 1 | 126.538 |
|
26
|
-
| 2 |
|
26
|
+
| 2 | 274.131 |
|
27
27
|
|
28
28
|
Scenario Outline: Calculations starting from a merchant with purchase amount
|
29
29
|
Given a purchase has "merchant.id" of "<id>"
|
@@ -33,7 +33,7 @@ Feature: Purchase Emissions Calculations
|
|
33
33
|
Examples:
|
34
34
|
| id | amount | emission |
|
35
35
|
| 1 | 107.11 | 126.538 |
|
36
|
-
| 2 | 107.11 |
|
36
|
+
| 2 | 107.11 | 274.131 |
|
37
37
|
|
38
38
|
Scenario Outline: Calculations starting from a merchant with purchase amount and date
|
39
39
|
Given a purchase has "merchant.id" of "<id>"
|
@@ -44,7 +44,7 @@ Feature: Purchase Emissions Calculations
|
|
44
44
|
Examples:
|
45
45
|
| id | amount | date | emission |
|
46
46
|
| 1 | 107.11 | 2010-07-28 | 126.538 |
|
47
|
-
| 2 | 107.11 | 2010-07-28 |
|
47
|
+
| 2 | 107.11 | 2010-07-28 | 274.131 |
|
48
48
|
|
49
49
|
Scenario Outline: Calculations starting from a merchant with purchase amount, date, and tax
|
50
50
|
Given a purchase has "merchant.id" of "<id>"
|
@@ -56,7 +56,7 @@ Feature: Purchase Emissions Calculations
|
|
56
56
|
Examples:
|
57
57
|
| id | amount | tax | date | emission |
|
58
58
|
| 1 | 108.00 | 8.00 | 2010-07-28 | 126.538 |
|
59
|
-
| 2 | 108.00 | 8.00 | 2010-07-28 |
|
59
|
+
| 2 | 108.00 | 8.00 | 2010-07-28 | 274.131 |
|
60
60
|
|
61
61
|
Scenario Outline: Calculations starting from a merchant category
|
62
62
|
Given a purchase has "merchant_category.mcc" of "<mcc>"
|
@@ -67,7 +67,7 @@ Feature: Purchase Emissions Calculations
|
|
67
67
|
Examples:
|
68
68
|
| mcc | cost | date | emission |
|
69
69
|
| 1111 | 100.00 | 2010-07-28 | 126.538 |
|
70
|
-
| 2222 | 100.00 | 2010-07-28 |
|
70
|
+
| 2222 | 100.00 | 2010-07-28 | 274.131 |
|
71
71
|
| 5111 | 100.00 | 2010-07-28 | 126.538 |
|
72
72
|
|
73
73
|
Scenario Outline: Calculations starting from industry
|
@@ -80,4 +80,4 @@ Feature: Purchase Emissions Calculations
|
|
80
80
|
| naics | cost | date | emission |
|
81
81
|
| 111111 | 100.00 | 2010-07-28 | 126.538 |
|
82
82
|
| 399900 | 100.00 | 2010-07-28 | 334.190 |
|
83
|
-
| 459000 | 100.00 | 2010-07-28 |
|
83
|
+
| 459000 | 100.00 | 2010-07-28 | 214.072 |
|
@@ -57,7 +57,8 @@ module BrighterPlanet
|
|
57
57
|
committee :industry_sector_shares do
|
58
58
|
quorum 'from industry sector ratios', :needs => [:industry_sector_ratios, :adjusted_cost] do |characteristics|
|
59
59
|
characteristics[:industry_sector_ratios].inject({}) do |new_ratios, (io_code, ratio)|
|
60
|
-
new_ratios[io_code]
|
60
|
+
new_ratios[io_code] ||= 0
|
61
|
+
new_ratios[io_code] += ratio * characteristics[:adjusted_cost]
|
61
62
|
new_ratios
|
62
63
|
end
|
63
64
|
end
|
@@ -67,8 +68,9 @@ module BrighterPlanet
|
|
67
68
|
quorum 'from industry ratios', :needs => :industry_ratios do |characteristics|
|
68
69
|
characteristics[:industry_ratios].inject({}) do |new_ratios, (naics_code, ratio)|
|
69
70
|
IndustrySector.where(:naics_code => naics_code).each do |industry_sector|
|
71
|
+
new_ratios[industry_sector.io_code] ||= 0
|
70
72
|
new_ratio = ratio * industry_sector.ratio
|
71
|
-
new_ratios[industry_sector.io_code]
|
73
|
+
new_ratios[industry_sector.io_code] += new_ratio
|
72
74
|
end
|
73
75
|
new_ratios
|
74
76
|
end
|
@@ -80,7 +82,9 @@ module BrighterPlanet
|
|
80
82
|
committee :industry_ratios do
|
81
83
|
quorum 'from non trade industry and industry product ratios', :needs => [:non_trade_industry_ratios, :industry_product_ratios] do |characteristics|
|
82
84
|
combined_ratios = characteristics[:non_trade_industry_ratios].
|
83
|
-
|
85
|
+
update(characteristics[:industry_product_ratios]) do |key, non_trade, ip_ratio|
|
86
|
+
non_trade + ip_ratio
|
87
|
+
end
|
84
88
|
end
|
85
89
|
end
|
86
90
|
|
@@ -88,7 +92,8 @@ module BrighterPlanet
|
|
88
92
|
quorum 'from product line industry product ratios', :needs => :product_line_industry_product_ratios do |characteristics|
|
89
93
|
characteristics[:product_line_industry_product_ratios].inject({}) do |new_ratios, (naics_product_code, ratio)|
|
90
94
|
IndustryProduct.where(:naics_product_code => naics_product_code).each do |industry_product|
|
91
|
-
new_ratios[industry_product.naics_code]
|
95
|
+
new_ratios[industry_product.naics_code] ||= 0
|
96
|
+
new_ratios[industry_product.naics_code] += ratio
|
92
97
|
end
|
93
98
|
new_ratios
|
94
99
|
end
|
@@ -99,8 +104,9 @@ module BrighterPlanet
|
|
99
104
|
quorum 'from product line ratios', :needs => :product_line_ratios do |characteristics|
|
100
105
|
characteristics[:product_line_ratios].inject({}) do |new_ratios, (ps_code, ratio)|
|
101
106
|
ProductLineIndustryProduct.where(:ps_code => ps_code).each do |plip|
|
107
|
+
new_ratios[plip.naics_product_code] ||= 0
|
102
108
|
new_ratio = ratio * plip.ratio
|
103
|
-
new_ratios[plip.naics_product_code]
|
109
|
+
new_ratios[plip.naics_product_code] += new_ratio
|
104
110
|
end
|
105
111
|
new_ratios
|
106
112
|
end
|
@@ -111,8 +117,9 @@ module BrighterPlanet
|
|
111
117
|
quorum 'from trade industry ratios', :needs => :trade_industry_ratios do |characteristics|
|
112
118
|
characteristics[:trade_industry_ratios].inject({}) do |new_ratios, (naics, ratio)|
|
113
119
|
IndustryProductLine.where(:naics_code => naics).each do |industry_product_line|
|
120
|
+
new_ratios[industry_product_line.ps_code] ||= 0
|
114
121
|
new_ratio = ratio * industry_product_line.ratio
|
115
|
-
new_ratios[industry_product_line.ps_code]
|
122
|
+
new_ratios[industry_product_line.ps_code] += new_ratio
|
116
123
|
end
|
117
124
|
new_ratios
|
118
125
|
end
|
@@ -120,15 +127,6 @@ module BrighterPlanet
|
|
120
127
|
end
|
121
128
|
|
122
129
|
committee :non_trade_industry_ratios do
|
123
|
-
quorum 'from merchant category industries', :needs => :merchant_category_industries do |characteristics|
|
124
|
-
characteristics[:merchant_category_industries].inject({}) do |hash, merchant_category_industry|
|
125
|
-
unless merchant_category_industry.industry.trade_industry?
|
126
|
-
hash[merchant_category_industry.naics_code] = merchant_category_industry.ratio
|
127
|
-
end
|
128
|
-
hash
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
130
|
quorum 'from industry', :needs => :industry do |characteristics|
|
133
131
|
if characteristics[:industry].trade_industry?
|
134
132
|
{}
|
@@ -137,23 +135,19 @@ module BrighterPlanet
|
|
137
135
|
end
|
138
136
|
end
|
139
137
|
|
140
|
-
quorum 'default' do
|
141
|
-
mci = MerchantCategoryIndustry.where(:mcc => 5111).first
|
142
|
-
{ mci.naics_code.to_s => mci.ratio }
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
committee :trade_industry_ratios do
|
147
138
|
quorum 'from merchant category industries', :needs => :merchant_category_industries do |characteristics|
|
148
139
|
characteristics[:merchant_category_industries].inject({}) do |hash, merchant_category_industry|
|
149
|
-
|
150
|
-
hash[merchant_category_industry.naics_code]
|
140
|
+
unless merchant_category_industry.industry.trade_industry?
|
141
|
+
hash[merchant_category_industry.naics_code] ||= 0
|
142
|
+
hash[merchant_category_industry.naics_code] += merchant_category_industry.ratio
|
151
143
|
end
|
152
144
|
hash
|
153
145
|
end
|
154
146
|
end
|
147
|
+
end
|
155
148
|
|
156
|
-
|
149
|
+
committee :trade_industry_ratios do
|
150
|
+
quorum 'from industry', :needs => :industry do |characteristics|
|
157
151
|
if characteristics[:industry].trade_industry?
|
158
152
|
{ characteristics[:industry].naics_code.to_s => 1 }
|
159
153
|
else
|
@@ -161,8 +155,14 @@ module BrighterPlanet
|
|
161
155
|
end
|
162
156
|
end
|
163
157
|
|
164
|
-
quorum '
|
165
|
-
{}
|
158
|
+
quorum 'from merchant category industries', :needs => :merchant_category_industries do |characteristics|
|
159
|
+
characteristics[:merchant_category_industries].inject({}) do |hash, merchant_category_industry|
|
160
|
+
if merchant_category_industry.industry.trade_industry?
|
161
|
+
hash[merchant_category_industry.naics_code] ||= 0
|
162
|
+
hash[merchant_category_industry.naics_code] += merchant_category_industry.ratio
|
163
|
+
end
|
164
|
+
hash
|
165
|
+
end
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -177,6 +177,10 @@ module BrighterPlanet
|
|
177
177
|
quorum 'from merchant', :needs => [:merchant] do |characteristics|
|
178
178
|
characteristics[:merchant].merchant_category
|
179
179
|
end
|
180
|
+
|
181
|
+
quorum 'default' do
|
182
|
+
MerchantCategory.find_by_mcc 5111
|
183
|
+
end
|
180
184
|
end
|
181
185
|
|
182
186
|
committee :adjusted_cost do
|
@@ -204,7 +208,7 @@ module BrighterPlanet
|
|
204
208
|
characteristics[:purchase_amount].to_f / 1.0711
|
205
209
|
end
|
206
210
|
|
207
|
-
quorum '
|
211
|
+
quorum 'default' do
|
208
212
|
# FIXME TODO research real average purchase amount
|
209
213
|
100
|
210
214
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: purchase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 4
|
10
|
+
version: 1.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andy Rossmeissl
|
@@ -19,14 +19,13 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2010-10-
|
22
|
+
date: 2010-10-07 00:00:00 -04:00
|
23
23
|
default_executable:
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
|
-
type: :development
|
27
|
-
prerelease: false
|
28
26
|
name: activerecord
|
29
|
-
|
27
|
+
prerelease: false
|
28
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
30
29
|
none: false
|
31
30
|
requirements:
|
32
31
|
- - ~>
|
@@ -37,12 +36,12 @@ dependencies:
|
|
37
36
|
- 0
|
38
37
|
- 0
|
39
38
|
version: 3.0.0
|
40
|
-
requirement: *id001
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
39
|
type: :development
|
43
|
-
|
40
|
+
version_requirements: *id001
|
41
|
+
- !ruby/object:Gem::Dependency
|
44
42
|
name: bundler
|
45
|
-
|
43
|
+
prerelease: false
|
44
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
46
45
|
none: false
|
47
46
|
requirements:
|
48
47
|
- - ~>
|
@@ -53,28 +52,26 @@ dependencies:
|
|
53
52
|
- 0
|
54
53
|
- 0
|
55
54
|
version: 1.0.0
|
56
|
-
requirement: *id002
|
57
|
-
- !ruby/object:Gem::Dependency
|
58
55
|
type: :development
|
59
|
-
|
56
|
+
version_requirements: *id002
|
57
|
+
- !ruby/object:Gem::Dependency
|
60
58
|
name: cucumber
|
61
|
-
|
59
|
+
prerelease: false
|
60
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
62
61
|
none: false
|
63
62
|
requirements:
|
64
|
-
- -
|
63
|
+
- - ">="
|
65
64
|
- !ruby/object:Gem::Version
|
66
|
-
hash:
|
65
|
+
hash: 3
|
67
66
|
segments:
|
68
67
|
- 0
|
69
|
-
|
70
|
-
- 0
|
71
|
-
version: 0.9.0
|
72
|
-
requirement: *id003
|
73
|
-
- !ruby/object:Gem::Dependency
|
68
|
+
version: "0"
|
74
69
|
type: :development
|
75
|
-
|
70
|
+
version_requirements: *id003
|
71
|
+
- !ruby/object:Gem::Dependency
|
76
72
|
name: jeweler
|
77
|
-
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
78
75
|
none: false
|
79
76
|
requirements:
|
80
77
|
- - ~>
|
@@ -85,12 +82,12 @@ dependencies:
|
|
85
82
|
- 4
|
86
83
|
- 0
|
87
84
|
version: 1.4.0
|
88
|
-
requirement: *id004
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
85
|
type: :development
|
91
|
-
|
86
|
+
version_requirements: *id004
|
87
|
+
- !ruby/object:Gem::Dependency
|
92
88
|
name: rake
|
93
|
-
|
89
|
+
prerelease: false
|
90
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
94
91
|
none: false
|
95
92
|
requirements:
|
96
93
|
- - ">="
|
@@ -99,12 +96,12 @@ dependencies:
|
|
99
96
|
segments:
|
100
97
|
- 0
|
101
98
|
version: "0"
|
102
|
-
requirement: *id005
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
99
|
type: :development
|
105
|
-
|
100
|
+
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
106
102
|
name: rdoc
|
107
|
-
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
108
105
|
none: false
|
109
106
|
requirements:
|
110
107
|
- - ">="
|
@@ -113,12 +110,12 @@ dependencies:
|
|
113
110
|
segments:
|
114
111
|
- 0
|
115
112
|
version: "0"
|
116
|
-
requirement: *id006
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
113
|
type: :development
|
119
|
-
|
114
|
+
version_requirements: *id006
|
115
|
+
- !ruby/object:Gem::Dependency
|
120
116
|
name: rspec
|
121
|
-
|
117
|
+
prerelease: false
|
118
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
122
119
|
none: false
|
123
120
|
requirements:
|
124
121
|
- - ~>
|
@@ -131,12 +128,12 @@ dependencies:
|
|
131
128
|
- beta
|
132
129
|
- 17
|
133
130
|
version: 2.0.0.beta.17
|
134
|
-
requirement: *id007
|
135
|
-
- !ruby/object:Gem::Dependency
|
136
131
|
type: :development
|
137
|
-
|
132
|
+
version_requirements: *id007
|
133
|
+
- !ruby/object:Gem::Dependency
|
138
134
|
name: sniff
|
139
|
-
|
135
|
+
prerelease: false
|
136
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
140
137
|
none: false
|
141
138
|
requirements:
|
142
139
|
- - ~>
|
@@ -147,12 +144,12 @@ dependencies:
|
|
147
144
|
- 1
|
148
145
|
- 16
|
149
146
|
version: 0.1.16
|
150
|
-
|
147
|
+
type: :development
|
148
|
+
version_requirements: *id008
|
151
149
|
- !ruby/object:Gem::Dependency
|
152
|
-
type: :runtime
|
153
|
-
prerelease: false
|
154
150
|
name: earth
|
155
|
-
|
151
|
+
prerelease: false
|
152
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
156
153
|
none: false
|
157
154
|
requirements:
|
158
155
|
- - ~>
|
@@ -163,12 +160,12 @@ dependencies:
|
|
163
160
|
- 2
|
164
161
|
- 4
|
165
162
|
version: 0.2.4
|
166
|
-
requirement: *id009
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
163
|
type: :runtime
|
169
|
-
|
164
|
+
version_requirements: *id009
|
165
|
+
- !ruby/object:Gem::Dependency
|
170
166
|
name: emitter
|
171
|
-
|
167
|
+
prerelease: false
|
168
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
172
169
|
none: false
|
173
170
|
requirements:
|
174
171
|
- - ~>
|
@@ -179,12 +176,12 @@ dependencies:
|
|
179
176
|
- 1
|
180
177
|
- 4
|
181
178
|
version: 0.1.4
|
182
|
-
requirement: *id010
|
183
|
-
- !ruby/object:Gem::Dependency
|
184
179
|
type: :runtime
|
185
|
-
|
180
|
+
version_requirements: *id010
|
181
|
+
- !ruby/object:Gem::Dependency
|
186
182
|
name: fastercsv
|
187
|
-
|
183
|
+
prerelease: false
|
184
|
+
requirement: &id011 !ruby/object:Gem::Requirement
|
188
185
|
none: false
|
189
186
|
requirements:
|
190
187
|
- - ~>
|
@@ -195,12 +192,12 @@ dependencies:
|
|
195
192
|
- 5
|
196
193
|
- 3
|
197
194
|
version: 1.5.3
|
198
|
-
requirement: *id011
|
199
|
-
- !ruby/object:Gem::Dependency
|
200
195
|
type: :runtime
|
201
|
-
|
196
|
+
version_requirements: *id011
|
197
|
+
- !ruby/object:Gem::Dependency
|
202
198
|
name: slither
|
203
|
-
|
199
|
+
prerelease: false
|
200
|
+
requirement: &id012 !ruby/object:Gem::Requirement
|
204
201
|
none: false
|
205
202
|
requirements:
|
206
203
|
- - ~>
|
@@ -211,7 +208,132 @@ dependencies:
|
|
211
208
|
- 99
|
212
209
|
- 3
|
213
210
|
version: 0.99.3
|
214
|
-
|
211
|
+
type: :runtime
|
212
|
+
version_requirements: *id012
|
213
|
+
- !ruby/object:Gem::Dependency
|
214
|
+
name: activerecord
|
215
|
+
prerelease: false
|
216
|
+
requirement: &id013 !ruby/object:Gem::Requirement
|
217
|
+
none: false
|
218
|
+
requirements:
|
219
|
+
- - ~>
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
hash: 7
|
222
|
+
segments:
|
223
|
+
- 3
|
224
|
+
- 0
|
225
|
+
- 0
|
226
|
+
version: 3.0.0
|
227
|
+
type: :development
|
228
|
+
version_requirements: *id013
|
229
|
+
- !ruby/object:Gem::Dependency
|
230
|
+
name: bundler
|
231
|
+
prerelease: false
|
232
|
+
requirement: &id014 !ruby/object:Gem::Requirement
|
233
|
+
none: false
|
234
|
+
requirements:
|
235
|
+
- - ~>
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
hash: 23
|
238
|
+
segments:
|
239
|
+
- 1
|
240
|
+
- 0
|
241
|
+
- 0
|
242
|
+
version: 1.0.0
|
243
|
+
type: :development
|
244
|
+
version_requirements: *id014
|
245
|
+
- !ruby/object:Gem::Dependency
|
246
|
+
name: cucumber
|
247
|
+
prerelease: false
|
248
|
+
requirement: &id015 !ruby/object:Gem::Requirement
|
249
|
+
none: false
|
250
|
+
requirements:
|
251
|
+
- - ">="
|
252
|
+
- !ruby/object:Gem::Version
|
253
|
+
hash: 3
|
254
|
+
segments:
|
255
|
+
- 0
|
256
|
+
version: "0"
|
257
|
+
type: :development
|
258
|
+
version_requirements: *id015
|
259
|
+
- !ruby/object:Gem::Dependency
|
260
|
+
name: jeweler
|
261
|
+
prerelease: false
|
262
|
+
requirement: &id016 !ruby/object:Gem::Requirement
|
263
|
+
none: false
|
264
|
+
requirements:
|
265
|
+
- - ~>
|
266
|
+
- !ruby/object:Gem::Version
|
267
|
+
hash: 7
|
268
|
+
segments:
|
269
|
+
- 1
|
270
|
+
- 4
|
271
|
+
- 0
|
272
|
+
version: 1.4.0
|
273
|
+
type: :development
|
274
|
+
version_requirements: *id016
|
275
|
+
- !ruby/object:Gem::Dependency
|
276
|
+
name: rake
|
277
|
+
prerelease: false
|
278
|
+
requirement: &id017 !ruby/object:Gem::Requirement
|
279
|
+
none: false
|
280
|
+
requirements:
|
281
|
+
- - ">="
|
282
|
+
- !ruby/object:Gem::Version
|
283
|
+
hash: 3
|
284
|
+
segments:
|
285
|
+
- 0
|
286
|
+
version: "0"
|
287
|
+
type: :development
|
288
|
+
version_requirements: *id017
|
289
|
+
- !ruby/object:Gem::Dependency
|
290
|
+
name: rdoc
|
291
|
+
prerelease: false
|
292
|
+
requirement: &id018 !ruby/object:Gem::Requirement
|
293
|
+
none: false
|
294
|
+
requirements:
|
295
|
+
- - ">="
|
296
|
+
- !ruby/object:Gem::Version
|
297
|
+
hash: 3
|
298
|
+
segments:
|
299
|
+
- 0
|
300
|
+
version: "0"
|
301
|
+
type: :development
|
302
|
+
version_requirements: *id018
|
303
|
+
- !ruby/object:Gem::Dependency
|
304
|
+
name: rspec
|
305
|
+
prerelease: false
|
306
|
+
requirement: &id019 !ruby/object:Gem::Requirement
|
307
|
+
none: false
|
308
|
+
requirements:
|
309
|
+
- - ~>
|
310
|
+
- !ruby/object:Gem::Version
|
311
|
+
hash: 62196417
|
312
|
+
segments:
|
313
|
+
- 2
|
314
|
+
- 0
|
315
|
+
- 0
|
316
|
+
- beta
|
317
|
+
- 17
|
318
|
+
version: 2.0.0.beta.17
|
319
|
+
type: :development
|
320
|
+
version_requirements: *id019
|
321
|
+
- !ruby/object:Gem::Dependency
|
322
|
+
name: sniff
|
323
|
+
prerelease: false
|
324
|
+
requirement: &id020 !ruby/object:Gem::Requirement
|
325
|
+
none: false
|
326
|
+
requirements:
|
327
|
+
- - ~>
|
328
|
+
- !ruby/object:Gem::Version
|
329
|
+
hash: 59
|
330
|
+
segments:
|
331
|
+
- 0
|
332
|
+
- 1
|
333
|
+
- 16
|
334
|
+
version: 0.1.16
|
335
|
+
type: :development
|
336
|
+
version_requirements: *id020
|
215
337
|
description: A software model in Ruby for the greenhouse gas emissions of a purchase
|
216
338
|
email: seamus@brighterplanet.com
|
217
339
|
executables: []
|
@@ -234,11 +356,10 @@ files:
|
|
234
356
|
- lib/test_support/purchase_record.rb
|
235
357
|
- lib/test_support/test_impact_vectors_adapter.rb
|
236
358
|
- lib/test_support/test_sector_direct_requirements_adapter.rb
|
237
|
-
- features/step_definitions/matrix.rb
|
238
|
-
- features/support/env.rb
|
239
|
-
- features/support/matrix_ext.rb
|
240
359
|
- features/purchase_committees.feature
|
241
360
|
- features/purchase_emissions.feature
|
361
|
+
- features/support/env.rb
|
362
|
+
- features/support/matrix_ext.rb
|
242
363
|
has_rdoc: true
|
243
364
|
homepage: http://github.com/brighterplanet/purchase
|
244
365
|
licenses: []
|
@@ -274,11 +395,10 @@ signing_key:
|
|
274
395
|
specification_version: 3
|
275
396
|
summary: A carbon model
|
276
397
|
test_files:
|
277
|
-
- features/step_definitions/matrix.rb
|
278
|
-
- features/support/env.rb
|
279
|
-
- features/support/matrix_ext.rb
|
280
398
|
- features/purchase_committees.feature
|
281
399
|
- features/purchase_emissions.feature
|
400
|
+
- features/support/env.rb
|
401
|
+
- features/support/matrix_ext.rb
|
282
402
|
- lib/test_support/db/schema.rb
|
283
403
|
- lib/test_support/purchase_record.rb
|
284
404
|
- lib/test_support/test_impact_vectors_adapter.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
Then /^the conclusion of the committee should be a vector with "(.*)" items$/ do |count|
|
2
|
-
vector = @report.conclusion
|
3
|
-
vector.size.should == count.to_i
|
4
|
-
end
|
5
|
-
|
6
|
-
Then /^the conclusion of the committee should be a vector with value "(.*)" and position for key "(.*)"$/ do |value, key|
|
7
|
-
vector = @report.conclusion
|
8
|
-
position = BrighterPlanet::Purchase.key_map.index key
|
9
|
-
compare_values vector[position], value
|
10
|
-
end
|
11
|
-
|
12
|
-
Then /^the conclusion of the committee should be a square matrix with "(\d+)" rows and columns$/ do |num|
|
13
|
-
matrix = @report.conclusion
|
14
|
-
matrix.row_size.should == num.to_i
|
15
|
-
matrix.should be_square
|
16
|
-
end
|
17
|
-
|
18
|
-
Then /^the conclusion of the committee should be a vector with values "(.*)"$/ do |column_values|
|
19
|
-
column_values = column_values.split(/,/).map(&:to_f)
|
20
|
-
vector = @report.conclusion
|
21
|
-
vector = vector.row(0) if vector.is_a? Matrix #some vectors are single-row matrices
|
22
|
-
|
23
|
-
vector.should have_column_values(column_values)
|
24
|
-
end
|