purchase 0.1.8 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/features/purchase_committees.feature +125 -193
- data/features/purchase_emissions.feature +69 -54
- data/features/step_definitions/matrix.rb +21 -0
- data/features/support/matrix_ext.rb +38 -0
- data/lib/purchase/carbon_model.rb +98 -64
- data/lib/purchase.rb +26 -0
- data/lib/test_support/test_impact_vectors_adapter.rb +60 -0
- data/lib/test_support/test_sector_direct_requirements_adapter.rb +57 -0
- metadata +63 -55
@@ -1,101 +1,92 @@
|
|
1
1
|
Feature: Purchase Committee Calculations
|
2
2
|
The purchase model should generate correct committee calculations
|
3
3
|
|
4
|
-
Scenario
|
5
|
-
Given a purchase emitter
|
6
|
-
And a characteristic "purchase_amount" of "
|
4
|
+
Scenario: Cost committee from purchase amount
|
5
|
+
Given a purchase emitter
|
6
|
+
And a characteristic "purchase_amount" of "107.11"
|
7
7
|
When the "cost" committee is calculated
|
8
|
-
Then the
|
9
|
-
|
10
|
-
| amount | cost |
|
11
|
-
| 831.23 | 748.107 |
|
12
|
-
| 11.00 | 9.9 |
|
8
|
+
Then the committee should have used quorum "from purchase amount"
|
9
|
+
And the conclusion of the committee should be "100"
|
13
10
|
|
14
11
|
Scenario Outline: Cost committee from purchase amount and tax
|
15
12
|
Given a purchase emitter
|
16
13
|
And a characteristic "purchase_amount" of "<amount>"
|
17
14
|
And a characteristic "tax" of "<tax>"
|
18
15
|
When the "cost" committee is calculated
|
19
|
-
Then the
|
16
|
+
Then the committee should have used quorum "from purchase amount and tax"
|
17
|
+
And the conclusion of the committee should be "<cost>"
|
20
18
|
Examples:
|
21
19
|
| amount | tax | cost |
|
22
20
|
| 10.00 | 1.00 | 9.00 |
|
23
21
|
|
24
|
-
Scenario
|
25
|
-
Given a purchase emitter
|
22
|
+
Scenario: Cost committee from default
|
23
|
+
Given a purchase emitter
|
24
|
+
When the "cost" committee is calculated
|
25
|
+
Then the conclusion of the committee should be "100"
|
26
|
+
|
27
|
+
Scenario Outline: Adjusted cost committee
|
28
|
+
Given a purchase emitter
|
26
29
|
And a characteristic "cost" of "<cost>"
|
27
30
|
And characteristic "date" of "<date>"
|
28
31
|
When the "adjusted_cost" committee is calculated
|
29
|
-
Then the
|
30
|
-
And the conclusion of the committee should be "<adjusted_cost>"
|
32
|
+
Then the conclusion of the committee should be "<adjusted_cost>"
|
31
33
|
Examples:
|
32
34
|
| cost | date | adjusted_cost |
|
33
35
|
| 831.23 | 2010-08-01 | 688.67439 |
|
34
36
|
| 11.00 | 2005-07-14 | 9.11350 |
|
35
37
|
|
36
|
-
Scenario Outline: Merchant category committee
|
37
|
-
Given a purchase emitter
|
38
|
+
Scenario Outline: Merchant category committee
|
39
|
+
Given a purchase emitter
|
38
40
|
And a characteristic "merchant.id" of "<id>"
|
39
41
|
When the "merchant_category" committee is calculated
|
40
42
|
Then the conclusion of the committee should have "mcc" of "<mcc>"
|
41
43
|
Examples:
|
42
44
|
| id | mcc |
|
43
|
-
|
|
44
|
-
|
|
45
|
+
| 3 | 5812 |
|
46
|
+
| 9 | 9999 |
|
45
47
|
|
46
|
-
Scenario
|
47
|
-
Given a purchase emitter
|
48
|
+
Scenario: Merchant category committee from default
|
49
|
+
Given a purchase emitter
|
50
|
+
When the "merchant_category" committee is calculated
|
51
|
+
Then the conclusion of the committee should have "mcc" of "5111"
|
52
|
+
|
53
|
+
Scenario Outline: Merchant categories industries committee
|
54
|
+
Given a purchase emitter
|
48
55
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
49
56
|
When the "merchant_categories_industries" committee is calculated
|
50
57
|
Then the conclusion of the committee should have a record identified with "naics_code" of "<naics>" and having "ratio" of "<ratio>"
|
51
58
|
Examples:
|
52
59
|
| 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
60
|
| 5812 | 72211 | 1 |
|
62
|
-
|
|
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 |
|
61
|
+
| 9999 | 999991 | 0.5 |
|
62
|
+
| 9999 | 999992 | 0.5 |
|
81
63
|
|
82
|
-
Scenario Outline: Industry shares committee
|
83
|
-
Given a purchase emitter
|
64
|
+
Scenario Outline: Industry shares committee
|
65
|
+
Given a purchase emitter
|
84
66
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
85
67
|
When the "merchant_categories_industries" committee is calculated
|
86
68
|
And the "industry_shares" committee is calculated
|
87
69
|
Then the conclusion of the committee should have a record identified with "naics_code" of "<naics>" and having "ratio" of "<share>"
|
88
70
|
Examples:
|
89
71
|
| mcc | naics | share |
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
94
|
-
|
95
|
-
|
72
|
+
| 5812 | 72211 | 1.0 |
|
73
|
+
| 9999 | 999991 | 0.5 |
|
74
|
+
| 9999 | 999992 | 0.5 |
|
75
|
+
|
76
|
+
Scenario Outline: Product line shares committee from industry
|
77
|
+
Given a purchase emitter
|
78
|
+
And a characteristic "naics_code" of "<naics>"
|
79
|
+
When the "product_line_shares" committee is calculated
|
80
|
+
Then the committee should have used quorum "from industry"
|
81
|
+
And the conclusion of the committee should have a record identified with "ps_code" of "<ps_code>" and having "ratio" of "<share>"
|
82
|
+
Examples:
|
83
|
+
| naics | ps_code | share |
|
84
|
+
| 72211 | | |
|
85
|
+
| 999992 | 99992 | 0.75 |
|
86
|
+
| 999992 | 99993 | 0.25 |
|
96
87
|
|
97
88
|
Scenario Outline: Product line shares committee from merchant category
|
98
|
-
Given a purchase emitter
|
89
|
+
Given a purchase emitter
|
99
90
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
100
91
|
When the "merchant_categories_industries" committee is calculated
|
101
92
|
And the "industry_shares" committee is calculated
|
@@ -103,162 +94,103 @@ Feature: Purchase Committee Calculations
|
|
103
94
|
Then the conclusion of the committee should have a record identified with "ps_code" of "<ps_code>" and having "ratio" of "<share>"
|
104
95
|
Examples:
|
105
96
|
| mcc | ps_code | share |
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
| 5111 | 20851 | 0.122 |
|
110
|
-
| 5111 | 20852 | 0.145 |
|
111
|
-
| 5111 | 20853 | 0.265 |
|
112
|
-
| 5111 | 20854 | 0.071 |
|
113
|
-
| 5111 | 29938 | 0.011 |
|
114
|
-
| 5111 | 29979 | 0.013 |
|
97
|
+
| 5812 | | |
|
98
|
+
| 9999 | 99992 | 0.375 |
|
99
|
+
| 9999 | 99993 | 0.125 |
|
115
100
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
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 |
|
101
|
+
Scenario Outline: Industries sectors committee from industry
|
102
|
+
Given a purchase emitter
|
103
|
+
And a characteristic "naics_code" of "<naics>"
|
104
|
+
When the "industries_sectors" committee is calculated
|
105
|
+
Then the committee should have used quorum "from industry"
|
106
|
+
And the conclusion of the committee should have a record identified with "io_code" of "<io_code>" and having "ratio" of "<share>"
|
107
|
+
Examples:
|
108
|
+
| naics | io_code | share |
|
109
|
+
| 45321 | 4A0000 | 1.0 |
|
110
|
+
| 443112 | 4A0000 | 1.0 |
|
111
|
+
| 72211 | 26 | 1.0 |
|
112
|
+
| 999991 | A | 0.75 |
|
113
|
+
| 999991 | B | 0.25 |
|
114
|
+
| 999992 | 4A0000 | 1.0 |
|
135
115
|
|
136
|
-
Scenario Outline:
|
116
|
+
Scenario Outline: Industries sectors committee from merchant category
|
137
117
|
Given a purchase emitter
|
138
118
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
119
|
+
And a characteristic "cost" of "100"
|
120
|
+
And a characteristic "date" of "2010-08-01"
|
121
|
+
When the "adjusted_cost" committee is calculated
|
122
|
+
And the "merchant_categories_industries" committee is calculated
|
123
|
+
And the "industry_shares" committee is calculated
|
124
|
+
And the "industries_sectors" committee is calculated
|
125
|
+
Then the committee should have used quorum "from industry shares"
|
126
|
+
And the conclusion of the committee should have a record identified with "io_code" of "<io_code>" and having "ratio" of "<share>"
|
127
|
+
Examples:
|
128
|
+
| mcc | io_code | share |
|
129
|
+
| 5812 | 26 | 1.0 |
|
130
|
+
| 9999 | A | 0.375 |
|
131
|
+
| 9999 | B | 0.125 |
|
132
|
+
|
133
|
+
Scenario Outline: Sector shares committee from industry and product line shares
|
134
|
+
Given a purchase emitter
|
135
|
+
And a characteristic "merchant_category.mcc" of "<mcc>"
|
139
136
|
When the "merchant_categories_industries" committee is calculated
|
140
137
|
And the "industry_shares" committee is calculated
|
141
138
|
And the "product_line_shares" committee is calculated
|
139
|
+
And the "industries_sectors" committee is calculated
|
142
140
|
And the "sector_shares" committee is calculated
|
143
|
-
Then the conclusion of the committee should be a vector with
|
141
|
+
Then the conclusion of the committee should be a vector with values "<26>,<A>,<B>,<C>,<D>"
|
144
142
|
Examples:
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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 |
|
143
|
+
|mcc | 26 | A | B | C | D |
|
144
|
+
|5218| 1.0 | 0 | 0 | 0 | 0 |
|
145
|
+
|9999| 0 | 0.5625| 0.3125| 0.0625| 0.0625|
|
173
146
|
|
174
|
-
Scenario
|
175
|
-
Given a purchase emitter
|
147
|
+
Scenario: Sector direct requirements
|
148
|
+
Given a purchase emitter
|
149
|
+
When the "sector_direct_requirements" committee is calculated
|
150
|
+
Then the conclusion of the committee should be a square matrix with "32" rows and columns
|
151
|
+
|
152
|
+
Scenario Outline: Economic flows from merchant category
|
153
|
+
Given a purchase emitter
|
176
154
|
And a characteristic "merchant_category.mcc" of "<mcc>"
|
177
|
-
|
155
|
+
And a characteristic "date" of "2010-08-01"
|
156
|
+
And a characteristic "cost" of "100"
|
157
|
+
When the "adjusted_cost" committee is calculated
|
158
|
+
And the "merchant_categories_industries" committee is calculated
|
159
|
+
And the "industry_shares" committee is calculated
|
178
160
|
And the "product_line_shares" committee is calculated
|
161
|
+
And the "industries_sectors" committee is calculated
|
179
162
|
And the "sector_shares" committee is calculated
|
180
|
-
And the "
|
181
|
-
|
163
|
+
And the "sector_direct_requirements" committee is calculated
|
164
|
+
And the "economic_flows" committee is calculated
|
165
|
+
Then the conclusion of the committee should be a vector with values "<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>,<12>,<13>,<14>,<15>,<16>,<17>,<18>,<19>,<20>,<21>,<22>,<23>,<24>,<25>,<26>,<44100>,<44101>,<44102>,<44103>,<44104>,<44105>"
|
182
166
|
Examples:
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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 |
|
167
|
+
|mcc | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 44100| 44101| 44102| 44103| 44104| 44105|
|
168
|
+
|3504|192.42878|190.54222|245.14686|242.78968|295.60384|292.81512|346.78566|404.30912|400.59986|465.29127|528.62004|482.35635|466.74323|468.52286|501.11032|468.42401|424.06313|393.05155|506.82714|413.31948|408.00708|380.41657|307.66401|449.85893|372.82038|836.30767|931.90473|897.58914|713.25686|712.54645|62108.49751|64007.92880|
|
169
|
+
|5111|217.60851|188.33439|240.23898|246.58722|289.15336|286.35133|338.69552|401.57566|392.30640|454.36248|510.67639|465.48678|453.29908|452.07535|479.07926|433.58397|390.81556|366.40189|414.39616|398.88015|410.43100|392.65385|319.38796|469.25412|389.47876|878.05118|979.36178|943.33243|749.79844|749.05163|65344.72371|67343.77541|
|
170
|
+
|5172|183.87087|182.06822|234.24153|231.98921|282.45806|279.79336|331.44594|386.67305|383.12559|443.95827|505.08363|460.93482|446.66308|449.71238|471.64803|451.80455|409.65115|384.25908|428.91553|462.17754|412.89024|378.40441|304.83450|439.98234|360.24151|801.81579|892.45620|859.55691|682.82806|682.14796|59460.87972|61279.36469|
|
171
|
+
|5732|183.11569|181.32043|231.15559|228.93294|278.83247|276.20197|324.59174|375.74672|372.29950|465.95439|483.12194|455.69859|419.53135|417.80920|435.45569|407.12840|367.62744|345.95575|392.16116|378.09709|388.34638|373.09854|303.76218|440.33643|377.80083|806.53673|894.12118|861.03177|683.26595|682.58541|59509.68769|61329.79292|
|
172
|
+
|5812|171.55784|169.87590|218.54218|216.44081|263.51360|261.02763|309.15838|360.69762|357.38846|414.47227|471.13666|429.92363|416.23221|419.67110|442.44048|419.01368|379.60402|362.16497|413.97706|402.64335|419.92739|407.41210|332.40488|496.30587|413.33528|951.16340|982.78937|943.83794|734.26687|733.53553|64092.82756|66054.79463|
|
215
173
|
|
216
|
-
Scenario Outline:
|
174
|
+
Scenario Outline: Impacts committee from economic flows
|
217
175
|
Given a purchase emitter
|
218
|
-
And a characteristic "
|
219
|
-
And a characteristic "
|
220
|
-
And a characteristic "
|
176
|
+
And a characteristic "merchant_category.mcc" of "<mcc>"
|
177
|
+
And a characteristic "date" of "2010-08-01"
|
178
|
+
And a characteristic "cost" of "100"
|
221
179
|
When the "adjusted_cost" committee is calculated
|
222
|
-
And the "
|
180
|
+
And the "merchant_categories_industries" committee is calculated
|
223
181
|
And the "industry_shares" committee is calculated
|
224
182
|
And the "product_line_shares" committee is calculated
|
183
|
+
And the "industries_sectors" committee is calculated
|
225
184
|
And the "sector_shares" committee is calculated
|
226
|
-
And the "
|
227
|
-
And the "
|
228
|
-
|
185
|
+
And the "sector_direct_requirements" committee is calculated
|
186
|
+
And the "economic_flows" committee is calculated
|
187
|
+
And the "impact_vectors" committee is calculated
|
188
|
+
And the "impacts" committee is calculated
|
189
|
+
Then the conclusion of the committee should be a vector with values "<1>,<2>,<3>,<4>,<5>,<6>,<7>,<8>,<9>,<10>,<11>,<12>,<13>,<14>,<15>,<16>,<17>,<18>,<19>,<20>,<21>,<22>,<23>,<24>,<25>,<26>,<44100>,<44101>,<44102>,<44103>,<44104>,<44105>"
|
229
190
|
Examples:
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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 |
|
191
|
+
|mcc | 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26| 44100| 44101| 44102| 44103| 44104| 44105|
|
192
|
+
|3504|155.86731|104.03605|87.76257|291.34762|319.25215|182.42382|196.62746|114.82379|148.22195|168.43544|116.29640|264.81364|253.90832|250.65973|50.61214|114.76388|97.53452|73.10758|283.31637|826.63897|530.40921|342.37491|61.53280|539.83071|596.51261|669.04614|652.33331|89.75891|499.27980|855.05574|86951.89652|19202.37864|
|
193
|
+
|5111|176.26289|102.83058|86.00555|295.90467|312.28563|178.39687|192.04036|114.04748|145.15336|164.47922|112.34880|255.55224|246.59470|241.86031|48.38700|106.22807|89.88757|68.15075|231.64745|797.76030|533.56031|353.38847|63.87759|563.10495|623.16602|702.44095|685.55325|94.33324|524.85891|898.86196|91482.61320|20203.13262|
|
194
|
+
|5172|148.93540| 99.40924|83.85847|278.38705|305.05470|174.31126|187.92985|109.81514|141.75647|160.71289|111.11839|253.05321|242.98472|240.59612|47.63645|110.69211|94.21976|71.47218|239.76378|924.35508|536.75732|340.56397|60.96690|527.97880|576.38642|641.45263|624.71934|85.95569|477.97964|818.57755|83245.23160|18383.80940|
|
195
|
+
|5732|148.32370| 99.00095|82.75370|274.71953|301.13906|172.07383|184.04352|106.71206|137.75081|168.67549|106.28682|250.17853|228.22505|223.52792|43.98102| 99.74646|84.55431|64.34777|219.21809|756.19418|504.85029|335.78869|60.75243|528.40372|604.48133|645.22938|625.88482|86.10317|478.28616|819.10249|83313.56277|18398.93787|
|
196
|
+
|5812|138.96185| 92.75224|78.23810|259.72898|284.59469|162.62021|175.29280|102.43812|132.23373|150.03896|103.65006|236.02807|226.43032|224.52403|44.68648|102.65835|87.30892|67.36268|231.41317|805.28671|545.90561|366.67089|66.48097|595.56705|661.33645|760.93072|687.95256|94.38379|513.98681|880.24264|89729.95858|19816.43838|
|
@@ -1,88 +1,103 @@
|
|
1
1
|
Feature: Purchase Emissions Calculations
|
2
2
|
The purchase model should generate correct emission calculations
|
3
|
-
|
3
|
+
|
4
|
+
Scenario: Calculations starting from nothing
|
5
|
+
Given a purchase has nothing
|
6
|
+
When emissions are calculated
|
7
|
+
Then the emission value should be within "0.001" kgs of "120694.715"
|
8
|
+
|
9
|
+
Scenario: Calculations starting from purchase amount
|
10
|
+
Given a purchase has "purchase_amount" of "107.11"
|
11
|
+
When emissions are calculated
|
12
|
+
Then the emission value should be within "0.001" kgs of "120694.715"
|
13
|
+
|
14
|
+
Scenario: Calculations starting from date
|
15
|
+
Given a purchase has "date" of "2010-07-28"
|
16
|
+
When emissions are calculated
|
17
|
+
Then the emission value should be within "0.001" kgs of "120694.715"
|
18
|
+
|
4
19
|
Scenario Outline: Calculations starting from a merchant
|
5
20
|
Given a purchase has "merchant.id" of "<id>"
|
6
|
-
And it has "cost" of "<cost>"
|
7
|
-
And it has "date" of "<date>"
|
8
21
|
When emissions are calculated
|
9
|
-
Then the emission value should be within
|
22
|
+
Then the emission value should be within "0.001" kgs of "<emission>"
|
10
23
|
Examples:
|
11
|
-
| id |
|
12
|
-
| 1 |
|
13
|
-
| 2 |
|
14
|
-
| 3 |
|
15
|
-
| 4 |
|
16
|
-
| 5 |
|
24
|
+
| id | emission |
|
25
|
+
| 1 | 120694.715|
|
26
|
+
| 2 | 110152.836|
|
27
|
+
| 3 | 118426.103|
|
28
|
+
| 4 | 115090.859|
|
29
|
+
| 5 | 110346.441|
|
17
30
|
|
18
31
|
Scenario Outline: Calculations starting from a merchant with purchase amount
|
19
32
|
Given a purchase has "merchant.id" of "<id>"
|
20
33
|
And it has "purchase_amount" of "<amount>"
|
21
|
-
And it has "date" of "<date>"
|
22
34
|
When emissions are calculated
|
23
|
-
Then the emission value should be within
|
35
|
+
Then the emission value should be within "0.001" kgs of "<emission>"
|
24
36
|
Examples:
|
25
|
-
| id | amount |
|
26
|
-
| 1 |
|
27
|
-
| 2 |
|
28
|
-
| 3 |
|
29
|
-
| 4 |
|
30
|
-
| 5 |
|
37
|
+
| id | amount | emission |
|
38
|
+
| 1 | 107.11 | 120694.715|
|
39
|
+
| 2 | 107.11 | 110152.836|
|
40
|
+
| 3 | 107.11 | 118426.103|
|
41
|
+
| 4 | 107.11 | 115090.859|
|
42
|
+
| 5 | 107.11 | 110346.441|
|
31
43
|
|
32
|
-
Scenario Outline: Calculations starting from a merchant with purchase amount and
|
44
|
+
Scenario Outline: Calculations starting from a merchant with purchase amount and date
|
45
|
+
Given a purchase has "merchant.id" of "<id>"
|
46
|
+
And it has "purchase_amount" of "<amount>"
|
47
|
+
And it has "date" of "<date>"
|
48
|
+
When emissions are calculated
|
49
|
+
Then the emission value should be within "0.001" kgs of "<emission>"
|
50
|
+
Examples:
|
51
|
+
| id | amount | date | emission |
|
52
|
+
| 1 | 107.11 | 2010-07-28 | 120694.715|
|
53
|
+
| 2 | 107.11 | 2010-07-28 | 110152.836|
|
54
|
+
| 3 | 107.11 | 2010-07-28 | 118426.103|
|
55
|
+
| 4 | 107.11 | 2010-07-28 | 115090.859|
|
56
|
+
| 5 | 107.11 | 2010-07-28 | 110346.441|
|
57
|
+
|
58
|
+
Scenario Outline: Calculations starting from a merchant with purchase amount, date, and tax
|
33
59
|
Given a purchase has "merchant.id" of "<id>"
|
34
60
|
And it has "purchase_amount" of "<amount>"
|
35
61
|
And it has "tax" of "<tax>"
|
36
62
|
And it has "date" of "<date>"
|
37
63
|
When emissions are calculated
|
38
|
-
Then the emission value should be within
|
64
|
+
Then the emission value should be within "0.001" kgs of "<emission>"
|
39
65
|
Examples:
|
40
|
-
| id | amount | tax | date | emission
|
41
|
-
| 1 |
|
42
|
-
| 2 |
|
43
|
-
| 3 |
|
44
|
-
| 4 |
|
45
|
-
| 5 |
|
66
|
+
| id | amount | tax | date | emission |
|
67
|
+
| 1 | 108.00 | 8.00 | 2010-07-28 | 120694.715|
|
68
|
+
| 2 | 108.00 | 8.00 | 2010-07-28 | 110152.836|
|
69
|
+
| 3 | 108.00 | 8.00 | 2010-07-28 | 118426.103|
|
70
|
+
| 4 | 108.00 | 8.00 | 2010-07-28 | 115090.859|
|
71
|
+
| 5 | 108.00 | 8.00 | 2010-07-28 | 110346.441|
|
46
72
|
|
47
73
|
Scenario Outline: Calculations starting from a merchant category
|
48
74
|
Given a purchase has "merchant_category.mcc" of "<mcc>"
|
49
75
|
And it has "cost" of "<cost>"
|
50
76
|
And it has "date" of "<date>"
|
51
77
|
When emissions are calculated
|
52
|
-
Then the emission value should be within 0.
|
78
|
+
Then the emission value should be within "0.001" kgs of "<emission>"
|
53
79
|
Examples:
|
54
|
-
| mcc | cost | date | emission
|
55
|
-
| 5111 | 100.00 | 2010-07-28 |
|
56
|
-
| 5732 | 100.00 | 2010-07-28 |
|
57
|
-
| 5812 | 100.00 | 2010-07-28 |
|
58
|
-
| 3504 | 100.00 | 2010-07-28 |
|
59
|
-
| 5172 | 100.00 | 2010-07-28 |
|
80
|
+
| mcc | cost | date | emission |
|
81
|
+
| 5111 | 100.00 | 2010-07-28 | 120694.715|
|
82
|
+
| 5732 | 100.00 | 2010-07-28 | 110152.836|
|
83
|
+
| 5812 | 100.00 | 2010-07-28 | 118426.103|
|
84
|
+
| 3504 | 100.00 | 2010-07-28 | 115090.859|
|
85
|
+
| 5172 | 100.00 | 2010-07-28 | 110346.441|
|
60
86
|
|
61
87
|
Scenario Outline: Calculations starting from industry
|
62
88
|
Given a purchase has "naics_code" of "<naics>"
|
63
89
|
And it has "cost" of "<cost>"
|
64
90
|
And it has "date" of "<date>"
|
65
91
|
When emissions are calculated
|
66
|
-
Then the emission value should be within 0.
|
92
|
+
Then the emission value should be within "0.001" kgs of "<emission>"
|
67
93
|
Examples:
|
68
94
|
| naics | cost | date | emission |
|
69
|
-
| 45321 | 100.00 | 2010-07-28 |
|
70
|
-
| 443112 | 100.00 | 2010-07-28 |
|
71
|
-
| 72211 | 100.00 | 2010-07-28 |
|
72
|
-
| 72111 | 100.00 | 2010-07-28 |
|
73
|
-
| 32411 | 100.00 | 2010-07-28 |
|
74
|
-
| 324121 | 100.00 | 2010-07-28 |
|
75
|
-
| 324122 | 100.00 | 2010-07-28 |
|
76
|
-
| 324191 | 100.00 | 2010-07-28 |
|
77
|
-
| 324199 | 100.00 | 2010-07-28 |
|
78
|
-
|
79
|
-
Scenario Outline: Calculations without merchant, merchant category, or industry
|
80
|
-
Given a purchase has "cost" of "<cost>"
|
81
|
-
And it has "date" of "<date>"
|
82
|
-
When emissions are calculated
|
83
|
-
Then the emission value should be within 0.1 kgs of <emission>
|
84
|
-
Examples:
|
85
|
-
| cost | date | emission |
|
86
|
-
| 100.00 | 2010-07-28 | 82.85 |
|
87
|
-
| 100.00 | 2010-08-28 | 82.85 |
|
88
|
-
| 120.00 | 2010-08-28 | 99.42 |
|
95
|
+
| 45321 | 100.00 | 2010-07-28 |120694.715|
|
96
|
+
| 443112 | 100.00 | 2010-07-28 |110152.836|
|
97
|
+
| 72211 | 100.00 | 2010-07-28 |118426.103|
|
98
|
+
| 72111 | 100.00 | 2010-07-28 |115090.859|
|
99
|
+
| 32411 | 100.00 | 2010-07-28 |112285.552|
|
100
|
+
| 324121 | 100.00 | 2010-07-28 | 94684.359|
|
101
|
+
| 324122 | 100.00 | 2010-07-28 |106509.038|
|
102
|
+
| 324191 | 100.00 | 2010-07-28 |104811.125|
|
103
|
+
| 324199 | 100.00 | 2010-07-28 |104355.468|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Then /^the conclusion of the committee should be a vector with value "(.*)" and position for key "(.*)"$/ do |value, key|
|
2
|
+
vector = @report.conclusion
|
3
|
+
position = BrighterPlanet::Purchase.key_map.index key
|
4
|
+
compare_values vector[position], value
|
5
|
+
end
|
6
|
+
|
7
|
+
Then /^the conclusion of the committee should be a square matrix with "(\d+)" rows and columns$/ do |num|
|
8
|
+
matrix = @report.conclusion
|
9
|
+
matrix.row_size.should == num.to_i
|
10
|
+
matrix.should be_square
|
11
|
+
end
|
12
|
+
|
13
|
+
Then /^the conclusion of the committee should be a vector with values "(.*)"$/ do |column_values|
|
14
|
+
column_values = column_values.split(/,/).map(&:to_f)
|
15
|
+
vector = @report.conclusion
|
16
|
+
vector = vector.row(0) if vector.is_a? Matrix #some vectors are single-row matrices
|
17
|
+
|
18
|
+
BrighterPlanet::Purchase.key_map.each_with_index do |key, index|
|
19
|
+
vector[index].should be_close(column_values[index].to_f, 0.00001)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class MatrixVectorHelper
|
2
|
+
def self.column_width(rows)
|
3
|
+
rows.map(&:to_s).map(&:length).max + 2
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Matrix
|
8
|
+
def inspect
|
9
|
+
keys = BrighterPlanet::Purchase.key_map
|
10
|
+
paddings = {}
|
11
|
+
keys.each_with_index do |key, i|
|
12
|
+
paddings[key] = MatrixVectorHelper.column_width(column(i).to_a + [key])
|
13
|
+
end
|
14
|
+
str = "Matrix: (#{row_size}x#{column_size})\n"
|
15
|
+
str += '|' + (['X'.center(5)] + keys.map { |k| k.center(paddings[k]) }).join('|') + "|\n"
|
16
|
+
@rows.each_with_index do |row, i|
|
17
|
+
items = [keys[i].center(5)]
|
18
|
+
row.each_with_index { |i, col| items << i.to_s.center(paddings[keys[col]]) }
|
19
|
+
str += '|' + items.join('|') + "|\n"
|
20
|
+
end
|
21
|
+
str
|
22
|
+
end
|
23
|
+
end
|
24
|
+
class Vector
|
25
|
+
def inspect
|
26
|
+
keys = BrighterPlanet::Purchase.key_map
|
27
|
+
paddings = {}
|
28
|
+
keys.each_with_index do |key, i|
|
29
|
+
paddings[key] = MatrixVectorHelper.column_width([to_a[i],key])
|
30
|
+
end
|
31
|
+
str = "Vector: (#{size})\n"
|
32
|
+
str += '|' + (keys.map { |k| k.center(paddings[k]) }).join('|') + "|\n"
|
33
|
+
items = []
|
34
|
+
to_a.each_with_index { |r, i| items << r.to_s.center(paddings[keys[i]]) }
|
35
|
+
str += '|' + items.join('|') + "|\n"
|
36
|
+
str
|
37
|
+
end
|
38
|
+
end
|