purchase 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,16 @@
1
1
  Feature: Purchase Committee Calculations
2
2
  The purchase model should generate correct committee calculations
3
3
 
4
+ Scenario Outline: Cost committee from purchase amount
5
+ Given a purchase emitter
6
+ And a characteristic "purchase_amount" of "<amount>"
7
+ When the "cost" committee is calculated
8
+ And the conclusion of the committee should be "<cost>"
9
+ Examples:
10
+ | amount | cost |
11
+ | 831.23 | 748.107 |
12
+ | 11.00 | 9.9 |
13
+
4
14
  Scenario Outline: Adjusted cost committee from cost and date
5
15
  Given a purchase emitter
6
16
  And a characteristic "cost" of "<cost>"
@@ -13,19 +23,6 @@ Feature: Purchase Committee Calculations
13
23
  | 831.23 | 2010-08-01 | 688.67439 |
14
24
  | 11.00 | 2005-07-14 | 9.11350 |
15
25
 
16
- Scenario Outline: Adjusted cost committee from purchase amount and date
17
- Given a purchase emitter
18
- And a characteristic "purchase_amount" of "<amount>"
19
- And characteristic "date" of "<date>"
20
- When the "cost" committee is calculated
21
- And the "adjusted_cost" committee is calculated
22
- Then the committee should have used quorum "from cost and date"
23
- And the conclusion of the committee should be "<adjusted_cost>"
24
- Examples:
25
- | amount | date | adjusted_cost |
26
- | 831.23 | 2010-08-01 | 619.80695 |
27
- | 11.00 | 2005-07-14 | 8.20215 |
28
-
29
26
  Scenario Outline: Merchant category committee from merchant
30
27
  Given a purchase emitter
31
28
  And a characteristic "merchant.id" of "<id>"
@@ -57,10 +54,16 @@ Feature: Purchase Committee Calculations
57
54
  And the "product_line_shares" committee is calculated
58
55
  Then the conclusion of the committee should have a record identified with "ps_code" of "<ps_code>" and having "ratio" of "<share>"
59
56
  Examples:
60
- | mcc | ps_code | share |
61
- | 5111 | 20370 | 0.6 |
62
- | 5111 | 20852 | 0.2 |
63
- | 5111 | 20853 | 0.2 |
57
+ | mcc | ps_code | share |
58
+ | 5111 | 20340 | 0.084 |
59
+ | 5111 | 20370 | 0.283 |
60
+ | 5111 | 20440 | 0.006 |
61
+ | 5111 | 20851 | 0.122 |
62
+ | 5111 | 20852 | 0.145 |
63
+ | 5111 | 20853 | 0.265 |
64
+ | 5111 | 20854 | 0.071 |
65
+ | 5111 | 29938 | 0.011 |
66
+ | 5111 | 29979 | 0.013 |
64
67
 
65
68
  Scenario Outline: Sector shares committee from merchant category
66
69
  Given a purchase emitter
@@ -71,21 +74,41 @@ Feature: Purchase Committee Calculations
71
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>"
72
75
  And the conclusion of the committee should have a record identified with "io_code" of "<io_code>" and having "share" of "<share>"
73
76
  Examples:
74
- | mcc | io_code | emission_factor | share |
75
- | 5111 | 334111 | 1.3 | 0.24 |
76
- | 5111 | 511200 | 1.0 | 0.18 |
77
- | 5111 | 33411A | 0.5 | 0.18 |
78
- | 5111 | 322230 | 1.4 | 0.2 |
79
- | 5111 | 339940 | 1.1 | 0.2 |
80
- | 5732 | 334300 | 1.2 | 0.25 |
81
- | 5732 | 33411A | 0.5 | 0.5 |
82
- | 5732 | 334210 | 1.6 | 0.2 |
83
- | 5812 | 722000 | 0.8 | 1.0 |
84
- | 5172 | 324110 | 2.0 | 0.8 |
85
- | 5172 | 324121 | 1.3 | 0.05 |
86
- | 5172 | 324122 | 0.9 | 0.05 |
87
- | 5172 | 324191 | 0.2 | 0.05 |
88
- | 5172 | 324199 | 1.2 | 0.05 |
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 |
89
112
 
90
113
  Scenario Outline: Emission factor from merchant category
91
114
  Given a purchase emitter
@@ -97,20 +120,40 @@ Feature: Purchase Committee Calculations
97
120
  Then the conclusion of the committee should have a record identified with "io_code" of "<io_code>" and having "factor" of "<emission_factor_share>"
98
121
  Examples:
99
122
  | mcc | io_code | emission_factor_share |
100
- | 5111 | 334111 | 0.312 |
101
- | 5111 | 33411A | 0.09 |
102
- | 5111 | 511200 | 0.18 |
103
- | 5111 | 339940 | 0.22 |
104
- | 5111 | 322230 | 0.28 |
105
- | 5732 | 33411A | 0.25 |
106
- | 5732 | 334300 | 0.3 |
107
- | 5732 | 334210 | 0.32 |
108
- | 5172 | 324110 | 1.6 |
109
- | 5172 | 324121 | 0.065 |
110
- | 5172 | 324122 | 0.045 |
111
- | 5172 | 324191 | 0.01 |
112
- | 5172 | 324199 | 0.06 |
113
- | 5812 | 722000 | 0.8 |
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 |
114
157
 
115
158
  Scenario: Emission factor from default
116
159
  Given a purchase emitter
@@ -131,19 +174,38 @@ Feature: Purchase Committee Calculations
131
174
  And the "sector_emissions" committee is calculated
132
175
  Then the conclusion of the committee should include "<emission>"
133
176
  Examples:
134
- | merchant | io_code | cost | date | emission |
135
- | 1 | 322230 | 100.00 | 2010-07-28 | 23.19801 |
136
- | 1 | 334111 | 100.00 | 2010-07-28 | 25.84921 |
137
- | 1 | 339940 | 100.00 | 2010-07-28 | 18.22701 |
138
- | 1 | 511200 | 100.00 | 2010-07-28 | 14.91301 |
139
- | 1 | 33411A | 100.00 | 2010-07-28 | 7.45650 |
140
- | 2 | 334210 | 100.00 | 2010-07-28 | 26.51201 |
141
- | 2 | 334300 | 100.00 | 2010-07-28 | 24.85501 |
142
- | 2 | 33411A | 100.00 | 2010-07-28 | 20.71251 |
143
- | 3 | 722000 | 100.00 | 2010-07-28 | 66.28003 |
144
- | 4 | 7211A0 | 100.00 | 2010-07-28 | 82.85004 |
145
- | 5 | 324110 | 100.00 | 2010-07-28 | 132.56007 |
146
- | 5 | 324121 | 100.00 | 2010-07-28 | 5.38525 |
147
- | 5 | 324122 | 100.00 | 2010-07-28 | 3.72825 |
148
- | 5 | 324191 | 100.00 | 2010-07-28 | 0.82850 |
149
- | 5 | 324199 | 100.00 | 2010-07-28 | 4.97100 |
177
+ | 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 |
@@ -9,11 +9,25 @@ Feature: Purchase Emissions Calculations
9
9
  Then the emission value should be within 1 kgs of <emission>
10
10
  Examples:
11
11
  | id | cost | date | emission |
12
- | 1 | 100.00 | 2010-07-28 | 89.64 |
13
- | 2 | 100.00 | 2010-07-28 | 72.08 |
12
+ | 1 | 100.00 | 2010-07-28 | 48.29 |
13
+ | 2 | 100.00 | 2010-07-28 | 52.88 |
14
14
  | 3 | 100.00 | 2010-07-28 | 66.28 |
15
- | 4 | 100.00 | 2010-07-28 | 82.85 |
15
+ | 4 | 100.00 | 2010-07-28 | 46.31 |
16
16
  | 5 | 100.00 | 2010-07-28 | 147.47 |
17
+
18
+ Scenario Outline: Calculations starting from a merchant with purchase amount
19
+ Given a purchase has "merchant.id" of "<id>"
20
+ And it has "purchase_amount" of "<amount>"
21
+ And it has "date" of "<date>"
22
+ When emissions are calculated
23
+ Then the emission value should be within 1 kgs of <emission>
24
+ Examples:
25
+ | id | amount | date | emission |
26
+ | 1 | 100.00 | 2010-07-28 | 43.46 |
27
+ | 2 | 100.00 | 2010-07-28 | 47.59 |
28
+ | 3 | 100.00 | 2010-07-28 | 59.65 |
29
+ | 4 | 100.00 | 2010-07-28 | 41.68 |
30
+ | 5 | 100.00 | 2010-07-28 | 132.72 |
17
31
 
18
32
  Scenario Outline: Calculations starting from a merchant category
19
33
  Given a purchase has "merchant_category.mcc" of "<mcc>"
@@ -23,10 +37,10 @@ Feature: Purchase Emissions Calculations
23
37
  Then the emission value should be within 0.1 kgs of <emission>
24
38
  Examples:
25
39
  | mcc | cost | date | emission |
26
- | 5111 | 100.00 | 2010-07-28 | 89.64 |
27
- | 5732 | 100.00 | 2010-07-28 | 72.08 |
40
+ | 5111 | 100.00 | 2010-07-28 | 48.29 |
41
+ | 5732 | 100.00 | 2010-07-28 | 52.88 |
28
42
  | 5812 | 100.00 | 2010-07-28 | 66.28 |
29
- | 3504 | 100.00 | 2010-07-28 | 82.85 |
43
+ | 3504 | 100.00 | 2010-07-28 | 46.31 |
30
44
  | 5172 | 100.00 | 2010-07-28 | 147.47 |
31
45
 
32
46
  Scenario Outline: Calculations starting from industry
@@ -37,10 +51,10 @@ Feature: Purchase Emissions Calculations
37
51
  Then the emission value should be within 0.1 kgs of <emission>
38
52
  Examples:
39
53
  | naics | cost | date | emission |
40
- | 45321 | 100.00 | 2010-07-28 | 89.64 |
41
- | 443112 | 100.00 | 2010-07-28 | 72.08 |
54
+ | 45321 | 100.00 | 2010-07-28 | 48.29 |
55
+ | 443112 | 100.00 | 2010-07-28 | 52.88 |
42
56
  | 72211 | 100.00 | 2010-07-28 | 66.28 |
43
- | 72111 | 100.00 | 2010-07-28 | 82.85 |
57
+ | 72111 | 100.00 | 2010-07-28 | 46.31 |
44
58
  | 32411 | 100.00 | 2010-07-28 | 132.56 |
45
59
  | 324121 | 100.00 | 2010-07-28 | 5.39 |
46
60
  | 324122 | 100.00 | 2010-07-28 | 3.73 |
@@ -120,8 +120,8 @@ module BrighterPlanet
120
120
 
121
121
  committee :cost do
122
122
  quorum 'from purchase amount', :needs => :purchase_amount do |characteristics|
123
- # FIXME TODO take out tax, then convert to 2002 US $ based on date and cost
124
- characteristics[:purchase_amount] * 0.9
123
+ # FIXME TODO take out tax
124
+ characteristics[:purchase_amount].to_f * 0.9
125
125
  end
126
126
  end
127
127
 
@@ -6,6 +6,7 @@ module BrighterPlanet
6
6
  def self.included(base)
7
7
  base.send :include, Characterizable
8
8
  base.characterize do
9
+ has :purchase_amount
9
10
  has :merchant
10
11
  has :merchant_category
11
12
  has :naics_code
@@ -11,7 +11,7 @@ module BrighterPlanet
11
11
  has.verb :take
12
12
  has.aspect :perfect
13
13
 
14
- has.modifier lambda { |purchase| "from #{flight.merchant}" }, :if => :merchant
14
+ has.modifier lambda { |purchase| "from #{purchase.merchant}" }, :if => :merchant
15
15
  has.modifier lambda { |purchase| "(#{purchase.inudstry} industry)" }, :if => :industry
16
16
  has.modifier lambda { |purchase| "for $#{purchase.purchase_amount}" }, :if => :purchase_amount
17
17
  has.modifier lambda { |purchase| "on #{date.to_formatted_s(:archive)}" }, :if => :date
@@ -10,5 +10,5 @@ class PurchaseRecord < ActiveRecord::Base
10
10
  belongs_to :merchant, :foreign_key => 'merchant_id'
11
11
  belongs_to :merchant_category, :foreign_key => 'mcc'
12
12
 
13
- attr_accessor :naics_code
13
+ attr_accessor :naics_code, :purchase_amount
14
14
  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: 31
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 4
10
+ version: 0.1.4
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-12 00:00:00 -04:00
22
+ date: 2010-08-15 00:00:00 -04:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency