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
@@ -2,11 +2,15 @@ require 'spec_helper'
2
2
  require 'earth/automobile/automobile_make_year_fleet'
3
3
 
4
4
  describe AutomobileMakeYearFleet do
5
- describe 'verify imported data', :sanity => true do
6
- it { AMYF.count.should == 1349 }
7
- it { AMYF.where('year >= 1978 AND year <= 2011').count.should == AMYF.count }
8
- it { AMYF.where('volume > 0').count.should == AMYF.count }
9
- it { AMYF.where('fuel_efficiency > 0').count.should == AMYF.count }
10
- it { AMYF.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == AMYF.count }
5
+ let(:amyf) { AutomobileMakeYearFleet }
6
+
7
+ describe 'Sanity check', :sanity => true do
8
+ let(:total) { amyf.count }
9
+
10
+ it { total.should == 1349 }
11
+ it { amyf.where('year >= 1978 AND year <= 2011').count.should == total }
12
+ it { amyf.where('volume > 0').count.should == total }
13
+ it { amyf.where('fuel_efficiency > 0').count.should == total }
14
+ it { amyf.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == total }
11
15
  end
12
16
  end
@@ -2,18 +2,19 @@ require 'spec_helper'
2
2
  require 'earth/automobile/automobile_make_year'
3
3
 
4
4
  describe AutomobileMakeYear do
5
- before :all do
6
- require 'earth/acronyms'
7
- end
5
+ let(:amy) { AutomobileMakeYear }
8
6
 
9
- describe 'verify imported data' do
10
- it { AMY.where("fuel_efficiency > 0").count.should == AMY.count }
11
- it { AMY.find("Honda 2011").fuel_efficiency.should be_within(1e-4).of(13.34186) }
12
- it { AMY.find("Honda 2012").fuel_efficiency.should be_within(1e-5).of(12.17321) }
7
+ describe 'Sanity check', :sanity => true do
8
+ let(:total) { amy.count }
9
+
10
+ it { total.should == 1276 }
11
+ it { amy.where("fuel_efficiency > 0").count.should == total }
12
+ it { amy.find("Honda 2011").fuel_efficiency.should be_within(1e-4).of(13.34186) }
13
+ it { amy.find("Honda 2012").fuel_efficiency.should be_within(1e-5).of(12.17321) }
13
14
 
14
15
  it 'has proper weightings' do
15
- AMY.connection.select_values("SELECT DISTINCT year FROM #{AMY.quoted_table_name}").each do |year|
16
- AMY.where(:year => year).first.weighting.should == AutomobileYear.weighting(year)
16
+ amy.connection.select_values("SELECT DISTINCT year FROM #{amy.quoted_table_name}").each do |year|
17
+ amy.where(:year => year).first.weighting.should == AutomobileYear.weighting(year)
17
18
  end
18
19
  end
19
20
  end
@@ -2,4 +2,7 @@ require 'spec_helper'
2
2
  require 'earth/automobile/automobile_model'
3
3
 
4
4
  describe AutomobileModel do
5
+ describe 'Sanity check', :sanity => true do
6
+ it { AutomobileModel.count.should == 2299 }
7
+ end
5
8
  end
@@ -2,20 +2,21 @@ require 'spec_helper'
2
2
  require 'earth/automobile/automobile_size_class'
3
3
 
4
4
  describe AutomobileSizeClass do
5
- describe 'verify', :sanity => true do
6
- it { AutomobileSizeClass.count.should == 15 }
7
- it { AutomobileSizeClass.where("fuel_efficiency_city > 0").count.should == AutomobileSizeClass.count }
8
- it { AutomobileSizeClass.where("fuel_efficiency_highway > 0").count.should == AutomobileSizeClass.count }
5
+ describe 'Sanity check', :sanity => true do
6
+ let(:total) { AutomobileSizeClass.count }
7
+ it { total.should == 15 }
8
+ it { AutomobileSizeClass.where("fuel_efficiency_city > 0").count.should == total }
9
+ it { AutomobileSizeClass.where("fuel_efficiency_highway > 0").count.should == total }
9
10
  it { AutomobileSizeClass.where("hybrid_fuel_efficiency_city_multiplier > 1.0").count.should == 7 }
10
11
  it { AutomobileSizeClass.where("hybrid_fuel_efficiency_highway_multiplier > 1.0").count.should == 7 }
11
12
  it { AutomobileSizeClass.where("conventional_fuel_efficiency_city_multiplier < 1.0").count.should == 7 }
12
13
  it { AutomobileSizeClass.where("conventional_fuel_efficiency_highway_multiplier < 1.0").count.should == 7 }
13
- end
14
-
15
- describe '.fallback' do
16
- it { AutomobileSizeClass.fallback.hybrid_fuel_efficiency_city_multiplier.should == 1.651 }
17
- it { AutomobileSizeClass.fallback.hybrid_fuel_efficiency_highway_multiplier.should == 1.213 }
18
- it { AutomobileSizeClass.fallback.conventional_fuel_efficiency_city_multiplier.should == 0.987 }
19
- it { AutomobileSizeClass.fallback.conventional_fuel_efficiency_highway_multiplier.should == 0.996 }
14
+
15
+ describe '.fallback' do
16
+ it { AutomobileSizeClass.fallback.hybrid_fuel_efficiency_city_multiplier.should == 1.651 }
17
+ it { AutomobileSizeClass.fallback.hybrid_fuel_efficiency_highway_multiplier.should == 1.213 }
18
+ it { AutomobileSizeClass.fallback.conventional_fuel_efficiency_city_multiplier.should == 0.987 }
19
+ it { AutomobileSizeClass.fallback.conventional_fuel_efficiency_highway_multiplier.should == 0.996 }
20
+ end
20
21
  end
21
22
  end
@@ -2,17 +2,17 @@ require 'spec_helper'
2
2
  require 'earth/automobile/automobile_type_fuel_control'
3
3
 
4
4
  describe AutomobileTypeFuelControl do
5
- before :all do
6
- require 'earth/acronyms'
7
- end
5
+ let(:atfc) { AutomobileTypeFuelControl }
8
6
 
9
- describe 'verify imported data', :sanity => true do
10
- it { ATFC.count.should == 20 }
11
- it { ATFC.where("ch4_emission_factor > 0").count.should == ATFC.count }
12
- it { ATFC.where("n2o_emission_factor > 0").count.should == ATFC.count }
7
+ describe 'Sanity check', :sanity => true do
8
+ let(:total) { atfc.count }
9
+
10
+ it { total.should == 20 }
11
+ it { atfc.where("ch4_emission_factor > 0").count.should == total }
12
+ it { atfc.where("n2o_emission_factor > 0").count.should == total }
13
13
 
14
14
  # spot checks
15
- it { ATFC.first.ch4_emission_factor.should be_within(1e-9).of(1.5534e-5) }
16
- it { ATFC.first.n2o_emission_factor.should be_within(1e-8).of(2.7775e-4) }
15
+ it { atfc.first.ch4_emission_factor.should be_within(1e-9).of(1.5534e-5) }
16
+ it { atfc.first.n2o_emission_factor.should be_within(1e-8).of(2.7775e-4) }
17
17
  end
18
18
  end
@@ -1,15 +1,30 @@
1
1
  require 'spec_helper'
2
- require 'earth/automobile/automobile_type_fuel'
2
+ require "#{Earth::FACTORY_DIR}/automobile_type_fuel"
3
+ require "#{Earth::FACTORY_DIR}/automobile_activity_year_type_fuel"
3
4
 
4
5
  describe AutomobileTypeFuel do
5
- let(:test_type_fuel) { AutomobileTypeFuel.find('Light-duty trucks gasoline') }
6
+ let(:atf) { AutomobileTypeFuel }
7
+ let(:aaytf) { AutomobileActivityYearTypeFuel }
6
8
 
7
- describe 'verify', :sanity => true do
8
- it { AutomobileTypeFuel.count.should == 4 }
9
- it { AutomobileTypeFuel.where("annual_distance > 0").count.should == AutomobileTypeFuel.count }
10
- it { AutomobileTypeFuel.where("ch4_emission_factor > 0").count.should == AutomobileTypeFuel.count }
11
- it { AutomobileTypeFuel.where("n2o_emission_factor > 0").count.should == AutomobileTypeFuel.count }
12
- it { AutomobileTypeFuel.where("vehicles > 0").count.should == AutomobileTypeFuel.count }
9
+ describe '#latest_activity_year_type_fuel' do
10
+ it 'should always be a match from the latest activity year' do
11
+ FactoryGirl.create :aaytf, :gas_car_2009
12
+ FactoryGirl.create :aaytf, :gas_car_2010
13
+ car_gas = FactoryGirl.create :atf, :car_gas
14
+ latest_year = aaytf.maximum :activity_year
15
+ car_gas.latest_activity_year_type_fuel.activity_year.should == latest_year
16
+ end
17
+ end
18
+
19
+ describe 'Sanity check', :sanity => true do
20
+ let(:total) { atf.count }
21
+ let(:test_type_fuel) { AutomobileTypeFuel.find('Light-duty trucks gasoline') }
22
+
23
+ it { total.should == 4 }
24
+ it { atf.where("annual_distance > 0").count.should == total }
25
+ it { atf.where("ch4_emission_factor > 0").count.should == total }
26
+ it { atf.where("n2o_emission_factor > 0").count.should == total }
27
+ it { atf.where("vehicles > 0").count.should == total }
13
28
 
14
29
  # spot checks
15
30
  it { test_type_fuel.annual_distance.should be_within(0.1).of(19626.6) }
@@ -22,14 +37,4 @@ describe AutomobileTypeFuel do
22
37
  it { test_type_fuel.fuel_consumption.should be_within(1).of(129_881_000_000) }
23
38
  it { test_type_fuel.fuel_consumption_units.should == 'litres' }
24
39
  end
25
-
26
- describe '#latest_activity_year_type_fuel' do
27
- it 'should always be a match from 2009' do
28
- AutomobileTypeFuel.safe_find_each do |atf|
29
- atf.latest_activity_year_type_fuel.type_name.should == atf.type_name
30
- atf.latest_activity_year_type_fuel.fuel_family.should == atf.fuel_family
31
- atf.latest_activity_year_type_fuel.activity_year.should == 2009
32
- end
33
- end
34
- end
35
40
  end
@@ -1,44 +1,52 @@
1
1
  require 'spec_helper'
2
- require 'earth/automobile/automobile_type_fuel_year_control'
2
+ require "#{Earth::FACTORY_DIR}/automobile_type_fuel_control"
3
+ require "#{Earth::FACTORY_DIR}/automobile_type_fuel_year_control"
3
4
 
4
5
  describe AutomobileTypeFuelYearControl do
5
- let(:test_year_control) { ATFYC.where(:type_name => 'Passenger cars', :fuel_family => 'gasoline', :year => 2005).first }
6
-
7
- before :all do
8
- require 'earth/acronyms'
9
- end
10
-
11
- describe 'verify imported data', :sanity => true do
12
- it { ATFYC.count.should == 142 }
13
-
14
- it 'total travel percent should sum to 1' do
15
- ATFYC.group([:type_name, :fuel_family, :year]).sum(:total_travel_percent).each do |grouping_criteria, total|
16
- total.should be_within(1e-5).of(1.0)
17
- end
18
- end
19
-
20
- it { ATFYC.where(:type_fuel_control_name => nil).count.should == 0 }
21
- end
6
+ let(:atfyc) { AutomobileTypeFuelYearControl }
22
7
 
23
8
  describe '.find_all_by_type_name_and_fuel_family_and_closest_year' do
24
- it { ATFYC.find_all_by_type_name_and_fuel_family_and_closest_year('Passenger cars', 'gasoline', 1980).should == ATFYC.find_all_by_type_name_and_fuel_family_and_year('Passenger cars', 'gasoline', 1985) }
25
- it { ATFYC.find_all_by_type_name_and_fuel_family_and_closest_year('Passenger cars', 'gasoline', 2005).should == ATFYC.find_all_by_type_name_and_fuel_family_and_year('Passenger cars', 'gasoline', 2005) }
26
- it { ATFYC.find_all_by_type_name_and_fuel_family_and_closest_year('Passenger cars', 'gasoline', 2012).should == ATFYC.find_all_by_type_name_and_fuel_family_and_year('Passenger cars', 'gasoline', 2010) }
9
+ it "should return all ATFYCs from the closest year" do
10
+ cars_2009_1 = FactoryGirl.create :atfyc, :cars_2009_1
11
+ cars_2009_2 = FactoryGirl.create :atfyc, :cars_2009_2
12
+ cars_2010_1 = FactoryGirl.create :atfyc, :cars_2010_1
13
+ cars_2010_2 = FactoryGirl.create :atfyc, :cars_2010_2
14
+
15
+ atfyc.find_all_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2011).should == [cars_2010_1, cars_2010_2]
16
+ atfyc.find_all_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2009).should == [cars_2009_1, cars_2009_2]
17
+ atfyc.find_all_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2005).should == [cars_2009_1, cars_2009_2]
18
+ end
27
19
  end
28
20
 
29
21
  describe '#ch4_emission_factor' do
30
- it { test_year_control.ch4_emission_factor.should be_within(1e-10).of(2.68743e-4) }
31
- end
32
-
33
- describe '#ch4_emission_factor_units' do
34
- it { test_year_control.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
22
+ it {
23
+ FactoryGirl.create :atfc, :car_tier_1
24
+ cars_2010_1 = FactoryGirl.create :atfyc, :cars_2010_1
25
+
26
+ cars_2010_1.ch4_emission_factor.should be_within(5e-3).of(0.04)
27
+ cars_2010_1.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre'
28
+ }
35
29
  end
36
30
 
37
31
  describe '#n2o_emission_factor' do
38
- it { test_year_control.n2o_emission_factor.should be_within(1e-10).of(6.66607e-4) }
32
+ it {
33
+ FactoryGirl.create :atfc, :car_tier_1
34
+ cars_2010_1 = FactoryGirl.create :atfyc, :cars_2010_1
35
+
36
+ cars_2010_1.n2o_emission_factor.should be_within(5e-3).of(0.08)
37
+ cars_2010_1.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre'
38
+ }
39
39
  end
40
40
 
41
- describe '#n2o_emission_factor_units' do
42
- it { test_year_control.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
41
+ describe 'Sanity check', :sanity => true do
42
+ it { atfyc.count.should == 142 }
43
+
44
+ it 'total travel percent should sum to 1' do
45
+ atfyc.group([:type_name, :fuel_family, :year]).sum(:total_travel_percent).each do |grouping_criteria, total|
46
+ total.should be_within(1e-5).of(1.0)
47
+ end
48
+ end
49
+
50
+ it { atfyc.where(:type_fuel_control_name => nil).count.should == 0 }
43
51
  end
44
52
  end
@@ -1,25 +1,50 @@
1
1
  require 'spec_helper'
2
- require 'earth/automobile/automobile_type_fuel_year'
2
+ require "#{Earth::FACTORY_DIR}/automobile_type_fuel_year"
3
+ require "#{Earth::FACTORY_DIR}/automobile_type_fuel_year_control"
3
4
 
4
5
  describe AutomobileTypeFuelYear, :data_miner => true do
5
- let(:test_atfy) { ATFY.where(:type_name => 'Passenger cars', :fuel_family => 'gasoline', :year => 2005).first }
6
+ let(:atfy) { AutomobileTypeFuelYear }
6
7
 
7
- before :all do
8
- require 'earth/acronyms'
8
+ describe '.find_by_type_name_and_fuel_family_and_closest_year' do
9
+ it "should return the ATFY from the closest year" do
10
+ cars_1984 = FactoryGirl.create :atfy, :cars_1984
11
+ cars_2009 = FactoryGirl.create :atfy, :cars_2009
12
+ cars_2011 = FactoryGirl.create :atfy, :cars_2011
13
+
14
+ atfy.find_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 1970).should == cars_1984
15
+ atfy.find_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2009).should == cars_2009
16
+ atfy.find_by_type_name_and_fuel_family_and_closest_year('cars', 'gas', 2012).should == cars_2011
17
+ end
18
+ end
19
+
20
+ describe '#type_fuel_year_controls' do
21
+ it "should return the controls from the closest year" do
22
+ FactoryGirl.create :atfyc, :cars_1985_1
23
+ FactoryGirl.create :atfyc, :cars_2009_1
24
+ FactoryGirl.create :atfyc, :cars_2009_2
25
+ FactoryGirl.create :atfyc, :cars_2010_1
26
+ FactoryGirl.create :atfyc, :cars_2010_2
27
+
28
+ FactoryGirl.create(:atfy, :cars_1984).type_fuel_year_controls.first.year.should == 1985
29
+ FactoryGirl.create(:atfy, :cars_2009).type_fuel_year_controls.first.year.should == 2009
30
+ FactoryGirl.create(:atfy, :cars_2011).type_fuel_year_controls.first.year.should == 2010
31
+ end
9
32
  end
10
33
 
11
- describe 'verify', :sanity => true do
12
- it { ATFY.count.should == 124 }
34
+ describe 'Sanity check', :sanity => true do
35
+ let(:test_atfy) { atfy.where(:type_name => 'Passenger cars', :fuel_family => 'gasoline', :year => 2005).first }
36
+
37
+ it { atfy.count.should == 124 }
13
38
 
14
39
  it 'shares should sum to 1' do
15
- ATFY.sum(:share_of_type, :group => [:type_name, :fuel_family]).each do |groupers, total|
40
+ atfy.sum(:share_of_type, :group => [:type_name, :fuel_family]).each do |groupers, total|
16
41
  total.should be_within(1e-2).of(1.0)
17
42
  end
18
43
  end
19
44
 
20
- it { ATFY.where("annual_distance > 0").count.should == ATFY.count }
21
- it { ATFY.where("ch4_emission_factor > 0").count.should == ATFY.count }
22
- it { ATFY.where("n2o_emission_factor > 0").count.should == ATFY.count }
45
+ it { atfy.where("annual_distance > 0").count.should == atfy.count }
46
+ it { atfy.where("ch4_emission_factor > 0").count.should == atfy.count }
47
+ it { atfy.where("n2o_emission_factor > 0").count.should == atfy.count }
23
48
 
24
49
  # spot checks
25
50
  it { test_atfy.annual_distance.should be_within(0.05).of(19598.6) }
@@ -29,30 +54,4 @@ describe AutomobileTypeFuelYear, :data_miner => true do
29
54
  it { test_atfy.n2o_emission_factor.should be_within(5e-6).of(0.00147) }
30
55
  it { test_atfy.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
31
56
  end
32
-
33
- describe '.find_by_type_name_and_fuel_family_and_closest_year' do
34
- it { ATFY.find_by_type_name_and_fuel_family_and_closest_year('Passenger cars', 'gasoline', 1970).should == ATFY.find_by_type_name_and_fuel_family_and_year('Passenger cars', 'gasoline', 1979) }
35
- it { ATFY.find_by_type_name_and_fuel_family_and_closest_year('Passenger cars', 'gasoline', 2005).should == ATFY.find_by_type_name_and_fuel_family_and_year('Passenger cars', 'gasoline', 2005) }
36
- it { ATFY.find_by_type_name_and_fuel_family_and_closest_year('Passenger cars', 'gasoline', 2012).should == ATFY.find_by_type_name_and_fuel_family_and_year('Passenger cars', 'gasoline', 2009) }
37
- end
38
-
39
- describe '#type_fuel_year_controls' do
40
- it "should find controls from 1985 when year < 1985" do
41
- ATFY.where("year < 1985").each do |atfy|
42
- atfy.type_fuel_year_controls.first.year.should == 1985
43
- end
44
- end
45
-
46
- it "should find controls from year when year from 1985 to 2010" do
47
- ATFY.where("year >= 1985 AND year <= 2010").each do |atfy|
48
- atfy.type_fuel_year_controls.first.year.should == atfy.year
49
- end
50
- end
51
-
52
- it "should find controls from 2010 when year > 2010" do
53
- ATFY.where("year > 2010").each do |atfy|
54
- atfy.type_fuel_year_controls.first.year.should == 2010
55
- end
56
- end
57
- end
58
57
  end
@@ -3,12 +3,14 @@ require 'earth/automobile/automobile_year'
3
3
 
4
4
  describe AutomobileYear do
5
5
  describe ".weighting(year)" do
6
- pending 'test data factories'
7
-
8
6
  (1985..2012).each do |year|
9
7
  it "returns a weighting between 0 and 1 for #{year}" do
10
8
  AutomobileYear.weighting(year).should > 0.0 and AutomobileYear.weighting(year).should < 1.0
11
9
  end
12
10
  end
13
11
  end
12
+
13
+ describe 'Sanity check', :sanity => true do
14
+ it { AutomobileYear.count.should == 28 }
15
+ end
14
16
  end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+ require 'earth/bus/bus_class'
3
+
4
+ describe BusClass do
5
+ describe 'Sanity check', :sanity => true do
6
+ it { BusClass.count.should == 2 }
7
+
8
+ # FIXME TODO more sanity checks
9
+ end
10
+ end
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
2
  require 'earth/bus/bus_fuel_control'
3
3
 
4
- describe 'BusFuelControl' do
5
- describe 'verify imported data', :sanity => true do
6
- it 'should have all the data' do
7
- BusFuelControl.count.should == 9
8
- end
4
+ describe BusFuelControl do
5
+ describe 'Sanity check', :sanity => true do
6
+ it { BusFuelControl.count.should == 9 }
9
7
  end
10
8
  end
@@ -1,13 +1,21 @@
1
1
  require 'spec_helper'
2
- require 'earth/bus/bus_fuel'
2
+ require "#{Earth::FACTORY_DIR}/bus_fuel"
3
+ require "#{Earth::FACTORY_DIR}/bus_fuel_year_control"
3
4
 
4
- describe 'BusFuel' do
5
- describe 'verify imported data', :sanity => true do
6
- it 'should have all the data' do
7
- BusFuel.count.should == 7
8
- end
9
- it 'is related to fuels' do
10
- BusFuel.last.fuel.should_not be_nil
5
+ describe BusFuel do
6
+ describe '#latest_fuel_year_controls' do
7
+ it 'returns the latest fuel year controls' do
8
+ FactoryGirl.create :bfyc, :gas_2009_1
9
+ a = FactoryGirl.create :bfyc, :gas_2010_1
10
+ b = FactoryGirl.create :bfyc, :gas_2010_2
11
+ gas = FactoryGirl.create :bus_fuel, :gas
12
+ gas.latest_fuel_year_controls.should == [a,b]
11
13
  end
12
14
  end
15
+
16
+ describe 'Sanity check', :sanity => true do
17
+ it { BusFuel.count.should == 7 }
18
+
19
+ # FIXME TODO more sanity checks
20
+ end
13
21
  end
@@ -1,13 +1,13 @@
1
1
  require 'spec_helper'
2
2
  require 'earth/bus/bus_fuel_year_control'
3
3
 
4
- describe 'BusFuelYearControl' do
5
- describe 'verify imported data', :sanity => true do
6
- it 'should have all the data' do
7
- BusFuelYearControl.count.should == 67
8
- end
9
- it 'is related to BusFuelControl' do
10
- BusFuelYearControl.first.control.should_not be_nil
4
+ describe BusFuelYearControl do
5
+ describe 'Sanity check', :sanity => true do
6
+ it { BusFuelYearControl.count.should == 67 }
7
+ it 'total travel percent should sum to 1' do
8
+ BusFuelYearControl.group([:bus_fuel_name, :year]).sum(:total_travel_percent).each do |grouping_criteria, total|
9
+ total.should be_within(5e-2).of(1.0)
10
+ end
11
11
  end
12
12
  end
13
13
  end