purchase 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/features/purchase_committees.feature +170 -117
- data/features/purchase_emissions.feature +15 -0
- data/lib/purchase/carbon_model.rb +49 -57
- metadata +4 -4
@@ -5,12 +5,22 @@ Feature: Purchase Committee Calculations
|
|
5
5
|
Given a purchase emitter
|
6
6
|
And a characteristic "purchase_amount" of "<amount>"
|
7
7
|
When the "cost" committee is calculated
|
8
|
-
|
8
|
+
Then the conclusion of the committee should be "<cost>"
|
9
9
|
Examples:
|
10
10
|
| amount | cost |
|
11
11
|
| 831.23 | 748.107 |
|
12
12
|
| 11.00 | 9.9 |
|
13
13
|
|
14
|
+
Scenario Outline: Cost committee from purchase amount and tax
|
15
|
+
Given a purchase emitter
|
16
|
+
And a characteristic "purchase_amount" of "<amount>"
|
17
|
+
And a characteristic "tax" of "<tax>"
|
18
|
+
When the "cost" committee is calculated
|
19
|
+
Then the conclusion of the committee should be "<cost>"
|
20
|
+
Examples:
|
21
|
+
| amount | tax | cost |
|
22
|
+
| 10.00 | 1.00 | 9.00 |
|
23
|
+
|
14
24
|
Scenario Outline: Adjusted cost committee from cost and date
|
15
25
|
Given a purchase emitter
|
16
26
|
And a characteristic "cost" of "<cost>"
|
@@ -33,10 +43,47 @@ Feature: Purchase Committee Calculations
|
|
33
43
|
| 1 | 5111 |
|
34
44
|
| 2 | 5732 |
|
35
45
|
|
36
|
-
Scenario Outline:
|
46
|
+
Scenario Outline: Merchant categories industries committee from merchant category
|
37
47
|
Given a purchase emitter
|
38
48
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
39
|
-
When the "
|
49
|
+
When the "merchant_categories_industries" committee is calculated
|
50
|
+
Then the conclusion of the committee should have a record identified with "naics_code" of "<naics>" and having "ratio" of "<ratio>"
|
51
|
+
Examples:
|
52
|
+
| mcc | naics | ratio |
|
53
|
+
| 3504 | 72111 | 1 |
|
54
|
+
| 5111 | 45321 | 1 |
|
55
|
+
| 5172 | 32411 | 0.8 |
|
56
|
+
| 5172 | 324121 | 0.05 |
|
57
|
+
| 5172 | 324122 | 0.05 |
|
58
|
+
| 5172 | 324191 | 0.05 |
|
59
|
+
| 5172 | 324199 | 0.05 |
|
60
|
+
| 5732 | 443112 | 1 |
|
61
|
+
| 5812 | 72211 | 1 |
|
62
|
+
| 8225 | 6623 | 0.5 |
|
63
|
+
|
64
|
+
Scenario Outline: Merchant categories industries committee from industry
|
65
|
+
Given a purchase emitter
|
66
|
+
And a characteristic "naics_code" of "<naics>"
|
67
|
+
When the "merchant_categories_industries" committee is calculated
|
68
|
+
Then the conclusion of the committee should have a record identified with "naics_code" of "<naics>" and having "ratio" of "<ratio>"
|
69
|
+
Examples:
|
70
|
+
| naics | ratio |
|
71
|
+
| 72111 | 1 |
|
72
|
+
| 45321 | 1 |
|
73
|
+
| 32411 | 0.8 |
|
74
|
+
| 324121 | 0.05 |
|
75
|
+
| 324122 | 0.05 |
|
76
|
+
| 324191 | 0.05 |
|
77
|
+
| 324199 | 0.05 |
|
78
|
+
| 443112 | 1 |
|
79
|
+
| 72211 | 1 |
|
80
|
+
| 6623 | 0.5 |
|
81
|
+
|
82
|
+
Scenario Outline: Industry shares committee from merchant categories industries
|
83
|
+
Given a purchase emitter
|
84
|
+
And a characteristic "merchant_category.mcc" of "<mcc>"
|
85
|
+
When the "merchant_categories_industries" committee is calculated
|
86
|
+
And the "industry_shares" committee is calculated
|
40
87
|
Then the conclusion of the committee should have a record identified with "naics_code" of "<naics>" and having "ratio" of "<share>"
|
41
88
|
Examples:
|
42
89
|
| mcc | naics | share |
|
@@ -50,7 +97,8 @@ Feature: Purchase Committee Calculations
|
|
50
97
|
Scenario Outline: Product line shares committee from merchant category
|
51
98
|
Given a purchase emitter
|
52
99
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
53
|
-
When the "
|
100
|
+
When the "merchant_categories_industries" committee is calculated
|
101
|
+
And the "industry_shares" committee is calculated
|
54
102
|
And the "product_line_shares" committee is calculated
|
55
103
|
Then the conclusion of the committee should have a record identified with "ps_code" of "<ps_code>" and having "ratio" of "<share>"
|
56
104
|
Examples:
|
@@ -65,52 +113,65 @@ Feature: Purchase Committee Calculations
|
|
65
113
|
| 5111 | 29938 | 0.011 |
|
66
114
|
| 5111 | 29979 | 0.013 |
|
67
115
|
|
68
|
-
|
116
|
+
Scenario Outline: Product line shares committee from industry
|
117
|
+
Given a purchase emitter
|
118
|
+
And a characteristic "naics_code" of "<naics>"
|
119
|
+
When the "product_line_shares" committee is calculated
|
120
|
+
Then the conclusion of the committee should have a record identified with "ps_code" of "<ps_code>" and having "ratio" of "<share>"
|
121
|
+
Examples:
|
122
|
+
| naics | ps_code | share |
|
123
|
+
| 45321 | 20340 | 0.084 |
|
124
|
+
| 45321 | 20370 | 0.283 |
|
125
|
+
| 45321 | 20440 | 0.006 |
|
126
|
+
| 45321 | 20851 | 0.122 |
|
127
|
+
| 45321 | 20852 | 0.145 |
|
128
|
+
| 45321 | 20853 | 0.265 |
|
129
|
+
| 45321 | 20854 | 0.071 |
|
130
|
+
| 45321 | 29938 | 0.011 |
|
131
|
+
| 45321 | 29979 | 0.013 |
|
132
|
+
| 443112 | 20375 | 0.5 |
|
133
|
+
| 443112 | 20321 | 0.25 |
|
134
|
+
| 443112 | 20865 | 0.2 |
|
135
|
+
|
136
|
+
Scenario Outline: Sector shares committee from industry and product line shares
|
69
137
|
Given a purchase emitter
|
70
138
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
71
|
-
When the "
|
139
|
+
When the "merchant_categories_industries" committee is calculated
|
140
|
+
And the "industry_shares" committee is calculated
|
72
141
|
And the "product_line_shares" committee is calculated
|
73
142
|
And the "sector_shares" committee is calculated
|
74
|
-
Then the conclusion of the committee should
|
75
|
-
And the conclusion of the committee should have a record identified with "io_code" of "<io_code>" and having "share" of "<share>"
|
143
|
+
Then the conclusion of the committee should be a vector with value "<share>" and position for key "<io_code>"
|
76
144
|
Examples:
|
77
|
-
| mcc | io_code |
|
78
|
-
|
|
79
|
-
| 5111 |
|
80
|
-
| 5111 |
|
81
|
-
| 5111 |
|
82
|
-
| 5111 |
|
83
|
-
| 5111 |
|
84
|
-
| 5111 |
|
85
|
-
| 5111 |
|
86
|
-
| 5111 |
|
87
|
-
| 5111 |
|
88
|
-
| 5111 |
|
89
|
-
| 5111 |
|
90
|
-
| 5111 |
|
91
|
-
| 5111 |
|
92
|
-
| 5111 |
|
93
|
-
| 5111 |
|
94
|
-
| 5111 |
|
95
|
-
| 5111 |
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
| 5732 |
|
103
|
-
| 5732 |
|
104
|
-
|
|
105
|
-
| 5812 | 722000 | 0.8 | 1 |
|
106
|
-
| 3504 | 7211A0 | 0.559 | 1 |
|
107
|
-
| 5172 | 324110 | 2 | 0.8 |
|
108
|
-
| 5172 | 324121 | 1.3 | 0.05 |
|
109
|
-
| 5172 | 324122 | 0.9 | 0.05 |
|
110
|
-
| 5172 | 324191 | 0.2 | 0.05 |
|
111
|
-
| 5172 | 324199 | 1.2 | 0.05 |
|
145
|
+
| mcc | io_code | share |
|
146
|
+
| 3504 | 19 | 0.559 |
|
147
|
+
| 5111 | 1 | 0.27916245 |
|
148
|
+
| 5111 | 3 | 0.00573573 |
|
149
|
+
| 5111 | 4 | 0.041823625 |
|
150
|
+
| 5111 | 5 | 0.000650412 |
|
151
|
+
| 5111 | 6 | 0.002021635 |
|
152
|
+
| 5111 | 7 | 0.131016 |
|
153
|
+
| 5111 | 8 | 0.016074 |
|
154
|
+
| 5111 | 9 | 0.005444 |
|
155
|
+
| 5111 | 10 | 0.006146 |
|
156
|
+
| 5111 | 11 | 0.001041495 |
|
157
|
+
| 5111 | 12 | 0.00452952 |
|
158
|
+
| 5111 | 13 | 0.045696 |
|
159
|
+
| 5111 | 14 | 0.06289245 |
|
160
|
+
| 5111 | 15 | 0.00614676 |
|
161
|
+
| 5111 | 16 | 0.00017721 |
|
162
|
+
| 5111 | 17 | 0.00035178 |
|
163
|
+
| 5111 | 18 | 0.00040365 |
|
164
|
+
| 5172 | 20 | 1.6 |
|
165
|
+
| 5172 | 21 | 0.065 |
|
166
|
+
| 5172 | 22 | 0.045 |
|
167
|
+
| 5172 | 23 | 0.01 |
|
168
|
+
| 5172 | 24 | 0.06 |
|
169
|
+
| 5732 | 10 | 0.181 |
|
170
|
+
| 5732 | 12 | 0.13725 |
|
171
|
+
| 5732 | 25 | 0.32 |
|
172
|
+
| 5812 | 26 | 0.8 |
|
112
173
|
|
113
|
-
Scenario Outline:
|
174
|
+
Scenario Outline: Economic flows from merchant category code
|
114
175
|
Given a purchase emitter
|
115
176
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
116
177
|
When the "industry_shares" committee is calculated
|
@@ -120,45 +181,37 @@ Feature: Purchase Committee Calculations
|
|
120
181
|
Then the conclusion of the committee should have a record identified with "io_code" of "<io_code>" and having "factor" of "<emission_factor_share>"
|
121
182
|
Examples:
|
122
183
|
| mcc | io_code | emission_factor_share |
|
123
|
-
|
|
124
|
-
| 5111 |
|
125
|
-
| 5111 |
|
126
|
-
| 5111 |
|
127
|
-
| 5111 |
|
128
|
-
| 5111 |
|
129
|
-
| 5111 |
|
130
|
-
| 5111 |
|
131
|
-
| 5111 |
|
132
|
-
| 5111 |
|
133
|
-
| 5111 |
|
134
|
-
| 5111 |
|
135
|
-
| 5111 |
|
136
|
-
| 5111 |
|
137
|
-
| 5111 |
|
138
|
-
| 5111 |
|
139
|
-
| 5111 |
|
140
|
-
| 5111 |
|
141
|
-
| 5111 |
|
142
|
-
| 5111 |
|
143
|
-
| 5111 |
|
144
|
-
| 5111 |
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
| 5172 | 324122 | 0.045 |
|
155
|
-
| 5172 | 324191 | 0.01 |
|
156
|
-
| 5172 | 324199 | 0.06 |
|
157
|
-
|
158
|
-
Scenario: Emission factor from default
|
159
|
-
Given a purchase emitter
|
160
|
-
When the "emission_factors" committee is calculated
|
161
|
-
Then the conclusion of the committee should have a record identified with "io_code" of "0" and having "factor" of "1"
|
184
|
+
| 3504 | 19 | 0.559 |
|
185
|
+
| 5111 | 1 | 0.06289245 |
|
186
|
+
| 5111 | 3 | 0.00017721 |
|
187
|
+
| 5111 | 4 | 0.131016 |
|
188
|
+
| 5111 | 5 | 0.01052952 |
|
189
|
+
| 5111 | 6 | 0.000650412 |
|
190
|
+
| 5111 | 6 | 0.001371223 |
|
191
|
+
| 5111 | 7 | 0.001449252 |
|
192
|
+
| 5111 | 8 | 0.0120984 |
|
193
|
+
| 5111 | 8 | 0.0160744 |
|
194
|
+
| 5111 | 9 | 0.00407185 |
|
195
|
+
| 5111 | 9 | 0.00544492 |
|
196
|
+
| 5111 | 10 | 0.004574956 |
|
197
|
+
| 5111 | 10 | 0.00614676 |
|
198
|
+
| 5111 | 11 | 0.00035178 |
|
199
|
+
| 5111 | 12 | 0.000418338 |
|
200
|
+
| 5111 | 13 | 0.045696 |
|
201
|
+
| 5111 | 14 | 0.041823625 |
|
202
|
+
| 5111 | 15 | 0.019665104 |
|
203
|
+
| 5111 | 16 | 0.001041495 |
|
204
|
+
| 5111 | 17 | 0.00040365 |
|
205
|
+
| 5111 | 18 | 0.00100347 |
|
206
|
+
| 5172 | 20 | 1.6 |
|
207
|
+
| 5172 | 21 | 0.065 |
|
208
|
+
| 5172 | 22 | 0.045 |
|
209
|
+
| 5172 | 23 | 0.01 |
|
210
|
+
| 5172 | 24 | 0.06 |
|
211
|
+
| 5732 | 10 | 0.181 |
|
212
|
+
| 5732 | 12 | 0.13725 |
|
213
|
+
| 5732 | 25 | 0.32 |
|
214
|
+
| 5812 | 26 | 0.8 |
|
162
215
|
|
163
216
|
Scenario Outline: Sector emissions from merchant id, cost, and date
|
164
217
|
Given a purchase emitter
|
@@ -175,37 +228,37 @@ Feature: Purchase Committee Calculations
|
|
175
228
|
Then the conclusion of the committee should include "<emission>"
|
176
229
|
Examples:
|
177
230
|
| merchant | io_code | cost | date | emission |
|
178
|
-
| 1 |
|
179
|
-
| 1 |
|
180
|
-
| 1 |
|
181
|
-
| 1 |
|
182
|
-
| 1 |
|
183
|
-
| 1 |
|
184
|
-
| 1 |
|
185
|
-
| 1 |
|
186
|
-
| 1 |
|
187
|
-
| 1 |
|
188
|
-
| 1 |
|
189
|
-
| 1 |
|
190
|
-
| 1 |
|
191
|
-
| 1 |
|
192
|
-
| 1 |
|
193
|
-
| 1 |
|
194
|
-
| 1 |
|
195
|
-
| 1 |
|
196
|
-
| 1 |
|
197
|
-
| 1 |
|
198
|
-
| 1 |
|
199
|
-
| 1 |
|
200
|
-
| 1 |
|
201
|
-
| 1 |
|
202
|
-
| 2 |
|
203
|
-
| 2 |
|
204
|
-
| 2 |
|
205
|
-
| 3 |
|
206
|
-
| 4 |
|
207
|
-
| 5 |
|
208
|
-
| 5 |
|
209
|
-
| 5 |
|
210
|
-
| 5 |
|
211
|
-
| 5 |
|
231
|
+
| 1 | 1 | 100.00 | 2010-07-28 | 0.48 |
|
232
|
+
| 1 | 1 | 100.00 | 2010-07-28 | 5.21 |
|
233
|
+
| 1 | 1 | 100.00 | 2010-07-28 | 8.19 |
|
234
|
+
| 1 | 1 | 100.00 | 2010-07-28 | 9.73 |
|
235
|
+
| 1 | 3 | 100.00 | 2010-07-28 | 0.01 |
|
236
|
+
| 1 | 4 | 100.00 | 2010-07-28 | 10.85 |
|
237
|
+
| 1 | 5 | 100.00 | 2010-07-28 | 0.38 |
|
238
|
+
| 1 | 6 | 100.00 | 2010-07-28 | 0.05 |
|
239
|
+
| 1 | 6 | 100.00 | 2010-07-28 | 0.11 |
|
240
|
+
| 1 | 7 | 100.00 | 2010-07-28 | 0.12 |
|
241
|
+
| 1 | 8 | 100.00 | 2010-07-28 | 1.00 |
|
242
|
+
| 1 | 8 | 100.00 | 2010-07-28 | 1.33 |
|
243
|
+
| 1 | 9 | 100.00 | 2010-07-28 | 0.34 |
|
244
|
+
| 1 | 9 | 100.00 | 2010-07-28 | 0.45 |
|
245
|
+
| 1 | 10 | 100.00 | 2010-07-28 | 0.38 |
|
246
|
+
| 1 | 10 | 100.00 | 2010-07-28 | 0.51 |
|
247
|
+
| 1 | 11 | 100.00 | 2010-07-28 | 0.03 |
|
248
|
+
| 1 | 12 | 100.00 | 2010-07-28 | 0.03 |
|
249
|
+
| 1 | 13 | 100.00 | 2010-07-28 | 3.79 |
|
250
|
+
| 1 | 14 | 100.00 | 2010-07-28 | 3.47 |
|
251
|
+
| 1 | 15 | 100.00 | 2010-07-28 | 1.63 |
|
252
|
+
| 1 | 16 | 100.00 | 2010-07-28 | 0.09 |
|
253
|
+
| 1 | 17 | 100.00 | 2010-07-28 | 0.03 |
|
254
|
+
| 1 | 18 | 100.00 | 2010-07-28 | 0.08 |
|
255
|
+
| 2 | 10 | 100.00 | 2010-07-28 | 15.00 |
|
256
|
+
| 2 | 12 | 100.00 | 2010-07-28 | 11.37 |
|
257
|
+
| 2 | 25 | 100.00 | 2010-07-28 | 26.51 |
|
258
|
+
| 3 | 26 | 100.00 | 2010-07-28 | 66.28 |
|
259
|
+
| 4 | 19 | 100.00 | 2010-07-28 | 46.31 |
|
260
|
+
| 5 | 20 | 100.00 | 2010-07-28 | 132.56 |
|
261
|
+
| 5 | 21 | 100.00 | 2010-07-28 | 5.39 |
|
262
|
+
| 5 | 22 | 100.00 | 2010-07-28 | 3.73 |
|
263
|
+
| 5 | 23 | 100.00 | 2010-07-28 | 0.83 |
|
264
|
+
| 5 | 24 | 100.00 | 2010-07-28 | 4.97 |
|
@@ -29,6 +29,21 @@ Feature: Purchase Emissions Calculations
|
|
29
29
|
| 4 | 100.00 | 2010-07-28 | 41.68 |
|
30
30
|
| 5 | 100.00 | 2010-07-28 | 132.72 |
|
31
31
|
|
32
|
+
Scenario Outline: Calculations starting from a merchant with purchase amount and tax
|
33
|
+
Given a purchase has "merchant.id" of "<id>"
|
34
|
+
And it has "purchase_amount" of "<amount>"
|
35
|
+
And it has "tax" of "<tax>"
|
36
|
+
And it has "date" of "<date>"
|
37
|
+
When emissions are calculated
|
38
|
+
Then the emission value should be within 1 kgs of <emission>
|
39
|
+
Examples:
|
40
|
+
| id | amount | tax | date | emission |
|
41
|
+
| 1 | 100.00 | 8.00 | 2010-07-28 | 44.43 |
|
42
|
+
| 2 | 100.00 | 8.00 | 2010-07-28 | 48.65 |
|
43
|
+
| 3 | 100.00 | 8.00 | 2010-07-28 | 60.98 |
|
44
|
+
| 4 | 100.00 | 8.00 | 2010-07-28 | 42.61 |
|
45
|
+
| 5 | 100.00 | 8.00 | 2010-07-28 | 135.68 |
|
46
|
+
|
32
47
|
Scenario Outline: Calculations starting from a merchant category
|
33
48
|
Given a purchase has "merchant_category.mcc" of "<mcc>"
|
34
49
|
And it has "cost" of "<cost>"
|
@@ -5,10 +5,6 @@ require 'date'
|
|
5
5
|
module BrighterPlanet
|
6
6
|
module Purchase
|
7
7
|
module CarbonModel
|
8
|
-
class MissingSectorForProductLineSector < Exception; end
|
9
|
-
class MissingEmissionFactor < Exception; end
|
10
|
-
class MissingSectorForIndustrySector < Exception; end
|
11
|
-
|
12
8
|
def self.included(base)
|
13
9
|
base.extend ::Leap::Subject
|
14
10
|
base.extend FastTimestamp
|
@@ -46,7 +42,9 @@ module BrighterPlanet
|
|
46
42
|
quorum 'from industry shares and product line shares', :needs => [:industry_shares, :product_line_shares] do |characteristics|
|
47
43
|
industry_shares = characteristics[:industry_shares]
|
48
44
|
industry_sector_shares = industry_shares.inject([]) do |list, industry_share|
|
49
|
-
|
45
|
+
industries_sectors = IndustriesSectors.
|
46
|
+
find_all_by_naics_code industry_share.naics_code
|
47
|
+
industries_sectors.each do |industry_sector|
|
50
48
|
io_code = industry_sector.io_code
|
51
49
|
unless ['420000','4A0000'].include?(io_code.to_s)
|
52
50
|
calculated_share = industry_share.ratio * industry_sector.ratio
|
@@ -69,13 +67,21 @@ module BrighterPlanet
|
|
69
67
|
|
70
68
|
industry_sector_shares + product_sector_shares
|
71
69
|
end
|
70
|
+
|
71
|
+
quorum 'from industry', :needs => :naics_code do |characteristics|
|
72
|
+
industries_sectors = IndustriesSectors.
|
73
|
+
find_all_by_naics_code characteristics[:naics_code]
|
74
|
+
vector_items = industries_sectors
|
75
|
+
end
|
72
76
|
end
|
73
77
|
|
74
78
|
committee :product_line_shares do
|
75
79
|
quorum 'from industry shares', :needs => :industry_shares do |characteristics|
|
76
80
|
industry_shares = characteristics[:industry_shares]
|
77
81
|
industry_shares.inject([]) do |list, industry_share|
|
78
|
-
|
82
|
+
industries_product_lines = IndustriesProductLines.
|
83
|
+
find_all_by_naics_code industry_share.naics_code
|
84
|
+
industries_product_lines.each do |industry_product_line|
|
79
85
|
ratio = industry_product_line.ratio * industry_share.ratio
|
80
86
|
list << ProductLineShare.new(industry_product_line.ps_code,
|
81
87
|
ratio)
|
@@ -83,14 +89,32 @@ module BrighterPlanet
|
|
83
89
|
list
|
84
90
|
end
|
85
91
|
end
|
92
|
+
|
93
|
+
quorum 'from industry', :needs => :naics_code do |characteristics|
|
94
|
+
IndustriesProductLines.
|
95
|
+
find_all_by_naics_code(characteristics[:naics_code]).
|
96
|
+
map do |industry_product_line|
|
97
|
+
ProductLineShare.new industry_product_line.ps_code,
|
98
|
+
industry_product_line.ratio
|
99
|
+
end
|
100
|
+
end
|
86
101
|
end
|
87
102
|
|
88
103
|
committee :industry_shares do
|
104
|
+
quorum 'from merchant_categories_industries', :needs => :merchant_categories_industries do |characteristics|
|
105
|
+
characteristics[:merchant_categories_industries].map do |mci|
|
106
|
+
IndustryShare.new mci.naics_code, mci.ratio
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
committee :merchant_categories_industries do
|
89
112
|
quorum 'from merchant category', :needs => :merchant_category do |characteristics|
|
90
|
-
|
113
|
+
characteristics[:merchant_category].merchant_categories_industries
|
91
114
|
end
|
92
115
|
quorum 'from industry', :needs => :naics_code do |characteristics|
|
93
|
-
|
116
|
+
industry = Industry.find_by_naics_code characteristics[:naics_code]
|
117
|
+
industry.merchant_categories_industries
|
94
118
|
end
|
95
119
|
end
|
96
120
|
|
@@ -98,6 +122,10 @@ module BrighterPlanet
|
|
98
122
|
quorum 'from merchant', :needs => [:merchant] do |characteristics|
|
99
123
|
characteristics[:merchant].merchant_category
|
100
124
|
end
|
125
|
+
|
126
|
+
quorum 'default' do
|
127
|
+
MerchantCategory.find_by_mcc 5111
|
128
|
+
end
|
101
129
|
end
|
102
130
|
|
103
131
|
committee :adjusted_cost do
|
@@ -107,7 +135,8 @@ module BrighterPlanet
|
|
107
135
|
2009 => 1.189, 2010 => 1.207, 2011 => 1.225, 2012 => 1.245,
|
108
136
|
2013 => 1.265 }
|
109
137
|
|
110
|
-
date =
|
138
|
+
date = characteristics[:date]
|
139
|
+
date = date.is_a?(String) ? Date.parse(date) : date
|
111
140
|
conversion_factor = @cpi_lookup[date.year] || 1.207
|
112
141
|
|
113
142
|
characteristics[:cost].to_f / conversion_factor
|
@@ -115,10 +144,18 @@ module BrighterPlanet
|
|
115
144
|
end
|
116
145
|
|
117
146
|
committee :cost do
|
147
|
+
quorum 'from purchase amount and tax', :needs => [:purchase_amount, :tax] do |characteristics|
|
148
|
+
characteristics[:purchase_amount].to_f - characteristics[:tax].to_f
|
149
|
+
end
|
150
|
+
|
118
151
|
quorum 'from purchase amount', :needs => :purchase_amount do |characteristics|
|
119
152
|
# FIXME TODO take out tax
|
120
153
|
characteristics[:purchase_amount].to_f * 0.9
|
121
154
|
end
|
155
|
+
|
156
|
+
quorum 'default' do
|
157
|
+
100
|
158
|
+
end
|
122
159
|
end
|
123
160
|
|
124
161
|
committee :date do
|
@@ -130,43 +167,7 @@ module BrighterPlanet
|
|
130
167
|
# FIXME TODO make other committees to report emissions by gas, by io sector, etc.
|
131
168
|
end
|
132
169
|
|
133
|
-
|
134
|
-
date = date.is_a?(Date) ? date : Date.parse(date)
|
135
|
-
end
|
136
|
-
|
137
|
-
class IndustryShare
|
138
|
-
class << self
|
139
|
-
def find_all_by_naics_code(naics_code)
|
140
|
-
industry = Industry.find_by_naics_code naics_code
|
141
|
-
from_merchant_categories_industries industry.merchant_categories_industries
|
142
|
-
end
|
143
|
-
def find_all_by_merchant_category(merchant_category)
|
144
|
-
from_merchant_categories_industries merchant_category.merchant_categories_industries
|
145
|
-
end
|
146
|
-
|
147
|
-
private
|
148
|
-
def from_merchant_categories_industries(merchant_categories_industries)
|
149
|
-
merchant_categories_industries.map do |mci|
|
150
|
-
new mci.naics_code, mci.ratio
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
attr_accessor :naics_code, :ratio
|
156
|
-
|
157
|
-
def initialize(naics_code, ratio)
|
158
|
-
self.naics_code = naics_code
|
159
|
-
self.ratio = ratio
|
160
|
-
end
|
161
|
-
|
162
|
-
def industries_product_lines
|
163
|
-
IndustriesProductLines.find_all_by_naics_code naics_code
|
164
|
-
end
|
165
|
-
|
166
|
-
def industries_sectors
|
167
|
-
IndustriesSectors.find_all_by_naics_code naics_code
|
168
|
-
end
|
169
|
-
end
|
170
|
+
class IndustryShare < Struct.new(:naics_code, :ratio); end
|
170
171
|
|
171
172
|
class ProductLineShare
|
172
173
|
attr_accessor :ps_code, :ratio
|
@@ -181,9 +182,7 @@ module BrighterPlanet
|
|
181
182
|
end
|
182
183
|
end
|
183
184
|
|
184
|
-
class SectorShare
|
185
|
-
attr_accessor :io_code, :share, :emission_factor
|
186
|
-
|
185
|
+
class SectorShare < Struct.new(:io_code, :share, :emission_factor)
|
187
186
|
def initialize(sector, share)
|
188
187
|
self.io_code = sector.io_code
|
189
188
|
self.share = share
|
@@ -191,14 +190,7 @@ module BrighterPlanet
|
|
191
190
|
end
|
192
191
|
end
|
193
192
|
|
194
|
-
class EmissionFactor
|
195
|
-
attr_accessor :io_code, :factor
|
196
|
-
|
197
|
-
def initialize(io_code, factor)
|
198
|
-
self.io_code = io_code
|
199
|
-
self.factor = factor
|
200
|
-
end
|
201
|
-
end
|
193
|
+
class EmissionFactor < Struct.new(:io_code, :factor); end
|
202
194
|
end
|
203
195
|
end
|
204
196
|
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: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Andy Rossmeissl
|
@@ -19,7 +19,7 @@ autorequire:
|
|
19
19
|
bindir: bin
|
20
20
|
cert_chain: []
|
21
21
|
|
22
|
-
date: 2010-
|
22
|
+
date: 2010-09-07 00:00:00 -04:00
|
23
23
|
default_executable:
|
24
24
|
dependencies:
|
25
25
|
- !ruby/object:Gem::Dependency
|