earth 0.11.20 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/data/automobile/annual_emission_controls.csv +143 -0
  2. data/data/automobile/annual_fuel_consumption.csv +81 -0
  3. data/data/automobile/annual_sizes.csv +541 -0
  4. data/data/automobile/auto_fuel_data.csv +13 -0
  5. data/data/automobile/auto_fuel_efs.csv +9 -0
  6. data/data/automobile/cafe_data.csv +1449 -0
  7. data/data/automobile/emission_control_techs.csv +21 -0
  8. data/data/automobile/hfc_emissions.csv +31 -0
  9. data/data/automobile/hybridity_multipliers.csv +8 -0
  10. data/data/automobile/sizes.csv +16 -0
  11. data/earth.gemspec +3 -2
  12. data/errata/aircraft/faa_errata.csv +1 -1
  13. data/errata/airline/bts_carrier_codes_errata.csv +44 -0
  14. data/errata/airport/openflights_errata.csv +450 -1
  15. data/errata/automobile_make_model_year_variant/feg_errata.csv +363 -1
  16. data/errata/automobile_make_year_fleet/cafe_errata.csv +69 -1
  17. data/errata/bts_aircraft/bts_errata.csv +1 -1
  18. data/errata/country/wri_errata.csv +1 -1
  19. data/errata/electricity/electric_market/nrel_errata.csv +13 -1
  20. data/errata/electricity/electric_utility/eia_errata.csv +18 -1
  21. data/errata/flight_segment/bts_errata.csv +4 -1
  22. data/lib/earth.rb +1 -0
  23. data/lib/earth/acronyms.rb +12 -0
  24. data/lib/earth/air/aircraft.rb +16 -0
  25. data/lib/earth/air/airline.rb +3 -0
  26. data/lib/earth/air/airline/data_miner.rb +18 -3
  27. data/lib/earth/air/airport.rb +2 -0
  28. data/lib/earth/air/bts_aircraft.rb +2 -0
  29. data/lib/earth/air/flight_distance_class.rb +2 -0
  30. data/lib/earth/air/flight_distance_class_seat_class.rb +2 -0
  31. data/lib/earth/air/flight_seat_class.rb +2 -0
  32. data/lib/earth/air/flight_segment.rb +10 -0
  33. data/lib/earth/air/flight_segment/data_miner.rb +10 -13
  34. data/lib/earth/automobile/automobile_activity_year.rb +21 -0
  35. data/lib/earth/automobile/automobile_activity_year/data_miner.rb +27 -0
  36. data/lib/earth/automobile/automobile_activity_year_type.rb +27 -0
  37. data/lib/earth/automobile/automobile_activity_year_type/data_miner.rb +27 -0
  38. data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +19 -0
  39. data/lib/earth/automobile/automobile_activity_year_type_fuel/data_miner.rb +57 -0
  40. data/lib/earth/automobile/automobile_fuel.rb +93 -86
  41. data/lib/earth/automobile/automobile_fuel/data_miner.rb +64 -70
  42. data/lib/earth/automobile/automobile_make.rb +5 -1
  43. data/lib/earth/automobile/automobile_make/data_miner.rb +10 -37
  44. data/lib/earth/automobile/automobile_make_model.rb +22 -3
  45. data/lib/earth/automobile/automobile_make_model/data_miner.rb +41 -15
  46. data/lib/earth/automobile/automobile_make_model_year.rb +18 -7
  47. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +43 -27
  48. data/lib/earth/automobile/automobile_make_model_year_variant.rb +44 -8
  49. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +182 -8
  50. data/lib/earth/automobile/automobile_make_year.rb +4 -2
  51. data/lib/earth/automobile/automobile_make_year/data_miner.rb +16 -15
  52. data/lib/earth/automobile/automobile_make_year_fleet.rb +2 -1
  53. data/lib/earth/automobile/automobile_make_year_fleet/data_miner.rb +5 -2
  54. data/lib/earth/automobile/automobile_model.rb +2 -1
  55. data/lib/earth/automobile/automobile_model/data_miner.rb +1 -2
  56. data/lib/earth/automobile/automobile_size_class.rb +7 -68
  57. data/lib/earth/automobile/automobile_size_class/data_miner.rb +16 -51
  58. data/lib/earth/automobile/automobile_type_fuel.rb +23 -0
  59. data/lib/earth/automobile/automobile_type_fuel/data_miner.rb +52 -0
  60. data/lib/earth/automobile/automobile_type_fuel_control.rb +2 -33
  61. data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +19 -4
  62. data/lib/earth/automobile/automobile_type_fuel_year.rb +17 -54
  63. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +40 -94
  64. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +25 -23
  65. data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +6 -2
  66. data/lib/earth/automobile/automobile_year.rb +38 -1
  67. data/lib/earth/automobile/automobile_year/data_miner.rb +1 -2
  68. data/lib/earth/automobile/dependencies.txt +22 -36
  69. data/lib/earth/bus/bus_class.rb +2 -0
  70. data/lib/earth/bus/bus_fuel.rb +2 -0
  71. data/lib/earth/bus/bus_fuel_control.rb +2 -0
  72. data/lib/earth/bus/bus_fuel_year_control.rb +2 -0
  73. data/lib/earth/computation/computation_carrier.rb +2 -0
  74. data/lib/earth/computation/computation_carrier_instance_class.rb +2 -0
  75. data/lib/earth/computation/computation_carrier_region.rb +2 -0
  76. data/lib/earth/conversions_ext.rb +6 -0
  77. data/lib/earth/diet/diet_class.rb +2 -0
  78. data/lib/earth/diet/food_group.rb +2 -0
  79. data/lib/earth/fuel/fuel.rb +2 -0
  80. data/lib/earth/fuel/fuel/data_miner.rb +15 -0
  81. data/lib/earth/fuel/fuel_price.rb +2 -0
  82. data/lib/earth/fuel/fuel_type.rb +2 -0
  83. data/lib/earth/fuel/fuel_year.rb +2 -0
  84. data/lib/earth/fuel/greenhouse_gas.rb +2 -0
  85. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +7 -7
  86. data/lib/earth/hospitality/lodging_class.rb +2 -0
  87. data/lib/earth/industry/industry.rb +2 -0
  88. data/lib/earth/industry/mecs_energy/data_miner.rb +1 -1
  89. data/lib/earth/industry/mecs_ratio/data_miner.rb +1 -1
  90. data/lib/earth/locality/census_division.rb +2 -0
  91. data/lib/earth/locality/census_region.rb +2 -0
  92. data/lib/earth/locality/climate_division.rb +2 -0
  93. data/lib/earth/locality/country.rb +4 -0
  94. data/lib/earth/locality/egrid_region.rb +3 -0
  95. data/lib/earth/locality/egrid_subregion.rb +2 -0
  96. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +7 -0
  97. data/lib/earth/locality/state.rb +7 -0
  98. data/lib/earth/locality/zip_code.rb +4 -0
  99. data/lib/earth/pet/breed.rb +7 -0
  100. data/lib/earth/pet/breed/data_miner.rb +1 -1
  101. data/lib/earth/pet/breed_gender.rb +2 -0
  102. data/lib/earth/pet/gender.rb +2 -0
  103. data/lib/earth/pet/species.rb +2 -0
  104. data/lib/earth/rail/country_rail_class.rb +2 -0
  105. data/lib/earth/rail/country_rail_traction.rb +2 -0
  106. data/lib/earth/rail/country_rail_traction_class.rb +2 -0
  107. data/lib/earth/rail/national_transit_database_company.rb +7 -0
  108. data/lib/earth/rail/national_transit_database_mode.rb +2 -0
  109. data/lib/earth/rail/national_transit_database_record.rb +22 -0
  110. data/lib/earth/rail/rail_class.rb +2 -0
  111. data/lib/earth/rail/rail_company.rb +16 -0
  112. data/lib/earth/rail/rail_fuel.rb +2 -0
  113. data/lib/earth/rail/rail_traction.rb +2 -0
  114. data/lib/earth/residence/air_conditioner_use.rb +2 -0
  115. data/lib/earth/residence/clothes_machine_use.rb +2 -0
  116. data/lib/earth/residence/dishwasher_use.rb +2 -0
  117. data/lib/earth/residence/residence_appliance.rb +2 -0
  118. data/lib/earth/residence/residence_class.rb +2 -0
  119. data/lib/earth/residence/residence_fuel_price.rb +2 -0
  120. data/lib/earth/residence/residence_fuel_type.rb +2 -0
  121. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +2 -0
  122. data/lib/earth/residence/urbanity.rb +2 -0
  123. data/lib/earth/shipping/carrier.rb +2 -0
  124. data/lib/earth/shipping/carrier_mode.rb +2 -0
  125. data/lib/earth/shipping/shipment_mode.rb +2 -0
  126. data/lib/earth/version.rb +1 -1
  127. data/spec/earth/air/airline_spec.rb +20 -0
  128. data/spec/earth/air/flight_segment_spec.rb +9 -4
  129. data/spec/earth/automobile/automobile_activity_year_spec.rb +30 -0
  130. data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +25 -0
  131. data/spec/earth/automobile/automobile_activity_year_type_spec.rb +38 -0
  132. data/spec/earth/automobile/automobile_fuel_spec.rb +91 -6
  133. data/spec/earth/automobile/automobile_make_model_spec.rb +74 -0
  134. data/spec/earth/automobile/automobile_make_model_year_spec.rb +90 -0
  135. data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +139 -90
  136. data/spec/earth/automobile/automobile_make_spec.rb +27 -0
  137. data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +8 -21
  138. data/spec/earth/automobile/automobile_make_year_spec.rb +28 -0
  139. data/spec/earth/automobile/automobile_model_spec.rb +15 -0
  140. data/spec/earth/automobile/automobile_size_class_spec.rb +31 -0
  141. data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +25 -0
  142. data/spec/earth/automobile/automobile_type_fuel_spec.rb +45 -0
  143. data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +51 -0
  144. data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +65 -0
  145. data/spec/earth/automobile/automobile_year_spec.rb +23 -0
  146. data/spec/earth/fuel/fuel_spec.rb +1 -1
  147. data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +11 -3
  148. data/spec/earth_spec.rb +3 -3
  149. data/spec/spec_helper.rb +1 -0
  150. metadata +78 -25
  151. data/lib/earth/automobile/automobile_size_class_year.rb +0 -44
  152. data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +0 -18
  153. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +0 -68
  154. data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +0 -116
  155. data/lib/earth/automobile/automobile_type_year.rb +0 -58
  156. data/lib/earth/automobile/automobile_type_year/data_miner.rb +0 -30
  157. data/spec/earth/automobile/automobile_type_fuel_year_age_spec.rb +0 -20
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_activity_year_type'
3
+
4
+ describe AutomobileActivityYearType do
5
+ before :all do
6
+ Earth.init :automobile, :load_data_miner => true
7
+ require 'earth/acronyms'
8
+ end
9
+
10
+ describe 'import', :data_miner => true do
11
+ it 'should import data' do
12
+ AAYT.run_data_miner!
13
+ end
14
+ end
15
+
16
+ describe 'verify', :sanity => true do
17
+ it { AAYT.count.should == 30 }
18
+ it { AAYT.where("hfc_emissions > 0").count.should == AAYT.count }
19
+ it { AAYT.where("hfc_emission_factor > 0").count.should == AAYT.count }
20
+
21
+ # spot check
22
+ it { AAYT.first.hfc_emissions.should be_within(0.1).of(31000000000) }
23
+ it { AAYT.first.hfc_emission_factor.should be_within(1e-5).of(0.02438) }
24
+ it { AAYT.first.hfc_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
25
+ end
26
+
27
+ describe '.find_by_type_name_and_closest_year' do
28
+ it { AAYT.find_by_type_name_and_closest_year('Passenger cars', 2010).should == AAYT.where(:type_name => 'Passenger cars', :activity_year => 2009).first }
29
+ it { AAYT.find_by_type_name_and_closest_year('Passenger cars', 2005).should == AAYT.where(:type_name => 'Passenger cars', :activity_year => 2005).first }
30
+ it { AAYT.find_by_type_name_and_closest_year('Passenger cars', 1994).should == AAYT.where(:type_name => 'Passenger cars', :activity_year => 1995).first }
31
+ end
32
+
33
+ describe '#activity_year_type_fuels' do
34
+ it 'should match' do
35
+ AAYT.first.activity_year_type_fuels.should == AAYTF.where(:activity_year => 1995, :type_name => 'Light-duty trucks')
36
+ end
37
+ end
38
+ end
@@ -2,9 +2,11 @@ require 'spec_helper'
2
2
  require 'earth/automobile'
3
3
 
4
4
  describe AutomobileFuel do
5
+ let(:fallback) { AutomobileFuel.fallback }
6
+
5
7
  describe 'import', :data_miner => true do
6
8
  before do
7
- Earth.init :automobile, :load_data_miner => true, :skip_parent_associations => :true
9
+ Earth.init :automobile, :load_data_miner => true
8
10
  end
9
11
 
10
12
  it 'should import data without problems' do
@@ -13,11 +15,94 @@ describe AutomobileFuel do
13
15
  end
14
16
 
15
17
  describe 'verify imported data', :sanity => true do
16
- it 'should have all the data' do
17
- AutomobileFuel.count.should == 9
18
- end
19
- it 'correctly assigns hfc_emission_factor' do
20
- AutomobileFuel.first.hfc_emission_factor.should == 0.124799
18
+ it { AutomobileFuel.count.should == 12 }
19
+ it { AutomobileFuel.where(:distance_key => nil).count.should == 0 }
20
+ it { AutomobileFuel.where("annual_distance >= 0").count.should == AutomobileFuel.count }
21
+ it { AutomobileFuel.where("energy_content >= 0").count.should == AutomobileFuel.count }
22
+ it { AutomobileFuel.where("co2_emission_factor >= 0").count.should == AutomobileFuel.count - 1 }
23
+ it { AutomobileFuel.where("co2_biogenic_emission_factor >= 0").count.should == AutomobileFuel.count - 1 }
24
+ it { AutomobileFuel.where("ch4_emission_factor >= 0").count.should == AutomobileFuel.count }
25
+ it { AutomobileFuel.where("n2o_emission_factor >= 0").count.should == AutomobileFuel.count }
26
+ it { AutomobileFuel.where("total_consumption >= 0").count.should == 2 }
27
+
28
+ it { AutomobileFuel.find('gasoline').annual_distance.should be_within(0.1).of(17568.6) }
29
+ it { AutomobileFuel.find('gasoline').energy_content.should be_within(1e-5).of(34.6272) }
30
+ it { AutomobileFuel.find('gasoline').co2_emission_factor.should be_within(1e-6).of(2.34183) }
31
+ it { AutomobileFuel.find('gasoline').ch4_emission_factor.should be_within(1e-8).of(4.2548e-4) }
32
+ it { AutomobileFuel.find('gasoline').n2o_emission_factor.should be_within(1e-6).of(5.7340e-3) }
33
+
34
+ it { AutomobileFuel.find('gasoline').annual_distance_units.should == 'kilometres' }
35
+ it { AutomobileFuel.find('gasoline').energy_content_units.should == 'megajoules_per_litre' }
36
+ it { AutomobileFuel.find('gasoline').co2_emission_factor_units.should == 'kilograms_per_litre' }
37
+ it { AutomobileFuel.find('gasoline').ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
38
+ it { AutomobileFuel.find('gasoline').n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
39
+
40
+ it { AutomobileFuel.find('diesel').annual_distance.should be_within(0.1).of(22410.2) }
41
+ it { AutomobileFuel.find('diesel').energy_content.should be_within(1e-5).of(38.5491) }
42
+ it { AutomobileFuel.find('diesel').co2_emission_factor.should be_within(1e-6).of(2.70219) }
43
+ it { AutomobileFuel.find('diesel').ch4_emission_factor.should be_within(1e-9).of(1.3887e-5) }
44
+ it { AutomobileFuel.find('diesel').n2o_emission_factor.should be_within(1e-8).of(2.5812e-4) }
45
+
46
+ it { AutomobileFuel.find('gasoline').total_consumption.should > 455_000_000_000 }
47
+ it { AutomobileFuel.find('diesel').total_consumption.should > 5_800_000_000 }
48
+
49
+ it { AutomobileFuel.find('Electricity').energy_content.should == 3.6 }
50
+ it { AutomobileFuel.find('Electricity').co2_emission_factor.should == nil }
51
+ it { AutomobileFuel.find('Electricity').co2_biogenic_emission_factor.should == nil }
52
+ it { AutomobileFuel.find('Electricity').ch4_emission_factor.should == 0 }
53
+ it { AutomobileFuel.find('Electricity').n2o_emission_factor.should == 0 }
54
+
55
+ it "all grades of gasoline should have same annual distance and emission factors" do
56
+ AutomobileFuel.where("name LIKE '%gasoline'").each do |fuel|
57
+ fuel.common_name.should == 'gasoline'
58
+ fuel.annual_distance.should == AutomobileFuel.gasoline.annual_distance
59
+ fuel.co2_emission_factor.should == AutomobileFuel.gasoline.co2_emission_factor
60
+ fuel.ch4_emission_factor.should == AutomobileFuel.gasoline.ch4_emission_factor
61
+ fuel.n2o_emission_factor.should == AutomobileFuel.gasoline.n2o_emission_factor
62
+ end
21
63
  end
22
64
  end
65
+
66
+ describe '.diesel' do
67
+ it { AutomobileFuel.diesel.should == AutomobileFuel.find('diesel') }
68
+ end
69
+
70
+ describe '.gasoline' do
71
+ it { AutomobileFuel.gasoline.should == AutomobileFuel.find('gasoline') }
72
+ end
73
+
74
+ describe '.fallback_blend_portion' do
75
+ it { AutomobileFuel.fallback_blend_portion.should be_within(1e-5).of(0.01260) }
76
+ end
77
+
78
+ describe '.fallback' do
79
+ it { AutomobileFuel.fallback.name.should == 'fallback' }
80
+ it { fallback.base_fuel.should == Fuel.find('Motor Gasoline') }
81
+ it { fallback.blend_fuel.should == Fuel.find('Distillate Fuel Oil No. 2') }
82
+ it { fallback.blend_portion.should be_within(1e-5).of(0.01260) }
83
+
84
+ it { fallback.annual_distance.should be_within(0.1).of(17629.6) }
85
+ it { fallback.energy_content.should be_within(1e-6).of(34.6766) }
86
+ it { fallback.co2_emission_factor.should be_within(1e-6).of(2.34637) }
87
+ it { fallback.co2_biogenic_emission_factor.should == 0.0 }
88
+ it { fallback.ch4_emission_factor.should be_within(1e-8).of(4.203e-4) }
89
+ it { fallback.n2o_emission_factor.should be_within(1e-8).of(5.665e-3) }
90
+
91
+ it { fallback.energy_content_units.should == 'megajoules_per_litre' }
92
+ it { fallback.co2_emission_factor_units.should == 'kilograms_per_litre' }
93
+ it { fallback.co2_biogenic_emission_factor_units.should == 'kilograms_per_litre' }
94
+ it { fallback.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
95
+ it { fallback.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
96
+ end
97
+
98
+ describe '#non_liquid?' do
99
+ it { AutomobileFuel.where(:energy_content_units => 'megajoules_per_litre').first.non_liquid?.should == false }
100
+ it { AutomobileFuel.where("energy_content_units != 'megajoules_per_litre'").first.non_liquid?.should == true }
101
+ end
102
+
103
+ describe '#same_as?' do
104
+ it { AutomobileFuel.find_by_code('G').same_as?(AutomobileFuel.find_by_code 'G').should == true }
105
+ it { AutomobileFuel.find_by_code('G').same_as?(AutomobileFuel.find_by_code 'R').should == true }
106
+ it { AutomobileFuel.find_by_code('G').same_as?(AutomobileFuel.find_by_code 'D').should == false }
107
+ end
23
108
  end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_make_model'
3
+
4
+ describe AutomobileMakeModel do
5
+ let(:civic) { AMM.where(:name => "Honda Civic").first }
6
+ let(:civic_years) { AMMY.where(:make_name => 'Honda', :model_name => 'Civic') }
7
+
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') }
13
+
14
+ before :all do
15
+ Earth.init :automobile, :load_data_miner => true, :skip_parent_associations => true
16
+ require 'earth/acronyms'
17
+ end
18
+
19
+ describe 'import', :data_miner => true do
20
+ it 'should import data' do
21
+ AMM.run_data_miner!
22
+ AMM.count.should == AMM.connection.select_value("SELECT COUNT(DISTINCT make_name, model_name) FROM #{AMMY.quoted_table_name}")
23
+ end
24
+ end
25
+
26
+ describe 'verify', :sanity => true do
27
+ it { AMM.where(:fuel_code => nil).count.should == 0 }
28
+ it { AMM.where("fuel_efficiency_city > 0").count.should == AMM.count }
29
+ it { AMM.where("fuel_efficiency_highway > 0").count.should == AMM.count }
30
+ it { AMM.where("alt_fuel_code IS NOT NULL").count.should == 157 }
31
+ it { AMM.where("alt_fuel_efficiency_city > 0").count.should == 157 }
32
+ it { AMM.where("alt_fuel_efficiency_highway > 0").count.should == 157 }
33
+ it { AMM.where(:type_name => nil).count.should == 0 }
34
+
35
+ # spot checks
36
+ it { civic.fuel_code.should == 'G' }
37
+ it { civic.fuel_efficiency_city.should be_within(1e-4).of(10.884) }
38
+ it { civic.fuel_efficiency_city_units.should == 'kilometres_per_litre' }
39
+ it { civic.fuel_efficiency_highway.should be_within(1e-4).of(14.2857) }
40
+ it { civic.fuel_efficiency_highway_units.should == 'kilometres_per_litre' }
41
+
42
+ it { civic.alt_fuel_code.should == nil }
43
+ it { civic.alt_fuel_efficiency_city.should == nil }
44
+ it { civic.alt_fuel_efficiency_city_units.should == nil }
45
+ it { civic.alt_fuel_efficiency_highway.should == nil }
46
+ it { civic.alt_fuel_efficiency_highway_units.should == nil }
47
+
48
+ it { civic.type_name.should == 'Passenger cars' }
49
+
50
+ it { civic_cng.fuel_code.should == 'C' }
51
+ it { civic_cng.fuel_efficiency_city.should be_within(1e-4).of(10.5237) }
52
+ it { civic_cng.fuel_efficiency_city_units.should == 'kilometres_per_litre' }
53
+ it { civic_cng.fuel_efficiency_highway.should be_within(1e-4).of(14.1971) }
54
+ it { civic_cng.fuel_efficiency_highway_units.should == 'kilometres_per_litre' }
55
+
56
+ it { f150_ffv.fuel_code.should == 'R' }
57
+ it { f150_ffv.fuel_efficiency_city.should be_within(1e-4).of(5.9628) }
58
+ it { f150_ffv.fuel_efficiency_city_units.should == 'kilometres_per_litre' }
59
+ it { f150_ffv.fuel_efficiency_highway.should be_within(1e-4).of(8.0427) }
60
+ it { f150_ffv.fuel_efficiency_highway_units.should == 'kilometres_per_litre' }
61
+
62
+ it { f150_ffv.alt_fuel_code.should == 'E' }
63
+ it { f150_ffv.alt_fuel_efficiency_city.should be_within(1e-4).of(4.3744) }
64
+ it { f150_ffv.alt_fuel_efficiency_city_units.should == 'kilometres_per_litre' }
65
+ it { f150_ffv.alt_fuel_efficiency_highway.should be_within(1e-4).of(5.842) }
66
+ it { f150_ffv.alt_fuel_efficiency_highway_units.should == 'kilometres_per_litre' }
67
+
68
+ it { f150_ffv.type_name.should == 'Light-duty trucks' }
69
+ end
70
+
71
+ describe '#model_years' do
72
+ it { civic.model_years.sort.should == civic_years.sort }
73
+ end
74
+ end
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_make_model_year'
3
+
4
+ describe AutomobileMakeModelYear do
5
+ before :all do
6
+ Earth.init :automobile, :load_data_miner => true, :skip_parent_associations => :true
7
+ require 'earth/acronyms'
8
+ end
9
+
10
+ describe 'import', :data_miner => true do
11
+ it 'should import data' do
12
+ AMMY.run_data_miner!
13
+ AMMY.count.should == AMMY.connection.select_value("SELECT COUNT(DISTINCT make_name, model_name, year) FROM #{AMMYV.quoted_table_name}")
14
+ end
15
+ end
16
+
17
+ describe 'verify imported data', :sanity => true do
18
+ it 'has data from all years' do
19
+ (1985..2012).each do |year|
20
+ 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}")
21
+ end
22
+ end
23
+
24
+ # confirm make, model, year aren't missing
25
+ it { AMMY.where(:make_name => nil).count.should == 0 }
26
+ it { AMMY.where(:model_name => nil).count.should == 0 }
27
+ it { AMMY.where(:year => nil).count.should == 0 }
28
+
29
+ it 'should have valid fuel codes' do
30
+ AMMY.connection.select_values("SELECT DISTINCT fuel_code FROM #{AMMY.quoted_table_name} WHERE fuel_code != 'G'").each do |code|
31
+ fail "#{code} is not a valid code" unless AutomobileMakeModelYearVariant::Parser::FUEL_CODES.values.include?(code)
32
+ end
33
+ end
34
+
35
+ it 'should have valid alt fuel codes' do
36
+ AMMY.connection.select_values("SELECT DISTINCT alt_fuel_code FROM #{AMMY.quoted_table_name} WHERE alt_fuel_code IS NOT NULL").each do |code|
37
+ fail "#{code} is not a valid code" unless AutomobileMakeModelYearVariant::Parser::FUEL_CODES.values.include?(code)
38
+ end
39
+ end
40
+
41
+ it { AMMY.where(:hybridity => true).count.should == 170 }
42
+
43
+ it 'should have proper weightings' do
44
+ AutomobileMakeModelYear.connection.select_values("SELECT DISTINCT year FROM #{AutomobileMakeModelYear.quoted_table_name}").each do |year|
45
+ AMMY.where(:year => year).first.weighting.should == AutomobileYear.weighting(year)
46
+ end
47
+ end
48
+
49
+ # confirm fuel efficiencies are valid and proper units
50
+ it { AMMY.where("fuel_efficiency_city > 0").count.should == AMMY.count }
51
+ it { AMMY.where("fuel_efficiency_highway > 0").count.should == AMMY.count }
52
+ it { AMMY.where(:fuel_efficiency_city_units => 'kilometres_per_litre').count.should == AMMY.count }
53
+ it { AMMY.where(:fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == AMMY.count }
54
+
55
+ # confirm alt fuel efficiencies are valid and proper units
56
+ it { AMMY.where("alt_fuel_efficiency_city > 0").count.should == AMMY.where("alt_fuel_code IS NOT NULL").count }
57
+ it { AMMY.where("alt_fuel_efficiency_highway > 0").count.should == AMMY.where("alt_fuel_code IS NOT NULL").count }
58
+ it { AMMY.where(:alt_fuel_efficiency_city_units => 'kilometres_per_litre').count.should == AMMY.where("alt_fuel_code IS NOT NULL").count }
59
+ it { AMMY.where(:alt_fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == AMMY.where("alt_fuel_code IS NOT NULL").count }
60
+
61
+ # # spot check fuel efficiency calcs
62
+ it { AMMY.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
63
+ it { AMMY.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
64
+
65
+ 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) }
66
+ 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) }
67
+
68
+ it { AMMY.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
69
+ it { AMMY.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
70
+
71
+ 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) }
72
+ 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) }
73
+
74
+ 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) }
75
+ 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) }
76
+
77
+ 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) }
78
+ 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) }
79
+
80
+ it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).fuel_efficiency_city.should be_within(0.0001).of(7.86516) }
81
+ it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).fuel_efficiency_highway.should be_within(0.0001).of(12.11660) }
82
+
83
+ it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).alt_fuel_efficiency_city.should == nil }
84
+ it { AMMY.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER'}).alt_fuel_efficiency_highway.should == nil }
85
+
86
+ it { AMMY.where(:type_name => nil).count.should == 0 }
87
+ it { AMMY.find(:first, :conditions => {:make_name => 'Toyota', :model_name => 'Prius'}).type_name.should == 'Passenger cars' }
88
+ it { AMMY.find(:first, :conditions => {:make_name => 'Toyota', :model_name => 'Highlander'}).type_name.should == 'Light-duty trucks' }
89
+ end
90
+ end
@@ -4,138 +4,187 @@ require 'earth/automobile/automobile_make_model_year_variant'
4
4
 
5
5
  describe AutomobileMakeModelYearVariant do
6
6
  before :all do
7
- Earth.init :automobile, :load_data_miner => true, :skip_parent_associations => :true
7
+ Earth.init :automobile, :load_data_miner => true
8
+ require 'earth/acronyms'
8
9
  end
9
10
 
10
11
  describe 'import', :data_miner => true do
11
12
  it 'should import data' do
12
- AutomobileMakeModelYearVariant.run_data_miner!
13
- AutomobileMakeModelYearVariant.count.should == 28811
13
+ AMMYV.run_data_miner!
14
+ AMMYV.count.should == 28433
14
15
  end
15
16
  end
16
17
 
17
18
  describe 'verify imported data', :sanity => true do
18
19
  # confirm we have right data from all years
19
- it { AutomobileMakeModelYearVariant.where(:year => 1985).count.should == 1152 }
20
- it { AutomobileMakeModelYearVariant.where(:year => 1986).count.should == 1183 }
21
- it { AutomobileMakeModelYearVariant.where(:year => 1987).count.should == 1206 }
22
- it { AutomobileMakeModelYearVariant.where(:year => 1988).count.should == 1104 }
23
- it { AutomobileMakeModelYearVariant.where(:year => 1989).count.should == 1137 }
24
- it { AutomobileMakeModelYearVariant.where(:year => 1990).count.should == 1049 }
25
- it { AutomobileMakeModelYearVariant.where(:year => 1991).count.should == 1062 }
26
- it { AutomobileMakeModelYearVariant.where(:year => 1992).count.should == 1055 }
27
- it { AutomobileMakeModelYearVariant.where(:year => 1993).count.should == 986 }
28
- it { AutomobileMakeModelYearVariant.where(:year => 1994).count.should == 963 }
29
- it { AutomobileMakeModelYearVariant.where(:year => 1995).count.should == 917 }
30
- it { AutomobileMakeModelYearVariant.where(:year => 1996).count.should == 750 }
31
- it { AutomobileMakeModelYearVariant.where(:year => 1997).count.should == 727 }
32
- it { AutomobileMakeModelYearVariant.where(:year => 1998).count.should == 794 }
33
- it { AutomobileMakeModelYearVariant.where(:year => 1999).count.should == 800 }
34
- it { AutomobileMakeModelYearVariant.where(:year => 2000).count.should == 845 }
35
- it { AutomobileMakeModelYearVariant.where(:year => 2001).count.should == 849 }
36
- it { AutomobileMakeModelYearVariant.where(:year => 2002).count.should == 940 }
37
- it { AutomobileMakeModelYearVariant.where(:year => 2003).count.should == 1031 }
38
- it { AutomobileMakeModelYearVariant.where(:year => 2004).count.should == 1134 }
39
- it { AutomobileMakeModelYearVariant.where(:year => 2005).count.should == 1105 }
40
- it { AutomobileMakeModelYearVariant.where(:year => 2006).count.should == 1076 }
41
- it { AutomobileMakeModelYearVariant.where(:year => 2007).count.should == 1184 }
42
- it { AutomobileMakeModelYearVariant.where(:year => 2008).count.should == 1247 }
43
- it { AutomobileMakeModelYearVariant.where(:year => 2009).count.should == 1182 }
44
- it { AutomobileMakeModelYearVariant.where(:year => 2010).count.should == 1107 }
45
- it { AutomobileMakeModelYearVariant.where(:year => 2011).count.should == 1097 }
46
- it { AutomobileMakeModelYearVariant.where(:year => 2012).count.should == 1129 }
47
-
48
- # confirm make, model, year aren't missing
49
- it { AutomobileMakeModelYearVariant.where(:make_name => nil).count.should == 0 }
50
- it { AutomobileMakeModelYearVariant.where(:model_name => nil).count.should == 0 }
51
- it { AutomobileMakeModelYearVariant.where(:year => nil).count.should == 0 }
20
+ it { AMMYV.where(:year => 1985).count.should == 1152 }
21
+ it { AMMYV.where(:year => 1986).count.should == 1183 }
22
+ it { AMMYV.where(:year => 1987).count.should == 1206 }
23
+ it { AMMYV.where(:year => 1988).count.should == 1104 }
24
+ it { AMMYV.where(:year => 1989).count.should == 1137 }
25
+ it { AMMYV.where(:year => 1990).count.should == 1049 }
26
+ it { AMMYV.where(:year => 1991).count.should == 1062 }
27
+ it { AMMYV.where(:year => 1992).count.should == 1055 }
28
+ it { AMMYV.where(:year => 1993).count.should == 986 }
29
+ it { AMMYV.where(:year => 1994).count.should == 963 }
30
+ it { AMMYV.where(:year => 1995).count.should == 917 }
31
+ it { AMMYV.where(:year => 1996).count.should == 750 }
32
+ it { AMMYV.where(:year => 1997).count.should == 727 }
33
+ it { AMMYV.where(:year => 1998).count.should == 794 }
34
+ it { AMMYV.where(:year => 1999).count.should == 800 }
35
+ it { AMMYV.where(:year => 2000).count.should == 834 }
36
+ it { AMMYV.where(:year => 2001).count.should == 846 }
37
+ it { AMMYV.where(:year => 2002).count.should == 933 }
38
+ it { AMMYV.where(:year => 2003).count.should == 995 }
39
+ it { AMMYV.where(:year => 2004).count.should == 1091 }
40
+ it { AMMYV.where(:year => 2005).count.should == 1069 }
41
+ it { AMMYV.where(:year => 2006).count.should == 1043 }
42
+ it { AMMYV.where(:year => 2007).count.should == 1126 }
43
+ it { AMMYV.where(:year => 2008).count.should == 1186 }
44
+ it { AMMYV.where(:year => 2009).count.should == 1092 }
45
+ it { AMMYV.where(:year => 2010).count.should == 1107 }
46
+ it { AMMYV.where(:year => 2011).count.should == 1097 }
47
+ it { AMMYV.where(:year => 2012).count.should == 1129 }
48
+
49
+ # confirm make, model, year, size class, and type aren't missing
50
+ it { AMMYV.where(:make_name => nil).count.should == 0 }
51
+ it { AMMYV.where(:model_name => nil).count.should == 0 }
52
+ it { AMMYV.where(:year => nil).count.should == 0 }
53
+ it { AMMYV.where(:size_class => nil).count.should == 0 }
54
+ it { AMMYV.where(:type_name => nil).count.should == 0 }
55
+
56
+ # confirm it handles special characters
57
+ it { AMMYV.where(:make_name => 'Citroën').count.should > 13 }
58
+
59
+ # confirm Chevy and GMC model names have been simplified
60
+ it { AMMYV.where("make_name IN ('Chevrolet', 'GMC') AND model_name REGEXP '^[CK][0-9]+'").count.should == 0 }
61
+
62
+ # confirm certain hybrids have been identified
63
+ it { AMMYV.where(:year => 2012, :make_name => 'Buick', :model_name => 'LACROSSE HYBRID').count.should == 1 }
64
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Buick', :model_name => 'LACROSSE HYBRID'}).fuel_efficiency.should be_within(1e-4).of(12.8701) }
65
+ it { AMMYV.where(:year => 2012, :make_name => 'Buick', :model_name => 'REGAL HYBRID').count.should == 1 }
66
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Buick', :model_name => 'REGAL HYBRID'}).fuel_efficiency.should be_within(1e-4).of(12.8701) }
67
+
68
+ # confirm dual-fuel and CNG variants have been merged and identified
69
+ it { AMMYV.where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => 'C').count.should == 0 }
70
+ it { AMMYV.where(:make_name => 'Chevrolet', :model_name => 'CAVALIER DUAL-FUEL', :fuel_code => 'R', :alt_fuel_code => 'C').count.should == 5 }
71
+ it { AMMYV.where(:fuel_code => 'C').count.should == AMMYV.where("model_name LIKE '%CNG'").count }
72
+
73
+ # confirm FFV variants have been merged
74
+ it { AMMYV.where(:fuel_code => 'E').count.should == 0 }
75
+ it { AMMYV.where(:alt_fuel_code => 'E').count.should > 750 }
76
+
77
+ # confirm flex-fuel variants of models where not all variants are flex-fuel have been identified
78
+ it { AMMYV.where("model_name LIKE '%FFV'").count.should > 700 }
79
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Toyota', :model_name => 'SEQUOIA FFV'}).alt_fuel_code.should == 'E' }
80
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Toyota', :model_name => 'SEQUOIA'}).alt_fuel_code.should == nil }
81
+
82
+ # confirm diesel variants of models where not all variants are diesel have been identified
83
+ it { AMMYV.where("model_name LIKE '%DIESEL'").count.should > 575 }
84
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Volkswagen', :model_name => 'JETTA DIESEL'}).fuel_code.should == 'D' }
85
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Volkswagen', :model_name => 'JETTA'}).fuel_code.should_not == 'D' }
86
+
87
+ it "type name shouldn't vary within a make model" do
88
+ AMMYV.connection.select_values(%{
89
+ SELECT * FROM
90
+ (SELECT make_name, model_name, GROUP_CONCAT(DISTINCT type_name) AS types
91
+ FROM #{AMMYV.quoted_table_name}
92
+ GROUP BY make_name, model_name) AS t1
93
+ WHERE types LIKE '%,%'
94
+ }).count.should == 0
95
+ end
52
96
 
53
97
  it 'should have valid transmissions' do
54
- AutomobileMakeModelYearVariant.connection.select_values("SELECT DISTINCT transmission FROM #{AutomobileMakeModelYearVariant.quoted_table_name}").each do |transmission|
55
- fail "#{transmission} is not a valid transmission" unless AutomobileMakeModelYearVariant::Parser::TRANSMISSIONS.values.include?(transmission)
98
+ AMMYV.connection.select_values("SELECT DISTINCT transmission FROM #{AMMYV.quoted_table_name}").each do |transmission|
99
+ fail "#{transmission} is not a valid transmission" unless AMMYV::Parser::TRANSMISSIONS.values.include?(transmission)
56
100
  end
57
101
  end
58
102
 
59
103
  it 'should have valid speeds' do
60
104
  valid_speeds = ["1", "3", "4", "5", "6", "7", "8", "variable"]
61
- AutomobileMakeModelYearVariant.connection.select_values("SELECT DISTINCT speeds FROM #{AutomobileMakeModelYearVariant.quoted_table_name}").each do |speeds|
105
+ AMMYV.connection.select_values("SELECT DISTINCT speeds FROM #{AMMYV.quoted_table_name}").each do |speeds|
62
106
  fail "#{speeds} is not a valid speeds" unless valid_speeds.include?(speeds)
63
107
  end
64
108
  end
65
109
 
66
110
  it 'should have valid drives' do
67
111
  valid_drives = ["FWD", "RWD", "4WD", "AWD", "PWD"] # PWD = part-time 4-wheel drive
68
- AutomobileMakeModelYearVariant.connection.select_values("SELECT DISTINCT drive FROM #{AutomobileMakeModelYearVariant.quoted_table_name}").each do |drive|
112
+ AMMYV.connection.select_values("SELECT DISTINCT drive FROM #{AMMYV.quoted_table_name}").each do |drive|
69
113
  fail "#{drive} is not a valid drive" unless valid_drives.include?(drive)
70
114
  end
71
115
  end
72
116
 
73
117
  it 'should have valid fuel codes' do
74
- AutomobileMakeModelYearVariant.connection.select_values("SELECT DISTINCT fuel_code FROM #{AutomobileMakeModelYearVariant.quoted_table_name}").each do |code|
75
- fail "#{code} is not a valid code" unless AutomobileMakeModelYearVariant::Parser::FUEL_CODES.values.include?(code)
118
+ AMMYV.connection.select_values("SELECT DISTINCT fuel_code FROM #{AMMYV.quoted_table_name}").each do |code|
119
+ fail "#{code} is not a valid code" unless AMMYV::Parser::FUEL_CODES.values.include?(code)
120
+ end
121
+ end
122
+
123
+ it 'should have valid alt fuel codes' do
124
+ AMMYV.connection.select_values("SELECT DISTINCT alt_fuel_code FROM #{AMMYV.quoted_table_name} WHERE alt_fuel_code IS NOT NULL").each do |code|
125
+ fail "#{code} is not a valid code" unless AMMYV::Parser::FUEL_CODES.values.include?(code)
76
126
  end
77
127
  end
78
128
 
79
129
  # confirm fuel efficiencies are valid and proper units
80
- it { AutomobileMakeModelYearVariant.where("fuel_efficiency > 0").count.should == AutomobileMakeModelYearVariant.count }
81
- it { AutomobileMakeModelYearVariant.where("fuel_efficiency_city > 0").count.should == AutomobileMakeModelYearVariant.count }
82
- it { AutomobileMakeModelYearVariant.where("fuel_efficiency_highway > 0").count.should == AutomobileMakeModelYearVariant.count }
83
- it { AutomobileMakeModelYearVariant.where("fuel_efficiency_units = 'kilometres_per_litre'").count.should == AutomobileMakeModelYearVariant.count }
84
- it { AutomobileMakeModelYearVariant.where("fuel_efficiency_city_units = 'kilometres_per_litre'").count.should == AutomobileMakeModelYearVariant.count }
85
- it { AutomobileMakeModelYearVariant.where("fuel_efficiency_highway_units = 'kilometres_per_litre'").count.should == AutomobileMakeModelYearVariant.count }
86
- it { AutomobileMakeModelYearVariant.where("alt_fuel_efficiency <= 0").count.should == 0 }
87
- it { AutomobileMakeModelYearVariant.where("alt_fuel_efficiency_city <= 0").count.should == 0 }
88
- it { AutomobileMakeModelYearVariant.where("alt_fuel_efficiency_highway <= 0").count.should == 0 }
89
- it { AutomobileMakeModelYearVariant.where("alt_fuel_efficiency_units != 'kilometres_per_litre'").count.should == 0 }
90
- it { AutomobileMakeModelYearVariant.where("alt_fuel_efficiency_city_units != 'kilometres_per_litre'").count.should == 0 }
91
- it { AutomobileMakeModelYearVariant.where("alt_fuel_efficiency_highway_units != 'kilometres_per_litre'").count.should == 0 }
92
-
93
- # confirm carline class is present for recent years
94
- it { AutomobileMakeModelYearVariant.where("year > 1997 AND carline_class IS NULL").count.should == 0 }
130
+ it { AMMYV.where("fuel_efficiency > 0").count.should == AMMYV.count }
131
+ it { AMMYV.where("fuel_efficiency_city > 0").count.should == AMMYV.count }
132
+ it { AMMYV.where("fuel_efficiency_highway > 0").count.should == AMMYV.count }
133
+ it { AMMYV.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == AMMYV.count }
134
+ it { AMMYV.where(:fuel_efficiency_city_units => 'kilometres_per_litre').count.should == AMMYV.count }
135
+ it { AMMYV.where(:fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == AMMYV.count }
136
+
137
+ # confirm alt fuel efficiencies are valid and proper units
138
+ it { AMMYV.where("alt_fuel_efficiency > 0").count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
139
+ it { AMMYV.where("alt_fuel_efficiency_city > 0").count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
140
+ it { AMMYV.where("alt_fuel_efficiency_highway > 0").count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
141
+ it { AMMYV.where(:alt_fuel_efficiency_units => 'kilometres_per_litre').count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
142
+ it { AMMYV.where(:alt_fuel_efficiency_city_units => 'kilometres_per_litre').count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
143
+ it { AMMYV.where(:alt_fuel_efficiency_highway_units => 'kilometres_per_litre').count.should == AMMYV.where("alt_fuel_code IS NOT NULL").count }
95
144
 
96
145
  # spot check fuel efficiency calcs
97
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
98
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
99
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency.should be_within(0.0001).of(16.0216) }
146
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
147
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
148
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency.should be_within(0.0001).of(16.0216) }
100
149
 
101
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
102
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(39.5384) }
103
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency.should be_within(0.0001).of(39.8996) }
150
+ 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) }
151
+ 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) }
152
+ it { AMMYV.find(:first, :conditions => {:year => 2012, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency.should be_within(0.0001).of(39.8996) }
104
153
 
105
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
106
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
107
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency.should be_within(0.0001).of(16.0216) }
154
+ it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_city.should be_within(0.0001).of(14.8800) }
155
+ it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency_highway.should be_within(0.0001).of(17.0057) }
156
+ it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).fuel_efficiency.should be_within(0.0001).of(16.0216) }
108
157
 
109
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_city.should be_within(0.0001).of(40.3887) }
110
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(38.2629) }
111
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency.should be_within(0.0001).of(39.1489) }
158
+ 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) }
159
+ 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) }
160
+ it { AMMYV.find(:first, :conditions => {:year => 2011, :make_name => 'Chevrolet', :model_name => 'VOLT'}).alt_fuel_efficiency.should be_within(0.0001).of(39.1489) }
112
161
 
113
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER', :alt_fuel_code => 'E'}).fuel_efficiency_city.should be_within(0.0001).of( 8.0777) }
114
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER', :alt_fuel_code => 'E'}).fuel_efficiency_highway.should be_within(0.0001).of(11.4789) }
115
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER', :alt_fuel_code => 'E'}).fuel_efficiency.should be_within(0.0001).of( 9.7192) }
162
+ 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) }
163
+ 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) }
164
+ it { AMMYV.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER FFV'}).fuel_efficiency.should be_within(0.0001).of( 9.7192) }
116
165
 
117
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER', :alt_fuel_code => 'E'}).alt_fuel_efficiency_city.should be_within(0.0001).of(5.9520) }
118
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER', :alt_fuel_code => 'E'}).alt_fuel_efficiency_highway.should be_within(0.0001).of(8.5029) }
119
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2010, :make_name => 'Dodge', :model_name => 'AVENGER', :alt_fuel_code => 'E'}).alt_fuel_efficiency.should be_within(0.0001).of(7.1797) }
166
+ 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) }
167
+ 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) }
168
+ 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) }
120
169
 
121
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency_city.should be_within(0.0001).of(20.2602) }
122
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency_highway.should be_within(0.0001).of(19.1879) }
123
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency.should be_within(0.0001).of(19.6347) }
170
+ it { AMMYV.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency_city.should be_within(0.0001).of(20.2602) }
171
+ it { AMMYV.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency_highway.should be_within(0.0001).of(19.1879) }
172
+ it { AMMYV.find(:first, :conditions => {:year => 2009, :make_name => 'Toyota', :model_name => 'PRIUS'}).fuel_efficiency.should be_within(0.0001).of(19.6347) }
124
173
 
125
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_city.should be_within(0.0001).of( 7.9773) }
126
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_highway.should be_within(0.0001).of(10.2480) }
127
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency.should be_within(0.0001).of( 9.1305) }
174
+ it { AMMYV.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_city.should be_within(0.0001).of( 7.9773) }
175
+ it { AMMYV.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_highway.should be_within(0.0001).of(10.2480) }
176
+ it { AMMYV.find(:first, :conditions => {:year => 1998, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency.should be_within(0.0001).of( 9.1305) }
128
177
 
129
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_city.should be_within(0.0001).of( 7.7886) }
130
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_highway.should be_within(0.0001).of(10.3739) }
131
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency.should be_within(0.0001).of( 9.0782) }
178
+ it { AMMYV.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_city.should be_within(0.0001).of( 7.7886) }
179
+ it { AMMYV.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency_highway.should be_within(0.0001).of(10.3739) }
180
+ it { AMMYV.find(:first, :conditions => {:year => 1997, :make_name => 'Honda', :model_name => 'ODYSSEY'}).fuel_efficiency.should be_within(0.0001).of( 9.0782) }
132
181
 
133
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency_city.should be_within(0.0001).of(5.8670) }
134
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency_highway.should be_within(0.0001).of(8.2903) }
135
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency.should be_within(0.0001).of(7.0399) }
182
+ it { AMMYV.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency_city.should be_within(0.0001).of(5.8670) }
183
+ it { AMMYV.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency_highway.should be_within(0.0001).of(8.2903) }
184
+ it { AMMYV.find(:first, :conditions => {:year => 1995, :make_name => 'Jaguar', :model_name => 'XJR'}).fuel_efficiency.should be_within(0.0001).of(7.0399) }
136
185
 
137
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency_city.should be_within(0.0001).of(5.8479) }
138
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency_highway.should be_within(0.0001).of(7.3958) }
139
- it { AutomobileMakeModelYearVariant.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency.should be_within(0.0001).of(6.6401) }
186
+ it { AMMYV.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency_city.should be_within(0.0001).of(5.8479) }
187
+ it { AMMYV.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency_highway.should be_within(0.0001).of(7.3958) }
188
+ it { AMMYV.find(:first, :conditions => {:year => 1985, :make_name => 'Jaguar', :model_name => 'XJ'}).fuel_efficiency.should be_within(0.0001).of(6.6401) }
140
189
  end
141
190
  end