purchase 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,102 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC
3
+ "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
4
+ "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
5
+ <html xmlns:svg='http://www.w3.org/2000/svg' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
6
+ <head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title>Purchase</title></head>
7
+ <body>
8
+ <h1 id='purchase'>Purchase</h1>
9
+
10
+ <p>The purchase gem is used by Brighter Planet&#8217;s Carbon Middleware platform to define a mathematical emissions model for a purchase activity. In addition, this gem defines how the model&#8217;s calculation is displayed in a human readable format.</p>
11
+
12
+ <p>Contributions are welcome and encouraged, as we believe that help from the scientific and developer communities will help us provide correct and transparent models of greenhouse gas-emitting activities. See the section on the Collaboration Cycle below.</p>
13
+
14
+ <h2 id='usage'>Usage</h2>
15
+
16
+ <p>The purchase gem defines a module, BrighterPlanet::Purchase that should be included into an ActiveRecord model. Calling #emission on an instance of the model will determine the amount of emissions (CO2e) generated by the activity.</p>
17
+
18
+ <pre><code>class PurchaseRecord &lt; ActiveRecord::Base
19
+ include BrighterPlanet::Purchase
20
+ ...
21
+ end
22
+
23
+ p = PurchaseRecord.new :merchant_category_code =&gt; 2324, :amount =&gt; 873.45
24
+ p.emission
25
+ # =&gt; 2472</code></pre>
26
+
27
+ <h2 id='getting_ready_for_development'>Getting Ready for Development</h2>
28
+
29
+ <p>Purchase uses bundler to manage dependencies. To prepare your environment, perform the following: git clone git://github.com/brighterplanet/purchase.git cd purchase gem install bundler (note: prior to bundler 1.0 release, add &#8211;pre) bundle install</p>
30
+
31
+ <h3 id='a_note_to_rvm_users_and_nonusers'>A Note to RVM Users (and Non-Users)</h3>
32
+
33
+ <p><a href='http://rvm.beginrescueend.com/'>RVM</a> is a great tool for testing and development as it can create independent gem environments.</p>
34
+
35
+ <p>Included in the repository is a .rvmrc that will automatically create a ruby 1.8.7 gemset for you named purchase. If you already have a gemset with the same name, simply replace the `pwd` within the .rvmrc to whatever name you want.</p>
36
+
37
+ <h2 id='testing'>Testing</h2>
38
+
39
+ <p>Our goal is to have sufficient testing coverage for our emissions models. We have chosen to write our tests using <a href='http://cukes.info'>cucumber</a> as the table-formatted testing fits well with our calculations tests and the plain-english stories lower the barrier to entry for programmers of all skill levels.</p>
40
+
41
+ <p>There are two main features:</p>
42
+
43
+ <ul>
44
+ <li>purchase_emissions.feature, which tests emission values for various inputs</li>
45
+
46
+ <li>purchase_committees.feature, which tests sub-calculations used within the model</li>
47
+ </ul>
48
+
49
+ <p>To run all tests: <code>rake</code> or <code>cucumber</code></p>
50
+
51
+ <p>To run individual tests: <code>cucumber features/name_of_feature.feature</code></p>
52
+
53
+ <p>To run a specific scenario: <code>cucumber features/name_of_feature.feature:line_number_of_scenario</code></p>
54
+
55
+ <h3 id='sniff'>Sniff</h3>
56
+
57
+ <p>The sniff gem is used to provide a testing environment that includes dependent data models and a database.</p>
58
+
59
+ <p>See: <a href='http://github.com/brighterplanet/sniff'>http://github.com/brighterplanet/sniff</a></p>
60
+
61
+ <h3 id='earth'>Earth</h3>
62
+
63
+ <p>The earth gem contains the model definitions for dependent data models. For instance, this is zip code data or fuel prices used in the emissions calculations. Earth will look for any test fixtures defined in lib/test_support/db/fixtures. These sample records are in csv format and are imported into the testing database.</p>
64
+
65
+ <h2 id='implementation'>Implementation</h2>
66
+
67
+ <p>See the README for the sniff gem: <a href='http://github.com/brighterplanet/sniff/blob/master/README.markdown'>http://github.com/brighterplanet/sniff/blob/master/README.markdown</a></p>
68
+
69
+ <h2 id='collaboration_cycle'>Collaboration cycle</h2>
70
+
71
+ <p>Brighter Planet vigorously encourages collaborative improvement of its emitter libraries. Collaboration requires a (free) GitHub account.</p>
72
+
73
+ <h3 id='you'>You</h3>
74
+
75
+ <ol>
76
+ <li>Fork the emitter repository on GitHub.</li>
77
+
78
+ <li>Write a test proving the existing implementation&#8217;s inadequacy. Ensure that the test fails. Commit the test.</li>
79
+
80
+ <li>Improve the code until your new test passes and commit your changes.</li>
81
+
82
+ <li>Push your changes to your GitHub fork.</li>
83
+
84
+ <li>Submit a pull request to brighterplanet.</li>
85
+ </ol>
86
+
87
+ <h3 id='brighter_planet'>Brighter Planet</h3>
88
+
89
+ <ol>
90
+ <li>Receive a pull request.</li>
91
+
92
+ <li>Pull changes from forked repository.</li>
93
+
94
+ <li>Ensure tests pass.</li>
95
+
96
+ <li>Review changes for scientific accuracy.</li>
97
+
98
+ <li>Merge changes to master repository and publish.</li>
99
+
100
+ <li>Direct production environment to use new emitter version.</li>
101
+ </ol>
102
+ </body></html>
@@ -1,17 +1,78 @@
1
- # purchase
1
+ # Purchase
2
2
 
3
- Description goes here.
3
+ The purchase gem is used by Brighter Planet's Carbon Middleware platform to define a mathematical emissions model for a purchase activity. In addition, this gem defines how the model's calculation is displayed in a human readable format.
4
4
 
5
- ## Note on Patches/Pull Requests
6
-
7
- * Fork the project.
8
- * Make your feature addition or bug fix.
9
- * Add tests for it. This is important so I don't break it in a
10
- future version unintentionally.
11
- * Commit, do not mess with rakefile, version, or history.
12
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
5
+ Contributions are welcome and encouraged, as we believe that help from the scientific and developer communities will help us provide correct and transparent models of greenhouse gas-emitting activities. See the section on the Collaboration Cycle below.
14
6
 
15
- ## Copyright
7
+ ## Usage
16
8
 
17
- Copyright (c) 2010 Andy Rossmeissl. See LICENSE for details.
9
+ The purchase gem defines a module, BrighterPlanet::Purchase that should be included into an ActiveRecord model. Calling #emission on an instance of the model will determine the amount of emissions (CO2e) generated by the activity.
10
+
11
+
12
+ class PurchaseRecord < ActiveRecord::Base
13
+ include BrighterPlanet::Purchase
14
+ ...
15
+ end
16
+
17
+ p = PurchaseRecord.new :merchant_category_code => 2324, :amount => 873.45
18
+ p.emission
19
+ # => 2472
20
+
21
+ ## Getting Ready for Development
22
+ Purchase uses bundler to manage dependencies. To prepare your environment, perform the following:
23
+ git clone git://github.com/brighterplanet/purchase.git
24
+ cd purchase
25
+ gem install bundler (note: prior to bundler 1.0 release, add --pre)
26
+ bundle install
27
+
28
+ ### A Note to RVM Users (and Non-Users)
29
+
30
+ [RVM](http://rvm.beginrescueend.com/) is a great tool for testing and development as it can create independent gem environments.
31
+
32
+ Included in the repository is a .rvmrc that will automatically create a ruby 1.8.7 gemset for you named purchase. If you already have a gemset with the same name, simply replace the \`pwd\` within the .rvmrc to whatever name you want.
33
+
34
+ ## Testing
35
+
36
+ Our goal is to have sufficient testing coverage for our emissions models. We have chosen to write our tests using [cucumber](http://cukes.info) as the table-formatted testing fits well with our calculations tests and the plain-english stories lower the barrier to entry for programmers of all skill levels.
37
+
38
+ There are two main features:
39
+ * purchase_emissions.feature, which tests emission values for various inputs
40
+ * purchase_committees.feature, which tests sub-calculations used within the model
41
+
42
+ To run all tests: `rake` or `cucumber`
43
+
44
+ To run individual tests: `cucumber features/name_of_feature.feature`
45
+
46
+ To run a specific scenario: `cucumber features/name_of_feature.feature:line_number_of_scenario`
47
+
48
+ ### Sniff
49
+
50
+ The sniff gem is used to provide a testing environment that loads dependent data models (defined in the earth gem), a database, and testing fixtures.
51
+
52
+ See: [http://github.com/brighterplanet/sniff](http://github.com/brighterplanet/sniff)
53
+
54
+ ### Earth
55
+
56
+ The earth gem contains the model definitions for dependent data models. For instance, this is zip code data or fuel prices used in the emissions calculations. Earth will look for any test fixtures defined in lib/test_support/db/fixtures. These sample records are in csv format and are imported into the testing database.
57
+
58
+ ## Implementation
59
+
60
+ See the README for the sniff gem: [http://github.com/brighterplanet/sniff/blob/master/README.markdown](http://github.com/brighterplanet/sniff/blob/master/README.markdown)
61
+
62
+ ## Collaboration cycle
63
+ Brighter Planet vigorously encourages collaborative improvement of its emitter libraries. Collaboration requires a (free) GitHub account.
64
+
65
+ ### You
66
+ 1. Fork the emitter repository on GitHub.
67
+ 1. Write a test proving the existing implementation's inadequacy. Ensure that the test fails. Commit the test.
68
+ 1. Improve the code until your new test passes and commit your changes.
69
+ 1. Push your changes to your GitHub fork.
70
+ 1. Submit a pull request to brighterplanet.
71
+
72
+ ### Brighter Planet
73
+ 1. Receive a pull request.
74
+ 1. Pull changes from forked repository.
75
+ 1. Ensure tests pass.
76
+ 1. Review changes for scientific accuracy.
77
+ 1. Merge changes to master repository and publish.
78
+ 1. Direct production environment to use new emitter version.
@@ -1,20 +1,13 @@
1
1
  Feature: Purchase Committee Calculations
2
2
  The purchase model should generate correct committee calculations
3
3
 
4
- Scenario Outline: Standard Calculations for
5
- Given a flight has "origin_airport.iata_code" of "<source>"
6
- And it has "destination_airport.iata_code" of "<dest>"
7
- And it has "airline.iata_code" of "<airline>"
4
+ Scenario Outline: From purchase amount and date committee
5
+ Given a purchase has "merchant_category_code" of "<mcc>"
6
+ And it has "purchase_amount" of "<amount>"
8
7
  And it has "date" of "<date>"
9
- And it used "aircraft.icao_code" "<aircraft>"
10
8
  When emissions are calculated
11
- Then the fuel committee should be close to <fuel>, +/-1
12
- And the fuel_per_segment committee should be close to <fuel_per_segment>, +/-10
13
- And the adjusted_distance_per_segment committee should be close to <adjusted_distance_per_segment>, +/-1
14
- And the load_factor committee should be close to <load_factor>, +/-0.001
15
- And the passengers committee should be exactly <passengers>
16
- And the adjusted_distance committee should be close to <adjusted_distance>, +/-1
9
+ Then the from_purchase_amount_and_date committee should be exactly <adjusted_cost>
17
10
  Examples:
18
- | source | dest | airline | date | aircraft | fuel | fuel_per_segment | adjusted_distance_per_segment | load_factor | passengers | adjusted_distance |
19
- | DTW | SFO | UA | 2010-06-25 | A320 | 24676 | 7612 | 1341 | 0.788 | 118 | 2241 |
20
- | IAD | CDG | AF | 2010-06-25 | A320 | 43477 | 13413 | 2492 | 0.800 | 120 | 4161 |
11
+ | mcc | amount | date | adjusted_cost |
12
+ | 1771 | 831.23 | 2010-08-01 | 700 |
13
+ | 3007 | 11.00 | 2005-07-14 | 10 |
@@ -3,9 +3,11 @@ Feature: Purchase Emissions Calculations
3
3
 
4
4
  Scenario Outline: Standard Calculations for a MCC
5
5
  Given a purchase has "merchant_category_code" of "<mcc>"
6
+ And it has "purchase_amount" of "<amount>"
7
+ And it has "date" of "<date>"
6
8
  When emissions are calculated
7
9
  Then the emission value should be within 1 kgs of <emission>
8
10
  Examples:
9
- | mcc | emission |
10
- | 1771 | 1153 |
11
- | 3007 | 2070 |
11
+ | mcc | amount | date | emission |
12
+ | 1771 | 831.23 | 2010-08-01 | 1153 |
13
+ | 3007 | 11.00 | 2005-07-14 | 2070 |
@@ -5,4 +5,4 @@ require 'cucumber'
5
5
  require 'cucumber/formatter/unicode' # Remove this line if you don't want Cucumber Unicode support
6
6
 
7
7
  require 'sniff'
8
- Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :earth => :all
8
+ Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :earth => :industry
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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
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-07-27 00:00:00 -04:00
22
+ date: 2010-07-28 00:00:00 -04:00
23
23
  default_executable:
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
@@ -144,12 +144,12 @@ dependencies:
144
144
  requirements:
145
145
  - - "="
146
146
  - !ruby/object:Gem::Version
147
- hash: 11
147
+ hash: 61
148
148
  segments:
149
149
  - 0
150
150
  - 0
151
- - 10
152
- version: 0.0.10
151
+ - 17
152
+ version: 0.0.17
153
153
  requirement: *id008
154
154
  - !ruby/object:Gem::Dependency
155
155
  type: :runtime
@@ -190,14 +190,14 @@ dependencies:
190
190
  version_requirements: &id011 !ruby/object:Gem::Requirement
191
191
  none: false
192
192
  requirements:
193
- - - "="
193
+ - - ">="
194
194
  - !ruby/object:Gem::Version
195
- hash: 17
195
+ hash: 3
196
196
  segments:
197
197
  - 0
198
198
  - 0
199
- - 7
200
- version: 0.0.7
199
+ - 14
200
+ version: 0.0.14
201
201
  requirement: *id011
202
202
  - !ruby/object:Gem::Dependency
203
203
  type: :runtime
@@ -287,6 +287,7 @@ extensions: []
287
287
 
288
288
  extra_rdoc_files:
289
289
  - LICENSE
290
+ - README.html
290
291
  - README.markdown
291
292
  files:
292
293
  - LICENSE
@@ -298,6 +299,7 @@ files:
298
299
  - lib/purchase/summarization.rb
299
300
  - lib/test_support/db/schema.rb
300
301
  - lib/test_support/purchase_record.rb
302
+ - README.html
301
303
  - features/support/env.rb
302
304
  - features/purchase_committees.feature
303
305
  - features/purchase_emissions.feature