shipment 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,206 @@
1
+ Feature: Shipment Committee Calculations
2
+ The shipment model should generate correct committee calculations
3
+
4
+ Scenario: Weight from nothing
5
+ Given a shipment emitter
6
+ When the "weight" committee is calculated
7
+ Then the committee should have used quorum "default"
8
+ And the conclusion of the committee should be "3.4"
9
+
10
+ Scenario: Package count from nothing
11
+ Given a shipment emitter
12
+ When the "package_count" committee is calculated
13
+ Then the committee should have used quorum "default"
14
+ And the conclusion of the committee should be "1"
15
+
16
+ Scenario: Carrier from nothing
17
+ Given a shipment emitter
18
+ When the "carrier" committee is calculated
19
+ Then the committee should have used quorum "default"
20
+ And the conclusion of the committee should be a fallback
21
+
22
+ Scenario: Mode from nothing
23
+ Given a shipment emitter
24
+ When the "mode" committee is calculated
25
+ Then the committee should have used quorum "default"
26
+ And the conclusion of the committee should be a fallback
27
+
28
+ Scenario: Segment count from nothing
29
+ Given a shipment emitter
30
+ When the "segment_count" committee is calculated
31
+ Then the committee should have used quorum "default"
32
+ And the conclusion of the committee should be "5"
33
+
34
+ Scenario Outline: Distance from origin zip code, destination zip code, and default mode
35
+ Given a shipment emitter
36
+ And a characteristic "origin_zip_code.name" of "<origin>"
37
+ And a characteristic "destination_zip_code.name" of "<destination>"
38
+ When the "mode" committee is calculated
39
+ And the "distance" committee is calculated
40
+ Then the committee should have used quorum "from origin zip code, destination zip code, and mode"
41
+ And the conclusion of the committee should be "<distance>"
42
+ Examples:
43
+ | origin | destination | distance |
44
+ | 05753 | 05753 | 0 |
45
+ | 05753 | 05401 | 53 |
46
+
47
+ Scenario Outline: Distance from origin zip code and destination zip code
48
+ Given a shipment emitter
49
+ And a characteristic "origin_zip_code.name" of "<origin>"
50
+ And a characteristic "destination_zip_code.name" of "<destination>"
51
+ And a characteristic "mode.name" of "<mode>"
52
+ When the "distance" committee is calculated
53
+ Then the committee should have used quorum "from origin zip code, destination zip code, and mode"
54
+ And the conclusion of the committee should be "<distance>"
55
+ Examples:
56
+ | origin | destination | mode | distance |
57
+ | 05753 | 05753 | courier | 0 |
58
+ | 05753 | 05401 | courier | 53 |
59
+ | 05753 | 20860 | courier | 8679 |
60
+ | 05401 | 05401 | air | 0 |
61
+ | 05401 | 94128 | air | 4133.31657 |
62
+ | 05401 | 20860 | air | 8693 |
63
+ | 05401 | 05401 | ground | 0 |
64
+ | 05401 | 94128 | ground | 4133 |
65
+ | 05401 | 20860 | ground | 8693 |
66
+
67
+ Scenario: Route inefficiency factor from nothing
68
+ Given a shipment emitter
69
+ When the "mode" committee is calculated
70
+ And the "route_inefficiency_factor" committee is calculated
71
+ Then the committee should have used quorum "from mode"
72
+ And the conclusion of the committee should be "1.05"
73
+
74
+ Scenario Outline: Route inefficiency factor from mode
75
+ Given a shipment emitter
76
+ And a characteristic "mode.name" of "<mode>"
77
+ When the "route_inefficiency_factor" committee is calculated
78
+ Then the committee should have used quorum "from mode"
79
+ And the conclusion of the committee should be "<factor>"
80
+ Examples:
81
+ | mode | factor |
82
+ | courier | 5.0 |
83
+ | ground | 1.0 |
84
+ | air | 1.1 |
85
+
86
+ Scenario: Dogleg factor from default segment count
87
+ Given a shipment emitter
88
+ When the "segment_count" committee is calculated
89
+ And the "dogleg_factor" committee is calculated
90
+ Then the committee should have used quorum "from segment count"
91
+ And the conclusion of the committee should be "5.0625"
92
+
93
+ Scenario Outline: Dogleg factor from segment count
94
+ Given a shipment emitter
95
+ And a characteristic "segment_count" of "<segments>"
96
+ When the "dogleg_factor" committee is calculated
97
+ Then the committee should have used quorum "from segment count"
98
+ And the conclusion of the committee should be "<factor>"
99
+ Examples:
100
+ | segments | factor |
101
+ | 1 | 1.0 |
102
+ | 2 | 1.5 |
103
+
104
+ Scenario: Adjusted distance from default
105
+ Given a shipment emitter
106
+ When the "adjusted_distance" committee is calculated
107
+ Then the committee should have used quorum "default"
108
+ And the conclusion of the committee should be "3219.0"
109
+
110
+ Scenario: Adjusted distance from distance, route inefficiency factor, and dogleg factor
111
+ Given a shipment emitter
112
+ And a characteristic "distance" of "100.0"
113
+ And a characteristic "route_inefficiency_factor" of "2.0"
114
+ And a characteristic "dogleg_factor" of "2.0"
115
+ When the "adjusted_distance" committee is calculated
116
+ Then the committee should have used quorum "from distance, route inefficiency factor, and dogleg factor"
117
+ And the conclusion of the committee should be "400.0"
118
+
119
+ Scenario: Transport emission factor from default mode
120
+ Given a shipment emitter
121
+ When the "mode" committee is calculated
122
+ And the "transport_emission_factor" committee is calculated
123
+ Then the committee should have used quorum "from mode"
124
+ And the conclusion of the committee should be "3.0"
125
+
126
+ Scenario Outline: Transport emission factor from mode
127
+ Given a shipment emitter
128
+ And a characteristic "mode.name" of "<mode>"
129
+ When the "transport_emission_factor" committee is calculated
130
+ Then the committee should have used quorum "from mode"
131
+ And the conclusion of the committee should be "<emission_factor>"
132
+ Examples:
133
+ | mode | emission_factor |
134
+ | courier | 2.0 |
135
+ | ground | 1.0 |
136
+ | air | 5.0 |
137
+
138
+ Scenario: Corporate emission factor from default carrier
139
+ Given a shipment emitter
140
+ When the "carrier" committee is calculated
141
+ And the "corporate_emission_factor" committee is calculated
142
+ Then the committee should have used quorum "from carrier"
143
+ And the conclusion of the committee should be "2.0"
144
+
145
+ Scenario: Corporate emission factor from carrier
146
+ Given a shipment emitter
147
+ And a characteristic "carrier.name" of "FedEx"
148
+ When the "corporate_emission_factor" committee is calculated
149
+ Then the committee should have used quorum "from carrier"
150
+ And the conclusion of the committee should be "2.0"
151
+
152
+ Scenario Outline: Transport emission from defaults
153
+ Given a shipment emitter
154
+ When the "weight" committee is calculated
155
+ And the "mode" committee is calculated
156
+ And the "adjusted_distance" committee is calculated
157
+ And the "transport_emission_factor" committee is calculated
158
+ And the "transport_emission" committee is calculated
159
+ Then the committee should have used quorum "from mode, weight, adjusted distance, and transport emission factor"
160
+ And the conclusion of the committee should be "600.0"
161
+
162
+ Scenario Outline: Transport emission from mode, weight, adjusted distance, and transport emission factor
163
+ Given a shipment emitter
164
+ And a characteristic "mode.name" of "<mode>"
165
+ And a characteristic "weight" of "<weight>"
166
+ And a characteristic "adjusted_distance" of "<adjusted_distance>"
167
+ And a characteristic "transport_emission_factor" of "<ef>"
168
+ When the "transport_emission" committee is calculated
169
+ Then the committee should have used quorum "from mode, weight, adjusted distance, and transport emission factor"
170
+ And the conclusion of the committee should be "<emission>"
171
+ Examples:
172
+ | mode | weight | adjusted_distance | ef | emission |
173
+ | courier | 2.0 | 100.0 | 2.0 | 2.0 |
174
+ | ground | 2.0 | 100.0 | 1.0 | 200.0 |
175
+ | air | 2.0 | 100.0 | 5.0 | 1000.0 |
176
+
177
+ Scenario: Corporate emission from package count and corporate emission factor
178
+ Given a shipment emitter
179
+ And a characteristic "package_count" of "2"
180
+ And a characteristic "corporate_emission_factor" of "2.0"
181
+ When the "corporate_emission" committee is calculated
182
+ Then the committee should have used quorum "from package count and corporate emission factor"
183
+ And the conclusion of the committee should be "4.0"
184
+
185
+ Scenario: Emission from transport emission and corporate emission
186
+ Given a shipment emitter
187
+ And a characteristic "transport_emission" of "400.0"
188
+ And a characteristic "corporate_emission" of "20.0"
189
+ When the "emission" committee is calculated
190
+ Then the committee should have used quorum "from transport emission and corporate emission"
191
+ And the conclusion of the committee should be "420.0"
192
+
193
+ # Scenario Outline: Duration from timestamps
194
+ # Given a shipment emitter
195
+ # And a characteristic "origin_timestamp" of "<origin>"
196
+ # And a characteristic "destination_timestamp" of "<destination>"
197
+ # When the "duration" committee is calculated
198
+ # Then the committee should have used quorum "from timestamps"
199
+ # And the conclusion of the committee should be "<duration>"
200
+ # Examples:
201
+ # | origin | destination | duration |
202
+ # | 2010-01-01T00:00:00Z | 2010-01-02T01:30:00Z | 01:30:00 | same timezone
203
+ # | 2010-01-01T00:00:00Z | 2010-01-02T09:30:00+08:00 | 01:30:00 | different timezones
204
+ # | 2010-01-01T00:00:00Z | 2009-12-31T20:30:00-05:00 | 01:30:00 | timezone change causes different days
205
+ # | 2010-01-01T12:00:00+12:00 | 2009-12-31T13:30:00-12:00 | 01:30:00 | cross intl date line eastwards
206
+ # | 2010-01-01T12:00:00-12:00 | 2009-01-02T13:30:00+12:00 | 01:30:00 | cross intl date line westwards
@@ -4,4 +4,51 @@ 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 "0"
7
+ Then the emission value should be within "0.1" kgs of "32835.8"
8
+
9
+ Scenario: Calculations from weight, package count, segment count
10
+ Given a shipment has "weight" of "10"
11
+ And it has "package_count" of "2"
12
+ And it has "segment_count" of "1"
13
+ When emissions are calculated
14
+ Then the emission value should be within "0.1" kgs of "96574.0"
15
+
16
+ Scenario Outline: Calculations from origin/destination
17
+ Given a shipment has "origin_zip_code.name" of "<origin>"
18
+ And it has "destination_zip_code.name" of "<destination>"
19
+ When emissions are calculated
20
+ Then the emission value should be within "0.1" kgs of "<emission>"
21
+ Examples:
22
+ | origin | destination | emission |
23
+ | 05401 | 05401 | 0.318 |
24
+ | 05401 | 94128 | 224106.1 |
25
+
26
+ Scenario: Calculations from carrier
27
+ Given a shipment has "carrier.name" of "FedEx"
28
+ When emissions are calculated
29
+ Then the emission value should be within "0.1" kgs of "32835.8"
30
+
31
+ Scenario Outline: Calculations from mode
32
+ Given a shipment has "mode.name" of "<mode>"
33
+ When emissions are calculated
34
+ Then the emission value should be within "0.1" kgs of "<emission>"
35
+ Examples:
36
+ | mode | emission |
37
+ | courier | 4.0 |
38
+ | ground | 10946.6 |
39
+ | air | 54725.0 |
40
+
41
+ Scenario Outline: Calculations from mode and origin/destination
42
+ Given a shipment has "mode.name" of "<mode>"
43
+ And it has "origin_zip_code.name" of "<origin>"
44
+ And it has "destination_zip_code.name" of "<destination>"
45
+ When emissions are calculated
46
+ Then the emission value should be within "0.1" kgs of "<emission>"
47
+ Examples:
48
+ | mode | origin | destination | emission |
49
+ | courier | 05401 | 05401 | 99999.9 |
50
+ | courier | 05401 | 94128 | 99999.9 |
51
+ | ground | 05401 | 05401 | 99999.9 |
52
+ | ground | 05401 | 94128 | 99999.9 |
53
+ | air | 05401 | 05401 | 99999.9 |
54
+ | air | 05401 | 94128 | 391297.9 |
@@ -7,4 +7,4 @@ require 'rspec'
7
7
  require 'rspec/expectations'
8
8
 
9
9
  require 'sniff'
10
- Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :cucumber => true, :earth => [:locality, :fuel]
10
+ Sniff.init File.join(File.dirname(__FILE__), '..', '..'), :cucumber => true, :earth => [:locality, :shipping]
@@ -24,17 +24,119 @@ module BrighterPlanet
24
24
  module CarbonModel
25
25
  def self.included(base)
26
26
  base.decide :emission, :with => :characteristics do
27
- ### Emission calculation
28
- # Returns the `emission` estimate (*kg CO<sub>2</sub>e*).
29
- # This is the total emission produced by the shipment venue.
30
27
  committee :emission do
31
- #### Default emission
32
- # **Complies:**
33
- #
34
- # Displays an error if the previous method fails.
28
+ # FIXME TODO deal with timeframe
29
+ quorum 'from transport emission and corporate emission', :needs => [:transport_emission, :corporate_emission] do |characteristics|
30
+ characteristics[:transport_emission] + characteristics[:corporate_emission]
31
+ end
32
+ end
33
+
34
+ committee :corporate_emission do
35
+ quorum 'from package count and corporate emission factor', :needs => [:package_count, :corporate_emission_factor] do |characteristics|
36
+ if characteristics[:package_count] > 0
37
+ characteristics[:package_count] * characteristics[:corporate_emission_factor]
38
+ else
39
+ raise "Invalid package_count: #{:package_count} (must be > 0)"
40
+ end
41
+ end
42
+ end
43
+
44
+ committee :transport_emission do
45
+ quorum 'from mode, weight, adjusted distance, and transport emission factor', :needs => [:mode, :weight, :adjusted_distance, :transport_emission_factor] do |characteristics|
46
+ # we're assuming here that the number of stops, rather than number of packages carried, is limiting factor on local delivery routes
47
+ if characteristics[:mode].name == "courier"
48
+ characteristics[:transport_emission_factor]
49
+ elsif characteristics[:weight] > 0
50
+ characteristics[:weight] * characteristics[:adjusted_distance] * characteristics[:transport_emission_factor]
51
+ else
52
+ raise "Invalid weight: #{:weight} (must be > 0)"
53
+ end
54
+ end
55
+ end
56
+
57
+ committee :corporate_emission_factor do
58
+ quorum 'from carrier', :needs => :carrier, do |characteristics|
59
+ characteristics[:carrier].corporate_emission_factor
60
+ end
61
+ end
62
+
63
+ committee :transport_emission_factor do
64
+ quorum 'from mode', :needs => :mode do |characteristics|
65
+ characteristics[:mode].transport_emission_factor
66
+ end
67
+ end
68
+
69
+ committee :adjusted_distance do
70
+ quorum 'from distance, route inefficiency factor, and dogleg factor', :needs => [:distance, :route_inefficiency_factor, :dogleg_factor] do |characteristics|
71
+ characteristics[:distance] * characteristics[:route_inefficiency_factor] * characteristics[:dogleg_factor]
72
+ end
73
+
74
+ quorum 'default' do
75
+ # ASSUMED: arbitrary
76
+ 3219
77
+ end
78
+ end
79
+
80
+ committee :dogleg_factor do
81
+ quorum 'from segment count', :needs => :segment_count do |characteristics|
82
+ if characteristics[:segment_count] > 0
83
+ # ASSUMED arbitrary
84
+ 1.5 ** (characteristics[:segment_count] - 1)
85
+ else
86
+ raise "Invalid segment_count: #{:segment_count} (must be > 0)"
87
+ end
88
+ end
89
+ end
90
+
91
+ committee :route_inefficiency_factor do
92
+ quorum 'from mode', :needs => :mode do |characteristics|
93
+ characteristics[:mode].route_inefficiency_factor
94
+ end
95
+ end
96
+
97
+ committee :distance do
98
+ quorum 'from origin zip code, destination zip code, and mode', :needs => [:origin_zip_code, :destination_zip_code], do |characteristics|
99
+ if characteristics[:origin_zip_code] == characteristics[:destination_zip_code]
100
+ # FIXME TODO
101
+ # Special calculation to deal with travel within the same zipcode
102
+ 0
103
+ else
104
+ characteristics[:origin_zip_code].distance_to(characteristics[:destination_zip_code], :units => :kms)
105
+ # FIXME TODO: calculate the distance via road using map directions
106
+ end
107
+ end
108
+ end
109
+
110
+ committee :segment_count do
111
+ quorum 'default' do
112
+ # 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
113
+ 5
114
+ end
115
+ end
116
+
117
+ committee :mode do
118
+ quorum 'default' do
119
+ ShipmentMode.fallback
120
+ end
121
+ end
122
+
123
+ committee :carrier do
124
+ quorum 'default' do
125
+ Carrier.fallback
126
+ end
127
+ end
128
+
129
+ committee :package_count do
130
+ quorum 'default' do
131
+ # ASSUMED arbitrary
132
+ 1
133
+ end
134
+ end
135
+
136
+ committee :weight do
35
137
  quorum 'default' do
36
- # raise "The emission committee's default quorum should never be called"
37
- 0
138
+ # ASSUMED based on average FedEx air package weight of 7.5 lbs
139
+ 3.4
38
140
  end
39
141
  end
40
142
  end
@@ -3,6 +3,13 @@ module BrighterPlanet
3
3
  module Characterization
4
4
  def self.included(base)
5
5
  base.characterize do
6
+ has :weight
7
+ has :package_count
8
+ has :carrier
9
+ has :mode
10
+ has :segment_count
11
+ has :origin_zip_code
12
+ has :destination_zip_code
6
13
  end
7
14
  end
8
15
  end
data/lib/shipment/data.rb CHANGED
@@ -4,6 +4,13 @@ module BrighterPlanet
4
4
  def self.included(base)
5
5
  base.data_miner do
6
6
  schema do
7
+ float 'weight'
8
+ integer 'package_count'
9
+ string 'carrier_name'
10
+ string 'mode_name'
11
+ integer 'segment_count'
12
+ string 'origin_zip_code_name'
13
+ string 'destination_zip_code_name'
7
14
  end
8
15
 
9
16
  process :run_data_miner_on_belongs_to_associations
@@ -2,6 +2,10 @@ module BrighterPlanet
2
2
  module Shipment
3
3
  module Relationships
4
4
  def self.included(base)
5
+ base.belongs_to :carrier, :foreign_key => 'carrier_name', :primary_key => 'name'
6
+ base.belongs_to :origin_zip_code, :foreign_key => 'zip_code_name', :primary_key => 'name', :class_name => 'ZipCode'
7
+ base.belongs_to :destination_zip_code, :foreign_key => 'zip_code_name', :primary_key => 'name', :class_name => 'ZipCode'
8
+ base.belongs_to :mode, :foreign_key => 'mode_name', :primary_key => 'name', :class_name => 'ShipmentMode'
5
9
  end
6
10
  end
7
11
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andy Rossmeissl
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2010-11-23 00:00:00 -05:00
21
+ date: 2010-12-10 00:00:00 -05:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -94,21 +94,6 @@ dependencies:
94
94
  type: :runtime
95
95
  prerelease: false
96
96
  version_requirements: *id005
97
- - !ruby/object:Gem::Dependency
98
- name: earth
99
- requirement: &id006 !ruby/object:Gem::Requirement
100
- none: false
101
- requirements:
102
- - - ~>
103
- - !ruby/object:Gem::Version
104
- segments:
105
- - 0
106
- - 3
107
- - 1
108
- version: 0.3.1
109
- type: :runtime
110
- prerelease: false
111
- version_requirements: *id006
112
97
  description: A software model in Ruby for the greenhouse gas emissions of a shipment
113
98
  email: andy@rossmeissl.net
114
99
  executables: []
@@ -130,6 +115,7 @@ files:
130
115
  - lib/shipment/summarization.rb
131
116
  - lib/test_support/shipment_record.rb
132
117
  - features/support/env.rb
118
+ - features/shipment_committees.feature
133
119
  - features/shipment_emissions.feature
134
120
  has_rdoc: true
135
121
  homepage: http://brighterplanet.github.com/shipment
@@ -145,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
145
131
  requirements:
146
132
  - - ">="
147
133
  - !ruby/object:Gem::Version
148
- hash: -143060881
134
+ hash: -856075423
149
135
  segments:
150
136
  - 0
151
137
  version: "0"
@@ -166,5 +152,6 @@ specification_version: 3
166
152
  summary: A carbon model for a shipment
167
153
  test_files:
168
154
  - features/support/env.rb
155
+ - features/shipment_committees.feature
169
156
  - features/shipment_emissions.feature
170
157
  - lib/test_support/shipment_record.rb