rail_trip 0.0.12 → 0.0.13
Sign up to get free protection for your applications and to get access to all the features.
- data/features/rail_trip_committees.feature +71 -9
- data/features/rail_trip_emissions.feature +28 -7
- data/features/support/env.rb +1 -1
- data/lib/rail_trip/carbon_model.rb +176 -92
- data/lib/rail_trip/characterization.rb +2 -1
- data/lib/rail_trip/data.rb +3 -4
- data/lib/rail_trip/summarization.rb +1 -1
- data/lib/test_support/rail_trip_record.rb +1 -18
- metadata +33 -31
@@ -1,14 +1,76 @@
|
|
1
1
|
Feature: Rail Trip Committee Calculations
|
2
2
|
The rail trip model should generate correct committee calculations
|
3
3
|
|
4
|
-
Scenario
|
4
|
+
Scenario: Date committee from timeframe
|
5
5
|
Given a rail trip emitter
|
6
|
-
And a characteristic "
|
7
|
-
|
6
|
+
And a characteristic "timeframe" of "2010-07-12/2010-11-28"
|
7
|
+
When the "date" committee is calculated
|
8
|
+
Then the conclusion of the committee should be "2010-07-12"
|
9
|
+
|
10
|
+
Scenario: Rail class committee from default
|
11
|
+
Given a rail trip emitter
|
12
|
+
When the "rail_class" committee is calculated
|
13
|
+
Then the conclusion of the committee should have "name" of "US average"
|
14
|
+
|
15
|
+
Scenario: Passengers committee from rail class
|
16
|
+
Given a rail trip emitter
|
17
|
+
And a characteristic "rail_class.name" of "commuter rail"
|
18
|
+
When the "passengers" committee is calculated
|
19
|
+
Then the conclusion of the committee should be "25.0"
|
20
|
+
|
21
|
+
Scenario: Speed committee from rail class
|
22
|
+
Given a rail trip emitter
|
23
|
+
And a characteristic "rail_class.name" of "commuter rail"
|
8
24
|
When the "speed" committee is calculated
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
25
|
+
Then the conclusion of the committee should be "50.0"
|
26
|
+
|
27
|
+
Scenario: Electricity intensity committee from rail class
|
28
|
+
Given a rail trip emitter
|
29
|
+
And a characteristic "rail_class.name" of "commuter rail"
|
30
|
+
When the "electricity_intensity" committee is calculated
|
31
|
+
Then the conclusion of the committee should be "12.0"
|
32
|
+
|
33
|
+
Scenario: Diesel intensity committee from rail class
|
34
|
+
Given a rail trip emitter
|
35
|
+
And a characteristic "rail_class.name" of "commuter rail"
|
36
|
+
When the "diesel_intensity" committee is calculated
|
37
|
+
Then the conclusion of the committee should be "0.75"
|
38
|
+
|
39
|
+
Scenario: Distance committee from duration and speed
|
40
|
+
Given a rail trip emitter
|
41
|
+
And a characteristic "duration" of "2"
|
42
|
+
And a characteristic "speed" of "50"
|
43
|
+
When the "distance" committee is calculated
|
44
|
+
Then the committee should have used quorum "from duration and speed"
|
45
|
+
And the conclusion of the committee should be "100.0"
|
46
|
+
|
47
|
+
Scenario: Distance committee from rail class
|
48
|
+
Given a rail trip emitter
|
49
|
+
And a characteristic "rail_class.name" of "commuter rail"
|
50
|
+
When the "distance" committee is calculated
|
51
|
+
Then the committee should have used quorum "from rail class"
|
52
|
+
And the conclusion of the committee should be "10.0"
|
53
|
+
|
54
|
+
Scenario: Electricity consumed committee from distance and electricity intensity
|
55
|
+
Given a rail trip emitter
|
56
|
+
And a characteristic "distance" of "100"
|
57
|
+
And a characteristic "electricity_intensity" of "2"
|
58
|
+
When the "electricity_consumed" committee is calculated
|
59
|
+
Then the conclusion of the committee should be "200.0"
|
60
|
+
|
61
|
+
Scenario: Diesel consumed committee from distance and diesel intensity
|
62
|
+
Given a rail trip emitter
|
63
|
+
And a characteristic "distance" of "100"
|
64
|
+
And a characteristic "diesel_intensity" of "2"
|
65
|
+
When the "diesel_consumed" committee is calculated
|
66
|
+
Then the conclusion of the committee should be "200.0"
|
67
|
+
|
68
|
+
Scenario: Electricity emission factor from default
|
69
|
+
Given a rail trip emitter
|
70
|
+
When the "electricity_emission_factor" committee is calculated
|
71
|
+
Then the conclusion of the committee should be "1.0"
|
72
|
+
|
73
|
+
Scenario: Diesel emission factor from default
|
74
|
+
Given a rail trip emitter
|
75
|
+
When the "diesel_emission_factor" committee is calculated
|
76
|
+
Then the conclusion of the committee should be "2.0"
|
@@ -1,12 +1,33 @@
|
|
1
1
|
Feature: Rail Trip Emissions Calculations
|
2
2
|
The rail trip model should generate correct emission calculations
|
3
3
|
|
4
|
-
Scenario
|
5
|
-
Given a rail trip has
|
6
|
-
And it has "distance_estimate" of "<distance>"
|
4
|
+
Scenario: Calculations for rail trip with nothing
|
5
|
+
Given a rail trip has nothing
|
7
6
|
When emissions are calculated
|
8
|
-
Then the emission value should be within "0.
|
7
|
+
Then the emission value should be within "0.01" kgs of "3.17"
|
8
|
+
|
9
|
+
Scenario Outline: Calculations for rail trip from date and timeframe
|
10
|
+
Given a rail trip has "date" of "<date>"
|
11
|
+
And it has "timeframe" of "<timeframe>"
|
12
|
+
When emissions are calculated
|
13
|
+
Then the emission value should be within "0.01" kgs of "<emission>"
|
9
14
|
Examples:
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
| date | timeframe | emission |
|
16
|
+
| 2010-07-12 | 2010-07-01/2010-07-10 | 0.0 |
|
17
|
+
| 2010-07-12 | 2010-07-01/2010-07-30 | 3.17 |
|
18
|
+
| 2010-07-12 | 2010-07-15/2010-07-30 | 0.0 |
|
19
|
+
|
20
|
+
Scenario: Calculations for rail trip from distance
|
21
|
+
Given a rail trip has "distance" of "100"
|
22
|
+
When emissions are calculated
|
23
|
+
Then the emission value should be within "0.01" kgs of "22.98"
|
24
|
+
|
25
|
+
Scenario: Calculations for rail trip from duration
|
26
|
+
Given a rail trip has "duration" of "2"
|
27
|
+
When emissions are calculated
|
28
|
+
Then the emission value should be within "0.01" kgs of "18.53"
|
29
|
+
|
30
|
+
Scenario: Calculations for rail trip from rail class
|
31
|
+
Given a rail trip has "rail_class.name" of "commuter rail"
|
32
|
+
When emissions are calculated
|
33
|
+
Then the emission value should be within "0.01" kgs of "5.40"
|
data/features/support/env.rb
CHANGED
@@ -5,4 +5,4 @@ require 'cucumber'
|
|
5
5
|
require 'cucumber/formatter/unicode'
|
6
6
|
|
7
7
|
require 'sniff'
|
8
|
-
Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :earth => :rail, :cucumber => true
|
8
|
+
Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :earth => [:rail, :fuel, :locality], :cucumber => true
|
@@ -2,148 +2,232 @@
|
|
2
2
|
# See LICENSE for details.
|
3
3
|
# Contact Brighter Planet for dual-license arrangements.
|
4
4
|
|
5
|
-
|
6
|
-
#
|
5
|
+
## Rail trip carbon model
|
6
|
+
# 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 rail travel**.
|
7
|
+
#
|
8
|
+
##### Calculations
|
9
|
+
# 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.
|
10
|
+
#
|
11
|
+
##### Timeframe and date
|
12
|
+
# The model estimates the emissions that occur during a particular `timeframe`. To do this it needs to know the trip's `date`. For example, if the `timeframe` is January 2010, a trip that occurred on January 11, 2010 will have emissions but a trip that occurred on Febraury 1, 2010 will not.
|
13
|
+
#
|
14
|
+
##### Methods
|
15
|
+
# To accomodate varying client input, each calculation may have one or more **methods**. These are listed under each calculation in order from most to least preferred. Each method is named according to the `values` it requires ('default' methods do not require any values). Methods are ignored if any of the values they require are unvailable. Calculations are ignored if all of their methods are unavailable.
|
16
|
+
#
|
17
|
+
##### Standard compliance
|
18
|
+
# 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 or will be unavailable.
|
19
|
+
#
|
20
|
+
##### Collaboration
|
21
|
+
# 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.
|
7
22
|
module BrighterPlanet
|
8
23
|
module RailTrip
|
9
|
-
|
10
|
-
#### Rail trip: carbon model
|
11
|
-
# This module is used by [Brighter Planet](http://brighterplanet.com)'s
|
12
|
-
# [emission estimate service](http://carbon.brighterplanet.com) to provide
|
13
|
-
# greenhouse gas emission estimates for rail trips.
|
14
|
-
#
|
15
|
-
# For more information see:
|
16
|
-
#
|
17
|
-
# * [API documentation](http://carbon.brighterplanet.com/rail_trips/options)
|
18
|
-
# * [Source code](http://github.com/brighterplanet/rail_trip)
|
19
|
-
#
|
20
|
-
##### Collaboration
|
21
|
-
# Contributions to this carbon model are actively encouraged and warmly welcomed.
|
22
|
-
# This library includes a comprehensive test suite to ensure that your changes
|
23
|
-
# do not cause regressions. All changes shold include test coverage for new
|
24
|
-
# functionality. Please see [sniff](http://github.com/brighterplanet/sniff#readme),
|
25
|
-
# our emitter testing framework, for more information.
|
26
24
|
module CarbonModel
|
27
25
|
def self.included(base)
|
28
|
-
##### The carbon model
|
29
|
-
|
30
|
-
# This `decide` block encapsulates the carbon model. The carbon model is
|
31
|
-
# executed with a set of "characteristics" as input. These characteristics are
|
32
|
-
# parsed from input received by the client request according to the
|
33
|
-
# [characterization](characterization.html).
|
34
26
|
base.decide :emission, :with => :characteristics do
|
35
|
-
|
36
|
-
#
|
37
|
-
committee :emission do
|
38
|
-
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
|
44
|
-
|
45
|
-
|
27
|
+
### Emission calculation
|
28
|
+
# Returns the `emission` estimate (*kg CO<sub>2</sub>e*).
|
29
|
+
committee :emission do
|
30
|
+
#### From fuel and passengers
|
31
|
+
# **Complies:** GHG Protocol, ISO-140641, Climate Registry Protocol
|
32
|
+
#
|
33
|
+
# - Checks whether the trip occurred during the `timeframe`
|
34
|
+
# - Multiplies `diesel use` (*l diesel*) by the `diesel emission factor` (*kg CO<sub>2</sub>e / l diesel*) to give diesel emissions (*kg CO<sub>2</sub>e*)
|
35
|
+
# - Multiplies `electricity use` (*kWh*) by the `electricity emission factor` (*kg CO<sub>2</sub>e / kWh electricity*) to give electricity emissions (*kg CO<sub>2</sub>e*)
|
36
|
+
# - Adds diesel and electricity emissions to give total emissions (*kg CO<sub>2</sub>e*)
|
37
|
+
# - Divides by passengers to give emissions per passenger (*kg CO<sub>2</sub>e*)
|
38
|
+
# - If the trip did not occur during the `timeframe`, `emission` is zero
|
39
|
+
quorum 'from date, fuel, emission factors, and passengers', :needs => [:diesel_consumed, :diesel_emission_factor, :electricity_consumed, :electricity_emission_factor, :passengers, :date] do |characteristics, timeframe|
|
40
|
+
date = characteristics[:date].is_a?(Date) ? characteristics[:date] : Date.parse(characteristics[:date].to_s)
|
41
|
+
if timeframe.include? date
|
42
|
+
(characteristics[:diesel_consumed] * characteristics[:diesel_emission_factor] + characteristics[:electricity_consumed] * characteristics[:electricity_emission_factor]) / characteristics[:passengers]
|
43
|
+
else
|
44
|
+
0
|
45
|
+
end
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
#
|
51
|
-
committee :
|
52
|
-
|
53
|
-
#
|
54
|
-
#
|
49
|
+
### Diesel emission factor calculation
|
50
|
+
# Returns the `diesel emission factor` (*kg CO<sub>2</sub>e / l*).
|
51
|
+
committee :diesel_emission_factor do
|
52
|
+
#### Default diesel emission factor
|
53
|
+
# **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
|
54
|
+
#
|
55
|
+
# Looks up [Distillate Fuel Oil 2](http://data.brighterplanet.com/fuel_types)'s `emission factor` (*kg CO<sub>2</sub>e / l*).
|
56
|
+
quorum 'default' do
|
57
|
+
diesel = FuelType.find_by_name "Distillate Fuel Oil 2"
|
58
|
+
diesel.emission_factor
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
### Electricity emission factor calculation
|
63
|
+
# Returns the `electricity emission factor` (*kg CO<sub>2</sub>e / kWh*).
|
64
|
+
committee :electricity_emission_factor do
|
65
|
+
#### Default electricity emission factor
|
66
|
+
# **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
|
67
|
+
#
|
68
|
+
# - Looks up the [U.S. Average](http://data.brighterplanet.com/egrid_subregions) `electricity emission factor` (*kg CO<sub>2</sub>e / l*)
|
69
|
+
# - Looks up the [U.S. Average](http://data.brighterplanet.com/egrid_regions) grid region `loss factor`
|
70
|
+
# - Divides the `electricity emission factor` by (1 - `loss factor`) to account for transmission and distribution losses
|
71
|
+
quorum 'default' do
|
72
|
+
subregion = EgridSubregion.find_by_abbreviation "US"
|
73
|
+
region = subregion.egrid_region
|
74
|
+
emission_factor = subregion.electricity_emission_factor / (1 - region.loss_factor)
|
75
|
+
emission_factor
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
### Diesel consumed calculation
|
80
|
+
# Returns the `diesel use` (*l*).
|
81
|
+
committee :diesel_consumed do
|
82
|
+
#### From distance and diesel intensity
|
83
|
+
# **Complies:** GHG Protocol, ISO-140641, Climate Registry Protocol
|
84
|
+
#
|
85
|
+
# Multiplies `distance` (*km*) by `diesel intensity` (*l / km*) to give *l*.
|
55
86
|
quorum 'from distance and diesel intensity', :needs => [:distance, :diesel_intensity] do |characteristics|
|
56
|
-
#( kilometres ) * ( litres diesel / kilometre )
|
57
87
|
characteristics[:distance] * characteristics[:diesel_intensity]
|
58
88
|
end
|
59
89
|
end
|
60
90
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
#
|
91
|
+
### Electricity consumed calculation
|
92
|
+
# Returns the `electricity use` (*kWh*).
|
93
|
+
committee :electricity_consumed do
|
94
|
+
#### From distance and electricity intensity
|
95
|
+
# **Complies:** GHG Protocol, ISO-140641, Climate Registry Protocol
|
96
|
+
#
|
97
|
+
# Multiplies `distance` (*km*) by `electricity intensity` (*kWh / km*) to give *kWh*.
|
66
98
|
quorum 'from distance and electricity intensity', :needs => [:distance, :electricity_intensity] do |characteristics|
|
67
|
-
#( kilometres ) * ( kWh / kilometre )
|
68
99
|
characteristics[:distance] * characteristics[:electricity_intensity]
|
69
100
|
end
|
70
101
|
end
|
71
102
|
|
72
|
-
|
73
|
-
#
|
74
|
-
committee :distance do
|
75
|
-
|
76
|
-
#
|
77
|
-
#
|
78
|
-
|
79
|
-
characteristics[:distance_estimate]
|
80
|
-
end
|
103
|
+
### Distance calculation
|
104
|
+
# Returns the `distance` traveled (*km*).
|
105
|
+
committee :distance do
|
106
|
+
#### Distance from client input
|
107
|
+
# **Complies:** All
|
108
|
+
#
|
109
|
+
# Uses the client-input `distance` (*km*).
|
81
110
|
|
82
|
-
|
83
|
-
#
|
84
|
-
|
85
|
-
|
111
|
+
#### Distance from duration and speed
|
112
|
+
# **Complies:** GHG Protocol, ISO-140641, Climate Registry Protocol
|
113
|
+
#
|
114
|
+
# Multiplies the `duration` (*hours*) by the `speed` (*km / hour*) to give *km*.
|
115
|
+
quorum 'from duration and speed', :needs => [:duration, :speed] do |characteristics|
|
86
116
|
characteristics[:duration] * characteristics[:speed]
|
87
117
|
end
|
88
118
|
|
89
|
-
|
90
|
-
#
|
119
|
+
#### Distance from rail class
|
120
|
+
# **Complies:** GHG Protocol, ISO-140641, Climate Registry Protocol
|
121
|
+
#
|
122
|
+
# Looks up the [rail class](http://data.brighterplanet.com/rail_classes) `distance`.
|
91
123
|
quorum 'from rail class', :needs => :rail_class do |characteristics|
|
92
124
|
characteristics[:rail_class].distance
|
93
125
|
end
|
94
126
|
end
|
95
127
|
|
96
|
-
|
97
|
-
#
|
98
|
-
|
99
|
-
|
100
|
-
#
|
128
|
+
### Duration calculation
|
129
|
+
# Returns the trip's `duration` (*hours*).
|
130
|
+
#### Duration from client input
|
131
|
+
# **Complies:** All
|
132
|
+
#
|
133
|
+
# Uses the client-input `duration` (*hours*).
|
134
|
+
|
135
|
+
### Diesel intensity calculation
|
136
|
+
# Returns the `diesel intensity` (*l / km*).
|
137
|
+
committee :diesel_intensity do
|
138
|
+
#### Diesel intensity from rail class
|
139
|
+
# **Complies:** GHG Protocol, ISO-140641, Climate Registry Protocol
|
140
|
+
#
|
141
|
+
# Looks up the [rail class](http://data.brighterplanet.com/rail_classes) `diesel intensity`.
|
101
142
|
quorum 'from rail class', :needs => :rail_class do |characteristics|
|
102
143
|
characteristics[:rail_class].diesel_intensity
|
103
144
|
end
|
104
145
|
end
|
105
146
|
|
106
|
-
|
107
|
-
#
|
108
|
-
committee :electricity_intensity do
|
109
|
-
|
110
|
-
#
|
147
|
+
### Electricity intensity calculation
|
148
|
+
# Returns the `electricity intensity` (*kWh / km*).
|
149
|
+
committee :electricity_intensity do
|
150
|
+
#### Electricity intensity from rail class
|
151
|
+
# **Complies:** GHG Protocol, ISO-140641, Climate Registry Protocol
|
152
|
+
#
|
153
|
+
# Looks up the [rail class](http://data.brighterplanet.com/rail_classes) `electricity intensity`.
|
111
154
|
quorum 'from rail class', :needs => :rail_class do |characteristics|
|
112
155
|
characteristics[:rail_class].electricity_intensity
|
113
156
|
end
|
114
157
|
end
|
115
158
|
|
116
|
-
|
117
|
-
#
|
118
|
-
committee :speed do
|
119
|
-
|
120
|
-
#
|
121
|
-
|
159
|
+
### Speed calculation
|
160
|
+
# Returns the average `speed` (*km / hour*).
|
161
|
+
committee :speed do
|
162
|
+
#### Speed from rail class
|
163
|
+
# **Complies:** GHG Protocol, ISO-140641, Climate Registry Protocol
|
164
|
+
#
|
165
|
+
# Looks up the [rail class](http://data.brighterplanet.com/rail_classes) `speed`.
|
166
|
+
quorum 'from rail class', :needs => :rail_class, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
|
122
167
|
characteristics[:rail_class].speed
|
123
168
|
end
|
124
169
|
end
|
125
170
|
|
126
|
-
|
127
|
-
#
|
171
|
+
### Passengers calculation
|
172
|
+
# Returns the total number of `passengers`.
|
128
173
|
committee :passengers do
|
129
|
-
|
130
|
-
#
|
131
|
-
|
174
|
+
#### Passengers from rail class
|
175
|
+
# **Complies:** GHG Protocol, ISO-140641, Climate Registry Protocol
|
176
|
+
#
|
177
|
+
# Looks up the [rail class](http://data.brighterplanet.com/rail_classes) `passengers`.
|
178
|
+
quorum 'from rail class', :needs => :rail_class, :complies => [:ghg_protocol, :iso, :tcr] do |characteristics|
|
132
179
|
characteristics[:rail_class].passengers
|
133
180
|
end
|
134
181
|
end
|
135
182
|
|
136
|
-
|
137
|
-
#
|
138
|
-
#
|
183
|
+
### Rail class calculation
|
184
|
+
# Returns the [rail class](http://data.brighterplanet.com/rail_classes).
|
185
|
+
# This is the type of rail the trip used.
|
139
186
|
committee :rail_class do
|
187
|
+
#### Rail class from client input
|
188
|
+
# **Complies:** All
|
189
|
+
#
|
190
|
+
# Uses the client-input [rail class](http://data.brighterplanet.com/rail_classes).
|
140
191
|
|
141
|
-
|
142
|
-
#
|
143
|
-
|
144
|
-
|
192
|
+
#### Default rail class
|
193
|
+
# **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
|
194
|
+
#
|
195
|
+
# Uses an artificial [rail class](http://data.brighterplanet.com/rail_classes) representing the U.S. average.
|
196
|
+
quorum 'default', :complies => [:ghg_protocol, :iso, :tcr] do
|
197
|
+
RailClass.find_by_name "US average"
|
145
198
|
end
|
146
199
|
end
|
200
|
+
|
201
|
+
### Date calculation
|
202
|
+
# Returns the `date` on which the trip occurred.
|
203
|
+
committee :date do
|
204
|
+
#### Date from client input
|
205
|
+
# **Complies:** All
|
206
|
+
#
|
207
|
+
# Uses the client-input `date`.
|
208
|
+
|
209
|
+
#### Date from timeframe
|
210
|
+
# **Complies:** GHG Protocol, ISO-14064-1, Climate Registry Protocol
|
211
|
+
#
|
212
|
+
# Assumes the trip occurred on the first day of the `timeframe`.
|
213
|
+
quorum 'from timeframe', :complies => [:ghg_protocol, :iso, :tcr] do |characteristics, timeframe|
|
214
|
+
timeframe.from
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
### Timeframe calculation
|
219
|
+
# Returns the `timeframe`.
|
220
|
+
# This is the period during which to calculate emissions.
|
221
|
+
|
222
|
+
#### Timeframe from client input
|
223
|
+
# **Complies:** All
|
224
|
+
#
|
225
|
+
# Uses the client-input `timeframe`.
|
226
|
+
|
227
|
+
#### Default timeframe
|
228
|
+
# **Complies:** All
|
229
|
+
#
|
230
|
+
# Uses the current calendar year.
|
147
231
|
end
|
148
232
|
end
|
149
233
|
end
|
@@ -24,7 +24,8 @@ module BrighterPlanet
|
|
24
24
|
base.characterize do
|
25
25
|
has :rail_class
|
26
26
|
has :duration, :measures => :time
|
27
|
-
has :
|
27
|
+
has :distance, :measures => :length
|
28
|
+
has :date
|
28
29
|
end
|
29
30
|
|
30
31
|
# Additional characteristics are gleaned from the carbon model.
|
data/lib/rail_trip/data.rb
CHANGED
@@ -19,11 +19,10 @@ module BrighterPlanet
|
|
19
19
|
base.data_miner do
|
20
20
|
# This `schema` block encapsulates the persistence schema.
|
21
21
|
schema do
|
22
|
-
string '
|
23
|
-
date 'date'
|
22
|
+
string 'rail_class_name'
|
24
23
|
float 'duration'
|
25
|
-
float '
|
26
|
-
|
24
|
+
float 'distance'
|
25
|
+
date 'date'
|
27
26
|
end
|
28
27
|
|
29
28
|
# This `process` block indicates that RailTrip's associated classes
|
@@ -20,7 +20,7 @@ module BrighterPlanet
|
|
20
20
|
# This `summarize` block encapsulates the summarization strategy, including
|
21
21
|
# terminology and inflection preference.
|
22
22
|
base.summarize do |has|
|
23
|
-
has.adjective lambda { |rail_trip| "#{rail_trip.
|
23
|
+
has.adjective lambda { |rail_trip| "#{rail_trip.distance_in_miles.adaptive_round(1)}-mile" }, :if => :distance
|
24
24
|
has.adjective lambda { |rail_trip| "#{rail_trip.duration}-hour" }, :if => :duration
|
25
25
|
has.identity 'rail trip'
|
26
26
|
has.verb :take
|
@@ -5,22 +5,5 @@ class RailTripRecord < ActiveRecord::Base
|
|
5
5
|
include BrighterPlanet::RailTrip
|
6
6
|
belongs_to :rail_class
|
7
7
|
|
8
|
-
conversion_accessor :
|
9
|
-
|
10
|
-
falls_back_on
|
11
|
-
|
12
|
-
class << self
|
13
|
-
def research(key)
|
14
|
-
case key
|
15
|
-
when :diesel_emission_factor
|
16
|
-
22.59.pounds_per_gallon.to(:kilograms_per_litre) # CO2 / diesel https://brighterplanet.sifterapp.com/projects/30/issues/455
|
17
|
-
when :electricity_emission_factor
|
18
|
-
1.36.pounds.to(:kilograms) # CO2 / kWh https://brighterplanet.sifterapp.com/projects/30/issues/455
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def emission_date
|
24
|
-
created_at.to_date #FIXME we should add a date characteristic for this emitter
|
25
|
-
end
|
8
|
+
conversion_accessor :distance, :external => :miles, :internal => :kilometres
|
26
9
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rail_trip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 5
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 13
|
10
|
+
version: 0.0.13
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Andy Rossmeissl
|
@@ -18,141 +19,141 @@ autorequire:
|
|
18
19
|
bindir: bin
|
19
20
|
cert_chain: []
|
20
21
|
|
21
|
-
date: 2010-
|
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
|
-
|
34
|
-
- 0
|
35
|
-
version: 3.0.0
|
36
|
+
version: "3"
|
36
37
|
type: :development
|
37
|
-
prerelease: false
|
38
38
|
version_requirements: *id001
|
39
39
|
- !ruby/object:Gem::Dependency
|
40
40
|
name: bundler
|
41
|
+
prerelease: false
|
41
42
|
requirement: &id002 !ruby/object:Gem::Requirement
|
42
43
|
none: false
|
43
44
|
requirements:
|
44
45
|
- - ~>
|
45
46
|
- !ruby/object:Gem::Version
|
47
|
+
hash: 23
|
46
48
|
segments:
|
47
49
|
- 1
|
48
50
|
- 0
|
49
51
|
- 0
|
50
52
|
version: 1.0.0
|
51
53
|
type: :development
|
52
|
-
prerelease: false
|
53
54
|
version_requirements: *id002
|
54
55
|
- !ruby/object:Gem::Dependency
|
55
56
|
name: cucumber
|
57
|
+
prerelease: false
|
56
58
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
59
|
none: false
|
58
60
|
requirements:
|
59
|
-
- -
|
61
|
+
- - ~>
|
60
62
|
- !ruby/object:Gem::Version
|
63
|
+
hash: 57
|
61
64
|
segments:
|
62
65
|
- 0
|
63
66
|
- 8
|
64
67
|
- 3
|
65
68
|
version: 0.8.3
|
66
69
|
type: :development
|
67
|
-
prerelease: false
|
68
70
|
version_requirements: *id003
|
69
71
|
- !ruby/object:Gem::Dependency
|
70
72
|
name: jeweler
|
73
|
+
prerelease: false
|
71
74
|
requirement: &id004 !ruby/object:Gem::Requirement
|
72
75
|
none: false
|
73
76
|
requirements:
|
74
|
-
- -
|
77
|
+
- - ~>
|
75
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 7
|
76
80
|
segments:
|
77
81
|
- 1
|
78
82
|
- 4
|
79
83
|
- 0
|
80
84
|
version: 1.4.0
|
81
85
|
type: :development
|
82
|
-
prerelease: false
|
83
86
|
version_requirements: *id004
|
84
87
|
- !ruby/object:Gem::Dependency
|
85
88
|
name: rake
|
89
|
+
prerelease: false
|
86
90
|
requirement: &id005 !ruby/object:Gem::Requirement
|
87
91
|
none: false
|
88
92
|
requirements:
|
89
93
|
- - ">="
|
90
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
91
96
|
segments:
|
92
97
|
- 0
|
93
98
|
version: "0"
|
94
99
|
type: :development
|
95
|
-
prerelease: false
|
96
100
|
version_requirements: *id005
|
97
101
|
- !ruby/object:Gem::Dependency
|
98
102
|
name: rdoc
|
103
|
+
prerelease: false
|
99
104
|
requirement: &id006 !ruby/object:Gem::Requirement
|
100
105
|
none: false
|
101
106
|
requirements:
|
102
107
|
- - ">="
|
103
108
|
- !ruby/object:Gem::Version
|
109
|
+
hash: 3
|
104
110
|
segments:
|
105
111
|
- 0
|
106
112
|
version: "0"
|
107
113
|
type: :development
|
108
|
-
prerelease: false
|
109
114
|
version_requirements: *id006
|
110
115
|
- !ruby/object:Gem::Dependency
|
111
116
|
name: rspec
|
117
|
+
prerelease: false
|
112
118
|
requirement: &id007 !ruby/object:Gem::Requirement
|
113
119
|
none: false
|
114
120
|
requirements:
|
115
|
-
- -
|
121
|
+
- - ~>
|
116
122
|
- !ruby/object:Gem::Version
|
123
|
+
hash: 7
|
117
124
|
segments:
|
118
125
|
- 2
|
119
|
-
|
120
|
-
- 0
|
121
|
-
- beta
|
122
|
-
- 17
|
123
|
-
version: 2.0.0.beta.17
|
126
|
+
version: "2"
|
124
127
|
type: :development
|
125
|
-
prerelease: false
|
126
128
|
version_requirements: *id007
|
127
129
|
- !ruby/object:Gem::Dependency
|
128
130
|
name: sniff
|
131
|
+
prerelease: false
|
129
132
|
requirement: &id008 !ruby/object:Gem::Requirement
|
130
133
|
none: false
|
131
134
|
requirements:
|
132
|
-
- -
|
135
|
+
- - ">="
|
133
136
|
- !ruby/object:Gem::Version
|
137
|
+
hash: 3
|
134
138
|
segments:
|
135
139
|
- 0
|
136
|
-
|
137
|
-
- 0
|
138
|
-
version: 0.2.0
|
140
|
+
version: "0"
|
139
141
|
type: :development
|
140
|
-
prerelease: false
|
141
142
|
version_requirements: *id008
|
142
143
|
- !ruby/object:Gem::Dependency
|
143
144
|
name: emitter
|
145
|
+
prerelease: false
|
144
146
|
requirement: &id009 !ruby/object:Gem::Requirement
|
145
147
|
none: false
|
146
148
|
requirements:
|
147
149
|
- - ~>
|
148
150
|
- !ruby/object:Gem::Version
|
151
|
+
hash: 13
|
149
152
|
segments:
|
150
153
|
- 0
|
151
|
-
-
|
152
|
-
|
153
|
-
version: 0.1.7
|
154
|
+
- 3
|
155
|
+
version: "0.3"
|
154
156
|
type: :runtime
|
155
|
-
prerelease: false
|
156
157
|
version_requirements: *id009
|
157
158
|
description: A software model in Ruby for the greenhouse gas emissions of an rail_trip
|
158
159
|
email: andy@rossmeissl.net
|
@@ -189,7 +190,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
189
190
|
requirements:
|
190
191
|
- - ">="
|
191
192
|
- !ruby/object:Gem::Version
|
192
|
-
hash:
|
193
|
+
hash: 3
|
193
194
|
segments:
|
194
195
|
- 0
|
195
196
|
version: "0"
|
@@ -198,6 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
199
|
requirements:
|
199
200
|
- - ">="
|
200
201
|
- !ruby/object:Gem::Version
|
202
|
+
hash: 3
|
201
203
|
segments:
|
202
204
|
- 0
|
203
205
|
version: "0"
|