Module: BrighterPlanet::BusTrip::CarbonModel

Defined in:
lib/bus_trip/carbon_model.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/bus_trip/carbon_model.rb', line 22

def self.included(base)
  base.decide :emission, :with => :characteristics do
    ### Emission calculation
    # Returns the `emission` estimate (*kg CO<sub>2</sub>e*)
    committee :emission do
      #### Emission from fuel, emission factors, and passengers
      # **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
      #
      # - Multiplies diesel consumed (*l*) by the diesel emission factor (*kg CO<sub>2</sub>e / l*) to give diesel emissions (*kg CO<sub>2</sub>e*)
      # - Multiplies alternaive fuel consumed (*l*) by the alternative fuels emission factor (*kg CO<sub>2</sub>e / l*) to give alternative fuels emissions (*kg CO<sub>2</sub>e*)
      # - Multiplies distance (*km*) by the air conditioning emission factor (*kg CO<sub>2</sub>e / km*) to give air conditioning emissions (*kg CO<sub>2</sub>e*)
      # - Sums the diesel, alternative fuels, and air conditioning emissions and divides by passengers to give emissions per passenger (*kg CO<sub>2</sub>e*)
      quorum 'from fuels, emission factors, and passengers', :needs => [:diesel_consumed, :diesel_emission_factor, :alternative_fuels_consumed, :alternative_fuels_emission_factor, :distance, :air_conditioning_emission_factor, :passengers] do |characteristics|
        (characteristics[:diesel_consumed] * characteristics[:diesel_emission_factor] + characteristics[:alternative_fuels_consumed] * characteristics[:alternative_fuels_emission_factor] + characteristics[:distance] * characteristics[:air_conditioning_emission_factor]) / characteristics[:passengers]
      end
    end
    
    ### Air conditioning emission factor calculation
    # Returns the `air conditioning emission factor` (*kg CO<sub>2</sub>e / km*).
    # This is used to account for fugitive emissions of air conditioning refrigerants.
    committee :air_conditioning_emission_factor do
      #### Air conditioning emission factor from bus class
      # **Complies:** GHG Protocol, ISO 14046-1, Climate Registry Protocol
      #
      # Looks up the [bus class](http://data.brighterplanet.com/bus_classes) `air conditioning emission factor` (*kg CO<sub>2</sub>e / km*).
      quorum 'from bus class', :needs => :bus_class do |characteristics|
        characteristics[:bus_class].air_conditioning_emission_factor
      end
    end
    
    ### Diesel emission factor calculation
    # Returns the `diesel emission factor` (*kg CO<sub>2</sub>e / l*).
    committee :diesel_emission_factor do
      #### Default diesel emission factor
      # **Complies:** GHG Protocol, ISO 14046-1, Climate Registry Protocol
      #
      # Looks up [Distillate Fuel Oil 2](http://data.brighterplanet.com/fuel_types)'s `emission factor` (*kg CO<sub>2</sub>e / l*).
      quorum 'default' do
        diesel = FuelType.find_by_name "Distillate Fuel Oil 2"
        diesel.emission_factor
      end
    end
    
    ### Alternative fuels emission factor calculation
    # Returns the `alternative fuels emission factor` (*kg CO<sub>2</sub>e / l*).
    committee :alternative_fuels_emission_factor do
      #### Default alternative fuels emission factor
      # **Complies:** GHG Protocol, ISO 14046-1, Climate Registry Protocol
      #
      # Uses an `alternative fuels emission factor` of 1.17 *kg CO<sub>2</sub>e / l*.
      quorum 'default' do
        9.742.pounds_per_gallon.to(:kilograms_per_litre)
      end
    end
    
    ### Diesel consumed calculation
    # Returns the `diesel consumed` (*l*).
    committee :diesel_consumed do
      #### Diesel consumed from distance and diesel intensity
      # **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
      #
      # Multiplies `distance` (*km*) by `diesel intensity` (*l / km*) to give *l*.
      quorum 'from distance and diesel intensity', :needs => [:distance, :diesel_intensity] do |characteristics|
        characteristics[:distance] * characteristics[:diesel_intensity]
      end
    end
    
    ### Alternative fuels consumed calculation
    # Returns the `alternative fuels consumed` (*l*).
    committee :alternative_fuels_consumed do
      #### Alternative fuels consumed from distance and alternative fuels intensity
      # **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
      #
      # Multiplies `distance` (*km*) by `alternative fuels intensity` (*l / km*) to give *l*.
      quorum 'from distance and alternative fuels intensity', :needs => [:distance, :alternative_fuels_intensity] do |characteristics|
        characteristics[:distance] * characteristics[:alternative_fuels_intensity]
      end
    end
    
    ### Distance calculation
    # Returns the `distance` travelled (*km*).
    committee :distance do
      #### Distance from client input
      # **Complies:** All
      #
      # Uses the client-input `distance` (*km*).
      
      #### Distance from duration and speed
      # **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
      #
      # Divides `duration` (*minutes*) by 60 and multiplies by `speed` (*km / hour*) to give *km*.
      quorum 'from duration and speed', :needs => [:duration, :speed] do |characteristics|
        characteristics[:duration] / 60 * characteristics[:speed]
      end
      
      #### Distance from bus class
      # **Complies:**
      #
      # Looks up the [bus class](http://data.brighterplanet.com/bus_classes) `distance` (*km*).
      quorum 'from bus class', :needs => :bus_class do |characteristics|
        characteristics[:bus_class].distance
      end
    end
    
    ### Speed calculation
    # Returns the average `speed` (*km / hour*).
    committee :speed do
      #### Speed from bus class
      # **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
      #
      # Looks up the [bus class](http://data.brighterplanet.com/bus_classes)' average `speed` (*km / hour*).
      quorum 'from bus class', :needs => :bus_class do |characteristics|
        characteristics[:bus_class].speed
      end
    end
    
    ### Duration calculation
    # Returns the trip's `duration` (*minutes*).
      #### Duration from client input
      # **Complies:** All
      #
      # Uses the client-input `duration` (*minutes*).
    
    ### Diesel intensity calculation
    # Returns the `diesel intensity` (*l / km*).
    committee :diesel_intensity do
      #### Diesel intensity from bus class
      # **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
      #
      # Looks up the [bus class](http://data.brighterplanet.com/bus_classes) `diesel intensity` (*l / km*).
      quorum 'from bus class', :needs => :bus_class do |characteristics|
        characteristics[:bus_class].diesel_intensity
      end
    end
    
    ### Alternative fuels intensity calculation
    # Returns the `alternative fuels intensity` (*l / km*).
    committee :alternative_fuels_intensity do
      #### Alternative fuels intensity from bus class
      # **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
      #
      # Looks up the [bus class](http://data.brighterplanet.com/bus_classes) `alternative fuels intensity` (*l / km*).
      quorum 'from bus class', :needs => :bus_class do |characteristics|
        characteristics[:bus_class].alternative_fuels_intensity
      end
    end
    
    ### Passengers calculation
    # Returns the number of `passengers` on the bus.
    committee :passengers do
      #### Passengers from bus class
      # **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
      #
      # Looks up the [bus class](http://data.brighterplanet.com/bus_classes)' average number of `passengers`.
      quorum 'from bus class', :needs => :bus_class do |characteristics|
        characteristics[:bus_class].passengers
      end
    end
    
    ### Bus class calculation
    # Returns the `bus class`.
    # This is the type of bus used.
    committee :bus_class do
      #### From client input
      # **Complies:** All
      #
      # Uses the client-input [bus class](http://data.brighterplanet.com/bus_classes).
      
      #### Default bus class
      # **Complies:** GHG Protocol, ISO 14064-1, Climate Registry Protocol
      #
      # Uses an artificial [bus class](http://data.brighterplanet.com/bus_classes) that represents the U.S. average.
      quorum 'default' do
        BusClass.fallback
      end
    end
  end
end