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,27 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_make'
3
+
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
+ before :all do
9
+ Earth.init :automobile, :load_data_miner => true, :skip_parent_associations => true
10
+ end
11
+
12
+ describe 'import', :data_miner => true do
13
+ it 'should import data' do
14
+ AutomobileMake.run_data_miner!
15
+ AutomobileMake.count.should == AutomobileMake.connection.select_value("SELECT COUNT(DISTINCT make_name) FROM #{AutomobileMakeYear.quoted_table_name}")
16
+ end
17
+ end
18
+
19
+ describe 'verify', :sanity => true do
20
+ it { AutomobileMake.where("fuel_efficiency > 0").count.should == AutomobileMake.count }
21
+ it { AutomobileMake.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == AutomobileMake.count }
22
+
23
+ # spot checks
24
+ it { honda.fuel_efficiency.should be_within(1e-4).of(13.0594) }
25
+ it { acura.fuel_efficiency.should be_within(1e-4).of(9.1347) }
26
+ end
27
+ end
@@ -4,33 +4,20 @@ require 'earth/automobile/automobile_make_year_fleet'
4
4
  describe AutomobileMakeYearFleet do
5
5
  describe 'import', :data_miner => true do
6
6
  before 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
  it 'should import data' do
11
- AutomobileMakeYearFleet.run_data_miner!
12
+ AMYF.run_data_miner!
12
13
  end
13
14
  end
14
15
 
15
16
  describe 'verify imported data', :sanity => true do
16
- it 'should have all the data' do
17
- AutomobileMakeYearFleet.count.should == 1349
18
- end
19
-
20
- it 'should have year from 1978 to 2011' do
21
- AutomobileMakeYearFleet.where('year IS NULL OR year < 1978 OR year > 2011').count.should == 0
22
- end
23
-
24
- it 'should have volume greater than zero' do
25
- AutomobileMakeYearFleet.where('volume IS NULL OR volume <= 0').count.should == 0
26
- end
27
-
28
- it 'should have fuel efficiency greater than zero' do
29
- AutomobileMakeYearFleet.where('fuel_efficiency IS NULL OR fuel_efficiency <= 0').count.should == 0
30
- end
31
-
32
- it 'should have fuel efficiency units of kilometres per litre' do
33
- AutomobileMakeYearFleet.where("fuel_efficiency_units IS NULL OR fuel_efficiency_units != 'kilometres_per_litre'").count.should == 0
34
- end
17
+ it { AMYF.count.should == 1349 }
18
+ it { AMYF.where('year >= 1978 AND year <= 2011').count.should == AMYF.count }
19
+ it { AMYF.where('volume > 0').count.should == AMYF.count }
20
+ it { AMYF.where('fuel_efficiency > 0').count.should == AMYF.count }
21
+ it { AMYF.where(:fuel_efficiency_units => 'kilometres_per_litre').count.should == AMYF.count }
35
22
  end
36
23
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_make_year'
3
+
4
+ describe AutomobileMakeYear 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
+ AMY.run_data_miner!
13
+ AMY.count.should == AMY.connection.select_value("SELECT COUNT(DISTINCT make_name, year) FROM #{AMMYV.quoted_table_name}")
14
+ end
15
+ end
16
+
17
+ describe 'verify imported data' do
18
+ it { AMY.where("fuel_efficiency > 0").count.should == AMY.count }
19
+ it { AMY.find("Honda 2011").fuel_efficiency.should be_within(1e-4).of(13.34186) }
20
+ it { AMY.find("Honda 2012").fuel_efficiency.should be_within(1e-5).of(12.17321) }
21
+
22
+ it 'has proper weightings' do
23
+ AMY.connection.select_values("SELECT DISTINCT year FROM #{AMY.quoted_table_name}").each do |year|
24
+ AMY.where(:year => year).first.weighting.should == AutomobileYear.weighting(year)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_model'
3
+
4
+ describe AutomobileModel do
5
+ before :all do
6
+ Earth.init :automobile, :load_data_miner => true
7
+ end
8
+
9
+ describe 'import', :data_miner => true do
10
+ it 'should import data' do
11
+ AutomobileModel.run_data_miner!
12
+ AutomobileModel.count.should == AutomobileModel.connection.select_value("SELECT COUNT(DISTINCT model_name) FROM #{AutomobileMakeModelYearVariant.quoted_table_name}")
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_size_class'
3
+
4
+ describe AutomobileSizeClass do
5
+ before :all do
6
+ Earth.init :automobile, :load_data_miner => true
7
+ end
8
+
9
+ describe 'import', :data_miner => true do
10
+ it 'should import data' do
11
+ AutomobileSizeClass.run_data_miner!
12
+ end
13
+ end
14
+
15
+ describe 'verify', :sanity => true do
16
+ it { AutomobileSizeClass.count.should == 15 }
17
+ it { AutomobileSizeClass.where("fuel_efficiency_city > 0").count.should == AutomobileSizeClass.count }
18
+ it { AutomobileSizeClass.where("fuel_efficiency_highway > 0").count.should == AutomobileSizeClass.count }
19
+ it { AutomobileSizeClass.where("hybrid_fuel_efficiency_city_multiplier > 1.0").count.should == 7 }
20
+ it { AutomobileSizeClass.where("hybrid_fuel_efficiency_highway_multiplier > 1.0").count.should == 7 }
21
+ it { AutomobileSizeClass.where("conventional_fuel_efficiency_city_multiplier < 1.0").count.should == 7 }
22
+ it { AutomobileSizeClass.where("conventional_fuel_efficiency_highway_multiplier < 1.0").count.should == 7 }
23
+ end
24
+
25
+ describe '.fallback' do
26
+ it { AutomobileSizeClass.fallback.hybrid_fuel_efficiency_city_multiplier.should == 1.651 }
27
+ it { AutomobileSizeClass.fallback.hybrid_fuel_efficiency_highway_multiplier.should == 1.213 }
28
+ it { AutomobileSizeClass.fallback.conventional_fuel_efficiency_city_multiplier.should == 0.987 }
29
+ it { AutomobileSizeClass.fallback.conventional_fuel_efficiency_highway_multiplier.should == 0.996 }
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_type_fuel_control'
3
+
4
+ describe AutomobileTypeFuelControl 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
+ ATFC.run_data_miner!
13
+ end
14
+ end
15
+
16
+ describe 'verify imported data', :sanity => true do
17
+ it { ATFC.count.should == 20 }
18
+ it { ATFC.where("ch4_emission_factor > 0").count.should == ATFC.count }
19
+ it { ATFC.where("n2o_emission_factor > 0").count.should == ATFC.count }
20
+
21
+ # spot checks
22
+ it { ATFC.first.ch4_emission_factor.should be_within(1e-9).of(1.5534e-5) }
23
+ it { ATFC.first.n2o_emission_factor.should be_within(1e-8).of(2.7775e-4) }
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_type_fuel'
3
+
4
+ describe AutomobileTypeFuel do
5
+ let(:test_type_fuel) { AutomobileTypeFuel.find('Light-duty trucks gasoline') }
6
+
7
+ before :all do
8
+ Earth.init :automobile, :load_data_miner => true
9
+ end
10
+
11
+ describe 'import', :data_miner => true do
12
+ it 'should import data' do
13
+ AutomobileTypeFuel.run_data_miner!
14
+ end
15
+ end
16
+
17
+ describe 'verify', :sanity => true do
18
+ it { AutomobileTypeFuel.count.should == 4 }
19
+ it { AutomobileTypeFuel.where("annual_distance > 0").count.should == AutomobileTypeFuel.count }
20
+ it { AutomobileTypeFuel.where("ch4_emission_factor > 0").count.should == AutomobileTypeFuel.count }
21
+ it { AutomobileTypeFuel.where("n2o_emission_factor > 0").count.should == AutomobileTypeFuel.count }
22
+ it { AutomobileTypeFuel.where("vehicles > 0").count.should == AutomobileTypeFuel.count }
23
+
24
+ # spot checks
25
+ it { test_type_fuel.annual_distance.should be_within(0.1).of(19626.6) }
26
+ it { test_type_fuel.annual_distance_units.should == 'kilometres' }
27
+ it { test_type_fuel.ch4_emission_factor.should be_within(1e-8).of(5.0749e-4) }
28
+ it { test_type_fuel.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
29
+ it { test_type_fuel.n2o_emission_factor.should be_within(1e-7).of(7.4864e-3) }
30
+ it { test_type_fuel.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
31
+ it { test_type_fuel.vehicles.should be_within(50).of(87_877_167) }
32
+ it { test_type_fuel.fuel_consumption.should be_within(1).of(129_881_000_000) }
33
+ it { test_type_fuel.fuel_consumption_units.should == 'litres' }
34
+ end
35
+
36
+ describe '#latest_activity_year_type_fuel' do
37
+ it 'should always be a match from 2009' do
38
+ AutomobileTypeFuel.find_each do |atf|
39
+ atf.latest_activity_year_type_fuel.type_name.should == atf.type_name
40
+ atf.latest_activity_year_type_fuel.fuel_common_name.should == atf.fuel_common_name
41
+ atf.latest_activity_year_type_fuel.activity_year.should == 2009
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_type_fuel_year_control'
3
+
4
+ describe AutomobileTypeFuelYearControl do
5
+ let(:test_year_control) { ATFYC.where(:type_name => 'Passenger cars', :fuel_common_name => 'gasoline', :year => 2005).first }
6
+
7
+ before :all do
8
+ Earth.init :automobile, :load_data_miner => true
9
+ require 'earth/acronyms'
10
+ end
11
+
12
+ describe 'import', :data_miner => true do
13
+ it 'should import data' do
14
+ ATFYC.run_data_miner!
15
+ end
16
+ end
17
+
18
+ describe 'verify imported data', :sanity => true do
19
+ it { ATFYC.count.should == 142 }
20
+
21
+ it 'total travel percent should sum to 1' do
22
+ ATFYC.group([:type_name, :fuel_common_name, :year]).sum(:total_travel_percent).each do |grouping_criteria, total|
23
+ total.should be_within(1e-5).of(1.0)
24
+ end
25
+ end
26
+
27
+ it { ATFYC.where(:type_fuel_control_name => nil).count.should == 0 }
28
+ end
29
+
30
+ describe '.find_all_by_type_name_and_fuel_common_name_and_closest_year' do
31
+ it { ATFYC.find_all_by_type_name_and_fuel_common_name_and_closest_year('Passenger cars', 'gasoline', 1980).should == ATFYC.find_all_by_type_name_and_fuel_common_name_and_year('Passenger cars', 'gasoline', 1985) }
32
+ it { ATFYC.find_all_by_type_name_and_fuel_common_name_and_closest_year('Passenger cars', 'gasoline', 2005).should == ATFYC.find_all_by_type_name_and_fuel_common_name_and_year('Passenger cars', 'gasoline', 2005) }
33
+ it { ATFYC.find_all_by_type_name_and_fuel_common_name_and_closest_year('Passenger cars', 'gasoline', 2012).should == ATFYC.find_all_by_type_name_and_fuel_common_name_and_year('Passenger cars', 'gasoline', 2010) }
34
+ end
35
+
36
+ describe '#ch4_emission_factor' do
37
+ it { test_year_control.ch4_emission_factor.should be_within(1e-10).of(2.68743e-4) }
38
+ end
39
+
40
+ describe '#ch4_emission_factor_units' do
41
+ it { test_year_control.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
42
+ end
43
+
44
+ describe '#n2o_emission_factor' do
45
+ it { test_year_control.n2o_emission_factor.should be_within(1e-10).of(6.66607e-4) }
46
+ end
47
+
48
+ describe '#n2o_emission_factor_units' do
49
+ it { test_year_control.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
50
+ end
51
+ end
@@ -0,0 +1,65 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_type_fuel_year'
3
+
4
+ describe AutomobileTypeFuelYear do
5
+ let(:test_atfy) { ATFY.where(:type_name => 'Passenger cars', :fuel_common_name => 'gasoline', :year => 2005).first }
6
+
7
+ before :all do
8
+ Earth.init :automobile, :load_data_miner => true
9
+ require 'earth/acronyms'
10
+ end
11
+
12
+ describe 'import', :data_miner => true do
13
+ it 'should import data' do
14
+ ATFY.run_data_miner!
15
+ end
16
+ end
17
+
18
+ describe 'verify', :sanity => true do
19
+ it { ATFY.count.should == 124 }
20
+
21
+ it 'shares should sum to 1' do
22
+ ATFY.sum(:share_of_type, :group => [:type_name, :fuel_common_name]).each do |groupers, total|
23
+ total.should be_within(1e-2).of(1.0)
24
+ end
25
+ end
26
+
27
+ it { ATFY.where("annual_distance > 0").count.should == ATFY.count }
28
+ it { ATFY.where("ch4_emission_factor > 0").count.should == ATFY.count }
29
+ it { ATFY.where("n2o_emission_factor > 0").count.should == ATFY.count }
30
+
31
+ # spot checks
32
+ it { test_atfy.annual_distance.should == be_within(0.01).of(19598.59) }
33
+ it { test_atfy.annual_distance_units.should == 'kilometres' }
34
+ it { test_atfy.ch4_emission_factor.should == be_within(1e-8).of(2.286e-4) }
35
+ it { test_atfy.ch4_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
36
+ it { test_atfy.n2o_emission_factor.should == be_within(1e-7).of(1.4688e-3) }
37
+ it { test_atfy.n2o_emission_factor_units.should == 'kilograms_co2e_per_kilometre' }
38
+ end
39
+
40
+ describe '.find_by_type_name_and_fuel_common_name_and_closest_year' do
41
+ it { ATFY.find_by_type_name_and_fuel_common_name_and_closest_year('Passenger cars', 'gasoline', 1970).should == ATFY.find_by_type_name_and_fuel_common_name_and_year('Passenger cars', 'gasoline', 1979) }
42
+ it { ATFY.find_by_type_name_and_fuel_common_name_and_closest_year('Passenger cars', 'gasoline', 2005).should == ATFY.find_by_type_name_and_fuel_common_name_and_year('Passenger cars', 'gasoline', 2005) }
43
+ it { ATFY.find_by_type_name_and_fuel_common_name_and_closest_year('Passenger cars', 'gasoline', 2012).should == ATFY.find_by_type_name_and_fuel_common_name_and_year('Passenger cars', 'gasoline', 2009) }
44
+ end
45
+
46
+ describe '#type_fuel_year_controls' do
47
+ it "should find controls from 1985 when year < 1985" do
48
+ ATFY.where("year < 1985").each do |atfy|
49
+ atfy.type_fuel_year_controls.first.year.should == 1985
50
+ end
51
+ end
52
+
53
+ it "should find controls from year when year from 1985 to 2010" do
54
+ ATFY.where("year >= 1985 AND year <= 2010").each do |atfy|
55
+ atfy.type_fuel_year_controls.first.year.should == atfy.year
56
+ end
57
+ end
58
+
59
+ it "should find controls from 2010 when year > 2010" do
60
+ ATFY.where("year > 2010").each do |atfy|
61
+ atfy.type_fuel_year_controls.first.year.should == 2010
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'earth/automobile/automobile_year'
3
+
4
+ describe AutomobileYear do
5
+ before :all do
6
+ Earth.init :automobile, :load_data_miner => true
7
+ end
8
+
9
+ describe 'import', :data_miner => true do
10
+ it 'should import data' do
11
+ AutomobileYear.run_data_miner!
12
+ AutomobileYear.count.should == AutomobileYear.connection.select_value("SELECT COUNT(DISTINCT year) FROM #{AutomobileMakeModelYearVariant.quoted_table_name}")
13
+ end
14
+ end
15
+
16
+ describe ".weighting(year)" do
17
+ (1985..2012).each do |year|
18
+ it "returns a weighting between 0 and 1 for #{year}" do
19
+ AutomobileYear.weighting(year).should > 0.0 and AutomobileYear.weighting(year).should < 1.0
20
+ end
21
+ end
22
+ end
23
+ end
@@ -15,7 +15,7 @@ describe Fuel do
15
15
 
16
16
  describe 'after importing data', :sanity => true do
17
17
  it 'should have all the data' do
18
- Fuel.count.should == 22
18
+ Fuel.count.should == 23
19
19
  end
20
20
 
21
21
  it 'should have a record for district heat' do
@@ -13,9 +13,17 @@ describe CommercialBuildingEnergyConsumptionSurveyResponse do
13
13
  end
14
14
 
15
15
  describe "verify imported data", :sanity => true do
16
- it "should have all the data" do
17
- CommercialBuildingEnergyConsumptionSurveyResponse.count.should == 5215
18
- end
16
+ it { CommercialBuildingEnergyConsumptionSurveyResponse.count.should == 5215 }
17
+
18
+ it { CommercialBuildingEnergyConsumptionSurveyResponse.where(:electricity_use => nil).count.should == 0 }
19
+ it { CommercialBuildingEnergyConsumptionSurveyResponse.where(:electricity_energy => nil).count.should == 0 }
20
+ it { CommercialBuildingEnergyConsumptionSurveyResponse.where(:natural_gas_use => nil).count.should == 0 }
21
+ it { CommercialBuildingEnergyConsumptionSurveyResponse.where(:natural_gas_energy => nil).count.should == 0 }
22
+ it { CommercialBuildingEnergyConsumptionSurveyResponse.where(:fuel_oil_use => nil).count.should == 0 }
23
+ it { CommercialBuildingEnergyConsumptionSurveyResponse.where(:fuel_oil_energy => nil).count.should == 0 }
24
+ it { CommercialBuildingEnergyConsumptionSurveyResponse.where(:district_heat_use => nil).count.should == 0 }
25
+ it { CommercialBuildingEnergyConsumptionSurveyResponse.where(:district_heat_energy => nil).count.should == 0 }
26
+
19
27
  it "should have room nights and fuel intensities per room night for lodging_records" do
20
28
  spot_check = CommercialBuildingEnergyConsumptionSurveyResponse.lodging_records.first
21
29
  spot_check.room_nights.should == 6205
data/spec/earth_spec.rb CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Earth do
4
4
  describe '.init' do
5
5
  before :all do
6
- Earth.init :all, :apply_schemas => true
6
+ Earth.init :all
7
7
  end
8
8
 
9
9
  it 'should require all Earth models' do
@@ -22,13 +22,13 @@ describe Earth do
22
22
 
23
23
  describe '.resources' do
24
24
  it 'should get a list of all resource names' do
25
- Earth.resources.length.should == 100
25
+ Earth.resources.length.should == 101
26
26
  Earth.resources.should include('Aircraft')
27
27
  Earth.resources.should include('Industry')
28
28
  end
29
29
  it 'should filter resource_map by domain' do
30
30
  Earth.resources('air').length.should == 8
31
- Earth.resources('automobile').length.should == 16
31
+ Earth.resources('automobile').length.should == 17
32
32
  Earth.resources('bus').length.should == 4
33
33
  Earth.resources('computation').length.should == 3
34
34
  Earth.resources('diet').length.should == 2
data/spec/spec_helper.rb CHANGED
@@ -44,6 +44,7 @@ ActiveRecord::Base.logger = logger
44
44
  DataMiner.logger = logger
45
45
 
46
46
  DataMiner::Run.auto_upgrade!
47
+ DataMiner.unit_converter = :conversions
47
48
 
48
49
  RSpec.configure do |c|
49
50
  unless ENV['ALL'] == 'true'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: earth
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.11.20
5
+ version: 0.12.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Seamus Abshere
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2012-05-14 00:00:00 Z
15
+ date: 2012-06-11 00:00:00 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activerecord
@@ -65,7 +65,7 @@ dependencies:
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: "2"
68
+ version: 2.2.0
69
69
  type: :runtime
70
70
  prerelease: false
71
71
  version_requirements: *id005
@@ -142,7 +142,7 @@ dependencies:
142
142
  requirements:
143
143
  - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: 0.0.6
145
+ version: 1.0.1
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: *id012
@@ -169,18 +169,18 @@ dependencies:
169
169
  prerelease: false
170
170
  version_requirements: *id014
171
171
  - !ruby/object:Gem::Dependency
172
- name: bueller
172
+ name: timeframe
173
173
  requirement: &id015 !ruby/object:Gem::Requirement
174
174
  none: false
175
175
  requirements:
176
176
  - - ">="
177
177
  - !ruby/object:Gem::Version
178
178
  version: "0"
179
- type: :development
179
+ type: :runtime
180
180
  prerelease: false
181
181
  version_requirements: *id015
182
182
  - !ruby/object:Gem::Dependency
183
- name: bundler
183
+ name: bueller
184
184
  requirement: &id016 !ruby/object:Gem::Requirement
185
185
  none: false
186
186
  requirements:
@@ -191,7 +191,7 @@ dependencies:
191
191
  prerelease: false
192
192
  version_requirements: *id016
193
193
  - !ruby/object:Gem::Dependency
194
- name: charisma
194
+ name: bundler
195
195
  requirement: &id017 !ruby/object:Gem::Requirement
196
196
  none: false
197
197
  requirements:
@@ -202,7 +202,7 @@ dependencies:
202
202
  prerelease: false
203
203
  version_requirements: *id017
204
204
  - !ruby/object:Gem::Dependency
205
- name: cucumber
205
+ name: charisma
206
206
  requirement: &id018 !ruby/object:Gem::Requirement
207
207
  none: false
208
208
  requirements:
@@ -213,7 +213,7 @@ dependencies:
213
213
  prerelease: false
214
214
  version_requirements: *id018
215
215
  - !ruby/object:Gem::Dependency
216
- name: mysql2
216
+ name: cucumber
217
217
  requirement: &id019 !ruby/object:Gem::Requirement
218
218
  none: false
219
219
  requirements:
@@ -224,7 +224,7 @@ dependencies:
224
224
  prerelease: false
225
225
  version_requirements: *id019
226
226
  - !ruby/object:Gem::Dependency
227
- name: pg
227
+ name: mysql2
228
228
  requirement: &id020 !ruby/object:Gem::Requirement
229
229
  none: false
230
230
  requirements:
@@ -235,7 +235,7 @@ dependencies:
235
235
  prerelease: false
236
236
  version_requirements: *id020
237
237
  - !ruby/object:Gem::Dependency
238
- name: rake
238
+ name: pg
239
239
  requirement: &id021 !ruby/object:Gem::Requirement
240
240
  none: false
241
241
  requirements:
@@ -246,7 +246,7 @@ dependencies:
246
246
  prerelease: false
247
247
  version_requirements: *id021
248
248
  - !ruby/object:Gem::Dependency
249
- name: rdoc
249
+ name: rake
250
250
  requirement: &id022 !ruby/object:Gem::Requirement
251
251
  none: false
252
252
  requirements:
@@ -257,7 +257,7 @@ dependencies:
257
257
  prerelease: false
258
258
  version_requirements: *id022
259
259
  - !ruby/object:Gem::Dependency
260
- name: rspec
260
+ name: rdoc
261
261
  requirement: &id023 !ruby/object:Gem::Requirement
262
262
  none: false
263
263
  requirements:
@@ -268,7 +268,7 @@ dependencies:
268
268
  prerelease: false
269
269
  version_requirements: *id023
270
270
  - !ruby/object:Gem::Dependency
271
- name: sqlite3-ruby
271
+ name: rspec
272
272
  requirement: &id024 !ruby/object:Gem::Requirement
273
273
  none: false
274
274
  requirements:
@@ -278,6 +278,17 @@ dependencies:
278
278
  type: :development
279
279
  prerelease: false
280
280
  version_requirements: *id024
281
+ - !ruby/object:Gem::Dependency
282
+ name: sqlite3-ruby
283
+ requirement: &id025 !ruby/object:Gem::Requirement
284
+ none: false
285
+ requirements:
286
+ - - ">="
287
+ - !ruby/object:Gem::Version
288
+ version: "0"
289
+ type: :development
290
+ prerelease: false
291
+ version_requirements: *id025
281
292
  description: An earth-simulation environment with ActiveRecord models and data
282
293
  email:
283
294
  - seamus@abshere.net
@@ -303,8 +314,19 @@ files:
303
314
  - TODO
304
315
  - bin/earth_tester.rb
305
316
  - certification_changelog.markdown
317
+ - data/automobile/annual_emission_controls.csv
318
+ - data/automobile/annual_fuel_consumption.csv
319
+ - data/automobile/annual_sizes.csv
320
+ - data/automobile/auto_fuel_data.csv
321
+ - data/automobile/auto_fuel_efs.csv
322
+ - data/automobile/cafe_data.csv
323
+ - data/automobile/emission_control_techs.csv
324
+ - data/automobile/hfc_emissions.csv
325
+ - data/automobile/hybridity_multipliers.csv
326
+ - data/automobile/sizes.csv
306
327
  - earth.gemspec
307
328
  - errata/aircraft/faa_errata.csv
329
+ - errata/airline/bts_carrier_codes_errata.csv
308
330
  - errata/airport/openflights_errata.csv
309
331
  - errata/automobile_make_model_year_variant/feg_errata.csv
310
332
  - errata/automobile_make_year_fleet/cafe_errata.csv
@@ -315,6 +337,7 @@ files:
315
337
  - errata/flight_segment/bts_errata.csv
316
338
  - errata/readme
317
339
  - lib/earth.rb
340
+ - lib/earth/acronyms.rb
318
341
  - lib/earth/air.rb
319
342
  - lib/earth/air/aircraft.rb
320
343
  - lib/earth/air/aircraft/data_miner.rb
@@ -335,6 +358,12 @@ files:
335
358
  - lib/earth/air/flight_segment/data_miner.rb
336
359
  - lib/earth/all.rb
337
360
  - lib/earth/automobile.rb
361
+ - lib/earth/automobile/automobile_activity_year.rb
362
+ - lib/earth/automobile/automobile_activity_year/data_miner.rb
363
+ - lib/earth/automobile/automobile_activity_year_type.rb
364
+ - lib/earth/automobile/automobile_activity_year_type/data_miner.rb
365
+ - lib/earth/automobile/automobile_activity_year_type_fuel.rb
366
+ - lib/earth/automobile/automobile_activity_year_type_fuel/data_miner.rb
338
367
  - lib/earth/automobile/automobile_fuel.rb
339
368
  - lib/earth/automobile/automobile_fuel/data_miner.rb
340
369
  - lib/earth/automobile/automobile_make.rb
@@ -353,18 +382,14 @@ files:
353
382
  - lib/earth/automobile/automobile_model/data_miner.rb
354
383
  - lib/earth/automobile/automobile_size_class.rb
355
384
  - lib/earth/automobile/automobile_size_class/data_miner.rb
356
- - lib/earth/automobile/automobile_size_class_year.rb
357
- - lib/earth/automobile/automobile_size_class_year/data_miner.rb
385
+ - lib/earth/automobile/automobile_type_fuel.rb
386
+ - lib/earth/automobile/automobile_type_fuel/data_miner.rb
358
387
  - lib/earth/automobile/automobile_type_fuel_control.rb
359
388
  - lib/earth/automobile/automobile_type_fuel_control/data_miner.rb
360
389
  - lib/earth/automobile/automobile_type_fuel_year.rb
361
390
  - lib/earth/automobile/automobile_type_fuel_year/data_miner.rb
362
- - lib/earth/automobile/automobile_type_fuel_year_age.rb
363
- - lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb
364
391
  - lib/earth/automobile/automobile_type_fuel_year_control.rb
365
392
  - lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb
366
- - lib/earth/automobile/automobile_type_year.rb
367
- - lib/earth/automobile/automobile_type_year/data_miner.rb
368
393
  - lib/earth/automobile/automobile_year.rb
369
394
  - lib/earth/automobile/automobile_year/data_miner.rb
370
395
  - lib/earth/automobile/data_miner.rb
@@ -542,14 +567,28 @@ files:
542
567
  - lib/earth/utils.rb
543
568
  - lib/earth/version.rb
544
569
  - spec/earth/air/aircraft_spec.rb
570
+ - spec/earth/air/airline_spec.rb
545
571
  - spec/earth/air/airport_spec.rb
546
572
  - spec/earth/air/bts_aircraft_spec.rb
547
573
  - spec/earth/air/flight_distance_class_spec.rb
548
574
  - spec/earth/air/flight_segment_spec.rb
575
+ - spec/earth/automobile/automobile_activity_year_spec.rb
576
+ - spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb
577
+ - spec/earth/automobile/automobile_activity_year_type_spec.rb
549
578
  - spec/earth/automobile/automobile_fuel_spec.rb
579
+ - spec/earth/automobile/automobile_make_model_spec.rb
580
+ - spec/earth/automobile/automobile_make_model_year_spec.rb
550
581
  - spec/earth/automobile/automobile_make_model_year_variant_spec.rb
582
+ - spec/earth/automobile/automobile_make_spec.rb
551
583
  - spec/earth/automobile/automobile_make_year_fleet_spec.rb
552
- - spec/earth/automobile/automobile_type_fuel_year_age_spec.rb
584
+ - spec/earth/automobile/automobile_make_year_spec.rb
585
+ - spec/earth/automobile/automobile_model_spec.rb
586
+ - spec/earth/automobile/automobile_size_class_spec.rb
587
+ - spec/earth/automobile/automobile_type_fuel_control_spec.rb
588
+ - spec/earth/automobile/automobile_type_fuel_spec.rb
589
+ - spec/earth/automobile/automobile_type_fuel_year_control_spec.rb
590
+ - spec/earth/automobile/automobile_type_fuel_year_spec.rb
591
+ - spec/earth/automobile/automobile_year_spec.rb
553
592
  - spec/earth/bus/bus_fuel_control_spec.rb
554
593
  - spec/earth/bus/bus_fuel_spec.rb
555
594
  - spec/earth/bus/bus_fuel_year_control_spec.rb
@@ -632,7 +671,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
632
671
  requirements:
633
672
  - - ">="
634
673
  - !ruby/object:Gem::Version
635
- hash: 254190567421235722
674
+ hash: 10494025636053515
636
675
  segments:
637
676
  - 0
638
677
  version: "0"
@@ -641,7 +680,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
641
680
  requirements:
642
681
  - - ">="
643
682
  - !ruby/object:Gem::Version
644
- hash: 254190567421235722
683
+ hash: 10494025636053515
645
684
  segments:
646
685
  - 0
647
686
  version: "0"
@@ -654,14 +693,28 @@ specification_version: 3
654
693
  summary: Land, sky, and sea
655
694
  test_files:
656
695
  - spec/earth/air/aircraft_spec.rb
696
+ - spec/earth/air/airline_spec.rb
657
697
  - spec/earth/air/airport_spec.rb
658
698
  - spec/earth/air/bts_aircraft_spec.rb
659
699
  - spec/earth/air/flight_distance_class_spec.rb
660
700
  - spec/earth/air/flight_segment_spec.rb
701
+ - spec/earth/automobile/automobile_activity_year_spec.rb
702
+ - spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb
703
+ - spec/earth/automobile/automobile_activity_year_type_spec.rb
661
704
  - spec/earth/automobile/automobile_fuel_spec.rb
705
+ - spec/earth/automobile/automobile_make_model_spec.rb
706
+ - spec/earth/automobile/automobile_make_model_year_spec.rb
662
707
  - spec/earth/automobile/automobile_make_model_year_variant_spec.rb
708
+ - spec/earth/automobile/automobile_make_spec.rb
663
709
  - spec/earth/automobile/automobile_make_year_fleet_spec.rb
664
- - spec/earth/automobile/automobile_type_fuel_year_age_spec.rb
710
+ - spec/earth/automobile/automobile_make_year_spec.rb
711
+ - spec/earth/automobile/automobile_model_spec.rb
712
+ - spec/earth/automobile/automobile_size_class_spec.rb
713
+ - spec/earth/automobile/automobile_type_fuel_control_spec.rb
714
+ - spec/earth/automobile/automobile_type_fuel_spec.rb
715
+ - spec/earth/automobile/automobile_type_fuel_year_control_spec.rb
716
+ - spec/earth/automobile/automobile_type_fuel_year_spec.rb
717
+ - spec/earth/automobile/automobile_year_spec.rb
665
718
  - spec/earth/bus/bus_fuel_control_spec.rb
666
719
  - spec/earth/bus/bus_fuel_spec.rb
667
720
  - spec/earth/bus/bus_fuel_year_control_spec.rb