sniff 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,77 +1,58 @@
1
1
  # sniff
2
- Testing environment for Brighter Planet Climate Middleware emission calculation gems.
3
-
4
- This gem provides:
5
- * Sample data used for calculations, representative of data found on http://data.brighterplanet.com
6
- * A database/ActiveRecord environment for said data
7
- * References to gems needed by each emitter gem
8
- * An autoloader that will load any models and sample data needed by the emitter gem being tested (see Usage)
9
-
10
- # Usage
11
- Within an emitter gem's test setup, you can:
12
- require 'sniff'
13
-
14
- Sniff.init '/path/to/emitter_project'
15
-
16
- If an emitter gem has its own test models and data, sniff will look for the models in `EMITTER_GEM_DIR/lib/test_support/data_models/` and the data fixtures in `EMITTER_GEM_DIR/lib/test_support/db/fixtures/`. It will also look for a schema in `EMITTER_GEM_DIR/lib/test_support/db/schema.rb`
17
-
18
- # How to contribute
19
- Typical contributions will include updates to test data.
20
-
21
- 1. Fork the project.
22
- 1. Make your feature addition or bug fix.
23
- 1. Commit, do not mess with rakefile, version, or history. (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)
24
- 1. Send me a pull request. Bonus points for topic branches.
25
-
26
- # Local Gems
27
- Sniff depends on several gems, some of which are developed by Brighter Planet. You can tell Sniff or any of the carbon gems to use your local repos in lieu of installed rubygems through the following steps:
28
-
29
-
30
- Paste the following functions into your ~/.bash_profile
31
- function mod_devgem() {
32
- var="LOCAL_`echo $2 | tr 'a-z' 'A-Z'`"
33
-
34
- if [ "$1" == "disable" ]
35
- then
36
- echo "unset $var"
37
- unset $var
38
- else
39
- dir=${3:-"~/$2"}
40
- echo "export $var=$dir"
41
- export $var=$dir
42
- fi
43
- }
44
-
45
- function devgems () {
46
- # Usage: devgems [enable|disable] [gemname]
47
- cmd=${1:-"enable"}
48
- if [ -z $2 ]
49
- then
50
- mod_devgem $cmd characterizable
51
- mod_devgem $cmd cohort_scope
52
- mod_devgem $cmd falls_back_on
53
- mod_devgem $cmd leap
54
- mod_devgem $cmd loose_tight_dictionary
55
- mod_devgem $cmd sniff
56
- mod_devgem $cmd data_miner
57
- else
58
- mod_devgem $cmd $2
59
- fi
60
- }
61
-
62
- To enable all local gems, run `devgems enable`
63
- To turn off devgems, run `devgems disable`
64
- To turn off a specific gem, run `devgems disable leap`
65
- To turn on a specific gem, run `devgems enable leap`
66
-
67
- Typical development process:
68
- cd ~
69
- git clone http://github.com/rossmeissl/leap.git
70
- cd leap
71
- <do some development on leap>
72
- cd ~/sniff
73
- devgems enable leap
74
- rake gemspec
75
- rm -f Gemfile.lock
76
- bundle install
77
- <run tests, e.g. `spec spec`>
2
+ Development and testing environment for Brighter Planet emitters.
3
+
4
+ ## Background
5
+ Brighter Planet's emitters, such as [`flight`](http://github.com/brighterplanet/flight), inhabit a complex production runtime environment backing its [emission estimates web service](http://carbon.brighterplanet.com). Sniff simulates this environment, including representative data, fixtures, and other supporting code, so that developers can test improvements to the emitters before submitting them back to Brighter Planet.
6
+
7
+ ### Caution
8
+ The data and other supporting information in the sniff environment is only representative of production data and in many cases is purely fictional, contrived to return predictable results in tests. Emission estimates and other information gleaned from execution within this environment will undoubtedly be--to put it simply--wrong. For real numbers, always use live queries to the [emission estimate web service](http://carbon.brighterplanet.com).
9
+
10
+ ## Usage
11
+ Sniff is never used directly but rather as a requirement of a specific emitter. Current production emitters include, for example:
12
+
13
+ * [Automobile](http://github.com/brighterplanet/automobile)
14
+ * [Flight](http://github.com/brighterplanet/flight)
15
+ * [Residence](http://github.com/brighterplanet/residence)
16
+
17
+ For a complete list, see the emission estimate service's [documentation](http://carbon.brighterplanet.com/use).
18
+
19
+ ## The emitter
20
+ An emitter is a software model of a real-world emission source, like a flight. Brighter Planet's emitter libraries each comprise a carbon model, an attribute curation policy, a persistence schema, and a summarization strategy.
21
+
22
+ ### Persistence schema
23
+ Although the production environment does not persist emitter instances, we nevertheless define emitter schemas to enable ActiveRecord assocations. An emitter's schema is defined in `lib/*emitter_name*/data.rb` within an emitter library. For example, here is [flight's schema](http://github.com/brighterplanet/flight/blob/master/lib/flight/data.rb).
24
+
25
+ Schema are defined using a DSL provided by the [data_miner](http://github.com/seamusabshere/data_miner) library.
26
+
27
+ ### Attribute curation policy
28
+ This defines how an emitter's attributes (initialized and stored with respect to the schema) are curated and decorated into a snapshot for later use by the carbon model. The policy is defined in `lib/*emitter_name*/characterization.rb` within an emitter library. For example, here is [flight's characterization](http://github.com/brighterplanet/flight/blob/master/lib/flight/characterization.rb).
29
+
30
+ Characterizations are defined using a DSL provided by the [characterizable](http://github.com/seamusabshere/characterizable) library.
31
+
32
+ ### Carbon model
33
+ An emission estimate is obtained by giving an emitter's curated characteristics as input to an execution of its carbon model. The model is defined in `lib/*emitter_name*/characterization.rb` within an emitter library. For example, here is [flight's carbon model](http://github.com/brighterplanet/flight/blob/master/lib/flight/carbon_model.rb).
34
+
35
+ Carbon models are defined using a DSL provided by the [leap](http://github.com/rossmeissl/leap) library.
36
+
37
+ ### Summarization strategy
38
+ Summaries are human-friendly descriptions of characterized emitters. The strategy is defined in `lib/*emitter_name*/summarization.rb` within an emitter library. For example, here is [flight's summarization strategy](http://github.com/brighterplanet/flight/blob/master/lib/flight/summarization.rb).
39
+
40
+ Summarizations are defined using a DSL provided by the [summary_judgement](http://github.com/rossmeissl/summary_judgement) library.
41
+
42
+ ## Collaboration cycle
43
+ Brighter Planet vigorously encourages collaborative improvement of its emitter libraries. Collaboration requires a (free) GitHub account.
44
+
45
+ ### You
46
+ 1. Fork the emitter repository on GitHub.
47
+ 1. Write a test proving the existing implementation's inadequacy. Ensure that the test fails. Commit the test.
48
+ 1. Improve the code until your new test passes and commit your changes.
49
+ 1. Push your changes to your GitHub fork.
50
+ 1. Submit a pull request to brighterplanet.
51
+
52
+ ### Brighter Planet
53
+ 1. Receive a pull request.
54
+ 1. Pull changes from forked repository.
55
+ 1. Ensure tests pass.
56
+ 1. Review changes for scientific accuracy.
57
+ 1. Merge changes to master repository and publish.
58
+ 1. Direct production environment to use new emitter version.
data/lib/sniff.rb CHANGED
@@ -9,6 +9,9 @@ module Sniff
9
9
  options[:earth] ||= :none
10
10
 
11
11
  Sniff::Database.init local_root, options
12
+
13
+ step_definitions = Dir.glob File.join(File.dirname(__FILE__), 'test_support', 'step_definitions', '**', '*.rb')
14
+ step_definitions.each { |definition| require definition }
12
15
  end
13
16
  end
14
17
 
@@ -0,0 +1,63 @@
1
+ require 'time'
2
+
3
+ Given /^a (.+) (has|used) "(.+)" (of\s?)?"(.*)"$/ do |emitter, _, field, __, value|
4
+ @emitter_class = emitter.gsub(/\s+/,'_').camelize
5
+ @emitter_class = "#{@emitter_class}Record".constantize
6
+ Given "it has \"#{field}\" of \"#{value}\""
7
+ end
8
+
9
+ Given /^it (has|used) "(.+)" (of\s?)?"(.*)"$/ do |_, field, __, value|
10
+ @activity_hash ||= {}
11
+ if value.present?
12
+ methods = field.split('.')
13
+ context = @activity_hash
14
+ methods.each do |method|
15
+ method = method.to_sym
16
+ context[method] ||= {}
17
+ value = Date.parse(value) if value =~ /\d{4}-\d{2}-\d{2}/
18
+ context[method] = value if method == methods.last.to_sym
19
+ context = context[method]
20
+ end
21
+ end
22
+ end
23
+
24
+ Given /^the current date is (.+)$/ do |current_date|
25
+ @current_date = Time.parse(current_date)
26
+ end
27
+
28
+ When /^emissions are calculated$/ do
29
+ @activity = @emitter_class.from_params_hash @activity_hash
30
+ if @current_date
31
+ Timecop.travel(@current_date) do
32
+ @emission = @activity.emission Timeframe.this_year
33
+ end
34
+ else
35
+ @emission = @activity.emission Timeframe.this_year
36
+ end
37
+ @characteristics = @activity.deliberations[:emission].characteristics
38
+ end
39
+
40
+ Then /^the emission value should be within (\d+) kgs of (\d+)$/ do |cusion, emissions|
41
+ @emission.should be_close(emissions.to_f, cusion.to_f)
42
+ end
43
+
44
+ Then /^the calculation should have used committees (.*)$/ do |committee_list|
45
+ committees = committee_list.split(/,\s*/)
46
+ committees.each do |committee|
47
+ @characteristics.keys.should include(committee)
48
+ end
49
+ end
50
+
51
+ Then /^the (.+) committee should be close to ([^,]+), \+\/-(.+)$/ do |committee, value, cusion|
52
+ @characteristics[committee.to_sym].to_f.should be_close(value.to_f, cusion.to_f)
53
+ end
54
+
55
+ Then /^the (.+) committee should be exactly (.*)$/ do |committee, value|
56
+ @characteristics[committee.to_sym].to_s.should == value
57
+ end
58
+
59
+ Then /^the active_subtimeframe committee should have timeframe (.*)$/ do |tf_string|
60
+ days, start, finish = tf_string.split(/,\s*/)
61
+ @characteristics[:active_subtimeframe].to_s.should =~ /#{days} days starting #{start} ending #{finish}/
62
+ end
63
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sniff
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Derek Kastner
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-20 00:00:00 -04:00
18
+ date: 2010-07-22 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -286,82 +286,63 @@ dependencies:
286
286
  requirement: *id017
287
287
  description: |
288
288
  # sniff
289
- Testing environment for Brighter Planet Climate Middleware emission calculation gems.
289
+ Development and testing environment for Brighter Planet emitters.
290
290
 
291
- This gem provides:
292
- * Sample data used for calculations, representative of data found on http://data.brighterplanet.com
293
- * A database/ActiveRecord environment for said data
294
- * References to gems needed by each emitter gem
295
- * An autoloader that will load any models and sample data needed by the emitter gem being tested (see Usage)
291
+ ## Background
292
+ Brighter Planet's emitters, such as [`flight`](http://github.com/brighterplanet/flight), inhabit a complex production runtime environment backing its [emission estimates web service](http://carbon.brighterplanet.com). Sniff simulates this environment, including representative data, fixtures, and other supporting code, so that developers can test improvements to the emitters before submitting them back to Brighter Planet.
296
293
 
297
- # Usage
298
- Within an emitter gem's test setup, you can:
299
- require 'sniff'
300
-
301
- Sniff.init '/path/to/emitter_project'
294
+ ### Caution
295
+ The data and other supporting information in the sniff environment is only representative of production data and in many cases is purely fictional, contrived to return predictable results in tests. Emission estimates and other information gleaned from execution within this environment will undoubtedly be--to put it simply--wrong. For real numbers, always use live queries to the [emission estimate web service](http://carbon.brighterplanet.com).
302
296
 
303
- If an emitter gem has its own test models and data, sniff will look for the models in `EMITTER_GEM_DIR/lib/test_support/data_models/` and the data fixtures in `EMITTER_GEM_DIR/lib/test_support/db/fixtures/`. It will also look for a schema in `EMITTER_GEM_DIR/lib/test_support/db/schema.rb`
297
+ ## Usage
298
+ Sniff is never used directly but rather as a requirement of a specific emitter. Current production emitters include, for example:
304
299
 
305
- # How to contribute
306
- Typical contributions will include updates to test data.
300
+ * [Automobile](http://github.com/brighterplanet/automobile)
301
+ * [Flight](http://github.com/brighterplanet/flight)
302
+ * [Residence](http://github.com/brighterplanet/residence)
307
303
 
308
- 1. Fork the project.
309
- 1. Make your feature addition or bug fix.
310
- 1. Commit, do not mess with rakefile, version, or history. (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)
311
- 1. Send me a pull request. Bonus points for topic branches.
304
+ For a complete list, see the emission estimate service's [documentation](http://carbon.brighterplanet.com/use).
312
305
 
313
- # Local Gems
314
- Sniff depends on several gems, some of which are developed by Brighter Planet. You can tell Sniff or any of the carbon gems to use your local repos in lieu of installed rubygems through the following steps:
306
+ ## The emitter
307
+ An emitter is a software model of a real-world emission source, like a flight. Brighter Planet's emitter libraries each comprise a carbon model, an attribute curation policy, a persistence schema, and a summarization strategy.
315
308
 
309
+ ### Persistence schema
310
+ Although the production environment does not persist emitter instances, we nevertheless define emitter schemas to enable ActiveRecord assocations. An emitter's schema is defined in `lib/*emitter_name*/data.rb` within an emitter library. For example, here is [flight's schema](http://github.com/brighterplanet/flight/blob/master/lib/flight/data.rb).
316
311
 
317
- Paste the following functions into your ~/.bash_profile
318
- function mod_devgem() {
319
- var="LOCAL_`echo $2 | tr 'a-z' 'A-Z'`"
320
-
321
- if [ "$1" == "disable" ]
322
- then
323
- echo "unset $var"
324
- unset $var
325
- else
326
- dir=${3:-"~/$2"}
327
- echo "export $var=$dir"
328
- export $var=$dir
329
- fi
330
- }
331
-
332
- function devgems () {
333
- # Usage: devgems [enable|disable] [gemname]
334
- cmd=${1:-"enable"}
335
- if [ -z $2 ]
336
- then
337
- mod_devgem $cmd characterizable
338
- mod_devgem $cmd cohort_scope
339
- mod_devgem $cmd falls_back_on
340
- mod_devgem $cmd leap
341
- mod_devgem $cmd loose_tight_dictionary
342
- mod_devgem $cmd sniff
343
- mod_devgem $cmd data_miner
344
- else
345
- mod_devgem $cmd $2
346
- fi
347
- }
312
+ Schema are defined using a DSL provided by the [data_miner](http://github.com/seamusabshere/data_miner) library.
348
313
 
349
- To enable all local gems, run `devgems enable`
350
- To turn off devgems, run `devgems disable`
351
- To turn off a specific gem, run `devgems disable leap`
352
- To turn on a specific gem, run `devgems enable leap`
314
+ ### Attribute curation policy
315
+ This defines how an emitter's attributes (initialized and stored with respect to the schema) are curated and decorated into a snapshot for later use by the carbon model. The policy is defined in `lib/*emitter_name*/characterization.rb` within an emitter library. For example, here is [flight's characterization](http://github.com/brighterplanet/flight/blob/master/lib/flight/characterization.rb).
353
316
 
354
- Typical development process:
355
- cd ~
356
- git clone http://github.com/rossmeissl/leap.git
357
- cd leap
358
- <do some development on leap>
359
- cd ~/sniff
360
- devgems enable leap
361
- rake gemspec
362
- rm -f Gemfile.lock
363
- bundle install
364
- <run tests, e.g. `spec spec`>
317
+ Characterizations are defined using a DSL provided by the [characterizable](http://github.com/seamusabshere/characterizable) library.
318
+
319
+ ### Carbon model
320
+ An emission estimate is obtained by giving an emitter's curated characteristics as input to an execution of its carbon model. The model is defined in `lib/*emitter_name*/characterization.rb` within an emitter library. For example, here is [flight's carbon model](http://github.com/brighterplanet/flight/blob/master/lib/flight/carbon_model.rb).
321
+
322
+ Carbon models are defined using a DSL provided by the [leap](http://github.com/rossmeissl/leap) library.
323
+
324
+ ### Summarization strategy
325
+ Summaries are human-friendly descriptions of characterized emitters. The strategy is defined in `lib/*emitter_name*/summarization.rb` within an emitter library. For example, here is [flight's summarization strategy](http://github.com/brighterplanet/flight/blob/master/lib/flight/summarization.rb).
326
+
327
+ Summarizations are defined using a DSL provided by the [summary_judgement](http://github.com/rossmeissl/summary_judgement) library.
328
+
329
+ ## Collaboration cycle
330
+ Brighter Planet vigorously encourages collaborative improvement of its emitter libraries. Collaboration requires a (free) GitHub account.
331
+
332
+ ### You
333
+ 1. Fork the emitter repository on GitHub.
334
+ 1. Write a test proving the existing implementation's inadequacy. Ensure that the test fails. Commit the test.
335
+ 1. Improve the code until your new test passes and commit your changes.
336
+ 1. Push your changes to your GitHub fork.
337
+ 1. Submit a pull request to brighterplanet.
338
+
339
+ ### Brighter Planet
340
+ 1. Receive a pull request.
341
+ 1. Pull changes from forked repository.
342
+ 1. Ensure tests pass.
343
+ 1. Review changes for scientific accuracy.
344
+ 1. Merge changes to master repository and publish.
345
+ 1. Direct production environment to use new emitter version.
365
346
 
366
347
  email: derek.kastner@brighterplanet.com
367
348
  executables: []
@@ -386,6 +367,7 @@ files:
386
367
  - lib/test_support/db/fixtures/states.csv
387
368
  - lib/test_support/db/fixtures/urbanities.csv
388
369
  - lib/test_support/db/fixtures/zip_codes.csv
370
+ - lib/test_support/step_definitions/carbon_steps.rb
389
371
  - README.markdown
390
372
  - spec/lib/sniff/database_spec.rb
391
373
  - spec/spec_helper.rb
@@ -426,3 +408,4 @@ summary: Test support for Brighter Planet carbon gems
426
408
  test_files:
427
409
  - spec/lib/sniff/database_spec.rb
428
410
  - spec/spec_helper.rb
411
+ - lib/test_support/step_definitions/carbon_steps.rb