purchase 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- And the conclusion of the committee should be "<cost>"
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: Industry shares committee from merchant category
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 "industry_shares" committee is calculated
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 "industry_shares" committee is calculated
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
- Scenario Outline: Sector shares committee from merchant category
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 "industry_shares" committee is calculated
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 have a record identified with "io_code" of "<io_code>" and having "emission_factor" of "<emission_factor>"
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 | emission_factor | share |
78
- | 5111 | 337212 | 0.544 | 0.084 |
79
- | 5111 | 334111 | 0.284 | 0.0566 |
80
- | 5111 | 334112 | 0.37 | 0.014716 |
81
- | 5111 | 33411A | 0.362 | 0.01698 |
82
- | 5111 | 511200 | 0.101 | 0.194704 |
83
- | 5111 | 333315 | 0.623 | 0.001044 |
84
- | 5111 | 3259A0 | 1.08 | 0.004194 |
85
- | 5111 | 334300 | 0.549 | 0.000762 |
86
- | 5111 | 322230 | 0.81 | 0.122 |
87
- | 5111 | 322230 | 0.81 | 0.145 |
88
- | 5111 | 322230 | 0.81 | 0.077645 |
89
- | 5111 | 339940 | 0.535 | 0.078175 |
90
- | 5111 | 325910 | 1.2 | 0.10918 |
91
- | 5111 | 33331A | 0.567 | 0.002556 |
92
- | 5111 | 333315 | 0.623 | 0.002201 |
93
- | 5111 | 334111 | 0.284 | 0.0426 |
94
- | 5111 | 334112 | 0.37 | 0.011005 |
95
- | 5111 | 33411A | 0.362 | 0.012638 |
96
- | 5111 | 323110 | 0.546 | 0.010505 |
97
- | 5111 | 323120 | 0.358 | 0.000495 |
98
- | 5111 | 532400 | 0.245 | 0.004251 |
99
- | 5111 | 812900 | 0.22 | 0.001599 |
100
- | 5111 | 532A00 | 0.23 | 0.001755 |
101
- | 5111 | 561400 | 0.186 | 0.005395 |
102
- | 5732 | 334300 | 0.549 | 0.25 |
103
- | 5732 | 33411A | 0.362 | 0.5 |
104
- | 5732 | 334210 | 1.6 | 0.2 |
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: Emission factor from merchant category
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
- | 5111 | 337212 | 0.045696 |
124
- | 5111 | 334111 | 0.0160744 |
125
- | 5111 | 334112 | 0.00544492 |
126
- | 5111 | 33411A | 0.00614676 |
127
- | 5111 | 511200 | 0.019665104 |
128
- | 5111 | 333315 | 0.000650412 |
129
- | 5111 | 3259A0 | 0.00452952 |
130
- | 5111 | 334300 | 0.000418338 |
131
- | 5111 | 322230 | 0.09882 |
132
- | 5111 | 322230 | 0.11745 |
133
- | 5111 | 322230 | 0.06289245 |
134
- | 5111 | 339940 | 0.041823625 |
135
- | 5111 | 325910 | 0.131016 |
136
- | 5111 | 33331A | 0.001449252 |
137
- | 5111 | 333315 | 0.001371223 |
138
- | 5111 | 334111 | 0.0120984 |
139
- | 5111 | 334112 | 0.00407185 |
140
- | 5111 | 33411A | 0.004574956 |
141
- | 5111 | 323110 | 0.00573573 |
142
- | 5111 | 323120 | 0.00017721 |
143
- | 5111 | 532400 | 0.001041495 |
144
- | 5111 | 812900 | 0.00035178 |
145
- | 5111 | 532A00 | 0.00040365 |
146
- | 5111 | 561400 | 0.00100347 |
147
- | 5732 | 334300 | 0.13725 |
148
- | 5732 | 33411A | 0.181 |
149
- | 5732 | 334210 | 0.32 |
150
- | 5812 | 722000 | 0.8 |
151
- | 3504 | 7211A0 | 0.559 |
152
- | 5172 | 324110 | 1.6 |
153
- | 5172 | 324121 | 0.065 |
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 | 337212 | 100.00 | 2010-07-28 | 3.79 |
179
- | 1 | 334111 | 100.00 | 2010-07-28 | 1.33 |
180
- | 1 | 334112 | 100.00 | 2010-07-28 | 0.45 |
181
- | 1 | 33411A | 100.00 | 2010-07-28 | 0.51 |
182
- | 1 | 511200 | 100.00 | 2010-07-28 | 1.63 |
183
- | 1 | 333315 | 100.00 | 2010-07-28 | 0.05 |
184
- | 1 | 3259A0 | 100.00 | 2010-07-28 | 0.38 |
185
- | 1 | 334300 | 100.00 | 2010-07-28 | 0.03 |
186
- | 1 | 322230 | 100.00 | 2010-07-28 | 8.19 |
187
- | 1 | 322230 | 100.00 | 2010-07-28 | 9.73 |
188
- | 1 | 322230 | 100.00 | 2010-07-28 | 5.21 |
189
- | 1 | 339940 | 100.00 | 2010-07-28 | 3.47 |
190
- | 1 | 325910 | 100.00 | 2010-07-28 | 10.85 |
191
- | 1 | 33331A | 100.00 | 2010-07-28 | 0.12 |
192
- | 1 | 333315 | 100.00 | 2010-07-28 | 0.11 |
193
- | 1 | 334111 | 100.00 | 2010-07-28 | 1.00 |
194
- | 1 | 334112 | 100.00 | 2010-07-28 | 0.34 |
195
- | 1 | 33411A | 100.00 | 2010-07-28 | 0.38 |
196
- | 1 | 323110 | 100.00 | 2010-07-28 | 0.48 |
197
- | 1 | 323120 | 100.00 | 2010-07-28 | 0.01 |
198
- | 1 | 532400 | 100.00 | 2010-07-28 | 0.09 |
199
- | 1 | 812900 | 100.00 | 2010-07-28 | 0.03 |
200
- | 1 | 532A00 | 100.00 | 2010-07-28 | 0.03 |
201
- | 1 | 561400 | 100.00 | 2010-07-28 | 0.08 |
202
- | 2 | 334300 | 100.00 | 2010-07-28 | 11.37 |
203
- | 2 | 33411A | 100.00 | 2010-07-28 | 15.00 |
204
- | 2 | 334210 | 100.00 | 2010-07-28 | 26.51 |
205
- | 3 | 722000 | 100.00 | 2010-07-28 | 66.28 |
206
- | 4 | 7211A0 | 100.00 | 2010-07-28 | 46.31 |
207
- | 5 | 324110 | 100.00 | 2010-07-28 | 132.56 |
208
- | 5 | 324121 | 100.00 | 2010-07-28 | 5.39 |
209
- | 5 | 324122 | 100.00 | 2010-07-28 | 3.73 |
210
- | 5 | 324191 | 100.00 | 2010-07-28 | 0.83 |
211
- | 5 | 324199 | 100.00 | 2010-07-28 | 4.97 |
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
- industry_share.industries_sectors.each do |industry_sector|
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
- industry_share.industries_product_lines.each do |industry_product_line|
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
- IndustryShare.find_all_by_merchant_category characteristics[:merchant_category]
113
+ characteristics[:merchant_category].merchant_categories_industries
91
114
  end
92
115
  quorum 'from industry', :needs => :naics_code do |characteristics|
93
- IndustryShare.find_all_by_naics_code characteristics[:naics_code]
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 = parse_date characteristics[: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
- def self.parse_date(date)
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 6
10
- version: 0.1.6
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-08-17 00:00:00 -04:00
22
+ date: 2010-09-07 00:00:00 -04:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency