Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

A carbon model

README.markdown

Flight

The flight gem is used by Brighter Planet's CM1 web service to define a mathematical impacts 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.

Build Status

Usage

The flight gem defines a module, BrighterPlanet::Flight that should be included into an ActiveRecord model. Calling #impact on an instance of the model will determine the amount of impacts (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.impact.carbon
# => 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 impacts 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_impacts.feature, which tests impact 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: https://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 impacts 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: https://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

  1. Fork the emitter repository on GitHub.
  2. Write a test proving the existing implementation's inadequacy. Ensure that the test fails. Commit the test.
  3. Improve the code until your new test passes and commit your changes.
  4. Push your changes to your GitHub fork.
  5. Submit a pull request to brighterplanet.

Brighter Planet

  1. Receive a pull request.
  2. Pull changes from forked repository.
  3. Ensure tests pass.
  4. Review changes for scientific accuracy.
  5. Merge changes to master repository and publish.
  6. Direct production environment to use new emitter version.

Copyright

Copyright © 2010 Brighter Planet. See LICENSE for details. Contact Brighter Planet for dual-license arrangements.

Something went wrong with that request. Please try again.