carbon 2.2.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,237 @@
1
+ require 'helper'
2
+ require 'timeframe'
3
+ require 'benchmark'
4
+
5
+ require 'my_nissan_altima'
6
+
7
+ Thread.abort_on_exception = true
8
+ Carbon.key = 'carbon_test'
9
+
10
+ describe Carbon do
11
+ before do
12
+ flush_cache!
13
+ end
14
+
15
+ describe '.query' do
16
+ context 'serial' do
17
+ it "calculates flight impact" do
18
+ VCR.use_cassette 'LAX->SFO flight', :record => :once do
19
+ result = Carbon.query('Flight', :origin_airport => 'LAX', :destination_airport => 'SFO', :segments_per_trip => 1, :trips => 1)
20
+ result.decisions.carbon.object.value.should be_within(50).of(200)
21
+ end
22
+ end
23
+ it "can be used on an object that responds to #as_impact_query" do
24
+ VCR.use_cassette '2006 Altima', :record => :once do
25
+ Carbon.query(MyNissanAltima.new(2006)).decisions.should == MyNissanAltima.new(2006).impact.decisions
26
+ end
27
+ end
28
+ it "gets back characteristics" do
29
+ VCR.use_cassette 'LAX->SFO flight', :record => :once do
30
+ result = Carbon.query('Flight', :origin_airport => 'LAX', :destination_airport => 'SFO', :segments_per_trip => 1, :trips => 1)
31
+ result.characteristics.origin_airport.description.should =~ %r{lax}i
32
+ end
33
+ end
34
+ it "tells you if the query is successful" do
35
+ VCR.use_cassette 'Flight', :record => :once do
36
+ result = Carbon.query('Flight')
37
+ result.success.should be_true
38
+ end
39
+ end
40
+ it "is gentle about errors" do
41
+ VCR.use_cassette 'Monkey', :record => :once do
42
+ result = Carbon.query('Monkey')
43
+ result.success.should be_false
44
+ end
45
+ end
46
+ it "sends timeframe properly" do
47
+ VCR.use_cassette 'timeframed flight', :record => :once do
48
+ result = Carbon.query('Flight', :timeframe => Timeframe.new(:year => 2009))
49
+ result.timeframe.should == '2009-01-01/2010-01-01'
50
+ end
51
+ end
52
+ it "sends key properly" do
53
+ VCR.use_cassette 'flight with key 1', :record => :once do
54
+ result = Carbon.query('Flight', :key => 'carbon_test1')
55
+ result.errors.first.should =~ /carbon_test1/
56
+ end
57
+ VCR.use_cassette 'flight with key 2', :record => :once do
58
+ result = Carbon.query('Flight', :key => 'carbon_test2')
59
+ result.errors.first.should =~ /carbon_test2/
60
+ end
61
+ end
62
+ it "allows choosing domain" do
63
+ VCR.use_cassette 'carbon.bp.com flight', :record => :once do
64
+ result = Carbon.query('Flight', :domain => 'http://carbon.brighterplanet.com')
65
+ result.carbon.value.should > 0
66
+ end
67
+ end
68
+ it "raises ArgumentError if args are bad" do
69
+ expect do
70
+ Carbon.query(['Flight'])
71
+ end.should raise_error(ArgumentError)
72
+ end
73
+ end
74
+
75
+ context 'in parallel', :multi => true do
76
+ before do
77
+ VCR.turn_off!
78
+ @queries = []
79
+ @queries << ['Flight', {:origin_airport => 'LAX', :destination_airport => 'SFO', :segments_per_trip => 1, :trips => 1}]
80
+ @queries << ['Flight', {:origin_airport => 'MSN', :destination_airport => 'ORD', :segments_per_trip => 1, :trips => 1}]
81
+ @queries << ['Flight', {:origin_airport => 'IAH', :destination_airport => 'DEN', :segments_per_trip => 1, :trips => 1}]
82
+ @queries << ['RailTrip', {:distance => 25}]
83
+ @queries << ['RailTrip', {:rail_class => 'commuter'}]
84
+ @queries << ['RailTrip', {:rail_traction => 'electric'}]
85
+ @queries << ['AutomobileTrip', {:make => 'Nissan', :model => 'Altima'}]
86
+ @queries << ['AutomobileTrip', {:make => 'Toyota', :model => 'Prius'}]
87
+ @queries << ['AutomobileTrip', {:make => 'Ford', :model => 'Taurus'}]
88
+ @queries << ['Residence', {:urbanity => 'City'}]
89
+ @queries << ['Residence', {:zip_code => '53703'}]
90
+ @queries << ['Residence', {:bathrooms => 4}]
91
+ @queries << ['Monkey', {:bananas => '1'}]
92
+ @queries << ['Monkey', {:bananas => '2'}]
93
+ @queries << ['Monkey', {:bananas => '3'}]
94
+ @queries = @queries.sort_by { rand }
95
+ end
96
+
97
+ after do
98
+ VCR.turn_on!
99
+ end
100
+
101
+ it "is easy to use" do
102
+ flight = ['Flight']
103
+ rail_trip = ['RailTrip']
104
+ results = Carbon.query([flight, rail_trip])
105
+ results[flight].decisions.should == Carbon.query('Flight').decisions
106
+ results[rail_trip].decisions.should == Carbon.query('RailTrip').decisions
107
+ end
108
+ it "doesn't hang up on 0 queries" do
109
+ Timeout.timeout(0.5) { Carbon.query([]) }.should ==(Hash.new)
110
+ end
111
+ it "raises if you pass it a block directly" do
112
+ expect do
113
+ Carbon.query([]) { }
114
+ end.should raise_error(ArgumentError)
115
+ end
116
+ it "can be used on objects that respond to #as_impact_query" do
117
+ a = MyNissanAltima.new(2001)
118
+ b = MyNissanAltima.new(2006)
119
+ ab1 = Carbon.query([a, b])
120
+ ab2 = Carbon.query([a.as_impact_query, b.as_impact_query])
121
+ ab1.keys.should == [a, b]
122
+ ab2.keys.should == [a.as_impact_query, b.as_impact_query]
123
+ ab1.each do |k, v|
124
+ ab2[k.as_impact_query].should == v
125
+ end
126
+ end
127
+ it "runs multiple queries at once" do
128
+ reference_results = @queries.inject({}) do |memo, query|
129
+ memo[query] = Carbon.query(*query)
130
+ memo
131
+ end
132
+ ts = []
133
+ 3.times do
134
+ ts << Thread.new do
135
+ flush_cache! # important!
136
+ multi_results = Carbon.query(@queries)
137
+ error_count = 0
138
+ multi_results.each do |query, result|
139
+ if result.success
140
+ result.decisions.carbon.object.value.should > 0
141
+ result.decisions.carbon.object.value.should < 10_000
142
+ else
143
+ error_count += 1
144
+ end
145
+ end
146
+ error_count.should == 3
147
+ reference_results.each do |query, reference_result|
148
+ if reference_result.success
149
+ multi_results[query].decisions.should == reference_result.decisions
150
+ else
151
+ multi_results[query].should == reference_result
152
+ end
153
+ end
154
+ end
155
+ end
156
+ ts.each do |t|
157
+ t.join
158
+ end
159
+ end
160
+ it "is faster than single threaded" do
161
+ # warm up the cache on the other end
162
+ @queries.each { |query| Carbon.query(*query) }
163
+ flush_cache! # important!
164
+ single_threaded_time = Benchmark.realtime do
165
+ @queries.each { |query| Carbon.query(*query) }
166
+ end
167
+ flush_cache! # important!
168
+ multi_threaded_time = Benchmark.realtime do
169
+ Carbon.query(@queries)
170
+ end
171
+ cached_single_threaded_time = Benchmark.realtime do
172
+ @queries.each { |query| Carbon.query(*query) }
173
+ end
174
+ cached_multi_threaded_time = Benchmark.realtime do
175
+ Carbon.query(@queries)
176
+ end
177
+ multi_threaded_time.should < single_threaded_time
178
+ cached_single_threaded_time.should < multi_threaded_time
179
+ cached_multi_threaded_time.should < multi_threaded_time
180
+ $stderr.puts " Multi-threaded was #{((single_threaded_time - multi_threaded_time) / single_threaded_time * 100).round}% faster than single-threaded"
181
+ $stderr.puts " Cached single-threaded was #{((multi_threaded_time - cached_single_threaded_time) / multi_threaded_time * 100).round}% faster than uncached multi-threaded"
182
+ $stderr.puts " Cached multi-threaded was #{((multi_threaded_time - cached_multi_threaded_time) / multi_threaded_time * 100).round}% faster than uncached multi-threaded"
183
+ end
184
+ it "safely uniq's and caches queries" do
185
+ reference_results = @queries.inject({}) do |memo, query|
186
+ memo[query] = Carbon.query(*query)
187
+ memo
188
+ end
189
+ flush_cache! # important!
190
+ 3.times do
191
+ multi_results = Carbon.query(@queries)
192
+ reference_results.each do |query, reference_result|
193
+ if reference_result.success
194
+ multi_results[query].decisions.should == reference_result.decisions
195
+ else
196
+ multi_results[query].should == reference_result
197
+ end
198
+ end
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ describe "mixin" do
205
+ describe :emit_as do
206
+ it "overwrites old emit_as blocks" do
207
+ eval %{class MyFoo; include Carbon; end}
208
+ MyFoo.emit_as('Automobile') { provide(:make) }
209
+ Carbon::Registry.instance['MyFoo'].characteristics.keys.should == [:make]
210
+ MyFoo.emit_as('Automobile') { provide(:model) }
211
+ Carbon::Registry.instance['MyFoo'].characteristics.keys.should == [:model]
212
+ end
213
+ end
214
+ describe '#impact' do
215
+ it 'calculates a single impact' do
216
+ VCR.use_cassette '2006 Altima', :record => :once do
217
+ impact = MyNissanAltima.new(2006).impact
218
+ impact.decisions.carbon.object.value.should > 0
219
+ impact.characteristics.make.description.should =~ %r{Nissan}i
220
+ impact.characteristics.model.description.should =~ %r{Altima}i
221
+ impact.characteristics.year.description.to_i.should == 2006
222
+ impact.characteristics.automobile_fuel.description.should =~ %r{regular gasoline}
223
+ end
224
+ end
225
+ it 'accepts a timeframe option' do
226
+ VCR.use_cassette '2006 Altima in 2010', :record => :once do
227
+ impact_2010 = MyNissanAltima.new(2006).impact(:timeframe => Timeframe.new(:year => 2010))
228
+ impact_2010.timeframe.should =~ /^2010-01-01/
229
+ end
230
+ VCR.use_cassette '2006 Altima in 2011', :record => :once do
231
+ impact_2011 = MyNissanAltima.new(2006).impact(:timeframe => Timeframe.new(:year => 2011))
232
+ impact_2011.timeframe.should =~ /^2011-01-01/
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
@@ -0,0 +1,69 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://impact.brighterplanet.com/automobiles.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: make=Nissan&model=Altima&year=2006&automobile_fuel%5Bcode%5D=R&key=carbon_test
9
+ headers:
10
+ accept:
11
+ - ! '*/*'
12
+ user-agent:
13
+ - Ruby
14
+ content-type:
15
+ - application/x-www-form-urlencoded
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ server:
22
+ - nginx
23
+ date:
24
+ - Fri, 08 Jun 2012 21:05:39 GMT
25
+ content-type:
26
+ - application/json
27
+ transfer-encoding:
28
+ - chunked
29
+ connection:
30
+ - keep-alive
31
+ status:
32
+ - 200 OK
33
+ body:
34
+ encoding: US-ASCII
35
+ string: ! '{"compliance":[],"decisions":{"carbon":{"description":"4520.8 kg","object":{"value":4520.789934497878,"units":"kilograms"},"methodology":"from
36
+ co2 emission, ch4 emission, n2o emission, and hfc emission"},"co2_emission":{"description":"4308.585980497603","object":4308.585980497603,"methodology":"from
37
+ fuel use and automobile fuel"},"co2_biogenic_emission":{"description":"0.0","object":0.0,"methodology":"from
38
+ fuel use and automobile fuel"},"ch4_emission":{"description":"4.537572120026403","object":4.537572120026403,"methodology":"from
39
+ fuel use and automobile fuel"},"n2o_emission":{"description":"15.37211589011779","object":15.37211589011779,"methodology":"from
40
+ fuel use and automobile fuel"},"hfc_emission":{"description":"192.29426599013075","object":192.29426599013075,"methodology":"from
41
+ fuel use and automobile fuel"},"energy":{"description":"63708.4 MJ","object":{"value":63708.41114166553,"units":"megajoules"},"methodology":"from
42
+ fuel use and automobile fuel"},"fuel_use":{"description":"1,839.8372129905256
43
+ l","object":{"value":1839.8372129905256,"units":"litres"},"methodology":"from
44
+ fuel efficiency and distance"},"distance":{"description":"17845.6","object":17845.6,"methodology":"from
45
+ annual distance"},"annual_distance":{"description":"17,845.6 km","object":{"value":17845.6,"units":"kilometres"},"methodology":"from
46
+ automobile fuel"},"speed":{"description":"50.94382232429702 km/h","object":{"value":50.94382232429702,"units":"kilometres_per_hour"},"methodology":"from
47
+ urbanity and safe country"},"fuel_efficiency":{"description":"9.699553783344362
48
+ km/l","object":{"value":9.699553783344362,"units":"kilometres_per_litre"},"methodology":"from
49
+ make model year and urbanity"},"hybridity_multiplier":{"description":"1.0","object":1.0,"methodology":"default"},"urbanity":{"description":"0.43","object":0.43,"methodology":"from
50
+ safe country"},"safe_country":{"description":null,"object":{"country":{"automobile_city_speed":32.0259,"automobile_city_speed_units":"kilometres_per_hour","automobile_fuel_efficiency":8.226530750610781,"automobile_fuel_efficiency_units":"kilometres_per_litre","automobile_highway_speed":91.8935,"automobile_highway_speed_units":"kilometres_per_hour","automobile_trip_distance":16.3348,"automobile_trip_distance_units":"kilometres","automobile_urbanity":0.43,"cooling_degree_days":null,"cooling_degree_days_units":null,"electricity_emission_factor":0.626089,"electricity_emission_factor_units":"kilograms_co2e_per_kilowatt_hour","electricity_loss_factor":0.096,"flight_route_inefficiency_factor":1.100000023841858,"heating_degree_days":null,"heating_degree_days_units":null,"iso_3166_alpha_3_code":null,"iso_3166_code":null,"iso_3166_numeric_code":null,"lodging_district_heat_intensity":1.7463,"lodging_district_heat_intensity_units":"megajoules_per_occupied_room_night","lodging_electricity_intensity":32.906,"lodging_electricity_intensity_units":"kilowatt_hours_per_occupied_room_night","lodging_fuel_oil_intensity":0.412389,"lodging_fuel_oil_intensity_units":"gallons_per_occupied_room_night","lodging_natural_gas_intensity":1.93316,"lodging_natural_gas_intensity_units":"cubic_metres_per_occupied_room_night","lodging_occupancy_rate":0.601,"name":"fallback","rail_passengers":null,"rail_speed":32.49720001220703,"rail_speed_units":"kilometres_per_hour","rail_trip_co2_emission_factor":0.06364482122342524,"rail_trip_co2_emission_factor_units":"kilograms_per_passenger_kilometre","rail_trip_diesel_intensity":0.008762920291076415,"rail_trip_diesel_intensity_units":"litres_per_passenger_kilometre","rail_trip_distance":37.11446191042177,"rail_trip_distance_units":"kilometres","rail_trip_electricity_intensity":0.10806735200626398,"rail_trip_electricity_intensity_units":"kilowatt_hour_per_passenger_kilometre"}},"methodology":"default"},"active_subtimeframe":{"description":"2012-01-01/2013-01-01","object":"2012-01-01/2013-01-01","methodology":"from
51
+ acquisition and retirement"},"acquisition":{"description":"2006-01-01","object":"2006-01-01","methodology":"from
52
+ year"},"retirement":{"description":"2013-01-01","object":"2013-01-01","methodology":"default"},"make_model_year":{"description":"Nissan
53
+ ALTIMA 2006","object":{"automobile_make_model_year":{"fuel_code":"R","fuel_efficiency_city":8.15793,"fuel_efficiency_city_units":"kilometres_per_litre","fuel_efficiency_highway":11.3122,"fuel_efficiency_highway_units":"kilometres_per_litre","hybridity":false,"make_name":"Nissan","model_name":"ALTIMA","name":"Nissan
54
+ ALTIMA 2006","year":2006}},"methodology":"from make, model, and year"},"make_year":{"description":"Nissan
55
+ 2006","object":{"automobile_make_year":{"fuel_efficiency":11.2297,"fuel_efficiency_units":"kilometres_per_litre","make_name":"Nissan","name":"Nissan
56
+ 2006","volume":1076456,"year":2006}},"methodology":"from make and year"},"make_model":{"description":"Nissan
57
+ ALTIMA","object":{"automobile_make_model":{"fuel_efficiency_city":8.47904,"fuel_efficiency_city_units":"kilometres_per_litre","fuel_efficiency_highway":11.65,"fuel_efficiency_highway_units":"kilometres_per_litre","make_name":"Nissan","model_name":"ALTIMA","name":"Nissan
58
+ ALTIMA"}},"methodology":"from make and model"}},"emitter":"Automobile","equivalents":{"cars_off_the_road_for_a_year":0.8227837680786138,"cars_off_the_road_for_a_month":9.86436363707437,"cars_off_the_road_for_a_week":42.744068830677435,"cars_off_the_road_for_a_day":300.0267447928861,"cars_to_priuses_for_a_year":1.6455675361572275,"cars_to_priuses_for_a_month":19.72872727414874,"cars_to_priuses_for_a_week":85.48813766135487,"cars_to_priuses_for_a_day":600.0534895857722,"one_way_domestic_flight":14.692567287118102,"round_trip_domestic_flight":7.346283643559051,"one_way_cross_country_flight":5.1627421051965765,"round_trip_cross_country_flight":2.5813710525982883,"vegan_meals_instead_of_non_vegan_ones":3637.820890021294,"days_of_veganism":1212.6069633404313,"weeks_of_veganism":173.22762871008968,"months_of_veganism":40.42038280434552,"years_of_veganism":3.32278060185594,"barrels_of_petroleum":10.515357387642064,"canisters_of_bbq_propane":188.36775420072308,"railroad_cars_full_of_coal":0.022603949672489392,"homes_energy_in_a_year":0.4385166236462941,"homes_energy_in_a_month":5.2395955340830405,"homes_energy_in_a_week":22.698886261113845,"homes_energy_in_a_day":159.3442828212467,"homes_electricity_in_a_year":0.664556120371188,"homes_electricity_in_a_month":7.9520694947817665,"homes_electricity_in_a_week":34.45746088074283,"homes_electricity_in_a_day":241.85774070570196,"homes_with_lowered_thermostat_2_degrees_for_a_winter":23.72962636617936,"homes_with_raised_thermostat_3_degrees_for_a_summer":10.669064245414992,"replaced_refrigerators":4.552435464039363,"loads_of_cold_laundry":2073.062473943216,"lightbulbs_for_a_year":8.345378219083083,"lightbulbs_for_a_month":101.55954587849482,"lightbulbs_for_a_week":435.25261331358666,"lightbulbs_for_a_day":3046.7818555649105,"lightbulbs_for_an_evening":18280.695654179395,"lightbulbs_to_CFLs_for_a_day":51860.13323463397,"lightbulbs_to_CFLs_for_a_week":7408.589170436301,"lightbulbs_to_CFLs_for_a_month":1728.6732175231018,"lightbulbs_to_CFLs_for_a_year":142.0839068513338,"days_with_lightbulbs_to_CFLs":1152.448811682068,"weeks_with_lightbulbs_to_CFLs":164.6336070446092,"months_with_lightbulbs_to_CFLs":38.41315207342846,"years_with_lightbulbs_to_CFLs":3.155511374279519,"recycled_kgs_of_trash":3117.785382276134,"recycled_bags_of_trash":1727.5520616193464},"methodology":"http://impact.brighterplanet.com/automobiles?automobile_fuel%5Bcode%5D=R&make=Nissan&model=Altima&timeframe=2012-01-01%2F2013-01-01&year=2006","scope":"The
59
+ automobile emission estimate is the total anthropogenic emissions from fuel
60
+ and air conditioning used by the automobile during the timeframe. It includes
61
+ CO2 emissions from combustion of non-biogenic fuel, CH4 and N2O emissions
62
+ from combustion of all fuel, and fugitive HFC emissions from air conditioning.","timeframe":"2012-01-01/2013-01-01","characteristics":{"make":{"description":"Nissan","object":{"automobile_make":{"fuel_efficiency":11.9656,"fuel_efficiency_units":"kilometres_per_litre","name":"Nissan"}}},"model":{"description":"ALTIMA","object":{"automobile_model":{"name":"ALTIMA"}}},"year":{"description":2006,"object":{"automobile_year":{"year":2006}}},"automobile_fuel":{"description":"regular
63
+ gasoline","object":{"automobile_fuel":{"annual_distance":17845.6,"annual_distance_units":"kilometres","base_fuel_name":"Motor
64
+ Gasoline","blend_fuel_name":null,"blend_portion":null,"ch4_emission_factor":0.00246629,"ch4_emission_factor_units":"kilograms_co2e_per_litre","co2_biogenic_emission_factor":0.0,"co2_biogenic_emission_factor_units":"kilograms_per_litre","co2_emission_factor":2.34183,"co2_emission_factor_units":"kilograms_per_litre","code":"R","distance_key":"gasoline","ef_key":"gasoline","emission_factor":2.45717,"emission_factor_units":"kilograms_co2e_per_litre","energy_content":34.6272,"energy_content_units":"megajoules_per_litre","hfc_emission_factor":0.104517,"hfc_emission_factor_units":"kilograms_co2e_per_litre","n2o_emission_factor":0.00835515,"n2o_emission_factor_units":"kilograms_co2e_per_litre","name":"regular
65
+ gasoline"}}}},"errors":["API key \"carbon_test\" could not be verified. Please
66
+ register at http://keys.brighterplanet.com"]}'
67
+ http_version: '1.1'
68
+ recorded_at: Fri, 08 Jun 2012 21:05:39 GMT
69
+ recorded_with: VCR 2.2.0
@@ -0,0 +1,230 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: http://impact.brighterplanet.com/monkeys.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: bananas=3&key=carbon_test
9
+ headers:
10
+ accept:
11
+ - ! '*/*'
12
+ user-agent:
13
+ - Ruby
14
+ content-type:
15
+ - application/x-www-form-urlencoded
16
+ response:
17
+ status:
18
+ code: 404
19
+ message: Not Found
20
+ headers:
21
+ server:
22
+ - nginx
23
+ date:
24
+ - Fri, 08 Jun 2012 21:06:18 GMT
25
+ content-type:
26
+ - application/json
27
+ transfer-encoding:
28
+ - chunked
29
+ connection:
30
+ - keep-alive
31
+ status:
32
+ - 404 Not Found
33
+ etag:
34
+ - b0dcd496ec3896280a7c636e2d5b9870
35
+ body:
36
+ encoding: US-ASCII
37
+ string: ! '{name: "HTTPError", message: "404 Not found"}
38
+
39
+ '
40
+ http_version: '1.1'
41
+ recorded_at: Fri, 08 Jun 2012 21:06:18 GMT
42
+ - request:
43
+ method: post
44
+ uri: http://impact.brighterplanet.com/monkeys.json
45
+ body:
46
+ encoding: US-ASCII
47
+ string: bananas=2&key=carbon_test
48
+ headers:
49
+ accept:
50
+ - ! '*/*'
51
+ user-agent:
52
+ - Ruby
53
+ content-type:
54
+ - application/x-www-form-urlencoded
55
+ response:
56
+ status:
57
+ code: 404
58
+ message: Not Found
59
+ headers:
60
+ server:
61
+ - nginx
62
+ date:
63
+ - Fri, 08 Jun 2012 21:06:18 GMT
64
+ content-type:
65
+ - application/json
66
+ transfer-encoding:
67
+ - chunked
68
+ connection:
69
+ - keep-alive
70
+ status:
71
+ - 404 Not Found
72
+ etag:
73
+ - b0dcd496ec3896280a7c636e2d5b9870
74
+ body:
75
+ encoding: US-ASCII
76
+ string: ! '{name: "HTTPError", message: "404 Not found"}
77
+
78
+ '
79
+ http_version: '1.1'
80
+ recorded_at: Fri, 08 Jun 2012 21:06:18 GMT
81
+ - request:
82
+ method: post
83
+ uri: http://impact.brighterplanet.com/monkeys.json
84
+ body:
85
+ encoding: US-ASCII
86
+ string: bananas=1&key=carbon_test
87
+ headers:
88
+ accept:
89
+ - ! '*/*'
90
+ user-agent:
91
+ - Ruby
92
+ content-type:
93
+ - application/x-www-form-urlencoded
94
+ response:
95
+ status:
96
+ code: 404
97
+ message: Not Found
98
+ headers:
99
+ server:
100
+ - nginx
101
+ date:
102
+ - Fri, 08 Jun 2012 21:06:18 GMT
103
+ content-type:
104
+ - application/json
105
+ transfer-encoding:
106
+ - chunked
107
+ connection:
108
+ - keep-alive
109
+ status:
110
+ - 404 Not Found
111
+ etag:
112
+ - b0dcd496ec3896280a7c636e2d5b9870
113
+ body:
114
+ encoding: US-ASCII
115
+ string: ! '{name: "HTTPError", message: "404 Not found"}
116
+
117
+ '
118
+ http_version: '1.1'
119
+ recorded_at: Fri, 08 Jun 2012 21:06:18 GMT
120
+ - request:
121
+ method: post
122
+ uri: http://impact.brighterplanet.com/rail_trips.json
123
+ body:
124
+ encoding: US-ASCII
125
+ string: rail_traction=electric&key=carbon_test
126
+ headers:
127
+ accept:
128
+ - ! '*/*'
129
+ user-agent:
130
+ - Ruby
131
+ content-type:
132
+ - application/x-www-form-urlencoded
133
+ response:
134
+ status:
135
+ code: 200
136
+ message: OK
137
+ headers:
138
+ server:
139
+ - nginx
140
+ date:
141
+ - Fri, 08 Jun 2012 21:06:18 GMT
142
+ content-type:
143
+ - application/json
144
+ transfer-encoding:
145
+ - chunked
146
+ connection:
147
+ - keep-alive
148
+ status:
149
+ - 200 OK
150
+ body:
151
+ encoding: US-ASCII
152
+ string: ! '{"compliance":[],"decisions":{"carbon":{"description":"2.4 kg","object":{"value":2.362143293092419,"units":"kilograms"},"methodology":"from
153
+ distance, co2 emission factor, date, and timeframe"},"co2_emission_factor":{"description":"0.06364482122342524","object":0.06364482122342524,"methodology":"default"},"diesel_consumption":{"description":"0.32523107136721763","object":0.32523107136721763,"methodology":"from
154
+ distance and diesel intensity"},"electricity_consumption":{"description":"4.010861619796626","object":4.010861619796626,"methodology":"from
155
+ distance and electricity intensity"},"diesel_intensity":{"description":"0.008762920291076415","object":0.008762920291076415,"methodology":"default"},"electricity_intensity":{"description":"0.10806735200626398","object":0.10806735200626398,"methodology":"default"},"distance":{"description":"37.11446191042177
156
+ km","object":{"value":37.11446191042177,"units":"kilometres"},"methodology":"default"},"speed":{"description":"32.49720001220703","object":32.49720001220703,"methodology":"default"},"date":{"description":"2012-01-01","object":"2012-01-01","methodology":"from
157
+ timeframe"}},"emitter":"RailTrip","equivalents":{"cars_off_the_road_for_a_year":0.0004299100793428203,"cars_off_the_road_for_a_month":0.005154196665527658,"cars_off_the_road_for_a_week":0.02233406483618882,"cars_off_the_road_for_a_day":0.15676600178937145,"cars_to_priuses_for_a_year":0.0008598201586856405,"cars_to_priuses_for_a_month":0.010308393331055316,"cars_to_priuses_for_a_week":0.04466812967237764,"cars_to_priuses_for_a_day":0.3135320035787429,"one_way_domestic_flight":0.007676965702550361,"round_trip_domestic_flight":0.0038384828512751804,"one_way_cross_country_flight":0.0026975676407115425,"round_trip_cross_country_flight":0.0013487838203557713,"vegan_meals_instead_of_non_vegan_ones":1.9007860000886594,"days_of_veganism":0.6335953333628864,"weeks_of_veganism":0.0905126067047153,"months_of_veganism":0.021119923183539314,"years_of_veganism":0.0017361753204229277,"barrels_of_petroleum":0.005494345299732966,"canisters_of_bbq_propane":0.09842342459328182,"railroad_cars_full_of_coal":1.1810716465462095e-05,"homes_energy_in_a_year":0.00022912789942996462,"homes_energy_in_a_month":0.0027377240766941137,"homes_energy_in_a_week":0.011860321474617037,"homes_energy_in_a_day":0.08325846465162849,"homes_electricity_in_a_year":0.00034723506408458556,"homes_electricity_in_a_month":0.004155010052549564,"homes_electricity_in_a_week":0.01800425617995042,"homes_electricity_in_a_day":0.1263723040371513,"homes_with_lowered_thermostat_2_degrees_for_a_winter":0.012398890145442107,"homes_with_raised_thermostat_3_degrees_for_a_summer":0.0055746581716981086,"replaced_refrigerators":0.002378678296144066,"loads_of_cold_laundry":1.0831891527670459,"lightbulbs_for_a_year":0.004360516519048605,"lightbulbs_for_a_month":0.053065549079321185,"lightbulbs_for_a_week":0.2274224319723519,"lightbulbs_for_a_day":1.5919641102363427,"lightbulbs_for_an_evening":9.551787023561348,"lightbulbs_to_CFLs_for_a_day":27.09727009527065,"lightbulbs_to_CFLs_for_a_week":3.8710379101405805,"lightbulbs_to_CFLs_for_a_month":0.9032434388425583,"lightbulbs_to_CFLs_for_a_year":0.07423980155860163,"days_with_lightbulbs_to_CFLs":0.6021622925617056,"weeks_with_lightbulbs_to_CFLs":0.08602217230454662,"months_with_lightbulbs_to_CFLs":0.02007113156140628,"years_with_lightbulbs_to_CFLs":0.0016487760185785085,"recycled_kgs_of_trash":1.6290639327976522,"recycled_bags_of_trash":0.9026576273058715},"methodology":"http://impact.brighterplanet.com/rail_trips?rail_traction=electric&timeframe=2012-01-01%2F2013-01-01","scope":"The
158
+ rail trip emission estimate is the anthropogenic emissions per passenger from
159
+ rail fuel combustion. It includes includes CO2 emissions from direct fuel
160
+ combustion and indirect fuel combustion to generate purchased electricity.","timeframe":"2012-01-01/2013-01-01","characteristics":{"rail_traction":{"description":"electric","object":{"rail_traction":{"name":"electric"}}}},"errors":["API
161
+ key \"carbon_test\" could not be verified. Please register at http://keys.brighterplanet.com"]}'
162
+ http_version: '1.1'
163
+ recorded_at: Fri, 08 Jun 2012 21:06:18 GMT
164
+ - request:
165
+ method: post
166
+ uri: http://impact.brighterplanet.com/automobiles.json
167
+ body:
168
+ encoding: US-ASCII
169
+ string: make=Nissan&model=Altima&year=2006&automobile_fuel%5Bcode%5D=R&timeframe=2010-01-01%2F2011-01-01&key=carbon_test
170
+ headers:
171
+ accept:
172
+ - ! '*/*'
173
+ user-agent:
174
+ - Ruby
175
+ content-type:
176
+ - application/x-www-form-urlencoded
177
+ response:
178
+ status:
179
+ code: 200
180
+ message: OK
181
+ headers:
182
+ server:
183
+ - nginx
184
+ date:
185
+ - Fri, 08 Jun 2012 21:06:18 GMT
186
+ content-type:
187
+ - application/json
188
+ transfer-encoding:
189
+ - chunked
190
+ connection:
191
+ - keep-alive
192
+ status:
193
+ - 200 OK
194
+ body:
195
+ encoding: US-ASCII
196
+ string: ! '{"compliance":[],"decisions":{"carbon":{"description":"4520.8 kg","object":{"value":4520.789934497878,"units":"kilograms"},"methodology":"from
197
+ co2 emission, ch4 emission, n2o emission, and hfc emission"},"co2_emission":{"description":"4308.585980497603","object":4308.585980497603,"methodology":"from
198
+ fuel use and automobile fuel"},"co2_biogenic_emission":{"description":"0.0","object":0.0,"methodology":"from
199
+ fuel use and automobile fuel"},"ch4_emission":{"description":"4.537572120026403","object":4.537572120026403,"methodology":"from
200
+ fuel use and automobile fuel"},"n2o_emission":{"description":"15.37211589011779","object":15.37211589011779,"methodology":"from
201
+ fuel use and automobile fuel"},"hfc_emission":{"description":"192.29426599013075","object":192.29426599013075,"methodology":"from
202
+ fuel use and automobile fuel"},"energy":{"description":"63708.4 MJ","object":{"value":63708.41114166553,"units":"megajoules"},"methodology":"from
203
+ fuel use and automobile fuel"},"fuel_use":{"description":"1,839.8372129905256
204
+ l","object":{"value":1839.8372129905256,"units":"litres"},"methodology":"from
205
+ fuel efficiency and distance"},"distance":{"description":"17845.6","object":17845.6,"methodology":"from
206
+ annual distance"},"annual_distance":{"description":"17,845.6 km","object":{"value":17845.6,"units":"kilometres"},"methodology":"from
207
+ automobile fuel"},"speed":{"description":"50.94382232429702 km/h","object":{"value":50.94382232429702,"units":"kilometres_per_hour"},"methodology":"from
208
+ urbanity and safe country"},"fuel_efficiency":{"description":"9.699553783344362
209
+ km/l","object":{"value":9.699553783344362,"units":"kilometres_per_litre"},"methodology":"from
210
+ make model year and urbanity"},"hybridity_multiplier":{"description":"1.0","object":1.0,"methodology":"default"},"urbanity":{"description":"0.43","object":0.43,"methodology":"from
211
+ safe country"},"safe_country":{"description":null,"object":{"country":{"automobile_city_speed":32.0259,"automobile_city_speed_units":"kilometres_per_hour","automobile_fuel_efficiency":8.226530750610781,"automobile_fuel_efficiency_units":"kilometres_per_litre","automobile_highway_speed":91.8935,"automobile_highway_speed_units":"kilometres_per_hour","automobile_trip_distance":16.3348,"automobile_trip_distance_units":"kilometres","automobile_urbanity":0.43,"cooling_degree_days":null,"cooling_degree_days_units":null,"electricity_emission_factor":0.626089,"electricity_emission_factor_units":"kilograms_co2e_per_kilowatt_hour","electricity_loss_factor":0.096,"flight_route_inefficiency_factor":1.100000023841858,"heating_degree_days":null,"heating_degree_days_units":null,"iso_3166_alpha_3_code":null,"iso_3166_code":null,"iso_3166_numeric_code":null,"lodging_district_heat_intensity":1.7463,"lodging_district_heat_intensity_units":"megajoules_per_occupied_room_night","lodging_electricity_intensity":32.906,"lodging_electricity_intensity_units":"kilowatt_hours_per_occupied_room_night","lodging_fuel_oil_intensity":0.412389,"lodging_fuel_oil_intensity_units":"gallons_per_occupied_room_night","lodging_natural_gas_intensity":1.93316,"lodging_natural_gas_intensity_units":"cubic_metres_per_occupied_room_night","lodging_occupancy_rate":0.601,"name":"fallback","rail_passengers":null,"rail_speed":32.49720001220703,"rail_speed_units":"kilometres_per_hour","rail_trip_co2_emission_factor":0.06364482122342524,"rail_trip_co2_emission_factor_units":"kilograms_per_passenger_kilometre","rail_trip_diesel_intensity":0.008762920291076415,"rail_trip_diesel_intensity_units":"litres_per_passenger_kilometre","rail_trip_distance":37.11446191042177,"rail_trip_distance_units":"kilometres","rail_trip_electricity_intensity":0.10806735200626398,"rail_trip_electricity_intensity_units":"kilowatt_hour_per_passenger_kilometre"}},"methodology":"default"},"active_subtimeframe":{"description":"2010-01-01/2011-01-01","object":"2010-01-01/2011-01-01","methodology":"from
212
+ acquisition and retirement"},"acquisition":{"description":"2006-01-01","object":"2006-01-01","methodology":"from
213
+ year"},"retirement":{"description":"2011-01-01","object":"2011-01-01","methodology":"default"},"make_model_year":{"description":"Nissan
214
+ ALTIMA 2006","object":{"automobile_make_model_year":{"fuel_code":"R","fuel_efficiency_city":8.15793,"fuel_efficiency_city_units":"kilometres_per_litre","fuel_efficiency_highway":11.3122,"fuel_efficiency_highway_units":"kilometres_per_litre","hybridity":false,"make_name":"Nissan","model_name":"ALTIMA","name":"Nissan
215
+ ALTIMA 2006","year":2006}},"methodology":"from make, model, and year"},"make_year":{"description":"Nissan
216
+ 2006","object":{"automobile_make_year":{"fuel_efficiency":11.2297,"fuel_efficiency_units":"kilometres_per_litre","make_name":"Nissan","name":"Nissan
217
+ 2006","volume":1076456,"year":2006}},"methodology":"from make and year"},"make_model":{"description":"Nissan
218
+ ALTIMA","object":{"automobile_make_model":{"fuel_efficiency_city":8.47904,"fuel_efficiency_city_units":"kilometres_per_litre","fuel_efficiency_highway":11.65,"fuel_efficiency_highway_units":"kilometres_per_litre","make_name":"Nissan","model_name":"ALTIMA","name":"Nissan
219
+ ALTIMA"}},"methodology":"from make and model"}},"emitter":"Automobile","equivalents":{"cars_off_the_road_for_a_year":0.8227837680786138,"cars_off_the_road_for_a_month":9.86436363707437,"cars_off_the_road_for_a_week":42.744068830677435,"cars_off_the_road_for_a_day":300.0267447928861,"cars_to_priuses_for_a_year":1.6455675361572275,"cars_to_priuses_for_a_month":19.72872727414874,"cars_to_priuses_for_a_week":85.48813766135487,"cars_to_priuses_for_a_day":600.0534895857722,"one_way_domestic_flight":14.692567287118102,"round_trip_domestic_flight":7.346283643559051,"one_way_cross_country_flight":5.1627421051965765,"round_trip_cross_country_flight":2.5813710525982883,"vegan_meals_instead_of_non_vegan_ones":3637.820890021294,"days_of_veganism":1212.6069633404313,"weeks_of_veganism":173.22762871008968,"months_of_veganism":40.42038280434552,"years_of_veganism":3.32278060185594,"barrels_of_petroleum":10.515357387642064,"canisters_of_bbq_propane":188.36775420072308,"railroad_cars_full_of_coal":0.022603949672489392,"homes_energy_in_a_year":0.4385166236462941,"homes_energy_in_a_month":5.2395955340830405,"homes_energy_in_a_week":22.698886261113845,"homes_energy_in_a_day":159.3442828212467,"homes_electricity_in_a_year":0.664556120371188,"homes_electricity_in_a_month":7.9520694947817665,"homes_electricity_in_a_week":34.45746088074283,"homes_electricity_in_a_day":241.85774070570196,"homes_with_lowered_thermostat_2_degrees_for_a_winter":23.72962636617936,"homes_with_raised_thermostat_3_degrees_for_a_summer":10.669064245414992,"replaced_refrigerators":4.552435464039363,"loads_of_cold_laundry":2073.062473943216,"lightbulbs_for_a_year":8.345378219083083,"lightbulbs_for_a_month":101.55954587849482,"lightbulbs_for_a_week":435.25261331358666,"lightbulbs_for_a_day":3046.7818555649105,"lightbulbs_for_an_evening":18280.695654179395,"lightbulbs_to_CFLs_for_a_day":51860.13323463397,"lightbulbs_to_CFLs_for_a_week":7408.589170436301,"lightbulbs_to_CFLs_for_a_month":1728.6732175231018,"lightbulbs_to_CFLs_for_a_year":142.0839068513338,"days_with_lightbulbs_to_CFLs":1152.448811682068,"weeks_with_lightbulbs_to_CFLs":164.6336070446092,"months_with_lightbulbs_to_CFLs":38.41315207342846,"years_with_lightbulbs_to_CFLs":3.155511374279519,"recycled_kgs_of_trash":3117.785382276134,"recycled_bags_of_trash":1727.5520616193464},"methodology":"http://impact.brighterplanet.com/automobiles?automobile_fuel%5Bcode%5D=R&make=Nissan&model=Altima&timeframe=2010-01-01%2F2011-01-01&year=2006","scope":"The
220
+ automobile emission estimate is the total anthropogenic emissions from fuel
221
+ and air conditioning used by the automobile during the timeframe. It includes
222
+ CO2 emissions from combustion of non-biogenic fuel, CH4 and N2O emissions
223
+ from combustion of all fuel, and fugitive HFC emissions from air conditioning.","timeframe":"2010-01-01/2011-01-01","characteristics":{"make":{"description":"Nissan","object":{"automobile_make":{"fuel_efficiency":11.9656,"fuel_efficiency_units":"kilometres_per_litre","name":"Nissan"}}},"model":{"description":"ALTIMA","object":{"automobile_model":{"name":"ALTIMA"}}},"year":{"description":2006,"object":{"automobile_year":{"year":2006}}},"automobile_fuel":{"description":"regular
224
+ gasoline","object":{"automobile_fuel":{"annual_distance":17845.6,"annual_distance_units":"kilometres","base_fuel_name":"Motor
225
+ Gasoline","blend_fuel_name":null,"blend_portion":null,"ch4_emission_factor":0.00246629,"ch4_emission_factor_units":"kilograms_co2e_per_litre","co2_biogenic_emission_factor":0.0,"co2_biogenic_emission_factor_units":"kilograms_per_litre","co2_emission_factor":2.34183,"co2_emission_factor_units":"kilograms_per_litre","code":"R","distance_key":"gasoline","ef_key":"gasoline","emission_factor":2.45717,"emission_factor_units":"kilograms_co2e_per_litre","energy_content":34.6272,"energy_content_units":"megajoules_per_litre","hfc_emission_factor":0.104517,"hfc_emission_factor_units":"kilograms_co2e_per_litre","n2o_emission_factor":0.00835515,"n2o_emission_factor_units":"kilograms_co2e_per_litre","name":"regular
226
+ gasoline"}}}},"errors":["API key \"carbon_test\" could not be verified. Please
227
+ register at http://keys.brighterplanet.com"]}'
228
+ http_version: '1.1'
229
+ recorded_at: Fri, 08 Jun 2012 21:06:18 GMT
230
+ recorded_with: VCR 2.2.0