flight 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -184,7 +184,7 @@ Feature: Flight Committee Calculations
184
184
  | code | seats |
185
185
  | BP-FM1 | 125.0 |
186
186
  | BP-BA1 | 120.0 |
187
- | BP-XX1 | 130.0 |
187
+ | BP-XX1s | 130.0 |
188
188
 
189
189
  Scenario Outline: Seats committee from aircraft missing seats
190
190
  Given a flight emitter
@@ -265,10 +265,10 @@ Feature: Flight Committee Calculations
265
265
  And the conclusion of the committee should have a record with "m1" equal to "4"
266
266
  And the conclusion of the committee should have a record with "endpoint_fuel" equal to "0"
267
267
  Examples:
268
- | code |
269
- | BP-XX1 |
270
- | BP-XX3 |
271
- | BP-XX4 |
268
+ | code |
269
+ | BP-XX1f |
270
+ | BP-XX3 |
271
+ | BP-XX4 |
272
272
 
273
273
  Scenario: Fuel use coefficients committee from aircraft class
274
274
  Given a flight emitter
@@ -0,0 +1,28 @@
1
+ module BrighterPlanet
2
+ module Flight
3
+ module CarbonModel
4
+ class FuelUseEquation < Struct.new(:m3, :m2, :m1, :endpoint_fuel)
5
+ def empty?
6
+ values.all?(&:nil?) or values.all?(&:zero?)
7
+ end
8
+
9
+ def values
10
+ [m3, m2, m1, endpoint_fuel]
11
+ end
12
+
13
+ def to_xml(options = {})
14
+ options[:indent] ||= 2
15
+ xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
16
+ xml.instruct! unless options[:skip_instruct]
17
+ xml.fuel_use_equation do |estimate_block|
18
+ estimate_block.endpoint_fuel endpoint_fuel, :type => 'float'
19
+ estimate_block.m1 m1, :type => 'float'
20
+ estimate_block.m2 m2, :type => 'float'
21
+ estimate_block.m3 m3, :type => 'float'
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
@@ -7,12 +7,13 @@ require 'timeframe'
7
7
  require 'date'
8
8
  require 'weighted_average'
9
9
  require 'builder'
10
+ require 'flight/carbon_model/fuel_use_equation'
10
11
 
11
12
  ## Flight carbon model
12
13
  # This model is used by [Brighter Planet](http://brighterplanet.com)'s carbon emission [web service](http://carbon.brighterplanet.com) to estimate the **greenhouse gas emissions of passenger air travel**.
13
14
  #
14
15
  ##### Timeframe and date
15
- # The model estimates the emissions that occur during a particular `timeframe`. To do this it needs to know the `date` on which the flight occurred. For example, if the `timeframe` is January 2010, a flight that occured on January 5, 2010 will have emissions but a flight that occured on February 1, 2010 will not. If no `timeframe` is specified, the default is the current year. If no `date` is specified, the default is the first day of the `timeframe`.
16
+ # The model estimates the emissions that occur during a particular `timeframe`. To do this it needs to know the `date` on which the flight occurred. For example, if the `timeframe` is January 2010, a flight that occurred on January 5, 2010 will have emissions but a flight that occurred on February 1, 2010 will not.
16
17
  #
17
18
  ##### Calculations
18
19
  # The final estimate is the result of the **calculations** detailed below. These calculations are performed in reverse order, starting with the last calculation listed and finishing with the `emission` calculation. Each calculation is named according to the value it returns.
@@ -24,21 +25,20 @@ require 'builder'
24
25
  # Each method lists any established calculation standards with which it **complies**. When compliance with a standard is requested, all methods that do not comply with that standard are ignored. This means that any values a particular method requires will have been calculated using a compliant method, because those are the only methods available. If any value did not have a compliant method in its calculation then it would be undefined, and the current method would have been ignored.
25
26
  #
26
27
  ##### Collaboration
27
- # Contributions to this carbon model are actively encouraged and warmly welcomed. This library includes a comprehensive test suite to ensure that your changes do not cause regressions. All changes shold include test coverage for new functionality. Please see [sniff](http://github.com/brighterplanet/sniff#readme), our emitter testing framework, for more information.
28
+ # Contributions to this carbon model are actively encouraged and warmly welcomed. This library includes a comprehensive test suite to ensure that your changes do not cause regressions. All changes should include test coverage for new functionality. Please see [sniff](http://github.com/brighterplanet/sniff#readme), our emitter testing framework, for more information.
28
29
  module BrighterPlanet
29
30
  module Flight
30
31
  module CarbonModel
31
32
  def self.included(base)
32
- base.extend FastTimestamp
33
33
  base.decide :emission, :with => :characteristics do
34
34
  ### Emission calculation
35
35
  # Returns the `emission` estimate in *kg CO<sub>2</sub>e*.
36
- # This is the passenger's share of the total flight emissions that occured during the `timeframe`.
36
+ # This is the passenger's share of the total flight emissions that occurred during the `timeframe`.
37
37
  committee :emission do
38
38
  #### Emission from fuel, emission factor, freight share, passengers, multipliers, and date
39
39
  # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
40
40
  #
41
- # - Checks whether the flight occured during the `timeframe`
41
+ # - Checks whether the flight occurred during the `timeframe`
42
42
  # - Multiplies `fuel use` (*kg fuel*) by an `emission factor` (*kg CO<sub>2</sub>e / kg fuel*) and an `aviation multiplier` to give total flight emissions in *kg CO<sub>2</sub>e*
43
43
  # - Multiplies by (1 - `freight share`) to take out emissions attributed to freight cargo and mail, leaving emissions attributed to passengers and their baggage
44
44
  # - Divides by the number of `passengers` and multiplies by a `seat class multiplier` to give `emission` for the passenger
@@ -281,7 +281,7 @@ module BrighterPlanet
281
281
  bts_code = flight_segment.aircraft_bts_code.to_s
282
282
  aircraft = relevant_aircraft[bts_code]
283
283
  aircraft_coefficient = aircraft.send(name)
284
- if aircraft_coefficient.nil? or aircraft_coefficient.zero?
284
+ if aircraft_coefficient.nil?
285
285
  aircraft_coefficient = aircraft.aircraft_class.send(name)
286
286
  end
287
287
  coefficient + (aircraft_coefficient * flight_segment.passengers)
@@ -574,57 +574,21 @@ module BrighterPlanet
574
574
  end
575
575
 
576
576
  ### Date calculation
577
- # Returns the `date` on which the flight occured.
577
+ # Returns the `date` on which the flight occurred.
578
578
  committee :date do
579
579
  #### Date from client input
580
580
  # **Complies:** All
581
581
  #
582
- # Uses the client-input value for `date`.
582
+ # Uses the client-input `date`.
583
583
 
584
584
  #### Date from timeframe
585
585
  # **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
586
586
  #
587
- # Assumes the flight occured on the first day of the `timeframe`.
587
+ # Assumes the flight occurred on the first day of the `timeframe`.
588
588
  quorum 'from timeframe', :complies => [:ghg_protocol, :iso, :tcr] do |characteristics, timeframe|
589
589
  timeframe.from
590
590
  end
591
591
  end
592
-
593
- ### Timeframe calculation
594
- # Returns the `timeframe`.
595
- # This is the period over which to calculate emissions.
596
-
597
- #### Timeframe from client input
598
- # **Complies:** All
599
- #
600
- # Uses the client-input value for `timeframe`.
601
-
602
- #### Default timeframe
603
- # **Complies:** All
604
- #
605
- # Uses the current calendar year.
606
- end
607
- end
608
-
609
- class FuelUseEquation < Struct.new(:m3, :m2, :m1, :endpoint_fuel)
610
- def empty?
611
- values.all?(&:nil?) or values.all?(&:zero?)
612
- end
613
-
614
- def values
615
- [m3, m2, m1, endpoint_fuel]
616
- end
617
-
618
- def to_xml(options = {})
619
- options[:indent] ||= 2
620
- xml = options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent])
621
- xml.instruct! unless options[:skip_instruct]
622
- xml.fuel_use_equation do |estimate_block|
623
- estimate_block.endpoint_fuel endpoint_fuel, :type => 'float'
624
- estimate_block.m1 m1, :type => 'float'
625
- estimate_block.m2 m2, :type => 'float'
626
- estimate_block.m3 m3, :type => 'float'
627
- end
628
592
  end
629
593
  end
630
594
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flight
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 23
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 1
8
- - 5
9
- version: 0.1.5
9
+ - 6
10
+ version: 0.1.6
10
11
  platform: ruby
11
12
  authors:
12
13
  - Andy Rossmeissl
@@ -18,165 +19,176 @@ autorequire:
18
19
  bindir: bin
19
20
  cert_chain: []
20
21
 
21
- date: 2010-11-06 00:00:00 -04:00
22
+ date: 2010-12-02 00:00:00 -05:00
22
23
  default_executable:
23
24
  dependencies:
24
25
  - !ruby/object:Gem::Dependency
25
26
  name: activerecord
27
+ prerelease: false
26
28
  requirement: &id001 !ruby/object:Gem::Requirement
27
29
  none: false
28
30
  requirements:
29
31
  - - ~>
30
32
  - !ruby/object:Gem::Version
33
+ hash: 5
31
34
  segments:
32
35
  - 3
33
36
  - 0
34
37
  - 1
35
38
  version: 3.0.1
36
39
  type: :development
37
- prerelease: false
38
40
  version_requirements: *id001
39
41
  - !ruby/object:Gem::Dependency
40
42
  name: bundler
43
+ prerelease: false
41
44
  requirement: &id002 !ruby/object:Gem::Requirement
42
45
  none: false
43
46
  requirements:
44
47
  - - ~>
45
48
  - !ruby/object:Gem::Version
49
+ hash: 23
46
50
  segments:
47
51
  - 1
48
52
  - 0
49
53
  - 0
50
54
  version: 1.0.0
51
55
  type: :development
52
- prerelease: false
53
56
  version_requirements: *id002
54
57
  - !ruby/object:Gem::Dependency
55
58
  name: cucumber
59
+ prerelease: false
56
60
  requirement: &id003 !ruby/object:Gem::Requirement
57
61
  none: false
58
62
  requirements:
59
63
  - - ">="
60
64
  - !ruby/object:Gem::Version
65
+ hash: 3
61
66
  segments:
62
67
  - 0
63
68
  version: "0"
64
69
  type: :development
65
- prerelease: false
66
70
  version_requirements: *id003
67
71
  - !ruby/object:Gem::Dependency
68
72
  name: jeweler
73
+ prerelease: false
69
74
  requirement: &id004 !ruby/object:Gem::Requirement
70
75
  none: false
71
76
  requirements:
72
77
  - - ~>
73
78
  - !ruby/object:Gem::Version
79
+ hash: 7
74
80
  segments:
75
81
  - 1
76
82
  - 4
77
83
  - 0
78
84
  version: 1.4.0
79
85
  type: :development
80
- prerelease: false
81
86
  version_requirements: *id004
82
87
  - !ruby/object:Gem::Dependency
83
88
  name: rake
89
+ prerelease: false
84
90
  requirement: &id005 !ruby/object:Gem::Requirement
85
91
  none: false
86
92
  requirements:
87
93
  - - ">="
88
94
  - !ruby/object:Gem::Version
95
+ hash: 3
89
96
  segments:
90
97
  - 0
91
98
  version: "0"
92
99
  type: :development
93
- prerelease: false
94
100
  version_requirements: *id005
95
101
  - !ruby/object:Gem::Dependency
96
102
  name: rdoc
103
+ prerelease: false
97
104
  requirement: &id006 !ruby/object:Gem::Requirement
98
105
  none: false
99
106
  requirements:
100
107
  - - ">="
101
108
  - !ruby/object:Gem::Version
109
+ hash: 3
102
110
  segments:
103
111
  - 0
104
112
  version: "0"
105
113
  type: :development
106
- prerelease: false
107
114
  version_requirements: *id006
108
115
  - !ruby/object:Gem::Dependency
109
116
  name: rspec
117
+ prerelease: false
110
118
  requirement: &id007 !ruby/object:Gem::Requirement
111
119
  none: false
112
120
  requirements:
113
121
  - - "="
114
122
  - !ruby/object:Gem::Version
123
+ hash: 13
115
124
  segments:
116
125
  - 2
117
126
  - 0
118
127
  - 1
119
128
  version: 2.0.1
120
129
  type: :development
121
- prerelease: false
122
130
  version_requirements: *id007
123
131
  - !ruby/object:Gem::Dependency
124
132
  name: sniff
133
+ prerelease: false
125
134
  requirement: &id008 !ruby/object:Gem::Requirement
126
135
  none: false
127
136
  requirements:
128
137
  - - ~>
129
138
  - !ruby/object:Gem::Version
139
+ hash: 19
130
140
  segments:
131
141
  - 0
132
- - 2
142
+ - 3
133
143
  - 0
134
- version: 0.2.0
144
+ version: 0.3.0
135
145
  type: :development
136
- prerelease: false
137
146
  version_requirements: *id008
138
147
  - !ruby/object:Gem::Dependency
139
148
  name: emitter
149
+ prerelease: false
140
150
  requirement: &id009 !ruby/object:Gem::Requirement
141
151
  none: false
142
152
  requirements:
143
153
  - - ~>
144
154
  - !ruby/object:Gem::Version
155
+ hash: 21
145
156
  segments:
146
157
  - 0
158
+ - 2
147
159
  - 1
148
- - 8
149
- version: 0.1.8
160
+ version: 0.2.1
150
161
  type: :runtime
151
- prerelease: false
152
162
  version_requirements: *id009
153
163
  - !ruby/object:Gem::Dependency
154
- name: builder
164
+ name: earth
165
+ prerelease: false
155
166
  requirement: &id010 !ruby/object:Gem::Requirement
156
167
  none: false
157
168
  requirements:
158
- - - ">="
169
+ - - ~>
159
170
  - !ruby/object:Gem::Version
171
+ hash: 17
160
172
  segments:
161
173
  - 0
162
- version: "0"
174
+ - 3
175
+ - 1
176
+ version: 0.3.1
163
177
  type: :runtime
164
- prerelease: false
165
178
  version_requirements: *id010
166
179
  - !ruby/object:Gem::Dependency
167
- name: earth
180
+ name: builder
181
+ prerelease: false
168
182
  requirement: &id011 !ruby/object:Gem::Requirement
169
183
  none: false
170
184
  requirements:
171
- - - ~>
185
+ - - ">="
172
186
  - !ruby/object:Gem::Version
187
+ hash: 3
173
188
  segments:
174
189
  - 0
175
- - 2
176
- - 7
177
- version: 0.2.7
190
+ version: "0"
178
191
  type: :runtime
179
- prerelease: false
180
192
  version_requirements: *id011
181
193
  description: A software model in Ruby for the greenhouse gas emissions of a flight
182
194
  email: andy@rossmeissl.net
@@ -193,6 +205,7 @@ files:
193
205
  - README.rdoc
194
206
  - lib/flight.rb
195
207
  - lib/flight/carbon_model.rb
208
+ - lib/flight/carbon_model/fuel_use_equation.rb
196
209
  - lib/flight/characterization.rb
197
210
  - lib/flight/data.rb
198
211
  - lib/flight/fallback.rb
@@ -201,8 +214,8 @@ files:
201
214
  - lib/test_support/flight_record.rb
202
215
  - README.markdown
203
216
  - features/support/env.rb
204
- - features/flight_emissions.feature
205
217
  - features/flight_committees.feature
218
+ - features/flight_emissions.feature
206
219
  has_rdoc: true
207
220
  homepage: http://github.com/brighterplanet/flight
208
221
  licenses: []
@@ -217,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
230
  requirements:
218
231
  - - ">="
219
232
  - !ruby/object:Gem::Version
220
- hash: -696785283
233
+ hash: 3
221
234
  segments:
222
235
  - 0
223
236
  version: "0"
@@ -226,6 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
226
239
  requirements:
227
240
  - - ">="
228
241
  - !ruby/object:Gem::Version
242
+ hash: 3
229
243
  segments:
230
244
  - 0
231
245
  version: "0"
@@ -238,6 +252,6 @@ specification_version: 3
238
252
  summary: A carbon model
239
253
  test_files:
240
254
  - features/support/env.rb
241
- - features/flight_emissions.feature
242
255
  - features/flight_committees.feature
256
+ - features/flight_emissions.feature
243
257
  - lib/test_support/flight_record.rb