earth 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. data/Rakefile +9 -21
  2. data/data/rail/ntd_companies.csv +1 -0
  3. data/data/rail/ntd_fuel_consumption.csv +1 -0
  4. data/data/rail/ntd_modes.csv +1 -0
  5. data/data/rail/ntd_service.csv +1 -0
  6. data/errata/flight_segment/bts_errata.csv +6 -0
  7. data/lib/earth.rb +1 -0
  8. data/lib/earth/air/aircraft.rb +3 -5
  9. data/lib/earth/air/airline.rb +2 -3
  10. data/lib/earth/air/airport.rb +4 -5
  11. data/lib/earth/air/bts_aircraft.rb +1 -1
  12. data/lib/earth/air/flight_distance_class.rb +0 -1
  13. data/lib/earth/air/flight_distance_class/data_miner.rb +0 -4
  14. data/lib/earth/air/flight_distance_class_seat_class.rb +0 -1
  15. data/lib/earth/air/flight_segment.rb +12 -13
  16. data/lib/earth/air/flight_segment/data_miner.rb +13 -0
  17. data/lib/earth/automobile/automobile_activity_year.rb +0 -1
  18. data/lib/earth/automobile/automobile_activity_year_type.rb +4 -4
  19. data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +1 -2
  20. data/lib/earth/automobile/automobile_fuel.rb +1 -2
  21. data/lib/earth/automobile/automobile_make.rb +0 -1
  22. data/lib/earth/automobile/automobile_make/data_miner.rb +2 -0
  23. data/lib/earth/automobile/automobile_make_model.rb +1 -2
  24. data/lib/earth/automobile/automobile_make_model_year_variant.rb +0 -1
  25. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +2 -223
  26. data/lib/earth/automobile/automobile_make_model_year_variant/parser.rb +224 -0
  27. data/lib/earth/automobile/automobile_make_year_fleet.rb +0 -1
  28. data/lib/earth/automobile/automobile_model.rb +0 -1
  29. data/lib/earth/automobile/automobile_size_class.rb +0 -1
  30. data/lib/earth/automobile/automobile_type_fuel.rb +0 -1
  31. data/lib/earth/automobile/automobile_type_fuel_control.rb +0 -1
  32. data/lib/earth/automobile/automobile_type_fuel_year.rb +4 -4
  33. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +7 -15
  34. data/lib/earth/automobile/automobile_year.rb +0 -1
  35. data/lib/earth/bus/bus_class.rb +0 -1
  36. data/lib/earth/bus/bus_fuel.rb +1 -72
  37. data/lib/earth/bus/bus_fuel_control.rb +0 -1
  38. data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -2
  39. data/lib/earth/bus/bus_fuel_year_control.rb +0 -1
  40. data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +0 -2
  41. data/lib/earth/computation/computation_carrier.rb +1 -11
  42. data/lib/earth/computation/computation_carrier_instance_class.rb +4 -25
  43. data/lib/earth/computation/computation_carrier_region.rb +0 -1
  44. data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -3
  45. data/lib/earth/diet/diet_class.rb +0 -1
  46. data/lib/earth/diet/food_group.rb +1 -1
  47. data/lib/earth/electricity/electric_market.rb +2 -0
  48. data/lib/earth/electricity/electric_utility.rb +11 -4
  49. data/lib/earth/electricity/electric_utility/data_miner.rb +2 -8
  50. data/lib/earth/electricity/green_button_adoption.rb +2 -1
  51. data/lib/earth/fuel/fuel.rb +20 -81
  52. data/lib/earth/fuel/fuel_year.rb +0 -44
  53. data/lib/earth/fuel/greenhouse_gas.rb +0 -40
  54. data/lib/earth/hospitality/lodging_class.rb +0 -1
  55. data/lib/earth/industry/cbecs_energy_intensity.rb +25 -29
  56. data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +1 -1
  57. data/lib/earth/industry/industry.rb +1 -2
  58. data/lib/earth/industry/mecs_energy.rb +9 -10
  59. data/lib/earth/industry/mecs_ratio.rb +2 -1
  60. data/lib/earth/industry/merchant_category.rb +1 -0
  61. data/lib/earth/industry/naics_2002.rb +2 -0
  62. data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +1 -0
  63. data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +1 -0
  64. data/lib/earth/industry/naics_2007.rb +1 -0
  65. data/lib/earth/industry/sic_1987.rb +1 -0
  66. data/lib/earth/locality/census_division.rb +1 -3
  67. data/lib/earth/locality/climate_division.rb +0 -1
  68. data/lib/earth/locality/country.rb +1 -2
  69. data/lib/earth/locality/country/data_miner.rb +4 -0
  70. data/lib/earth/locality/egrid_country.rb +0 -1
  71. data/lib/earth/locality/egrid_region.rb +1 -3
  72. data/lib/earth/locality/egrid_subregion.rb +1 -3
  73. data/lib/earth/locality/electricity_mix.rb +2 -4
  74. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +0 -1
  75. data/lib/earth/locality/state.rb +0 -1
  76. data/lib/earth/locality/zip_code.rb +0 -1
  77. data/lib/earth/model.rb +1 -1
  78. data/lib/earth/pet/breed.rb +0 -1
  79. data/lib/earth/pet/breed_gender.rb +0 -1
  80. data/lib/earth/pet/gender.rb +0 -1
  81. data/lib/earth/pet/species.rb +1 -3
  82. data/lib/earth/rail/country_rail_class.rb +0 -1
  83. data/lib/earth/rail/country_rail_traction.rb +0 -1
  84. data/lib/earth/rail/country_rail_traction_class.rb +0 -1
  85. data/lib/earth/rail/national_transit_database_company.rb +1 -3
  86. data/lib/earth/rail/national_transit_database_company/data_miner.rb +1 -1
  87. data/lib/earth/rail/national_transit_database_mode.rb +0 -1
  88. data/lib/earth/rail/national_transit_database_mode/data_miner.rb +1 -1
  89. data/lib/earth/rail/national_transit_database_record.rb +0 -1
  90. data/lib/earth/rail/national_transit_database_record/data_miner.rb +2 -2
  91. data/lib/earth/rail/rail_class.rb +0 -1
  92. data/lib/earth/rail/rail_class/data_miner.rb +5 -4
  93. data/lib/earth/rail/rail_company.rb +0 -1
  94. data/lib/earth/rail/rail_fuel.rb +0 -1
  95. data/lib/earth/rail/rail_traction.rb +0 -1
  96. data/lib/earth/rail/rail_traction/data_miner.rb +2 -8
  97. data/lib/earth/residence/air_conditioner_use.rb +0 -1
  98. data/lib/earth/residence/clothes_machine_use.rb +0 -1
  99. data/lib/earth/residence/dishwasher_use.rb +0 -1
  100. data/lib/earth/residence/residence_appliance.rb +0 -1
  101. data/lib/earth/residence/residence_class.rb +0 -1
  102. data/lib/earth/residence/residence_fuel_price.rb +1 -2
  103. data/lib/earth/residence/urbanity.rb +0 -1
  104. data/lib/earth/shipping/carrier.rb +1 -52
  105. data/lib/earth/shipping/carrier_mode.rb +0 -34
  106. data/lib/earth/shipping/shipment_mode.rb +0 -26
  107. data/lib/earth/tasks.rb +14 -4
  108. data/lib/earth/version.rb +1 -1
  109. data/spec/earth/air/aircraft_spec.rb +9 -1
  110. data/spec/earth/air/airline_spec.rb +2 -2
  111. data/spec/earth/air/airport_spec.rb +1 -2
  112. data/spec/earth/air/bts_aircraft_spec.rb +2 -2
  113. data/spec/earth/air/flight_distance_class_seat_class_spec.rb +22 -0
  114. data/spec/earth/air/flight_distance_class_spec.rb +26 -18
  115. data/spec/earth/air/flight_seat_class_spec.rb +12 -0
  116. data/spec/earth/air/flight_segment_spec.rb +38 -33
  117. data/spec/earth/automobile/automobile_activity_year_spec.rb +20 -14
  118. data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +14 -10
  119. data/spec/earth/automobile/automobile_activity_year_type_spec.rb +28 -20
  120. data/spec/earth/automobile/automobile_fuel_spec.rb +106 -52
  121. data/spec/earth/automobile/automobile_make_model_spec.rb +103 -62
  122. data/spec/earth/automobile/automobile_make_model_year_spec.rb +69 -46
  123. data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +108 -109
  124. data/spec/earth/automobile/automobile_make_spec.rb +8 -8
  125. data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +10 -6
  126. data/spec/earth/automobile/automobile_make_year_spec.rb +10 -9
  127. data/spec/earth/automobile/automobile_model_spec.rb +3 -0
  128. data/spec/earth/automobile/automobile_size_class_spec.rb +12 -11
  129. data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +9 -9
  130. data/spec/earth/automobile/automobile_type_fuel_spec.rb +23 -18
  131. data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +37 -29
  132. data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +35 -36
  133. data/spec/earth/automobile/automobile_year_spec.rb +4 -2
  134. data/spec/earth/bus/bus_class_spec.rb +10 -0
  135. data/spec/earth/bus/bus_fuel_control_spec.rb +3 -5
  136. data/spec/earth/bus/bus_fuel_spec.rb +16 -8
  137. data/spec/earth/bus/bus_fuel_year_control_spec.rb +7 -7
  138. data/spec/earth/computation/computation_carrrier_instance_class_spec.rb +17 -0
  139. data/spec/earth/computation/computation_carrrier_region_spec.rb +10 -0
  140. data/spec/earth/computation/computation_carrrier_spec.rb +17 -0
  141. data/spec/earth/diet/diet_class_spec.rb +14 -0
  142. data/spec/earth/diet/food_group_spec.rb +26 -0
  143. data/spec/earth/electricity/electric_market_spec.rb +4 -5
  144. data/spec/earth/electricity/electric_utility_spec.rb +30 -19
  145. data/spec/earth/electricity/green_button_adoption_spec.rb +29 -7
  146. data/spec/earth/fuel/fuel_spec.rb +88 -14
  147. data/spec/earth/fuel/fuel_year_spec.rb +21 -0
  148. data/spec/earth/fuel/greenhouse_gas_spec.rb +23 -0
  149. data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +13 -10
  150. data/spec/earth/hospitality/lodging_class_spec.rb +1 -1
  151. data/spec/earth/industry/cbecs_energy_intensity_spec.rb +72 -72
  152. data/spec/earth/industry/industry_spec.rb +16 -9
  153. data/spec/earth/industry/mecs_energy_spec.rb +76 -72
  154. data/spec/earth/industry/mecs_ratio_spec.rb +35 -31
  155. data/spec/earth/industry/merchant_category_spec.rb +7 -5
  156. data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +10 -19
  157. data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +9 -19
  158. data/spec/earth/industry/naics_2002_spec.rb +1 -11
  159. data/spec/earth/industry/naics_2007_spec.rb +2 -11
  160. data/spec/earth/industry/sic_1987_spec.rb +3 -14
  161. data/spec/earth/locality/census_division_spec.rb +25 -0
  162. data/spec/earth/locality/census_region_spec.rb +8 -0
  163. data/spec/earth/locality/climate_division_spec.rb +13 -0
  164. data/spec/earth/locality/country_spec.rb +24 -23
  165. data/spec/earth/locality/egrid_country_spec.rb +7 -6
  166. data/spec/earth/locality/egrid_region_spec.rb +6 -6
  167. data/spec/earth/locality/egrid_subregion_spec.rb +14 -14
  168. data/spec/earth/locality/electricity_mix_spec.rb +17 -17
  169. data/spec/earth/locality/padd_spec.rb +21 -0
  170. data/spec/earth/locality/state_spec.rb +8 -11
  171. data/spec/earth/locality/zip_code_spec.rb +29 -22
  172. data/spec/earth/pet/breed_gender_spec.rb +8 -0
  173. data/spec/earth/pet/breed_spec.rb +8 -0
  174. data/spec/earth/pet/gender_spec.rb +8 -0
  175. data/spec/earth/pet/species_spec.rb +11 -5
  176. data/spec/earth/rail/country_rail_class_spec.rb +16 -0
  177. data/spec/earth/rail/country_rail_traction_class_spec.rb +14 -0
  178. data/spec/earth/rail/country_rail_traction_spec.rb +14 -0
  179. data/spec/earth/rail/national_transit_database_company_spec.rb +103 -0
  180. data/spec/earth/rail/national_transit_database_mode_spec.rb +21 -0
  181. data/spec/earth/rail/national_transit_database_record_spec.rb +31 -0
  182. data/spec/earth/rail/rail_class_spec.rb +8 -0
  183. data/spec/earth/rail/rail_company_spec.rb +20 -0
  184. data/spec/earth/rail/rail_fuel_spec.rb +19 -0
  185. data/spec/earth/rail/rail_traction_spec.rb +8 -0
  186. data/spec/earth/residence/air_conditioner_use_spec.rb +17 -0
  187. data/spec/earth/residence/clothes_machine_use_spec.rb +11 -0
  188. data/spec/earth/residence/dishwasher_use_spec.rb +11 -0
  189. data/spec/earth/residence/residence_appliance_spec.rb +19 -0
  190. data/spec/earth/residence/residence_class_spec.rb +15 -0
  191. data/spec/earth/residence/residence_fuel_price_spec.rb +12 -0
  192. data/spec/earth/residence/residence_fuel_type_spec.rb +18 -0
  193. data/spec/earth/residence/residential_energy_consumption_survey_response_spec.rb +13 -0
  194. data/spec/earth/residence/urbanity_spec.rb +8 -0
  195. data/spec/earth/shipping/carrier_mode_spec.rb +18 -0
  196. data/spec/earth/shipping/carrier_spec.rb +27 -0
  197. data/spec/earth/shipping/shipment_mode_spec.rb +16 -0
  198. data/spec/earth_spec.rb +1 -1
  199. data/spec/factories/airline.rb +0 -1
  200. data/spec/factories/airport.rb +0 -1
  201. data/spec/factories/automobile_activity_year.rb +8 -0
  202. data/spec/factories/automobile_activity_year_type.rb +8 -0
  203. data/spec/factories/automobile_activity_year_type_fuel.rb +9 -0
  204. data/spec/factories/automobile_fuel.rb +15 -0
  205. data/spec/factories/automobile_make.rb +9 -0
  206. data/spec/factories/automobile_make_model.rb +10 -0
  207. data/spec/factories/automobile_make_model_year.rb +9 -0
  208. data/spec/factories/automobile_model.rb +9 -0
  209. data/spec/factories/automobile_type_fuel.rb +7 -0
  210. data/spec/factories/automobile_type_fuel_control.rb +16 -0
  211. data/spec/factories/automobile_type_fuel_year.rb +9 -0
  212. data/spec/factories/automobile_type_fuel_year_control.rb +11 -0
  213. data/spec/factories/bus_fuel.rb +7 -0
  214. data/spec/factories/bus_fuel_year_control.rb +9 -0
  215. data/spec/factories/cbecs_energy_intensity.rb +15 -0
  216. data/spec/factories/commercial_building_energy_consumption_survey_response.rb +10 -0
  217. data/spec/factories/electric_utility.rb +8 -0
  218. data/spec/factories/flight_distance_class.rb +8 -0
  219. data/spec/factories/flight_segment.rb +0 -1
  220. data/spec/factories/food_group.rb +8 -0
  221. data/spec/factories/fuel.rb +8 -0
  222. data/spec/factories/fuel_year.rb +8 -0
  223. data/spec/factories/green_button_adoption.rb +8 -0
  224. data/spec/factories/greenhouse_gas.rb +7 -0
  225. data/spec/factories/industry.rb +9 -0
  226. data/spec/factories/mecs_energy.rb +15 -0
  227. data/spec/factories/mecs_ratio.rb +15 -0
  228. data/spec/factories/national_transit_database_company.rb +8 -0
  229. data/spec/factories/national_transit_database_mode.rb +8 -0
  230. data/spec/factories/national_transit_database_record.rb +9 -0
  231. data/spec/factories/residence_appliance.rb +7 -0
  232. data/spec/factories/zip_code.rb +9 -0
  233. data/spec/spec_helper.rb +36 -19
  234. metadata +346 -66
  235. data/lib/earth/acronyms.rb +0 -12
  236. data/lib/earth/rail/rail_company_traction.rb +0 -24
  237. data/lib/earth/rail/rail_company_traction/data_miner.rb +0 -4
  238. data/lib/earth/rail/rail_company_traction_class.rb +0 -26
  239. data/lib/earth/rail/rail_company_traction_class/data_miner.rb +0 -4
@@ -1,23 +1,29 @@
1
1
  require 'spec_helper'
2
- require 'earth/automobile/automobile_activity_year'
2
+ require "#{Earth::FACTORY_DIR}/automobile_activity_year"
3
3
 
4
4
  describe AutomobileActivityYear do
5
- before :all do
6
- require 'earth/acronyms'
5
+ let(:aay) { AutomobileActivityYear }
6
+
7
+ describe '.find_by_closest_year' do
8
+ it "returns the closest year" do
9
+ aay.delete_all
10
+ twenty_nine = FactoryGirl.create :aay, :twenty_nine
11
+ twenty_ten = FactoryGirl.create :aay, :twenty_ten
12
+
13
+ aay.find_by_closest_year(2011).should == twenty_ten
14
+ aay.find_by_closest_year(2009).should == twenty_nine
15
+ aay.find_by_closest_year(2005).should == twenty_nine
16
+ end
7
17
  end
8
18
 
9
- describe 'verify', :sanity => true do
10
- it { AAY.count.should == 15 }
11
- it { AAY.where("hfc_emission_factor > 0").count.should == AAY.count }
19
+ describe 'Sanity check', :sanity => true do
20
+ let(:total) { aay.count }
21
+
22
+ it { total.should == 15 }
23
+ it { aay.where("hfc_emission_factor > 0").count.should == total }
12
24
 
13
25
  # spot check
14
- it { AAY.first.hfc_emission_factor.should be_within(1e-5).of(0.01656) }
15
- it { AAY.first.hfc_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
16
- end
17
-
18
- describe '.find_by_closest_year' do
19
- it { AAY.find_by_closest_year(1994).should == AAY.find(1995) }
20
- it { AAY.find_by_closest_year(2005).should == AAY.find(2005) }
21
- it { AAY.find_by_closest_year(2010).should == AAY.find(2009) }
26
+ it { aay.first.hfc_emission_factor.should be_within(1e-5).of(0.01656) }
27
+ it { aay.first.hfc_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
22
28
  end
23
29
  end
@@ -1,18 +1,22 @@
1
1
  require 'spec_helper'
2
- require 'earth/automobile/automobile_activity_year_type_fuel'
2
+ require "#{Earth::FACTORY_DIR}/automobile_activity_year_type_fuel"
3
3
 
4
4
  describe AutomobileActivityYearTypeFuel do
5
- before :all do
6
- require 'earth/acronyms'
7
- end
5
+ let(:aaytf) { AutomobileActivityYearTypeFuel }
8
6
 
9
- describe 'verify', :sanity => true do
10
- it { AAYTF.count.should == 120 }
11
- it { AAYTF.where(:distance => nil).count.should == 0 }
12
- it { AAYTF.where("fuel_family != 'alternative' AND fuel_consumption IS NULL").count.should == 0 }
7
+ describe '.latest' do
8
+ it "returns all records from the latest year" do
9
+ FactoryGirl.create :aaytf, :gas_car_2009
10
+ d = FactoryGirl.create :aaytf, :diesel_car_2010
11
+ g = FactoryGirl.create :aaytf, :gas_car_2010
12
+
13
+ aaytf.latest.should == [d, g]
14
+ end
13
15
  end
14
16
 
15
- describe '.latest' do
16
- it { AAYTF.latest.should == AAYTF.where(:activity_year => 2009) }
17
+ describe 'Sanity check', :sanity => true do
18
+ it { aaytf.count.should == 120 }
19
+ it { aaytf.where(:distance => nil).count.should == 0 }
20
+ it { aaytf.where("fuel_family != 'alternative' AND fuel_consumption IS NULL").count.should == 0 }
17
21
  end
18
22
  end
@@ -1,31 +1,39 @@
1
1
  require 'spec_helper'
2
- require 'earth/automobile/automobile_activity_year_type'
2
+ require "#{Earth::FACTORY_DIR}/automobile_activity_year_type"
3
+ require "#{Earth::FACTORY_DIR}/automobile_activity_year_type_fuel"
3
4
 
4
5
  describe AutomobileActivityYearType do
5
- before :all do
6
- require 'earth/acronyms'
7
- end
8
-
9
- describe 'verify', :sanity => true do
10
- it { AAYT.count.should == 30 }
11
- it { AAYT.where("hfc_emissions > 0").count.should == AAYT.count }
12
- it { AAYT.where("hfc_emission_factor > 0").count.should == AAYT.count }
13
-
14
- # spot check
15
- it { AAYT.first.hfc_emissions.should be_within(0.1).of(31000000000) }
16
- it { AAYT.first.hfc_emission_factor.should be_within(1e-5).of(0.02438) }
17
- it { AAYT.first.hfc_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
18
- end
6
+ let(:aayt) { AutomobileActivityYearType }
19
7
 
20
8
  describe '.find_by_type_name_and_closest_year' do
21
- it { AAYT.find_by_type_name_and_closest_year('Passenger cars', 2010).should == AAYT.where(:type_name => 'Passenger cars', :activity_year => 2009).first }
22
- it { AAYT.find_by_type_name_and_closest_year('Passenger cars', 2005).should == AAYT.where(:type_name => 'Passenger cars', :activity_year => 2005).first }
23
- it { AAYT.find_by_type_name_and_closest_year('Passenger cars', 1994).should == AAYT.where(:type_name => 'Passenger cars', :activity_year => 1995).first }
9
+ it 'returns the AAYT with the closest year' do
10
+ cars_2009 = FactoryGirl.create :aayt, :cars_2009
11
+ cars_2010 = FactoryGirl.create :aayt, :cars_2010
12
+
13
+ aayt.find_by_type_name_and_closest_year('cars', 2011).should == cars_2010
14
+ aayt.find_by_type_name_and_closest_year('cars', 2009).should == cars_2009
15
+ aayt.find_by_type_name_and_closest_year('cars', 2000).should == cars_2009
16
+ end
24
17
  end
25
18
 
26
19
  describe '#activity_year_type_fuels' do
27
- it 'should match' do
28
- AAYT.first.activity_year_type_fuels.should == AAYTF.where(:activity_year => 1995, :type_name => 'Light-duty trucks')
20
+ it 'returns activity year type fuels with the same activity year and type name' do
21
+ d = FactoryGirl.create :aaytf, :diesel_car_2010
22
+ g = FactoryGirl.create :aaytf, :gas_car_2010
23
+ cars_2010 = FactoryGirl.create :aayt, :cars_2010
24
+ cars_2010.activity_year_type_fuels.should == [d,g]
29
25
  end
30
26
  end
27
+
28
+ describe 'Sanity check', :sanity => true do
29
+ let(:total) { aayt.count }
30
+ it { total.should == 30 }
31
+ it { aayt.where("hfc_emissions > 0").count.should == total }
32
+ it { aayt.where("hfc_emission_factor > 0").count.should == total }
33
+
34
+ # spot check
35
+ it { aayt.first.hfc_emissions.should be_within(0.1).of(31000000000) }
36
+ it { aayt.first.hfc_emission_factor.should be_within(1e-5).of(0.02438) }
37
+ it { aayt.first.hfc_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
38
+ end
31
39
  end
@@ -1,18 +1,93 @@
1
1
  require 'spec_helper'
2
- require 'earth/automobile'
2
+ require "#{Earth::FACTORY_DIR}/automobile_fuel"
3
3
 
4
4
  describe AutomobileFuel do
5
- let(:fallback) { AutomobileFuel.fallback }
5
+ describe '.diesel' do
6
+ it "should return diesel" do
7
+ AutomobileFuel.delete_all
8
+ diesel = FactoryGirl.create :automobile_fuel, :diesel
9
+ AutomobileFuel.diesel.should == diesel
10
+ end
11
+ end
12
+
13
+ describe '.gasoline' do
14
+ it "should return gasoline" do
15
+ AutomobileFuel.delete_all
16
+ gas = FactoryGirl.create :automobile_fuel, :gas
17
+ AutomobileFuel.gasoline.should == gas
18
+ end
19
+ end
20
+
21
+ describe '.fallback_blend_portion' do
22
+ it "should return diesel's share of total US gasoline and diesel consumption" do
23
+ AutomobileFuel.delete_all
24
+ diesel = FactoryGirl.create :automobile_fuel, :diesel
25
+ gas = FactoryGirl.create :automobile_fuel, :gas
26
+ AutomobileFuel.fallback_blend_portion.should be_within(5e-2).of(0.1)
27
+ end
28
+ end
29
+
30
+ describe '#non_liquid?' do
31
+ it "should return true if energy content units are megajoules per litre" do
32
+ AutomobileFuel.delete_all
33
+ gas = FactoryGirl.create :automobile_fuel, :gas
34
+ cng = FactoryGirl.create :automobile_fuel, :cng
35
+
36
+ gas.non_liquid?.should == false
37
+ cng.non_liquid?.should == true
38
+ end
39
+ end
40
+
41
+ describe '#same_as?(other_auto_fuel)' do
42
+ it "should consider all grades of gasoline as the same" do
43
+ AutomobileFuel.delete_all
44
+ gas = FactoryGirl.create :automobile_fuel, :gas
45
+ regular = FactoryGirl.create :automobile_fuel, :regular
46
+ premium = FactoryGirl.create :automobile_fuel, :premium
47
+
48
+ gas.same_as?(gas).should == true
49
+ gas.same_as?(regular).should == true
50
+ gas.same_as?(premium).should == true
51
+ regular.same_as?(premium).should == true
52
+ end
53
+
54
+ it "should consider identical non-gasoline fuels as the same" do
55
+ AutomobileFuel.delete_all
56
+ b5 = FactoryGirl.create :automobile_fuel, :b5
57
+ b20 = FactoryGirl.create :automobile_fuel, :b20
58
+
59
+ b5.same_as?(b5).should == true
60
+ b5.same_as?(b20).should == false
61
+ end
62
+ end
6
63
 
7
- describe 'verify imported data', :sanity => true do
8
- it { AutomobileFuel.count.should == 12 }
64
+ describe '#suffix' do
65
+ it "returns 'DIESEL' for diesel and biodiesel fuels" do
66
+ %w{ D BP-B5 BP-B20 BP-B100 }.each do |fuel_code|
67
+ AutomobileFuel.new(:code => fuel_code).suffix.should == 'DIESEL'
68
+ end
69
+ end
70
+
71
+ it "returns 'FFV' for ethanol" do
72
+ AutomobileFuel.new(:code => 'E').suffix.should == 'FFV'
73
+ end
74
+
75
+ it "returns 'CNG' for cng" do
76
+ AutomobileFuel.new(:code => 'C').suffix.should == 'CNG'
77
+ end
78
+ end
79
+
80
+ describe 'Sanity check', :sanity => true do
81
+ let(:total) { AutomobileFuel.count }
82
+
83
+ it { total.should == 12 }
9
84
  it { AutomobileFuel.where(:distance_key => nil).count.should == 0 }
10
- it { AutomobileFuel.where("annual_distance >= 0").count.should == AutomobileFuel.count }
11
- it { AutomobileFuel.where("energy_content >= 0").count.should == AutomobileFuel.count }
12
- it { AutomobileFuel.where("co2_emission_factor >= 0").count.should == AutomobileFuel.count - 1 }
13
- it { AutomobileFuel.where("co2_biogenic_emission_factor >= 0").count.should == AutomobileFuel.count - 1 }
14
- it { AutomobileFuel.where("ch4_emission_factor >= 0").count.should == AutomobileFuel.count }
15
- it { AutomobileFuel.where("n2o_emission_factor >= 0").count.should == AutomobileFuel.count }
85
+ it { AutomobileFuel.where("annual_distance >= 0").count.should == total }
86
+ it { AutomobileFuel.where("energy_content >= 0").count.should == total }
87
+ it { AutomobileFuel.where("co2_emission_factor >= 0").count.should == total - 1 }
88
+ it { AutomobileFuel.where("co2_biogenic_emission_factor >= 0").count.should == total - 1 }
89
+ it { AutomobileFuel.where("ch4_emission_factor >= 0").count.should == total }
90
+ it { AutomobileFuel.where("n2o_emission_factor >= 0").count.should == total }
16
91
  it { AutomobileFuel.where("total_consumption >= 0").count.should == 2 }
17
92
 
18
93
  it { AutomobileFuel.find('gasoline').annual_distance.should be_within(0.1).of(17568.6) }
@@ -51,48 +126,27 @@ describe AutomobileFuel do
51
126
  fuel.n2o_emission_factor.should == AutomobileFuel.gasoline.n2o_emission_factor
52
127
  end
53
128
  end
54
- end
55
-
56
- describe '.diesel' do
57
- it { AutomobileFuel.diesel.should == AutomobileFuel.find('diesel') }
58
- end
59
-
60
- describe '.gasoline' do
61
- it { AutomobileFuel.gasoline.should == AutomobileFuel.find('gasoline') }
62
- end
63
-
64
- describe '.fallback_blend_portion' do
65
- it { AutomobileFuel.fallback_blend_portion.should be_within(1e-5).of(0.01260) }
66
- end
67
-
68
- describe '.fallback' do
69
- it { AutomobileFuel.fallback.name.should == 'fallback' }
70
- it { fallback.base_fuel.should == Fuel.find('Motor Gasoline') }
71
- it { fallback.blend_fuel.should == Fuel.find('Distillate Fuel Oil No. 2') }
72
- it { fallback.blend_portion.should be_within(1e-5).of(0.01260) }
73
-
74
- it { fallback.annual_distance.should be_within(0.1).of(17629.6) }
75
- it { fallback.energy_content.should be_within(1e-6).of(34.6766) }
76
- it { fallback.co2_emission_factor.should be_within(1e-6).of(2.34637) }
77
- it { fallback.co2_biogenic_emission_factor.should == 0.0 }
78
- it { fallback.ch4_emission_factor.should be_within(1e-8).of(4.203e-4) }
79
- it { fallback.n2o_emission_factor.should be_within(1e-8).of(5.665e-3) }
80
129
 
81
- it { fallback.energy_content_units.should == 'megajoules_per_litre' }
82
- it { fallback.co2_emission_factor_units.should == 'kilograms_per_litre' }
83
- it { fallback.co2_biogenic_emission_factor_units.should == 'kilograms_per_litre' }
84
- it { fallback.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
85
- it { fallback.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
86
- end
87
-
88
- describe '#non_liquid?' do
89
- it { AutomobileFuel.where(:energy_content_units => 'megajoules_per_litre').first.non_liquid?.should == false }
90
- it { AutomobileFuel.where("energy_content_units != 'megajoules_per_litre'").first.non_liquid?.should == true }
91
- end
92
-
93
- describe '#same_as?' do
94
- it { AutomobileFuel.find_by_code('G').same_as?(AutomobileFuel.find_by_code 'G').should == true }
95
- it { AutomobileFuel.find_by_code('G').same_as?(AutomobileFuel.find_by_code 'R').should == true }
96
- it { AutomobileFuel.find_by_code('G').same_as?(AutomobileFuel.find_by_code 'D').should == false }
130
+ describe '.fallback' do
131
+ let(:fallback) { AutomobileFuel.fallback }
132
+
133
+ it { fallback.name.should == 'fallback' }
134
+ it { fallback.base_fuel.should == Fuel.find('Motor Gasoline') }
135
+ it { fallback.blend_fuel.should == Fuel.find('Distillate Fuel Oil No. 2') }
136
+ it { fallback.blend_portion.should be_within(1e-5).of(0.01260) }
137
+
138
+ it { fallback.annual_distance.should be_within(0.1).of(17629.6) }
139
+ it { fallback.energy_content.should be_within(1e-6).of(34.6766) }
140
+ it { fallback.co2_emission_factor.should be_within(1e-6).of(2.34637) }
141
+ it { fallback.co2_biogenic_emission_factor.should == 0.0 }
142
+ it { fallback.ch4_emission_factor.should be_within(1e-8).of(4.203e-4) }
143
+ it { fallback.n2o_emission_factor.should be_within(1e-8).of(5.665e-3) }
144
+
145
+ it { fallback.energy_content_units.should == 'megajoules_per_litre' }
146
+ it { fallback.co2_emission_factor_units.should == 'kilograms_per_litre' }
147
+ it { fallback.co2_biogenic_emission_factor_units.should == 'kilograms_per_litre' }
148
+ it { fallback.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
149
+ it { fallback.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
150
+ end
97
151
  end
98
152
  end
@@ -1,28 +1,113 @@
1
1
  require 'spec_helper'
2
- require 'earth/automobile/automobile_make_model'
2
+ require "#{Earth::FACTORY_DIR}/automobile_fuel"
3
+ require "#{Earth::FACTORY_DIR}/automobile_make"
4
+ require "#{Earth::FACTORY_DIR}/automobile_make_model"
5
+ require "#{Earth::FACTORY_DIR}/automobile_make_model_year"
6
+ require "#{Earth::FACTORY_DIR}/automobile_model"
3
7
 
4
8
  describe AutomobileMakeModel do
5
- let(:civic) { AMM.where(:name => "Honda Civic").first }
6
- let(:civic_years) { AMMY.where(:make_name => 'Honda', :model_name => 'Civic') }
9
+ let(:amm) { AutomobileMakeModel }
10
+ let(:ammy) { AutomobileMakeModelYear }
7
11
 
8
- let(:civic_cng) { AMM.where(:name => "Honda Civic CNG").first }
9
- let(:civic_cng_years) { AMMY.where(:make_name => 'Honda', :model_name => 'Civic CNG') }
10
-
11
- let(:f150_ffv) { AMM.where(:name => "Ford F150 FFV").first }
12
- let(:f150_ffv_years) { AMMY.where(:make_name => 'Ford', :model_name => 'F150 FFV') }
12
+ describe '.custom_find' do
13
+ it 'finds diesel models' do
14
+ amm.delete_all
15
+ AutomobileMake.delete_all
16
+ AutomobileModel.delete_all
17
+ AutomobileFuel.delete_all
18
+
19
+ FactoryGirl.create :amm, :vw_jetta
20
+ FactoryGirl.create :amm, :vw_jetta_diesel
21
+ vw = FactoryGirl.create :automobile_make, :vw
22
+ jetta = FactoryGirl.create :automobile_model, :jetta
23
+
24
+ %w{ diesel b5 b20 b100 }.each do |fuel|
25
+ f = FactoryGirl.create :automobile_fuel, fuel.to_sym
26
+ amm.custom_find(
27
+ { :make => vw, :model => jetta, :automobile_fuel => f }
28
+ ).name.should == 'Volkswagen JETTA DIESEL'
29
+ end
30
+ end
31
+
32
+ it 'finds flex-fuel models' do
33
+ amm.delete_all
34
+ AutomobileMake.delete_all
35
+ AutomobileModel.delete_all
36
+ AutomobileFuel.delete_all
37
+
38
+ FactoryGirl.create :amm, :ford_f150_ffv
39
+ ford = FactoryGirl.create :automobile_make, :ford
40
+ f150 = FactoryGirl.create :automobile_model, :f150
41
+ e85 = FactoryGirl.create :automobile_fuel, :e85
42
+
43
+ amm.custom_find(
44
+ { :make => ford, :model => f150, :automobile_fuel => e85 }
45
+ ).name.should == 'Ford F150 FFV'
46
+ end
47
+
48
+ it 'finds cng models' do
49
+ amm.delete_all
50
+ AutomobileMake.delete_all
51
+ AutomobileModel.delete_all
52
+ AutomobileFuel.delete_all
53
+
54
+ FactoryGirl.create :amm, :honda_civic_cng
55
+ honda = FactoryGirl.create :automobile_make, :honda
56
+ civic = FactoryGirl.create :automobile_model, :civic
57
+ cng = FactoryGirl.create :automobile_fuel, :cng
58
+
59
+ amm.custom_find(
60
+ { :make => honda, :model => civic, :automobile_fuel => cng }
61
+ ).name.should == 'Honda CIVIC CNG'
62
+ end
63
+
64
+ it 'ignores fuel if it does not help' do
65
+ amm.delete_all
66
+ AutomobileMake.delete_all
67
+ AutomobileModel.delete_all
68
+ AutomobileFuel.delete_all
69
+
70
+ FactoryGirl.create :amm, :vw_jetta
71
+ FactoryGirl.create :amm, :vw_jetta_diesel
72
+ vw = FactoryGirl.create :automobile_make, :vw
73
+ jetta = FactoryGirl.create :automobile_model, :jetta
74
+ cng = FactoryGirl.create :automobile_fuel, :cng
75
+
76
+ amm.custom_find(
77
+ { :make => vw, :model => jetta, :automobile_fuel => cng }
78
+ ).name.should == 'Volkswagen JETTA'
79
+ end
80
+ end
13
81
 
14
- before :all do
15
- require 'earth/acronyms'
82
+ describe '#model_years' do
83
+ it "returns all the associated model years" do
84
+ ammy.delete_all
85
+ amm.delete_all
86
+
87
+ FactoryGirl.create :ammy, :honda_civic_2000
88
+ FactoryGirl.create :ammy, :honda_civic_cng_2000
89
+ FactoryGirl.create :ammy, :honda_civic_cng_2001
90
+
91
+ amm = FactoryGirl.create :amm, :honda_civic_cng
92
+ amm.model_years.should == ammy.where(:make_name => 'Honda', :model_name => 'CIVIC CNG')
93
+ end
16
94
  end
17
95
 
18
- describe 'verify', :sanity => true do
19
- it { AMM.where(:fuel_code => nil).count.should == 0 }
20
- it { AMM.where("fuel_efficiency_city > 0").count.should == AMM.count }
21
- it { AMM.where("fuel_efficiency_highway > 0").count.should == AMM.count }
22
- it { AMM.where("alt_fuel_code IS NOT NULL").count.should == 157 }
23
- it { AMM.where("alt_fuel_efficiency_city > 0").count.should == 157 }
24
- it { AMM.where("alt_fuel_efficiency_highway > 0").count.should == 157 }
25
- it { AMM.where(:type_name => nil).count.should == 0 }
96
+ describe 'Sanity check', :sanity => true do
97
+ let(:total) { amm.count }
98
+ let(:civic) { amm.where(:name => "Honda Civic").first }
99
+ let(:civic_cng) { amm.where(:name => "Honda Civic CNG").first }
100
+ let(:f150_ffv) { amm.where(:name => "Ford F150 FFV").first }
101
+
102
+ it { total.should == 2353 }
103
+
104
+ it { amm.where(:fuel_code => nil).count.should == 0 }
105
+ it { amm.where("fuel_efficiency_city > 0").count.should == total }
106
+ it { amm.where("fuel_efficiency_highway > 0").count.should == total }
107
+ it { amm.where("alt_fuel_code IS NOT NULL").count.should == 157 }
108
+ it { amm.where("alt_fuel_efficiency_city > 0").count.should == 157 }
109
+ it { amm.where("alt_fuel_efficiency_highway > 0").count.should == 157 }
110
+ it { amm.where(:type_name => nil).count.should == 0 }
26
111
 
27
112
  # spot checks
28
113
  it { civic.fuel_code.should == 'G' }
@@ -59,48 +144,4 @@ describe AutomobileMakeModel do
59
144
 
60
145
  it { f150_ffv.type_name.should == 'Light-duty trucks' }
61
146
  end
62
-
63
- describe '.custom_find' do
64
- it 'considers fuel' do
65
- %w{ diesel B5 B20 B100 }.each do |fuel|
66
- AMM.custom_find(
67
- {
68
- :make => AutomobileMake.find('Volkswagen'),
69
- :model => AutomobileModel.find('Jetta'),
70
- :automobile_fuel => AutomobileFuel.find(fuel)
71
- }
72
- ).name.should == 'Volkswagen JETTA DIESEL'
73
- end
74
-
75
- AMM.custom_find(
76
- {
77
- :make => AutomobileMake.find('Ford'),
78
- :model => AutomobileModel.find('F150'),
79
- :automobile_fuel => AutomobileFuel.find('E85')
80
- }
81
- ).name.should == 'Ford F150 FFV'
82
-
83
- AMM.custom_find(
84
- {
85
- :make => AutomobileMake.find('Honda'),
86
- :model => AutomobileModel.find('Civic'),
87
- :automobile_fuel => AutomobileFuel.find('CNG')
88
- }
89
- ).name.should == 'Honda CIVIC CNG'
90
- end
91
-
92
- it 'ignores fuel if it does not help' do
93
- AMM.custom_find(
94
- {
95
- :make => AutomobileMake.find('Volkswagen'),
96
- :model => AutomobileModel.find('Jetta'),
97
- :automobile_fuel => AutomobileFuel.find('CNG')
98
- }
99
- ).name.should == 'Volkswagen JETTA'
100
- end
101
- end
102
-
103
- describe '#model_years' do
104
- it { civic.model_years.sort.should == civic_years.sort }
105
- end
106
147
  end