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,81 +2,104 @@ require 'spec_helper'
2
2
  require 'earth/automobile/automobile_make_model_year'
3
3
 
4
4
  describe AutomobileMakeModelYear do
5
- before :all do
6
- require 'earth/acronyms'
7
- end
5
+ let(:ammy) { AutomobileMakeModelYear }
6
+ let(:ammyv) { AutomobileMakeModelYearVariant }
8
7
 
9
- describe 'verify imported data', :sanity => true do
10
- it 'has data from all years' do
11
- (1985..2012).each do |year|
12
- AMMY.where(:year => year).count.should == AMMY.connection.select_value("SELECT COUNT(DISTINCT make_name, model_name) FROM #{AutomobileMakeModelYearVariant.quoted_table_name} WHERE year = #{year}")
13
- end
14
- end
8
+ describe 'Sanity check', :sanity => true do
9
+ # confirm we have right data from all years
10
+ it { ammy.where(:year => 1985).count.should == 360 }
11
+ it { ammy.where(:year => 1986).count.should == 350 }
12
+ it { ammy.where(:year => 1987).count.should == 385 }
13
+ it { ammy.where(:year => 1988).count.should == 370 }
14
+ it { ammy.where(:year => 1989).count.should == 373 }
15
+ it { ammy.where(:year => 1990).count.should == 349 }
16
+ it { ammy.where(:year => 1991).count.should == 363 }
17
+ it { ammy.where(:year => 1992).count.should == 337 }
18
+ it { ammy.where(:year => 1993).count.should == 322 }
19
+ it { ammy.where(:year => 1994).count.should == 318 }
20
+ it { ammy.where(:year => 1995).count.should == 320 }
21
+ it { ammy.where(:year => 1996).count.should == 286 }
22
+ it { ammy.where(:year => 1997).count.should == 277 }
23
+ it { ammy.where(:year => 1998).count.should == 301 }
24
+ it { ammy.where(:year => 1999).count.should == 308 }
25
+ it { ammy.where(:year => 2000).count.should == 320 }
26
+ it { ammy.where(:year => 2001).count.should == 341 }
27
+ it { ammy.where(:year => 2002).count.should == 377 }
28
+ it { ammy.where(:year => 2003).count.should == 410 }
29
+ it { ammy.where(:year => 2004).count.should == 437 }
30
+ it { ammy.where(:year => 2005).count.should == 445 }
31
+ it { ammy.where(:year => 2006).count.should == 431 }
32
+ it { ammy.where(:year => 2007).count.should == 499 }
33
+ it { ammy.where(:year => 2008).count.should == 539 }
34
+ it { ammy.where(:year => 2009).count.should == 496 }
35
+ it { ammy.where(:year => 2010).count.should == 530 }
36
+ it { ammy.where(:year => 2011).count.should == 562 }
37
+ it { ammy.where(:year => 2012).count.should == 591 }
15
38
 
16
39
  # confirm make, model, year aren't missing
17
- it { AMMY.where(:make_name => nil).count.should == 0 }
18
- it { AMMY.where(:model_name => nil).count.should == 0 }
19
- it { AMMY.where(:year => nil).count.should == 0 }
40
+ it { ammy.where(:make_name => nil).count.should == 0 }
41
+ it { ammy.where(:model_name => nil).count.should == 0 }
42
+ it { ammy.where(:year => nil).count.should == 0 }
20
43
 
21
44
  it 'should have valid fuel codes' do
22
- AMMY.connection.select_values("SELECT DISTINCT fuel_code FROM #{AMMY.quoted_table_name} WHERE fuel_code != 'G'").each do |code|
23
- fail "#{code} is not a valid code" unless AutomobileMakeModelYearVariant::Parser::FUEL_CODES.values.include?(code)
45
+ ammy.connection.select_values("SELECT DISTINCT fuel_code FROM #{ammy.quoted_table_name} WHERE fuel_code != 'G'").each do |code|
46
+ fail "#{code} is not a valid code" unless ammyv::Parser::FUEL_CODES.values.include?(code)
24
47
  end
25
48
  end
26
49
 
27
50
  it 'should have valid alt fuel codes' do
28
- AMMY.connection.select_values("SELECT DISTINCT alt_fuel_code FROM #{AMMY.quoted_table_name} WHERE alt_fuel_code IS NOT NULL").each do |code|
29
- fail "#{code} is not a valid code" unless AutomobileMakeModelYearVariant::Parser::FUEL_CODES.values.include?(code)
51
+ ammy.connection.select_values("SELECT DISTINCT alt_fuel_code FROM #{ammy.quoted_table_name} WHERE alt_fuel_code IS NOT NULL").each do |code|
52
+ fail "#{code} is not a valid code" unless ammyv::Parser::FUEL_CODES.values.include?(code)
30
53
  end
31
54
  end
32
55
 
33
- it { AMMY.where(:hybridity => true).count.should == 170 }
56
+ it { ammy.where(:hybridity => true).count.should == 170 }
34
57
 
35
58
  it 'should have proper weightings' do
36
- AutomobileMakeModelYear.connection.select_values("SELECT DISTINCT year FROM #{AutomobileMakeModelYear.quoted_table_name}").each do |year|
37
- AMMY.where(:year => year).first.weighting.should == AutomobileYear.weighting(year)
59
+ ammy.connection.select_values("SELECT DISTINCT year FROM #{ammy.quoted_table_name}").each do |year|
60
+ ammy.where(:year => year).first.weighting.should == AutomobileYear.weighting(year)
38
61
  end
39
62
  end
40
63
 
41
64
  # confirm fuel efficiencies are valid and proper units
42
- it { AMMY.where("fuel_efficiency_city > 0").count.should == AMMY.count }
43
- it { AMMY.where("fuel_efficiency_highway > 0").count.should == AMMY.count }
44
- it { AMMY.where(:fuel_efficiency_city_units => 'kilometres_per_litre').count.should == AMMY.count }
45
- it { AMMY.where(:fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == AMMY.count }
65
+ it { ammy.where("fuel_efficiency_city > 0").count.should == ammy.count }
66
+ it { ammy.where("fuel_efficiency_highway > 0").count.should == ammy.count }
67
+ it { ammy.where(:fuel_efficiency_city_units => 'kilometres_per_litre').count.should == ammy.count }
68
+ it { ammy.where(:fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == ammy.count }
46
69
 
47
70
  # confirm alt fuel efficiencies are valid and proper units
48
- it { AMMY.where("alt_fuel_efficiency_city > 0").count.should == AMMY.where("alt_fuel_code IS NOT NULL").count }
49
- it { AMMY.where("alt_fuel_efficiency_highway > 0").count.should == AMMY.where("alt_fuel_code IS NOT NULL").count }
50
- it { AMMY.where(:alt_fuel_efficiency_city_units => 'kilometres_per_litre').count.should == AMMY.where("alt_fuel_code IS NOT NULL").count }
51
- it { AMMY.where(:alt_fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == AMMY.where("alt_fuel_code IS NOT NULL").count }
71
+ it { ammy.where("alt_fuel_efficiency_city > 0").count.should == ammy.where("alt_fuel_code IS NOT NULL").count }
72
+ it { ammy.where("alt_fuel_efficiency_highway > 0").count.should == ammy.where("alt_fuel_code IS NOT NULL").count }
73
+ it { ammy.where(:alt_fuel_efficiency_city_units => 'kilometres_per_litre').count.should == ammy.where("alt_fuel_code IS NOT NULL").count }
74
+ it { ammy.where(:alt_fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == ammy.where("alt_fuel_code IS NOT NULL").count }
52
75
 
53
76
  # # spot check fuel efficiency calcs
54
- it { AMMY.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
55
- it { AMMY.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
77
+ it { ammy.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
78
+ it { ammy.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
56
79
 
57
- it { AMMY.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
58
- it { AMMY.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(39.5384) }
80
+ it { ammy.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
81
+ it { ammy.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(39.5384) }
59
82
 
60
- it { AMMY.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
61
- it { AMMY.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
83
+ it { ammy.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
84
+ it { ammy.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
62
85
 
63
- it { AMMY.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
64
- it { AMMY.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(38.2629) }
86
+ it { ammy.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
87
+ it { ammy.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(38.2629) }
65
88
 
66
- it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency_city.should be_within(0.0001).of( 8.0777) }
67
- it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency_highway.should be_within(0.0001).of(11.4789) }
89
+ it { ammy.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency_city.should be_within(0.0001).of( 8.0777) }
90
+ it { ammy.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency_highway.should be_within(0.0001).of(11.4789) }
68
91
 
69
- it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency_city.should be_within(0.0001).of(5.9520) }
70
- it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(8.5029) }
92
+ it { ammy.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency_city.should be_within(0.0001).of(5.9520) }
93
+ it { ammy.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(8.5029) }
71
94
 
72
- it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).fuel_efficiency_city.should be_within(0.0001).of(7.86516) }
73
- it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).fuel_efficiency_highway.should be_within(0.0001).of(12.11660) }
95
+ it { ammy.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).fuel_efficiency_city.should be_within(0.0001).of(7.86516) }
96
+ it { ammy.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).fuel_efficiency_highway.should be_within(0.0001).of(12.11660) }
74
97
 
75
- it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).alt_fuel_efficiency_city.should == nil }
76
- it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).alt_fuel_efficiency_highway.should == nil }
98
+ it { ammy.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).alt_fuel_efficiency_city.should == nil }
99
+ it { ammy.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).alt_fuel_efficiency_highway.should == nil }
77
100
 
78
- it { AMMY.where(:type_name => nil).count.should == 0 }
79
- it { AMMY.find(:first, :conditions => {:make_name => 'Toyota', :model_name => 'Prius'}).type_name.should == 'Passenger cars' }
80
- it { AMMY.find(:first, :conditions => {:make_name => 'Toyota', :model_name => 'Highlander'}).type_name.should == 'Light-duty trucks' }
101
+ it { ammy.where(:type_name => nil).count.should == 0 }
102
+ it { ammy.find(:first, :conditions => {:make_name => 'Toyota', :model_name => 'Prius'}).type_name.should == 'Passenger cars' }
103
+ it { ammy.find(:first, :conditions => {:make_name => 'Toyota', :model_name => 'Highlander'}).type_name.should == 'Light-duty trucks' }
81
104
  end
82
105
  end
@@ -3,180 +3,179 @@ require 'spec_helper'
3
3
  require 'earth/automobile/automobile_make_model_year_variant'
4
4
 
5
5
  describe AutomobileMakeModelYearVariant do
6
- before :all do
7
- require 'earth/acronyms'
8
- end
6
+ let(:ammyv) { AutomobileMakeModelYearVariant }
9
7
 
10
- describe 'verify imported data', :sanity => true do
8
+ describe 'Sanity check', :sanity => true do
11
9
  # confirm we have right data from all years
12
- it { AMMYV.where(:year => 1985).count.should == 1152 }
13
- it { AMMYV.where(:year => 1986).count.should == 1183 }
14
- it { AMMYV.where(:year => 1987).count.should == 1206 }
15
- it { AMMYV.where(:year => 1988).count.should == 1104 }
16
- it { AMMYV.where(:year => 1989).count.should == 1137 }
17
- it { AMMYV.where(:year => 1990).count.should == 1049 }
18
- it { AMMYV.where(:year => 1991).count.should == 1062 }
19
- it { AMMYV.where(:year => 1992).count.should == 1055 }
20
- it { AMMYV.where(:year => 1993).count.should == 986 }
21
- it { AMMYV.where(:year => 1994).count.should == 963 }
22
- it { AMMYV.where(:year => 1995).count.should == 917 }
23
- it { AMMYV.where(:year => 1996).count.should == 750 }
24
- it { AMMYV.where(:year => 1997).count.should == 727 }
25
- it { AMMYV.where(:year => 1998).count.should == 794 }
26
- it { AMMYV.where(:year => 1999).count.should == 800 }
27
- it { AMMYV.where(:year => 2000).count.should == 834 }
28
- it { AMMYV.where(:year => 2001).count.should == 846 }
29
- it { AMMYV.where(:year => 2002).count.should == 933 }
30
- it { AMMYV.where(:year => 2003).count.should == 995 }
31
- it { AMMYV.where(:year => 2004).count.should == 1091 }
32
- it { AMMYV.where(:year => 2005).count.should == 1069 }
33
- it { AMMYV.where(:year => 2006).count.should == 1043 }
34
- it { AMMYV.where(:year => 2007).count.should == 1126 }
35
- it { AMMYV.where(:year => 2008).count.should == 1186 }
36
- it { AMMYV.where(:year => 2009).count.should == 1092 }
37
- it { AMMYV.where(:year => 2010).count.should == 1107 }
38
- it { AMMYV.where(:year => 2011).count.should == 1097 }
39
- it { AMMYV.where(:year => 2012).count.should == 1129 }
10
+ it { ammyv.where(:year => 1985).count.should == 1152 }
11
+ it { ammyv.where(:year => 1986).count.should == 1183 }
12
+ it { ammyv.where(:year => 1987).count.should == 1206 }
13
+ it { ammyv.where(:year => 1988).count.should == 1104 }
14
+ it { ammyv.where(:year => 1989).count.should == 1137 }
15
+ it { ammyv.where(:year => 1990).count.should == 1049 }
16
+ it { ammyv.where(:year => 1991).count.should == 1062 }
17
+ it { ammyv.where(:year => 1992).count.should == 1055 }
18
+ it { ammyv.where(:year => 1993).count.should == 986 }
19
+ it { ammyv.where(:year => 1994).count.should == 963 }
20
+ it { ammyv.where(:year => 1995).count.should == 917 }
21
+ it { ammyv.where(:year => 1996).count.should == 750 }
22
+ it { ammyv.where(:year => 1997).count.should == 727 }
23
+ it { ammyv.where(:year => 1998).count.should == 794 }
24
+ it { ammyv.where(:year => 1999).count.should == 800 }
25
+ it { ammyv.where(:year => 2000).count.should == 834 }
26
+ it { ammyv.where(:year => 2001).count.should == 846 }
27
+ it { ammyv.where(:year => 2002).count.should == 933 }
28
+ it { ammyv.where(:year => 2003).count.should == 995 }
29
+ it { ammyv.where(:year => 2004).count.should == 1091 }
30
+ it { ammyv.where(:year => 2005).count.should == 1069 }
31
+ it { ammyv.where(:year => 2006).count.should == 1043 }
32
+ it { ammyv.where(:year => 2007).count.should == 1126 }
33
+ it { ammyv.where(:year => 2008).count.should == 1186 }
34
+ it { ammyv.where(:year => 2009).count.should == 1092 }
35
+ it { ammyv.where(:year => 2010).count.should == 1107 }
36
+ it { ammyv.where(:year => 2011).count.should == 1097 }
37
+ it { ammyv.where(:year => 2012).count.should == 1129 }
40
38
 
41
39
  # confirm make, model, year, size class, and type aren't missing
42
- it { AMMYV.where(:make_name => nil).count.should == 0 }
43
- it { AMMYV.where(:model_name => nil).count.should == 0 }
44
- it { AMMYV.where(:year => nil).count.should == 0 }
45
- it { AMMYV.where(:size_class => nil).count.should == 0 }
46
- it { AMMYV.where(:type_name => nil).count.should == 0 }
40
+ it { ammyv.where(:make_name => nil).count.should == 0 }
41
+ it { ammyv.where(:model_name => nil).count.should == 0 }
42
+ it { ammyv.where(:year => nil).count.should == 0 }
43
+ it { ammyv.where(:size_class => nil).count.should == 0 }
44
+ it { ammyv.where(:type_name => nil).count.should == 0 }
47
45
 
48
46
  # confirm it handles special characters
49
- it { AMMYV.where(:make_name => 'Citroën').count.should > 13 }
47
+ it { ammyv.where(:make_name => 'Citroën').count.should > 13 }
50
48
 
51
49
  # confirm Chevy and GMC model names have been simplified
52
- it { AMMYV.where("make_name IN ('Chevrolet', 'GMC') AND model_name REGEXP '^[CK][0-9]+'").count.should == 0 }
50
+ it { ammyv.where("make_name IN ('Chevrolet', 'GMC') AND model_name REGEXP '^[CK][0-9]+'").count.should == 0 }
53
51
 
54
52
  # confirm certain hybrids have been identified
55
- it { AMMYV.where(:year => 2012, :make_name => 'Buick', :model_name => 'LACROSSE HYBRID').count.should == 1 }
56
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Buick', :model_name => 'LACROSSE HYBRID'}).fuel_efficiency.should be_within(1e-4).of(12.8701) }
57
- it { AMMYV.where(:year => 2012, :make_name => 'Buick', :model_name => 'REGAL HYBRID').count.should == 1 }
58
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Buick', :model_name => 'REGAL HYBRID'}).fuel_efficiency.should be_within(1e-4).of(12.8701) }
53
+ it { ammyv.where(:year => 2012, :make_name => 'Buick', :model_name => 'LACROSSE HYBRID').count.should == 1 }
54
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Buick', :model_name => 'LACROSSE HYBRID'}).fuel_efficiency.should be_within(1e-4).of(12.8701) }
55
+ it { ammyv.where(:year => 2012, :make_name => 'Buick', :model_name => 'REGAL HYBRID').count.should == 1 }
56
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Buick', :model_name => 'REGAL HYBRID'}).fuel_efficiency.should be_within(1e-4).of(12.8701) }
59
57
 
60
58
  # confirm dual-fuel and CNG variants have been merged and identified
61
- it { AMMYV.where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => 'C').count.should == 0 }
62
- it { AMMYV.where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => 'R', :alt_fuel_code => 'C').count.should == 5 }
63
- it { AMMYV.where(:fuel_code => 'C').count.should == AMMYV.where("model_name LIKE '%CNG'").count }
59
+ it { ammyv.where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => 'C').count.should == 0 }
60
+ it { ammyv.where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => 'R', :alt_fuel_code => 'C').count.should == 5 }
61
+ it { ammyv.where(:fuel_code => 'C').count.should == ammyv.where("model_name LIKE '%CNG'").count }
64
62
 
65
63
  # confirm FFV variants have been merged
66
- it { AMMYV.where(:fuel_code => 'E').count.should == 0 }
67
- it { AMMYV.where(:alt_fuel_code => 'E').count.should > 750 }
64
+ it { ammyv.where(:fuel_code => 'E').count.should == 0 }
65
+ it { ammyv.where(:alt_fuel_code => 'E').count.should > 750 }
68
66
 
69
67
  # confirm flex-fuel variants of models where not all variants are flex-fuel have been identified
70
- it { AMMYV.where("model_name LIKE '%FFV'").count.should > 700 }
71
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Toyota', :model_name => 'SEQUOIA FFV'}).alt_fuel_code.should == 'E' }
72
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Toyota', :model_name => 'SEQUOIA'}).alt_fuel_code.should == nil }
68
+ it { ammyv.where("model_name LIKE '%FFV'").count.should > 700 }
69
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Toyota', :model_name => 'SEQUOIA FFV'}).alt_fuel_code.should == 'E' }
70
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Toyota', :model_name => 'SEQUOIA'}).alt_fuel_code.should == nil }
73
71
 
74
72
  # confirm diesel variants of models where not all variants are diesel have been identified
75
- it { AMMYV.where("model_name LIKE '%DIESEL'").count.should > 575 }
76
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Volkswagen', :model_name => 'JETTA DIESEL'}).fuel_code.should == 'D' }
77
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Volkswagen', :model_name => 'JETTA'}).fuel_code.should_not == 'D' }
73
+ it { ammyv.where("model_name LIKE '%DIESEL'").count.should > 575 }
74
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Volkswagen', :model_name => 'JETTA DIESEL'}).fuel_code.should == 'D' }
75
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Volkswagen', :model_name => 'JETTA'}).fuel_code.should_not == 'D' }
78
76
 
79
77
  it "type name shouldn't vary within a make model" do
80
- AMMYV.connection.select_values(%{
78
+ ammyv.connection.select_values(%{
81
79
  SELECT * FROM
82
80
  (SELECT make_name, model_name, GROUP_CONCAT(DISTINCT type_name) AS types
83
- FROM #{AMMYV.quoted_table_name}
81
+ FROM #{ammyv.quoted_table_name}
84
82
  GROUP BY make_name, model_name) AS t1
85
83
  WHERE types LIKE '%,%'
86
84
  }).count.should == 0
87
85
  end
88
86
 
89
87
  it 'should have valid transmissions' do
90
- AMMYV.connection.select_values("SELECT DISTINCT transmission FROM #{AMMYV.quoted_table_name}").each do |transmission|
91
- fail "#{transmission} is not a valid transmission" unless AMMYV::Parser::TRANSMISSIONS.values.include?(transmission)
88
+ ammyv.connection.select_values("SELECT DISTINCT transmission FROM #{ammyv.quoted_table_name}").each do |transmission|
89
+ fail "#{transmission} is not a valid transmission" unless AutomobileMakeModelYearVariant::Parser::TRANSMISSIONS.values.include?(transmission)
92
90
  end
93
91
  end
94
92
 
95
93
  it 'should have valid speeds' do
96
94
  valid_speeds = ["1", "3", "4", "5", "6", "7", "8", "variable"]
97
- AMMYV.connection.select_values("SELECT DISTINCT speeds FROM #{AMMYV.quoted_table_name}").each do |speeds|
95
+ ammyv.connection.select_values("SELECT DISTINCT speeds FROM #{ammyv.quoted_table_name}").each do |speeds|
98
96
  fail "#{speeds} is not a valid speeds" unless valid_speeds.include?(speeds)
99
97
  end
100
98
  end
101
99
 
102
100
  it 'should have valid drives' do
103
101
  valid_drives = ["FWD", "RWD", "4WD", "AWD", "PWD"] # PWD = part-time 4-wheel drive
104
- AMMYV.connection.select_values("SELECT DISTINCT drive FROM #{AMMYV.quoted_table_name}").each do |drive|
102
+ ammyv.connection.select_values("SELECT DISTINCT drive FROM #{ammyv.quoted_table_name}").each do |drive|
105
103
  fail "#{drive} is not a valid drive" unless valid_drives.include?(drive)
106
104
  end
107
105
  end
108
106
 
109
107
  it 'should have valid fuel codes' do
110
- AMMYV.connection.select_values("SELECT DISTINCT fuel_code FROM #{AMMYV.quoted_table_name}").each do |code|
111
- fail "#{code} is not a valid code" unless AMMYV::Parser::FUEL_CODES.values.include?(code)
108
+ ammyv.connection.select_values("SELECT DISTINCT fuel_code FROM #{ammyv.quoted_table_name}").each do |code|
109
+ fail "#{code} is not a valid code" unless AutomobileMakeModelYearVariant::Parser::FUEL_CODES.values.include?(code)
112
110
  end
113
111
  end
114
112
 
115
113
  it 'should have valid alt fuel codes' do
116
- AMMYV.connection.select_values("SELECT DISTINCT alt_fuel_code FROM #{AMMYV.quoted_table_name} WHERE alt_fuel_code IS NOT NULL").each do |code|
117
- fail "#{code} is not a valid code" unless AMMYV::Parser::FUEL_CODES.values.include?(code)
114
+ ammyv.connection.select_values("SELECT DISTINCT alt_fuel_code FROM #{ammyv.quoted_table_name} WHERE alt_fuel_code IS NOT NULL").each do |code|
115
+ fail "#{code} is not a valid code" unless AutomobileMakeModelYearVariant::Parser::FUEL_CODES.values.include?(code)
118
116
  end
119
117
  end
120
118
 
121
119
  # confirm fuel efficiencies are valid and proper units
122
- it { AMMYV.where("fuel_efficiency > 0").count.should == AMMYV.count }
123
- it { AMMYV.where("fuel_efficiency_city > 0").count.should == AMMYV.count }
124
- it { AMMYV.where("fuel_efficiency_highway > 0").count.should == AMMYV.count }
125
- it { AMMYV.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == AMMYV.count }
126
- it { AMMYV.where(:fuel_efficiency_city_units => 'kilometres_per_litre').count.should == AMMYV.count }
127
- it { AMMYV.where(:fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == AMMYV.count }
120
+ let(:total) { ammyv.count }
121
+ it { ammyv.where("fuel_efficiency > 0").count.should == total }
122
+ it { ammyv.where("fuel_efficiency_city > 0").count.should == total }
123
+ it { ammyv.where("fuel_efficiency_highway > 0").count.should == total }
124
+ it { ammyv.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == total }
125
+ it { ammyv.where(:fuel_efficiency_city_units => 'kilometres_per_litre').count.should == total }
126
+ it { ammyv.where(:fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == total }
128
127
 
129
128
  # confirm alt fuel efficiencies are valid and proper units
130
- it { AMMYV.where("alt_fuel_efficiency > 0").count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
131
- it { AMMYV.where("alt_fuel_efficiency_city > 0").count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
132
- it { AMMYV.where("alt_fuel_efficiency_highway > 0").count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
133
- it { AMMYV.where(:alt_fuel_efficiency_units => 'kilometres_per_litre').count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
134
- it { AMMYV.where(:alt_fuel_efficiency_city_units => 'kilometres_per_litre').count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
135
- it { AMMYV.where(:alt_fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
129
+ it { ammyv.where("alt_fuel_efficiency > 0").count.should == ammyv.where("alt_fuel_code IS NOT NULL").count }
130
+ it { ammyv.where("alt_fuel_efficiency_city > 0").count.should == ammyv.where("alt_fuel_code IS NOT NULL").count }
131
+ it { ammyv.where("alt_fuel_efficiency_highway > 0").count.should == ammyv.where("alt_fuel_code IS NOT NULL").count }
132
+ it { ammyv.where(:alt_fuel_efficiency_units => 'kilometres_per_litre').count.should == ammyv.where("alt_fuel_code IS NOT NULL").count }
133
+ it { ammyv.where(:alt_fuel_efficiency_city_units => 'kilometres_per_litre').count.should == ammyv.where("alt_fuel_code IS NOT NULL").count }
134
+ it { ammyv.where(:alt_fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == ammyv.where("alt_fuel_code IS NOT NULL").count }
136
135
 
137
136
  # spot check fuel efficiency calcs
138
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
139
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
140
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency.should be_within(0.0001).of(16.0216) }
137
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
138
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
139
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency.should be_within(0.0001).of(16.0216) }
141
140
 
142
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
143
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(39.5384) }
144
- it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency.should be_within(0.0001).of(39.8996) }
141
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
142
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(39.5384) }
143
+ it { ammyv.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency.should be_within(0.0001).of(39.8996) }
145
144
 
146
- it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
147
- it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
148
- it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency.should be_within(0.0001).of(16.0216) }
145
+ it { ammyv.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
146
+ it { ammyv.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
147
+ it { ammyv.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency.should be_within(0.0001).of(16.0216) }
149
148
 
150
- it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
151
- it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(38.2629) }
152
- it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency.should be_within(0.0001).of(39.1489) }
149
+ it { ammyv.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
150
+ it { ammyv.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(38.2629) }
151
+ it { ammyv.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency.should be_within(0.0001).of(39.1489) }
153
152
 
154
- it { AMMYV.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency_city.should be_within(0.0001).of( 8.0777) }
155
- it { AMMYV.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency_highway.should be_within(0.0001).of(11.4789) }
156
- it { AMMYV.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency.should be_within(0.0001).of( 9.7192) }
153
+ it { ammyv.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency_city.should be_within(0.0001).of( 8.0777) }
154
+ it { ammyv.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency_highway.should be_within(0.0001).of(11.4789) }
155
+ it { ammyv.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency.should be_within(0.0001).of( 9.7192) }
157
156
 
158
- it { AMMYV.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency_city.should be_within(0.0001).of(5.9520) }
159
- it { AMMYV.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(8.5029) }
160
- it { AMMYV.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency.should be_within(0.0001).of(7.1797) }
157
+ it { ammyv.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency_city.should be_within(0.0001).of(5.9520) }
158
+ it { ammyv.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(8.5029) }
159
+ it { ammyv.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).alt_fuel_efficiency.should be_within(0.0001).of(7.1797) }
161
160
 
162
- it { AMMYV.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency_city.should be_within(0.0001).of(20.2602) }
163
- it { AMMYV.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency_highway.should be_within(0.0001).of(19.1879) }
164
- it { AMMYV.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency.should be_within(0.0001).of(19.6347) }
161
+ it { ammyv.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency_city.should be_within(0.0001).of(20.2602) }
162
+ it { ammyv.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency_highway.should be_within(0.0001).of(19.1879) }
163
+ it { ammyv.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency.should be_within(0.0001).of(19.6347) }
165
164
 
166
- it { AMMYV.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_city.should be_within(0.0001).of( 7.9773) }
167
- it { AMMYV.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_highway.should be_within(0.0001).of(10.2480) }
168
- it { AMMYV.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency.should be_within(0.0001).of( 9.1305) }
165
+ it { ammyv.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_city.should be_within(0.0001).of( 7.9773) }
166
+ it { ammyv.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_highway.should be_within(0.0001).of(10.2480) }
167
+ it { ammyv.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency.should be_within(0.0001).of( 9.1305) }
169
168
 
170
- it { AMMYV.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_city.should be_within(0.0001).of( 7.7886) }
171
- it { AMMYV.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_highway.should be_within(0.0001).of(10.3739) }
172
- it { AMMYV.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency.should be_within(0.0001).of( 9.0782) }
169
+ it { ammyv.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_city.should be_within(0.0001).of( 7.7886) }
170
+ it { ammyv.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_highway.should be_within(0.0001).of(10.3739) }
171
+ it { ammyv.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency.should be_within(0.0001).of( 9.0782) }
173
172
 
174
- it { AMMYV.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency_city.should be_within(0.0001).of(5.8670) }
175
- it { AMMYV.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency_highway.should be_within(0.0001).of(8.2903) }
176
- it { AMMYV.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency.should be_within(0.0001).of(7.0399) }
173
+ it { ammyv.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency_city.should be_within(0.0001).of(5.8670) }
174
+ it { ammyv.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency_highway.should be_within(0.0001).of(8.2903) }
175
+ it { ammyv.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency.should be_within(0.0001).of(7.0399) }
177
176
 
178
- it { AMMYV.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency_city.should be_within(0.0001).of(5.8479) }
179
- it { AMMYV.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency_highway.should be_within(0.0001).of(7.3958) }
180
- it { AMMYV.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency.should be_within(0.0001).of(6.6401) }
177
+ it { ammyv.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency_city.should be_within(0.0001).of(5.8479) }
178
+ it { ammyv.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency_highway.should be_within(0.0001).of(7.3958) }
179
+ it { ammyv.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency.should be_within(0.0001).of(6.6401) }
181
180
  end
182
181
  end
@@ -2,15 +2,15 @@ require 'spec_helper'
2
2
  require 'earth/automobile/automobile_make'
3
3
 
4
4
  describe AutomobileMake do
5
- let(:honda) { AutomobileMake.find('Honda') } # MakeYear with fe from CAFE data
6
- let(:acura) { AutomobileMake.find('Acura') } # MakeYear with fe from average of variants
7
-
8
- describe 'verify', :sanity => true do
9
- it { AutomobileMake.where("fuel_efficiency > 0").count.should == AutomobileMake.count }
10
- it { AutomobileMake.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == AutomobileMake.count }
5
+ describe 'Sanity check', :sanity => true do
6
+ let(:total) { AutomobileMake.count }
7
+
8
+ it { total.should == 81 }
9
+ it { AutomobileMake.where("fuel_efficiency > 0").count.should == total }
10
+ it { AutomobileMake.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == total }
11
11
 
12
12
  # spot checks
13
- it { honda.fuel_efficiency.should be_within(1e-4).of(13.0594) }
14
- it { acura.fuel_efficiency.should be_within(1e-4).of(9.1347) }
13
+ it { AutomobileMake.find('Honda').fuel_efficiency.should be_within(1e-4).of(13.0594) } # fe from CAFE data
14
+ it { AutomobileMake.find('Acura').fuel_efficiency.should be_within(1e-4).of(9.1347) } # fe from average of variants
15
15
  end
16
16
  end