flight 0.0.14 → 0.0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +78 -0
- data/features/flight_committees.feature +249 -17
- data/features/flight_emissions.feature +1 -1
- data/features/support/env.rb +1 -1
- metadata +11 -9
data/README.markdown
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Flight
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
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.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
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.
|
10
|
+
|
11
|
+
|
12
|
+
class FlightRecord < ActiveRecord::Base
|
13
|
+
include BrighterPlanet::Flight
|
14
|
+
...
|
15
|
+
end
|
16
|
+
|
17
|
+
f = FlightRecord.new :origin_airport => { :iata_code => 'DTW'}, :destination_airport => { :iata_code => 'SFO' }
|
18
|
+
f.emission
|
19
|
+
# => 2472
|
20
|
+
|
21
|
+
## Getting Ready for Development
|
22
|
+
Flight uses bundler to manage dependencies. To prepare your environment, perform the following:
|
23
|
+
git clone git://github.com/brighterplanet/flight.git
|
24
|
+
cd flight
|
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 flight. 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
|
+
* flight_emissions.feature, which tests emission values for various inputs
|
40
|
+
* flight_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,252 @@
|
|
1
1
|
Feature: Flight Committee Calculations
|
2
2
|
The flight model should generate correct committee calculations
|
3
3
|
|
4
|
-
Scenario
|
5
|
-
Given a flight
|
6
|
-
And
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
And
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
Scenario: Cohort committee from t100 with usable characteristics
|
5
|
+
Given a flight emitter
|
6
|
+
And a characteristic "origin_airport.iata_code" of "DTW"
|
7
|
+
When the "cohort" committee is calculated
|
8
|
+
Then the conclusion of the committee should have a record with "count" equal to "34"
|
9
|
+
|
10
|
+
Scenario: Cohort committee from t100 with no usable characteristics
|
11
|
+
Given a flight emitter
|
12
|
+
And a characteristic "seat_class.name" of "business"
|
13
|
+
When the "cohort" committee is calculated
|
14
|
+
Then the conclusion of the committee should be nil
|
15
|
+
|
16
|
+
Scenario Outline: Date committee from timeframe
|
17
|
+
Given a flight emitter
|
18
|
+
And a characteristic "timeframe" of "<timeframe>"
|
19
|
+
When the "date" committee is calculated
|
20
|
+
Then the committee should have used quorum "from timeframe"
|
21
|
+
And the conclusion of the committee should be "<from>"
|
22
|
+
Examples:
|
23
|
+
| timeframe | from |
|
24
|
+
| 2010-07-15/2010-07-20 | 2010-07-15 |
|
25
|
+
|
26
|
+
Scenario Outline: Date committee from nil timeframe
|
27
|
+
Given a flight emitter
|
28
|
+
And a characteristic "timeframe" of "<timeframe>"
|
29
|
+
When the "date" committee is calculated
|
30
|
+
Then the conclusion of the committee should be "<from>"
|
31
|
+
Examples:
|
32
|
+
| timeframe | from |
|
33
|
+
| | |
|
34
|
+
|
35
|
+
Scenario Outline: Date committee from creation date
|
36
|
+
Given a flight emitter
|
37
|
+
And a characteristic "creation_date" of "<creation_date>"
|
38
|
+
When the "date" committee is calculated
|
39
|
+
Then the committee should have used quorum "from creation date"
|
40
|
+
And the conclusion of the committee should be "<date>"
|
41
|
+
Examples:
|
42
|
+
| creation_date | date |
|
43
|
+
| 2010-07-15 | 2010-07-15 |
|
44
|
+
|
45
|
+
Scenario Outline: Seat class multiplier committee from seat class
|
46
|
+
Given a flight emitter
|
47
|
+
And a characteristic "seat_class.name" of "<seat_class>"
|
48
|
+
When the "seat_class_multiplier" committee is calculated
|
49
|
+
Then the committee should have used quorum "from seat class"
|
50
|
+
And the conclusion of the committee should be "<multiplier>"
|
51
|
+
Examples:
|
52
|
+
| seat_class | multiplier |
|
53
|
+
| business | 1.69 |
|
54
|
+
| economy | 0.94 |
|
55
|
+
| first | 1.47 |
|
56
|
+
|
57
|
+
Scenario: Seat class multiplier committee from default
|
58
|
+
Given a flight emitter
|
59
|
+
When the "seat_class_multiplier" committee is calculated
|
60
|
+
Then the committee should have used quorum "default"
|
61
|
+
And the conclusion of the committee should be "1.0"
|
62
|
+
|
63
|
+
Scenario Outline: Domesticity committee from airline for domestic airlines
|
64
|
+
Given a flight emitter
|
65
|
+
And a characteristic "airline.name" of "<airline>"
|
66
|
+
When the "domesticity" committee is calculated
|
67
|
+
Then the committee should have used quorum "from airline"
|
68
|
+
And the conclusion of the committee should have a record with "name" equal to "<domesticity>"
|
69
|
+
Examples:
|
70
|
+
| airline | domesticity |
|
71
|
+
| Midwest Aviation | Domestic Data, US Carriers Only |
|
72
|
+
|
73
|
+
Scenario Outline: Domesticity committee from airline for international airlines
|
74
|
+
Given a flight emitter
|
75
|
+
And a characteristic "airline.name" of "<airline>"
|
76
|
+
When the "domesticity" committee is calculated
|
77
|
+
Then the conclusion of the committee should be nil
|
78
|
+
Examples:
|
79
|
+
| airline |
|
80
|
+
| Aeroflot |
|
81
|
+
| United Airlines |
|
82
|
+
|
83
|
+
Scenario Outline: Domesticity committee from destination airport for domestic airports
|
84
|
+
Given a flight emitter
|
85
|
+
And a characteristic "destination_airport.iata_code" of "<iata_code>"
|
86
|
+
When the "domesticity" committee is calculated
|
87
|
+
Then the committee should have used quorum "from destination"
|
88
|
+
And the conclusion of the committee should have a record with "name" equal to "<domesticity>"
|
89
|
+
Examples:
|
90
|
+
| iata_code | domesticity |
|
91
|
+
| ALO | Domestic Data, US Carriers Only |
|
92
|
+
| TXK | Domestic Data, US Carriers Only |
|
93
|
+
|
94
|
+
Scenario Outline: Domesticity committee from destination airport for international airports
|
95
|
+
Given a flight emitter
|
96
|
+
And a characteristic "destination_airport.iata_code" of "<iata_code>"
|
97
|
+
When the "domesticity" committee is calculated
|
98
|
+
Then the conclusion of the committee should be nil
|
99
|
+
Examples:
|
100
|
+
| iata_code |
|
101
|
+
| DTW |
|
102
|
+
| IAD |
|
103
|
+
| GRR |
|
104
|
+
|
105
|
+
Scenario Outline: Domesticity committee from origin airport for domestic airports
|
106
|
+
Given a flight emitter
|
107
|
+
And a characteristic "origin_airport.iata_code" of "<iata_code>"
|
108
|
+
When the "domesticity" committee is calculated
|
109
|
+
Then the committee should have used quorum "from origin"
|
110
|
+
And the conclusion of the committee should have a record with "name" equal to "<domesticity>"
|
111
|
+
Examples:
|
112
|
+
| iata_code | domesticity |
|
113
|
+
| ALO | Domestic Data, US Carriers Only |
|
114
|
+
| TXK | Domestic Data, US Carriers Only |
|
115
|
+
|
116
|
+
Scenario Outline: Domesticity committee from destination for international airports
|
117
|
+
Given a flight emitter
|
118
|
+
And a characteristic "destination_airport.iata_code" of "<iata_code>"
|
119
|
+
When the "domesticity" committee is calculated
|
120
|
+
Then the conclusion of the committee should be nil
|
121
|
+
Examples:
|
122
|
+
| iata_code |
|
123
|
+
| DTW |
|
124
|
+
| IAD |
|
125
|
+
| GRR |
|
126
|
+
|
127
|
+
Scenario Outline: Domesticity committee from airports for domestic route
|
128
|
+
Given a flight emitter
|
129
|
+
And a characteristic "origin_airport.iata_code" of "<origin>"
|
130
|
+
And a characteristic "destination_airport.iata_code" of "<destination>"
|
131
|
+
When the "domesticity" committee is calculated
|
132
|
+
Then the committee should have used quorum "from origin"
|
133
|
+
And the conclusion of the committee should have a record with "name" equal to "<domesticity>"
|
134
|
+
Examples:
|
135
|
+
| origin | destination | domesticity |
|
136
|
+
| DTW | SFO | Domestic Data, US Carriers Only |
|
137
|
+
|
138
|
+
Scenario Outline: Domesticity committee from airports for international route
|
139
|
+
Given a flight emitter
|
140
|
+
And a characteristic "origin_airport.iata_code" of "<origin>"
|
141
|
+
And a characteristic "destination_airport.iata_code" of "<destination>"
|
142
|
+
When the "domesticity" committee is calculated
|
143
|
+
Then the conclusion of the committee should be nil
|
144
|
+
Examples:
|
145
|
+
| origin | destination |
|
146
|
+
| DTW | CDG |
|
147
|
+
|
148
|
+
Scenario: Trips committee
|
149
|
+
Given a flight emitter
|
150
|
+
When the "trips" committee is calculated
|
151
|
+
Then the conclusion of the committee should be "1.941"
|
152
|
+
|
153
|
+
Scenario: Freight share committee from cohort
|
154
|
+
Given a flight emitter
|
155
|
+
And a characteristic "origin_airport.iata_code" of "DTW"
|
156
|
+
When the "cohort" committee is calculated
|
157
|
+
And the "freight_share" committee is calculated
|
158
|
+
Then the committee should have used quorum "from cohort"
|
159
|
+
And the conclusion of the committee should be "0.11876"
|
160
|
+
|
161
|
+
Scenario: Fuel type committee from default
|
162
|
+
Given a flight emitter
|
163
|
+
When the "fuel_type" committee is calculated
|
164
|
+
Then the conclusion of the committee should have a record with "emission_factor" equal to "2.527139"
|
165
|
+
|
166
|
+
Scenario Outline: Emission factor committee
|
167
|
+
Given a flight emitter
|
168
|
+
And pending - no fuel type records yet
|
169
|
+
|
170
|
+
Scenario Outline: Radiative forcing index committee
|
171
|
+
Given a flight emitter
|
172
|
+
And pending - no fuel type records yet
|
173
|
+
|
174
|
+
Scenario Outline: Radiative forcing index committee
|
175
|
+
Given a flight emitter
|
176
|
+
And pending - no fuel type records yet
|
177
|
+
|
178
|
+
Scenario: Emplanements per trip committee from default
|
179
|
+
Given a flight emitter
|
180
|
+
When the "emplanements_per_trip" committee is calculated
|
181
|
+
Then the conclusion of the committee should be "1.67"
|
182
|
+
|
183
|
+
Scenario: Distance committee from default
|
184
|
+
Given a flight emitter
|
185
|
+
When the "distance" committee is calculated
|
186
|
+
Then the committee should have used quorum "default"
|
187
|
+
And the conclusion of the committee should be "1121.73083"
|
188
|
+
|
189
|
+
Scenario Outline: Distance committee from cohort
|
190
|
+
Given a flight emitter
|
191
|
+
And a characteristic "origin_airport.iata_code" of "<origin>"
|
192
|
+
And a characteristic "destination_airport.iata_code" of "<destination>"
|
193
|
+
And a characteristic "aircraft.icao_code" of "<craft>"
|
194
|
+
And a characteristic "airline.iata_code" of "<airline>"
|
195
|
+
And a characteristic "propulsion.name" of "<propulsion>"
|
196
|
+
And a characteristic "domesticity.name" of "<domesticity>"
|
197
|
+
When the "cohort" committee is calculated
|
198
|
+
And the "distance" committee is calculated
|
199
|
+
Then the committee should have used quorum "from cohort"
|
200
|
+
And the conclusion of the committee should be "<distance>"
|
201
|
+
Examples:
|
202
|
+
| origin | destination | craft | airline | propulsion | domesticity | distance |
|
203
|
+
| DTW | | A320 | UA | | Domestic Data, US Carriers Only | 325 |
|
204
|
+
|
205
|
+
Scenario Outline: Distance committee from distance class
|
206
|
+
Given a flight emitter
|
207
|
+
And a characteristic "distance_class.name" of "<distance_class>"
|
208
|
+
When the "distance" committee is calculated
|
209
|
+
Then the committee should have used quorum "from distance class"
|
210
|
+
And the conclusion of the committee should be "<distance>"
|
211
|
+
Examples:
|
212
|
+
| distance_class | distance |
|
213
|
+
| epic | 8689.74081 |
|
214
|
+
| long | 2606.92764 |
|
215
|
+
| medium | 868.97408 |
|
216
|
+
| short | 217.24406 |
|
217
|
+
|
218
|
+
Scenario Outline: Distance committee from distance estimate
|
219
|
+
Given a flight emitter
|
220
|
+
And a characteristic "distance_estimate" of "<distance_estimate>"
|
221
|
+
When the "distance" committee is calculated
|
222
|
+
Then the committee should have used quorum "from distance estimate"
|
223
|
+
And the conclusion of the committee should be "<distance>"
|
224
|
+
Examples:
|
225
|
+
| distance_estimate | distance |
|
226
|
+
| 123 | 66.41468 |
|
227
|
+
|
228
|
+
Scenario Outline: Distance committee from airports
|
229
|
+
Given a flight emitter
|
230
|
+
And a characteristic "origin_airport.iata_code" of "<origin>"
|
231
|
+
And a characteristic "destination_airport.iata_code" of "<destination>"
|
232
|
+
When the "distance" committee is calculated
|
233
|
+
Then the committee should have used quorum "from airports"
|
234
|
+
And the conclusion of the committee should be "<distance>"
|
235
|
+
Examples:
|
236
|
+
| origin | destination | distance |
|
237
|
+
| DTW | SFO | 1803.65517 |
|
238
|
+
| IAD | DCA | 20.32743 |
|
239
|
+
| MSP | FRA | 3809.26855 |
|
240
|
+
|
241
|
+
Scenario Outline: Adjusted distance committee from distance
|
242
|
+
Given a flight emitter
|
243
|
+
And a characteristic "distance_estimate" of "<distance_estimate>"
|
244
|
+
When the "distance" committee is calculated
|
245
|
+
And the "emplanements_per_trip" committee is calculated
|
246
|
+
And the "adjusted_distance" committee is calculated
|
247
|
+
Then the conclusion of the committee should be "<distance>"
|
248
|
+
Examples:
|
249
|
+
| distance_estimate | distance |
|
250
|
+
| 0 | 0 |
|
251
|
+
| 1 | 0.67092 |
|
252
|
+
| 1254 | 841.33709 |
|
@@ -8,7 +8,7 @@ Feature: Flight Emissions Calculations
|
|
8
8
|
And it has "date" of "<date>"
|
9
9
|
And it used "aircraft.icao_code" "<aircraft>"
|
10
10
|
When emissions are calculated
|
11
|
-
Then the emission value should be within
|
11
|
+
Then the emission value should be within 1 kgs of <emission>
|
12
12
|
Examples:
|
13
13
|
| source | dest | airline | date | aircraft | emission |
|
14
14
|
| DTW | SFO | UA | 2010-06-25 | A320 | 1153 |
|
data/features/support/env.rb
CHANGED
@@ -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 => :air
|
8
|
+
Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :earth => :air, :cucumber => true
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 63
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 16
|
10
|
+
version: 0.0.16
|
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-
|
22
|
+
date: 2010-08-11 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:
|
147
|
+
hash: 31
|
148
148
|
segments:
|
149
149
|
- 0
|
150
|
-
-
|
151
|
-
-
|
152
|
-
version: 0.
|
150
|
+
- 1
|
151
|
+
- 2
|
152
|
+
version: 0.1.2
|
153
153
|
requirement: *id008
|
154
154
|
- !ruby/object:Gem::Dependency
|
155
155
|
type: :runtime
|
@@ -238,7 +238,7 @@ dependencies:
|
|
238
238
|
version_requirements: &id014 !ruby/object:Gem::Requirement
|
239
239
|
none: false
|
240
240
|
requirements:
|
241
|
-
- - "
|
241
|
+
- - ">="
|
242
242
|
- !ruby/object:Gem::Version
|
243
243
|
hash: 13
|
244
244
|
segments:
|
@@ -318,6 +318,7 @@ extensions: []
|
|
318
318
|
|
319
319
|
extra_rdoc_files:
|
320
320
|
- LICENSE
|
321
|
+
- README.markdown
|
321
322
|
- README.rdoc
|
322
323
|
files:
|
323
324
|
- LICENSE
|
@@ -329,6 +330,7 @@ files:
|
|
329
330
|
- lib/flight/summarization.rb
|
330
331
|
- lib/test_support/db/schema.rb
|
331
332
|
- lib/test_support/flight_record.rb
|
333
|
+
- README.markdown
|
332
334
|
- features/support/env.rb
|
333
335
|
- features/flight_committees.feature
|
334
336
|
- features/flight_emissions.feature
|