shipment 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/features/shipment_committees.feature +173 -99
- data/features/shipment_emissions.feature +80 -21
- data/features/step_definitions/shipment_steps.rb +1 -1
- data/lib/shipment/carbon_model.rb +61 -34
- data/lib/shipment/characterization.rb +2 -2
- data/lib/shipment/data.rb +2 -2
- data/vendor/plugin/mapquest/lib/mapquest_directions.rb +5 -1
- metadata +48 -24
@@ -1,54 +1,161 @@
|
|
1
1
|
Feature: Shipment Committee Calculations
|
2
2
|
The shipment model should generate correct committee calculations
|
3
3
|
|
4
|
-
Scenario:
|
4
|
+
Scenario: Verified weight from nothing
|
5
5
|
Given a shipment emitter
|
6
|
-
When the "
|
6
|
+
When the "verified_weight" committee is calculated
|
7
7
|
Then the committee should have used quorum "default"
|
8
8
|
And the conclusion of the committee should be "3.4"
|
9
9
|
|
10
|
-
Scenario:
|
10
|
+
Scenario: Verified weight from invalid weight
|
11
11
|
Given a shipment emitter
|
12
|
-
|
12
|
+
And a characteristic "weight" of "0.0"
|
13
|
+
When the "verified_weight" committee is calculated
|
14
|
+
Then the committee should have used quorum "default"
|
15
|
+
And the conclusion of the committee should be "3.4"
|
16
|
+
|
17
|
+
Scenario: Verified weight from valid weight
|
18
|
+
Given a shipment emitter
|
19
|
+
And a characteristic "weight" of "2.0"
|
20
|
+
When the "verified_weight" committee is calculated
|
21
|
+
Then the committee should have used quorum "from weight"
|
22
|
+
And the conclusion of the committee should be "2.0"
|
23
|
+
|
24
|
+
Scenario: Verified package count from nothing
|
25
|
+
Given a shipment emitter
|
26
|
+
When the "verified_package_count" committee is calculated
|
13
27
|
Then the committee should have used quorum "default"
|
14
28
|
And the conclusion of the committee should be "1"
|
15
29
|
|
30
|
+
Scenario: Verified package count from invalid package count
|
31
|
+
Given a shipment emitter
|
32
|
+
And a characteristic "package_count" of "0.0"
|
33
|
+
When the "verified_package_count" committee is calculated
|
34
|
+
Then the committee should have used quorum "default"
|
35
|
+
And the conclusion of the committee should be "1"
|
36
|
+
|
37
|
+
Scenario: Verified package count from valid package count
|
38
|
+
Given a shipment emitter
|
39
|
+
And a characteristic "package_count" of "2"
|
40
|
+
When the "verified_package_count" committee is calculated
|
41
|
+
Then the committee should have used quorum "from package count"
|
42
|
+
And the conclusion of the committee should be "2"
|
43
|
+
|
44
|
+
Scenario Outline: Origin from zip code
|
45
|
+
Given a shipment emitter
|
46
|
+
And a characteristic "origin_zip_code" of "<zip>"
|
47
|
+
When the "origin" committee is calculated
|
48
|
+
Then the committee should have used quorum "from origin zip code"
|
49
|
+
And the conclusion of the committee should be "<origin>"
|
50
|
+
Examples:
|
51
|
+
| zip | origin |
|
52
|
+
| 05753 | 05753 |
|
53
|
+
| 00000 | 00000 |
|
54
|
+
|
55
|
+
Scenario Outline: Origin location from geocodeable origin
|
56
|
+
Given a shipment emitter
|
57
|
+
And a characteristic "origin" of "<origin>"
|
58
|
+
When the "origin_location" committee is calculated
|
59
|
+
Then the committee should have used quorum "from origin"
|
60
|
+
And the conclusion of the committee should be "<location>"
|
61
|
+
Examples:
|
62
|
+
| origin | location |
|
63
|
+
| 05753 | 43.9968185,-73.1491165 |
|
64
|
+
| San Francisco, CA | 37.7749295,-122.4194155 |
|
65
|
+
| Address: 488 Haight Street, San Francisco, CA | 37.7722302,-122.4303328 |
|
66
|
+
| Canterbury, Kent, UK | 51.2772689,1.0805173 |
|
67
|
+
|
68
|
+
Scenario Outline: Origin location from non-geocodeable origin
|
69
|
+
Given a shipment emitter
|
70
|
+
And a characteristic "origin" of "<origin>"
|
71
|
+
When the "origin_location" committee is calculated
|
72
|
+
Then the conclusion of the committee should be nil
|
73
|
+
Examples:
|
74
|
+
| origin |
|
75
|
+
| 00000 |
|
76
|
+
| Bag End, Hobbiton, Westfarthing, The Shire, Eriador, Middle Earth |
|
77
|
+
|
78
|
+
Scenario Outline: Destination from zip code
|
79
|
+
Given a shipment emitter
|
80
|
+
And a characteristic "destination_zip_code" of "<zip>"
|
81
|
+
When the "destination" committee is calculated
|
82
|
+
Then the committee should have used quorum "from destination zip code"
|
83
|
+
And the conclusion of the committee should be "<destination>"
|
84
|
+
Examples:
|
85
|
+
| zip | destination |
|
86
|
+
| 05401 | 05401 |
|
87
|
+
| 00000 | 00000 |
|
88
|
+
|
89
|
+
Scenario Outline: Destination location from geocodeable destination
|
90
|
+
Given a shipment emitter
|
91
|
+
And a characteristic "destination" of "<destination>"
|
92
|
+
When the "destination_location" committee is calculated
|
93
|
+
Then the committee should have used quorum "from destination"
|
94
|
+
And the conclusion of the committee should be "<location>"
|
95
|
+
Examples:
|
96
|
+
| destination | location |
|
97
|
+
| 05401 | 44.4774456,-73.2163467 |
|
98
|
+
| San Francisco, CA | 37.7749295,-122.4194155 |
|
99
|
+
| Address: 488 Haight Street, San Francisco, CA | 37.7722302,-122.4303328 |
|
100
|
+
| Canterbury, Kent, UK | 51.2772689,1.0805173 |
|
101
|
+
|
102
|
+
Scenario Outline: Destination location from non-geocodeable destination
|
103
|
+
Given a shipment emitter
|
104
|
+
And a characteristic "destination" of "<destination>"
|
105
|
+
When the "destination_location" committee is calculated
|
106
|
+
Then the conclusion of the committee should be nil
|
107
|
+
Examples:
|
108
|
+
| destination |
|
109
|
+
| 00000 |
|
110
|
+
| Bag End, Hobbiton, Westfarthing, The Shire, Eriador, Middle Earth |
|
111
|
+
|
16
112
|
Scenario: Segment count from nothing
|
17
113
|
Given a shipment emitter
|
18
114
|
When the "segment_count" committee is calculated
|
19
115
|
Then the committee should have used quorum "default"
|
20
116
|
And the conclusion of the committee should be "5"
|
21
117
|
|
22
|
-
Scenario
|
118
|
+
Scenario: Carrier mode from carrier and mode
|
119
|
+
Given a shipment emitter
|
120
|
+
And a characteristic "carrier.name" of "FedEx"
|
121
|
+
And a characteristic "mode.name" of "ground"
|
122
|
+
When the "carrier_mode" committee is calculated
|
123
|
+
Then the committee should have used quorum "from carrier and mode"
|
124
|
+
And the conclusion of the committee should have "name" of "FedEx ground"
|
125
|
+
|
126
|
+
Scenario Outline: Distance by road from locations and mode
|
23
127
|
Given a shipment emitter
|
24
128
|
And a characteristic "origin" of "<origin>"
|
25
129
|
And a characteristic "destination" of "<destination>"
|
130
|
+
And a characteristic "mode.name" of "<mode>"
|
131
|
+
And a characteristic "mapquest_api_key" of "ABC123"
|
132
|
+
And mapquest determines the distance to be "<mapquest_distance>"
|
26
133
|
When the "origin_location" committee is calculated
|
27
134
|
And the "destination_location" committee is calculated
|
28
135
|
And the "distance" committee is calculated
|
29
|
-
Then the
|
136
|
+
Then the committee should have used quorum "by road"
|
137
|
+
And the conclusion of the committee should be "<distance>"
|
30
138
|
Examples:
|
31
|
-
| origin | destination | distance |
|
32
|
-
| 05753 | 05753 | 0
|
33
|
-
|
34
|
-
|
139
|
+
| origin | destination | mode | mapquest_distance | distance |
|
140
|
+
| 05753 | 05753 | ground | 0.0 | 0.0 |
|
141
|
+
| 05753 | 05401 | ground | 57.93638 | 57.93638 |
|
142
|
+
| 05753 | 05753 | courier | 0.0 | 0.0 |
|
143
|
+
| 05753 | 05401 | courier | 57.93638 | 57.93638 |
|
144
|
+
|
145
|
+
Scenario: Distance by road from undriveable locations and mode
|
35
146
|
Given a shipment emitter
|
36
|
-
And a characteristic "origin" of "
|
37
|
-
And a characteristic "destination" of "
|
147
|
+
And a characteristic "origin" of "Lansing, MI"
|
148
|
+
And a characteristic "destination" of "Canterbury, Kent, UK"
|
38
149
|
And a characteristic "mode.name" of "ground"
|
39
150
|
And a characteristic "mapquest_api_key" of "ABC123"
|
40
|
-
And mapquest determines the distance to be "
|
151
|
+
# And mapquest determines the distance to be "400 Could not find a data set capable of performing the route."
|
41
152
|
When the "origin_location" committee is calculated
|
42
153
|
And the "destination_location" committee is calculated
|
43
154
|
And the "distance" committee is calculated
|
44
|
-
Then the committee should have used quorum "
|
45
|
-
And the conclusion of the committee should be "
|
46
|
-
Examples:
|
47
|
-
| origin | destination | mapquest_distance | distance |
|
48
|
-
| 05753 | 05401 | 53 | 53 |
|
49
|
-
| 05753 | 05401 | 33 | 33 |
|
155
|
+
Then the committee should have used quorum "as the crow flies"
|
156
|
+
And the conclusion of the committee should be "6192.60039"
|
50
157
|
|
51
|
-
Scenario Outline: Distance from
|
158
|
+
Scenario Outline: Distance as the crow flies from locations and mode
|
52
159
|
Given a shipment emitter
|
53
160
|
And a characteristic "origin" of "<origin>"
|
54
161
|
And a characteristic "destination" of "<destination>"
|
@@ -57,76 +164,28 @@ Feature: Shipment Committee Calculations
|
|
57
164
|
When the "origin_location" committee is calculated
|
58
165
|
And the "destination_location" committee is calculated
|
59
166
|
And the "distance" committee is calculated
|
60
|
-
Then the committee should have used quorum "
|
167
|
+
Then the committee should have used quorum "as the crow flies"
|
61
168
|
And the conclusion of the committee should be "<distance>"
|
62
169
|
Examples:
|
63
170
|
| origin | destination | distance |
|
64
|
-
| 05753 |
|
171
|
+
| 05753 | 05401 | 53.75967 |
|
65
172
|
| Lansing, MI | Canterbury, Kent, UK | 6192.60039 |
|
66
|
-
| 05753 | Canterbury, Kent, UK | 5384.08989 |
|
67
173
|
|
68
|
-
Scenario
|
174
|
+
Scenario: Distance as the crow flies from locations
|
69
175
|
Given a shipment emitter
|
70
|
-
And a characteristic "origin" of "
|
176
|
+
And a characteristic "origin" of "05753"
|
177
|
+
And a characteristic "destination" of "05401"
|
71
178
|
When the "origin_location" committee is calculated
|
72
|
-
Then the committee should have used quorum "from origin"
|
73
|
-
And the conclusion of the committee should be "<location>"
|
74
|
-
Examples:
|
75
|
-
| origin | location |
|
76
|
-
| 05753 | 43.9968185,-73.1491165 |
|
77
|
-
| Address: San Francisco, CA | 37.7749295,-122.4194155 |
|
78
|
-
| Address: 488 Haight Street, San Francisco, CA | 37.7721568,-122.4302295 |
|
79
|
-
| Address: Canterbury, Kent, UK | 51.2772689,1.0805173 |
|
80
|
-
|
81
|
-
Scenario Outline: Origin location from origin_zip_code
|
82
|
-
Given a shipment emitter
|
83
|
-
And a characteristic "origin_zip_code" of "<origin>"
|
84
|
-
When the "origin" committee is calculated
|
85
|
-
And the "origin_location" committee is calculated
|
86
|
-
Then the conclusion of the committee should be "<location>"
|
87
|
-
Examples:
|
88
|
-
| origin | location |
|
89
|
-
| 05753 | 43.9968185,-73.1491165 |
|
90
|
-
|
91
|
-
Scenario Outline: Destination location from destination
|
92
|
-
Given a shipment emitter
|
93
|
-
And a characteristic "destination" of "<destination>"
|
94
|
-
When the "destination_location" committee is calculated
|
95
|
-
Then the committee should have used quorum "from destination"
|
96
|
-
And the conclusion of the committee should be "<location>"
|
97
|
-
Examples:
|
98
|
-
| destination | location |
|
99
|
-
| 05753 | 43.9968185,-73.1491165 |
|
100
|
-
| Address: 488 Haight Street, San Francisco, CA | 37.7721568,-122.4302295 |
|
101
|
-
| Address: Canterbury, Kent, UK | 51.2772689,1.0805173 |
|
102
|
-
|
103
|
-
Scenario Outline: Destination location from destination_zip_code
|
104
|
-
Given a shipment emitter
|
105
|
-
And a characteristic "destination_zip_code" of "<destination>"
|
106
|
-
When the "destination" committee is calculated
|
107
179
|
And the "destination_location" committee is calculated
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
| 05753 | 43.9968185,-73.1491165 |
|
112
|
-
|
113
|
-
Scenario: Origin committee from uncodable origin
|
114
|
-
Given a shipment emitter
|
115
|
-
And a characteristic "origin" of "Bag End, Hobbiton, Westfarthing, The Shire, Eriador, Middle Earth"
|
116
|
-
When the "origin_location" committee is calculated
|
117
|
-
Then the conclusion of the committee should be nil
|
118
|
-
|
119
|
-
Scenario: Destination committee from uncodable destination
|
120
|
-
Given a shipment emitter
|
121
|
-
And a characteristic "destination" of "Bag End, Hobbiton, Westfarthing, The Shire, Eriador, Middle Earth"
|
122
|
-
When the "destination_location" committee is calculated
|
123
|
-
Then the conclusion of the committee should be nil
|
180
|
+
And the "distance" committee is calculated
|
181
|
+
Then the committee should have used quorum "as the crow flies"
|
182
|
+
And the conclusion of the committee should be "53.75967"
|
124
183
|
|
125
184
|
Scenario: Route inefficiency factor from default
|
126
185
|
Given a shipment emitter
|
127
186
|
When the "route_inefficiency_factor" committee is calculated
|
128
187
|
Then the committee should have used quorum "default"
|
129
|
-
And the conclusion of the committee should be "1.
|
188
|
+
And the conclusion of the committee should be "1.03"
|
130
189
|
|
131
190
|
Scenario Outline: Route inefficiency factor from mode
|
132
191
|
Given a shipment emitter
|
@@ -136,17 +195,10 @@ Feature: Shipment Committee Calculations
|
|
136
195
|
And the conclusion of the committee should be "<factor>"
|
137
196
|
Examples:
|
138
197
|
| mode | factor |
|
139
|
-
| courier |
|
198
|
+
| courier | 1.0 |
|
140
199
|
| ground | 1.0 |
|
141
200
|
| air | 1.1 |
|
142
201
|
|
143
|
-
Scenario: Dogleg factor from default segment count
|
144
|
-
Given a shipment emitter
|
145
|
-
When the "segment_count" committee is calculated
|
146
|
-
And the "dogleg_factor" committee is calculated
|
147
|
-
Then the committee should have used quorum "from segment count"
|
148
|
-
And the conclusion of the committee should be "5.0625"
|
149
|
-
|
150
202
|
Scenario Outline: Dogleg factor from segment count
|
151
203
|
Given a shipment emitter
|
152
204
|
And a characteristic "segment_count" of "<segments>"
|
@@ -156,7 +208,8 @@ Feature: Shipment Committee Calculations
|
|
156
208
|
Examples:
|
157
209
|
| segments | factor |
|
158
210
|
| 1 | 1.0 |
|
159
|
-
|
|
211
|
+
| 5 | 1.8 |
|
212
|
+
| -1 | 1.8 |
|
160
213
|
|
161
214
|
Scenario: Adjusted distance from default
|
162
215
|
Given a shipment emitter
|
@@ -177,50 +230,71 @@ Feature: Shipment Committee Calculations
|
|
177
230
|
Given a shipment emitter
|
178
231
|
When the "transport_emission_factor" committee is calculated
|
179
232
|
Then the committee should have used quorum "default"
|
180
|
-
And the conclusion of the committee should be "0.
|
233
|
+
And the conclusion of the committee should be "0.0005266"
|
181
234
|
|
182
|
-
Scenario Outline: Transport emission factor from
|
235
|
+
Scenario Outline: Transport emission factor from carrier
|
236
|
+
Given a shipment emitter
|
237
|
+
And a characteristic "carrier.name" of "FedEx"
|
238
|
+
When the "transport_emission_factor" committee is calculated
|
239
|
+
Then the committee should have used quorum "from carrier"
|
240
|
+
And the conclusion of the committee should be "1.0"
|
241
|
+
|
242
|
+
Scenario Outline: Transport emission factor from mode, verified weight, and adjusted distance
|
183
243
|
Given a shipment emitter
|
184
244
|
And a characteristic "mode.name" of "<mode>"
|
185
|
-
And a characteristic "
|
245
|
+
And a characteristic "verified_weight" of "<weight>"
|
186
246
|
And a characteristic "adjusted_distance" of "<adjusted_distance>"
|
187
247
|
When the "transport_emission_factor" committee is calculated
|
188
|
-
Then the committee should have used quorum "from mode, weight, and adjusted distance"
|
248
|
+
Then the committee should have used quorum "from mode, verified weight, and adjusted distance"
|
189
249
|
And the conclusion of the committee should be "<emission_factor>"
|
190
250
|
Examples:
|
191
251
|
| mode | weight | adjusted_distance | emission_factor |
|
192
|
-
| courier | 2.0 | 5.0 | 0
|
252
|
+
| courier | 2.0 | 5.0 | 100.0 |
|
193
253
|
| ground | 2.0 | 50.0 | 1.0 |
|
194
254
|
| air | 2.0 | 50.0 | 5.0 |
|
195
255
|
|
256
|
+
Scenario Outline: Transport emission factor from carrier mode, verified weight, and adjusted distance
|
257
|
+
Given a shipment emitter
|
258
|
+
And a characteristic "carrier_mode.name" of "<carrier_mode>"
|
259
|
+
And a characteristic "verified_weight" of "<weight>"
|
260
|
+
And a characteristic "adjusted_distance" of "<adjusted_distance>"
|
261
|
+
When the "transport_emission_factor" committee is calculated
|
262
|
+
Then the committee should have used quorum "from carrier mode, verified weight, and adjusted distance"
|
263
|
+
And the conclusion of the committee should be "<emission_factor>"
|
264
|
+
Examples:
|
265
|
+
| carrier_mode | weight | adjusted_distance | emission_factor |
|
266
|
+
| FedEx courier | 2.0 | 5.0 | 110.0 |
|
267
|
+
| FedEx ground | 2.0 | 50.0 | 2.0 |
|
268
|
+
| FedEx air | 2.0 | 50.0 | 6.0 |
|
269
|
+
|
196
270
|
Scenario: Corporate emission factor from default
|
197
271
|
Given a shipment emitter
|
198
272
|
When the "corporate_emission_factor" committee is calculated
|
199
273
|
Then the committee should have used quorum "default"
|
200
|
-
And the conclusion of the committee should be "0.
|
274
|
+
And the conclusion of the committee should be "0.221"
|
201
275
|
|
202
276
|
Scenario: Corporate emission factor from carrier
|
203
277
|
Given a shipment emitter
|
204
278
|
And a characteristic "carrier.name" of "FedEx"
|
205
279
|
When the "corporate_emission_factor" committee is calculated
|
206
280
|
Then the committee should have used quorum "from carrier"
|
207
|
-
And the conclusion of the committee should be "
|
281
|
+
And the conclusion of the committee should be "1500.0"
|
208
282
|
|
209
|
-
Scenario: Transport emission from weight, adjusted distance, and transport emission factor
|
283
|
+
Scenario: Transport emission from verified weight, adjusted distance, and transport emission factor
|
210
284
|
Given a shipment emitter
|
211
|
-
And a characteristic "
|
285
|
+
And a characteristic "verified_weight" of "2.0"
|
212
286
|
And a characteristic "adjusted_distance" of "100.0"
|
213
287
|
And a characteristic "transport_emission_factor" of "2.0"
|
214
288
|
When the "transport_emission" committee is calculated
|
215
|
-
Then the committee should have used quorum "from weight, adjusted distance, and transport emission factor"
|
289
|
+
Then the committee should have used quorum "from verified weight, adjusted distance, and transport emission factor"
|
216
290
|
And the conclusion of the committee should be "400.0"
|
217
291
|
|
218
|
-
Scenario: Corporate emission from package count and corporate emission factor
|
292
|
+
Scenario: Corporate emission from verified package count and corporate emission factor
|
219
293
|
Given a shipment emitter
|
220
|
-
And a characteristic "
|
294
|
+
And a characteristic "verified_package_count" of "2"
|
221
295
|
And a characteristic "corporate_emission_factor" of "2.0"
|
222
296
|
When the "corporate_emission" committee is calculated
|
223
|
-
Then the committee should have used quorum "from package count and corporate emission factor"
|
297
|
+
Then the committee should have used quorum "from verified package count and corporate emission factor"
|
224
298
|
And the conclusion of the committee should be "4.0"
|
225
299
|
|
226
300
|
Scenario: Emission from transport emission and corporate emission
|
@@ -4,29 +4,31 @@ Feature: Shipment Emissions Calculations
|
|
4
4
|
Scenario: Calculations starting from nothing
|
5
5
|
Given a shipment has nothing
|
6
6
|
When emissions are calculated
|
7
|
-
Then the emission value should be within "0.1" kgs of "
|
7
|
+
Then the emission value should be within "0.1" kgs of "6.0"
|
8
8
|
|
9
9
|
Scenario: Calculations from weight, package count, segment count
|
10
10
|
Given a shipment has "weight" of "10"
|
11
11
|
And it has "package_count" of "2"
|
12
12
|
And it has "segment_count" of "1"
|
13
13
|
When emissions are calculated
|
14
|
-
Then the emission value should be within "0.1" kgs of "
|
14
|
+
Then the emission value should be within "0.1" kgs of "17.4"
|
15
15
|
|
16
|
-
Scenario
|
17
|
-
Given a shipment has "
|
18
|
-
And it has "
|
16
|
+
Scenario: Calculations from origin/destination zip code
|
17
|
+
Given a shipment has "origin_zip_code" of "05753"
|
18
|
+
And it has "destination_zip_code" of "05401"
|
19
19
|
When emissions are calculated
|
20
|
-
Then the emission value should be within "0.1" kgs of "
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
Then the emission value should be within "0.1" kgs of "0.4"
|
21
|
+
|
22
|
+
Scenario: Calculations from origin/destination
|
23
|
+
Given a shipment has "origin" of "Lansing, MI"
|
24
|
+
And it has "destination" of "Canterbury, Kent, UK"
|
25
|
+
When emissions are calculated
|
26
|
+
Then the emission value should be within "0.1" kgs of "20.8"
|
25
27
|
|
26
28
|
Scenario: Calculations from carrier
|
27
29
|
Given a shipment has "carrier.name" of "FedEx"
|
28
30
|
When emissions are calculated
|
29
|
-
Then the emission value should be within "0.1" kgs of "
|
31
|
+
Then the emission value should be within "0.1" kgs of "34333.8"
|
30
32
|
|
31
33
|
Scenario Outline: Calculations from mode
|
32
34
|
Given a shipment has "mode.name" of "<mode>"
|
@@ -34,9 +36,20 @@ Feature: Shipment Emissions Calculations
|
|
34
36
|
Then the emission value should be within "0.1" kgs of "<emission>"
|
35
37
|
Examples:
|
36
38
|
| mode | emission |
|
37
|
-
| courier | 2
|
38
|
-
| ground | 10944.
|
39
|
-
| air | 54723.
|
39
|
+
| courier | 1000.2 |
|
40
|
+
| ground | 10944.8 |
|
41
|
+
| air | 54723.2 |
|
42
|
+
|
43
|
+
Scenario Outline: Calculations from carrier and mode
|
44
|
+
Given a shipment has "mode.name" of "<mode>"
|
45
|
+
And it has "carrier.name" of "FedEx"
|
46
|
+
When emissions are calculated
|
47
|
+
Then the emission value should be within "0.1" kgs of "<emission>"
|
48
|
+
Examples:
|
49
|
+
| mode | emission |
|
50
|
+
| courier | 2600.0 |
|
51
|
+
| ground | 23389.2 |
|
52
|
+
| air | 67167.6 |
|
40
53
|
|
41
54
|
Scenario Outline: Calculations from mode and origin/destination
|
42
55
|
Given a shipment has "mode.name" of "<mode>"
|
@@ -45,10 +58,56 @@ Feature: Shipment Emissions Calculations
|
|
45
58
|
When emissions are calculated
|
46
59
|
Then the emission value should be within "0.1" kgs of "<emission>"
|
47
60
|
Examples:
|
48
|
-
| mode | origin
|
49
|
-
| courier | 05753
|
50
|
-
| courier |
|
51
|
-
| ground | 05753
|
52
|
-
| ground |
|
53
|
-
| air | 05753
|
54
|
-
| air |
|
61
|
+
| mode | origin | destination | emission |
|
62
|
+
| courier | 05753 | 05401 | 1000.2 |
|
63
|
+
| courier | Lansing, MI | Canterbury, Kent, UK | 1000.2 |
|
64
|
+
| ground | 05753 | 05401 | 329.2 |
|
65
|
+
| ground | Lansing, MI | Canterbury, Kent, UK | 37898.9 |
|
66
|
+
| air | 05753 | 05401 | 1809.8 |
|
67
|
+
| air | Lansing, MI | Canterbury, Kent, UK | 208443.2 |
|
68
|
+
|
69
|
+
Scenario Outline: Calculations from mode and carrier
|
70
|
+
Given a shipment has "carrier.name" of "FedEx"
|
71
|
+
And it has "mode.name" of "<mode>"
|
72
|
+
When emissions are calculated
|
73
|
+
Then the emission value should be within "0.1" kgs of "<emission>"
|
74
|
+
Examples:
|
75
|
+
| mode | emission |
|
76
|
+
| courier | 2600.0 |
|
77
|
+
| ground | 23389.2 |
|
78
|
+
| air | 67167.6 |
|
79
|
+
|
80
|
+
Scenario Outline: Calculations from mode, carrier, and origin/destination
|
81
|
+
Given a shipment has "carrier.name" of "FedEx"
|
82
|
+
And it has "mode.name" of "<mode>"
|
83
|
+
And it has "origin" of "<origin>"
|
84
|
+
And it has "destination" of "<destination>"
|
85
|
+
When emissions are calculated
|
86
|
+
Then the emission value should be within "0.1" kgs of "<emission>"
|
87
|
+
Examples:
|
88
|
+
| mode | origin | destination | emission |
|
89
|
+
| courier | 05753 | 05401 | 2600.0 |
|
90
|
+
| courier | Lansing, MI | Canterbury, Kent, UK | 2600.0 |
|
91
|
+
| ground | 05753 | 05401 | 2158.0 |
|
92
|
+
| ground | Lansing, MI | Canterbury, Kent, UK | 77297.4 |
|
93
|
+
| air | 05753 | 05401 | 3671.5 |
|
94
|
+
| air | Lansing, MI | Canterbury, Kent, UK | 251631.5 |
|
95
|
+
|
96
|
+
Scenario Outline: Calculations from everything
|
97
|
+
Given a shipment has "weight" of "10.0"
|
98
|
+
And it has "package_count" of "2.0"
|
99
|
+
And it has "segment_count" of "1.0"
|
100
|
+
And it has "carrier.name" of "FedEx"
|
101
|
+
And it has "mode.name" of "<mode>"
|
102
|
+
And it has "origin" of "<origin>"
|
103
|
+
And it has "destination" of "<destination>"
|
104
|
+
When emissions are calculated
|
105
|
+
Then the emission value should be within "0.1" kgs of "<emission>"
|
106
|
+
Examples:
|
107
|
+
| mode | origin | destination | emission |
|
108
|
+
| courier | 05753 | 05401 | 4100.0 |
|
109
|
+
| courier | Lansing, MI | Canterbury, Kent, UK | 4100.0 |
|
110
|
+
| ground | 05753 | 05401 | 4075.2 |
|
111
|
+
| ground | Lansing, MI | Canterbury, Kent, UK | 126852.0 |
|
112
|
+
| air | 05753 | 05401 | 6548.1 |
|
113
|
+
| air | Lansing, MI | Canterbury, Kent, UK | 411711.6 |
|
@@ -1,4 +1,4 @@
|
|
1
1
|
Given /^mapquest determines the distance to be "([^\"]*)"$/ do |distance|
|
2
|
-
mockquest = mock MapQuestDirections, :
|
2
|
+
mockquest = mock MapQuestDirections, :distance_in_kilometres => distance
|
3
3
|
MapQuestDirections.stub!(:new).and_return mockquest
|
4
4
|
end
|
@@ -35,23 +35,15 @@ module BrighterPlanet
|
|
35
35
|
end
|
36
36
|
|
37
37
|
committee :corporate_emission do
|
38
|
-
quorum 'from package count and corporate emission factor', :needs => [:
|
39
|
-
|
40
|
-
characteristics[:package_count] * characteristics[:corporate_emission_factor]
|
41
|
-
else
|
42
|
-
raise "Invalid package_count: #{:package_count} (must be > 0)"
|
43
|
-
end
|
38
|
+
quorum 'from verified package count and corporate emission factor', :needs => [:verified_package_count, :corporate_emission_factor] do |characteristics|
|
39
|
+
characteristics[:verified_package_count] * characteristics[:corporate_emission_factor]
|
44
40
|
end
|
45
41
|
end
|
46
42
|
|
47
43
|
committee :transport_emission do
|
48
|
-
quorum 'from weight, adjusted distance, and transport emission factor', :needs => [:
|
49
|
-
# we're assuming
|
50
|
-
|
51
|
-
characteristics[:weight] * characteristics[:adjusted_distance] * characteristics[:transport_emission_factor]
|
52
|
-
else
|
53
|
-
raise "Invalid weight: :weight (must be > 0)"
|
54
|
-
end
|
44
|
+
quorum 'from verified weight, adjusted distance, and transport emission factor', :needs => [:verified_weight, :adjusted_distance, :transport_emission_factor] do |characteristics|
|
45
|
+
# we're assuming that the number of stops, rather than number of packages carried, is limiting factor on local delivery routes
|
46
|
+
characteristics[:verified_weight] * characteristics[:adjusted_distance] * characteristics[:transport_emission_factor]
|
55
47
|
end
|
56
48
|
end
|
57
49
|
|
@@ -66,16 +58,28 @@ module BrighterPlanet
|
|
66
58
|
end
|
67
59
|
|
68
60
|
committee :transport_emission_factor do
|
69
|
-
quorum 'from mode, weight, and adjusted distance', :needs => [:
|
61
|
+
quorum 'from carrier mode, verified weight, and adjusted distance', :needs => [:carrier_mode, :verified_weight, :adjusted_distance] do |characteristics|
|
62
|
+
if characteristics[:carrier_mode].mode_name == "courier"
|
63
|
+
characteristics[:carrier_mode].transport_emission_factor / (characteristics[:verified_weight] * characteristics[:adjusted_distance])
|
64
|
+
else
|
65
|
+
characteristics[:carrier_mode].transport_emission_factor
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
quorum 'from mode, verified weight, and adjusted distance', :needs => [:mode, :verified_weight, :adjusted_distance] do |characteristics|
|
70
70
|
if characteristics[:mode].name == "courier"
|
71
|
-
characteristics[:mode].transport_emission_factor / (characteristics[:
|
71
|
+
characteristics[:mode].transport_emission_factor / (characteristics[:verified_weight] * characteristics[:adjusted_distance])
|
72
72
|
else
|
73
73
|
characteristics[:mode].transport_emission_factor
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
+
quorum 'from carrier', :needs => :carrier do |characteristics|
|
78
|
+
characteristics[:carrier].transport_emission_factor
|
79
|
+
end
|
80
|
+
|
77
81
|
quorum 'default' do
|
78
|
-
|
82
|
+
Carrier.fallback.transport_emission_factor
|
79
83
|
end
|
80
84
|
end
|
81
85
|
|
@@ -88,12 +92,11 @@ module BrighterPlanet
|
|
88
92
|
3219 # ASSUMED: arbitrary
|
89
93
|
end
|
90
94
|
end
|
91
|
-
|
95
|
+
|
92
96
|
committee :dogleg_factor do
|
93
97
|
quorum 'from segment count', :needs => :segment_count do |characteristics|
|
94
|
-
if characteristics[:segment_count]
|
95
|
-
|
96
|
-
1.5 ** (characteristics[:segment_count] - 1)
|
98
|
+
if characteristics[:segment_count] == 1
|
99
|
+
1.0
|
97
100
|
else
|
98
101
|
1.8 # based on our sample FedEx tracking numbers
|
99
102
|
end
|
@@ -106,25 +109,25 @@ module BrighterPlanet
|
|
106
109
|
end
|
107
110
|
|
108
111
|
quorum 'default' do
|
109
|
-
|
112
|
+
Carrier.fallback.route_inefficiency_factor
|
110
113
|
end
|
111
114
|
end
|
112
|
-
|
115
|
+
|
113
116
|
committee :distance do
|
114
|
-
quorum '
|
115
|
-
if characteristics[:origin_location] == characteristics[:destination_location]
|
116
|
-
0
|
117
|
-
end
|
118
|
-
end
|
119
|
-
quorum 'from mapquest', :needs => [:origin_location, :destination_location, :mode, :mapquest_api_key] do |characteristics|
|
117
|
+
quorum 'by road', :needs => [:origin_location, :destination_location, :mode, :mapquest_api_key] do |characteristics|
|
120
118
|
unless characteristics[:mode].name == 'air'
|
121
119
|
mapquest = MapQuestDirections.new characteristics[:origin_location],
|
122
120
|
characteristics[:destination_location],
|
123
121
|
characteristics[:mapquest_api_key]
|
124
|
-
|
122
|
+
begin
|
123
|
+
mapquest.distance_in_kilometres
|
124
|
+
rescue
|
125
|
+
nil
|
126
|
+
end
|
125
127
|
end
|
126
128
|
end
|
127
|
-
|
129
|
+
|
130
|
+
quorum 'as the crow flies', :needs => [:origin_location, :destination_location] do |characteristics|
|
128
131
|
Mapper.distance_between(
|
129
132
|
characteristics[:origin_location],
|
130
133
|
characteristics[:destination_location],
|
@@ -132,6 +135,12 @@ module BrighterPlanet
|
|
132
135
|
end
|
133
136
|
end
|
134
137
|
|
138
|
+
committee :carrier_mode do
|
139
|
+
quorum 'from carrier and mode', :needs => [:carrier, :mode] do |characteristics|
|
140
|
+
CarrierMode.find_by_carrier_name_and_mode_name(characteristics[:carrier].name, characteristics[:mode].name)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
135
144
|
committee :segment_count do
|
136
145
|
quorum 'default' do
|
137
146
|
# ASSUMED based on the fact that FedEx has a hub-spoke system with central and regional distribution centers so seems reasonable for average package to go through four FedEx facilities
|
@@ -147,7 +156,8 @@ module BrighterPlanet
|
|
147
156
|
end
|
148
157
|
|
149
158
|
committee :destination do
|
150
|
-
|
159
|
+
# For backwards compatability
|
160
|
+
quorum 'from destination zip code', :needs => :destination_zip_code do |characteristics|
|
151
161
|
characteristics[:destination_zip_code]
|
152
162
|
end
|
153
163
|
end
|
@@ -160,18 +170,35 @@ module BrighterPlanet
|
|
160
170
|
end
|
161
171
|
|
162
172
|
committee :origin do
|
163
|
-
|
173
|
+
# For backwards compatability
|
174
|
+
quorum 'from origin zip code', :needs => :origin_zip_code do |characteristics|
|
164
175
|
characteristics[:origin_zip_code]
|
165
176
|
end
|
166
177
|
end
|
167
178
|
|
168
|
-
committee :
|
179
|
+
committee :verified_package_count do
|
180
|
+
quorum 'from package count', :needs => :package_count do |characteristics|
|
181
|
+
if characteristics[:package_count] > 0
|
182
|
+
characteristics[:package_count]
|
183
|
+
else
|
184
|
+
nil
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
169
188
|
quorum 'default' do
|
170
189
|
1 # ASSUMED arbitrary
|
171
190
|
end
|
172
191
|
end
|
173
192
|
|
174
|
-
committee :
|
193
|
+
committee :verified_weight do
|
194
|
+
quorum 'from weight', :needs => :weight do |characteristics|
|
195
|
+
if characteristics[:weight] > 0
|
196
|
+
characteristics[:weight]
|
197
|
+
else
|
198
|
+
nil
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
175
202
|
quorum 'default' do
|
176
203
|
3.4 # ASSUMED based on average FedEx air package weight of 7.5 lbs
|
177
204
|
end
|
@@ -10,8 +10,8 @@ module BrighterPlanet
|
|
10
10
|
has :segment_count
|
11
11
|
has :origin
|
12
12
|
has :destination
|
13
|
-
has :origin_zip_code
|
14
|
-
has :destination_zip_code
|
13
|
+
has :origin_zip_code # for backwards compatability - note that this is a string, not a ZipCode
|
14
|
+
has :destination_zip_code # for backwards compatability - note that this is a string, not a ZipCode
|
15
15
|
has :mapquest_api_key, :display => lambda { |key| "secret key" }
|
16
16
|
end
|
17
17
|
end
|
data/lib/shipment/data.rb
CHANGED
@@ -11,8 +11,8 @@ module BrighterPlanet
|
|
11
11
|
integer 'segment_count'
|
12
12
|
string 'origin'
|
13
13
|
string 'destination'
|
14
|
-
string 'origin_zip_code'
|
15
|
-
string 'destination_zip_code'
|
14
|
+
string 'origin_zip_code' # For backwards compatability
|
15
|
+
string 'destination_zip_code' # For backwards compatability
|
16
16
|
string 'mapquest_api_key'
|
17
17
|
end
|
18
18
|
|
@@ -33,9 +33,13 @@ class MapQuestDirections
|
|
33
33
|
convert_to_minutes(drive_time)
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def distance_in_kilometres
|
37
37
|
distance_in_miles = doc.css("distance").first.text.to_i
|
38
38
|
end
|
39
|
+
|
40
|
+
def distance_in_kilometres
|
41
|
+
distance_in_kilometres = doc.css("distance").first.text.to_f.miles.to(:kilometres)
|
42
|
+
end
|
39
43
|
|
40
44
|
private
|
41
45
|
def convert_to_minutes(text)
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shipment
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Andy Rossmeissl
|
@@ -18,95 +19,117 @@ autorequire:
|
|
18
19
|
bindir: bin
|
19
20
|
cert_chain: []
|
20
21
|
|
21
|
-
date: 2010-12-
|
22
|
+
date: 2010-12-16 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: rake
|
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
|
-
name:
|
72
|
+
name: sniff
|
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
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
- 4
|
83
|
+
- 4
|
84
|
+
version: 0.4.4
|
85
|
+
type: :development
|
86
|
+
version_requirements: *id004
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: emitter
|
89
|
+
prerelease: false
|
90
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ~>
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
hash: 19
|
74
96
|
segments:
|
75
97
|
- 0
|
76
98
|
- 3
|
77
99
|
- 0
|
78
100
|
version: 0.3.0
|
79
101
|
type: :runtime
|
80
|
-
|
81
|
-
version_requirements: *id004
|
102
|
+
version_requirements: *id005
|
82
103
|
- !ruby/object:Gem::Dependency
|
83
104
|
name: earth
|
84
|
-
|
105
|
+
prerelease: false
|
106
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
85
107
|
none: false
|
86
108
|
requirements:
|
87
109
|
- - ~>
|
88
110
|
- !ruby/object:Gem::Version
|
111
|
+
hash: 1
|
89
112
|
segments:
|
90
113
|
- 0
|
91
114
|
- 3
|
92
|
-
-
|
93
|
-
version: 0.3.
|
115
|
+
- 9
|
116
|
+
version: 0.3.9
|
94
117
|
type: :runtime
|
95
|
-
|
96
|
-
version_requirements: *id005
|
118
|
+
version_requirements: *id006
|
97
119
|
- !ruby/object:Gem::Dependency
|
98
120
|
name: geokit
|
99
|
-
|
121
|
+
prerelease: false
|
122
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
100
123
|
none: false
|
101
124
|
requirements:
|
102
125
|
- - ">="
|
103
126
|
- !ruby/object:Gem::Version
|
127
|
+
hash: 3
|
104
128
|
segments:
|
105
129
|
- 0
|
106
130
|
version: "0"
|
107
131
|
type: :runtime
|
108
|
-
|
109
|
-
version_requirements: *id006
|
132
|
+
version_requirements: *id007
|
110
133
|
description: A software model in Ruby for the greenhouse gas emissions of a shipment
|
111
134
|
email: andy@rossmeissl.net
|
112
135
|
executables: []
|
@@ -127,14 +150,14 @@ files:
|
|
127
150
|
- lib/shipment/relationships.rb
|
128
151
|
- lib/shipment/summarization.rb
|
129
152
|
- lib/test_support/shipment_record.rb
|
130
|
-
- features/support/env.rb
|
131
153
|
- features/step_definitions/shipment_steps.rb
|
154
|
+
- features/support/env.rb
|
132
155
|
- features/shipment_committees.feature
|
133
156
|
- features/shipment_emissions.feature
|
134
|
-
- vendor/plugin/mapquest/spec/lib/mapquest_directions_spec.rb
|
135
|
-
- vendor/plugin/mapquest/spec/spec_helper.rb
|
136
157
|
- vendor/plugin/mapquest/init.rb
|
137
158
|
- vendor/plugin/mapquest/lib/mapquest_directions.rb
|
159
|
+
- vendor/plugin/mapquest/spec/lib/mapquest_directions_spec.rb
|
160
|
+
- vendor/plugin/mapquest/spec/spec_helper.rb
|
138
161
|
has_rdoc: true
|
139
162
|
homepage: http://brighterplanet.github.com/shipment
|
140
163
|
licenses: []
|
@@ -149,7 +172,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
172
|
requirements:
|
150
173
|
- - ">="
|
151
174
|
- !ruby/object:Gem::Version
|
152
|
-
hash:
|
175
|
+
hash: 3
|
153
176
|
segments:
|
154
177
|
- 0
|
155
178
|
version: "0"
|
@@ -158,6 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
181
|
requirements:
|
159
182
|
- - ">="
|
160
183
|
- !ruby/object:Gem::Version
|
184
|
+
hash: 3
|
161
185
|
segments:
|
162
186
|
- 0
|
163
187
|
version: "0"
|
@@ -169,12 +193,12 @@ signing_key:
|
|
169
193
|
specification_version: 3
|
170
194
|
summary: A carbon model for a shipment
|
171
195
|
test_files:
|
172
|
-
- features/support/env.rb
|
173
196
|
- features/step_definitions/shipment_steps.rb
|
197
|
+
- features/support/env.rb
|
174
198
|
- features/shipment_committees.feature
|
175
199
|
- features/shipment_emissions.feature
|
176
200
|
- lib/test_support/shipment_record.rb
|
177
|
-
- vendor/plugin/mapquest/spec/lib/mapquest_directions_spec.rb
|
178
|
-
- vendor/plugin/mapquest/spec/spec_helper.rb
|
179
201
|
- vendor/plugin/mapquest/init.rb
|
180
202
|
- vendor/plugin/mapquest/lib/mapquest_directions.rb
|
203
|
+
- vendor/plugin/mapquest/spec/lib/mapquest_directions_spec.rb
|
204
|
+
- vendor/plugin/mapquest/spec/spec_helper.rb
|