Flight
The flight gem is used by Brighter Planet's Carbon Middleware platform to define a mathematical emissions model for a flight on any airline or aircraft. In addition, this gem defines how the model's calculation is displayed in a human readable format.
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.
Usage
The flight gem defines a module, BrighterPlanet::Flight 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.
class FlightRecord < ActiveRecord::Base
include BrighterPlanet::Flight
...
end
f = FlightRecord.new :origin_airport => { :iata_code => 'DTW'}, :destination_airport => { :iata_code => 'SFO' }
f.emission
# => 2472
Getting Ready for Development
Flight uses bundler to manage dependencies. To prepare your environment, perform the following: git clone git://github.com/brighterplanet/flight.git cd flight gem install bundler (note: prior to bundler 1.0 release, add --pre) bundle install
A Note to RVM Users (and Non-Users)
RVM is a great tool for testing and development as it can create independent gem environments.
Included in the repository is a .rvmrc that will automatically create a ruby 1.8.7 gemset for you named flight. If you already have a gemset with the same name, simply replace the `pwd` within the .rvmrc to whatever name you want.
Testing
Our goal is to have sufficient testing coverage for our emissions models. We have chosen to write our tests using cucumber 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.
There are two main features:
- flight_emissions.feature, which tests emission values for various inputs
- flight_committees.feature, which tests sub-calculations used within the model
To run all tests: rake
or cucumber
To run individual tests: cucumber features/name_of_feature.feature
To run a specific scenario: cucumber features/name_of_feature.feature:line_number_of_scenario
Sniff
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.
See: http://github.com/brighterplanet/sniff
Earth
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.
Implementation
See the README for the sniff gem: http://github.com/brighterplanet/sniff/blob/master/README.markdown
Collaboration cycle
Brighter Planet vigorously encourages collaborative improvement of its emitter libraries. Collaboration requires a (free) GitHub account.
You
- Fork the emitter repository on GitHub.
- Write a test proving the existing implementation's inadequacy. Ensure that the test fails. Commit the test.
- Improve the code until your new test passes and commit your changes.
- Push your changes to your GitHub fork.
- Submit a pull request to brighterplanet.
Brighter Planet
- Receive a pull request.
- Pull changes from forked repository.
- Ensure tests pass.
- Review changes for scientific accuracy.
- Merge changes to master repository and publish.
- Direct production environment to use new emitter version.
Copyright
Copyright © 2010 Brighter Planet. See LICENSE for details. Contact Brighter Planet for dual-license arrangements.