earth 0.11.10 → 0.11.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. data/Gemfile +4 -0
  2. data/Guardfile +35 -0
  3. data/README.markdown +94 -20
  4. data/Rakefile +4 -0
  5. data/earth.gemspec +14 -12
  6. data/lib/earth/air/aircraft.rb +2 -2
  7. data/lib/earth/air/aircraft_instance.rb +2 -2
  8. data/lib/earth/air/aircraft_instance_seat_class.rb +2 -2
  9. data/lib/earth/air/airline.rb +2 -2
  10. data/lib/earth/air/airport.rb +2 -2
  11. data/lib/earth/air/bts_aircraft.rb +2 -2
  12. data/lib/earth/air/flight_distance_class.rb +1 -1
  13. data/lib/earth/air/flight_distance_class_seat_class.rb +1 -1
  14. data/lib/earth/air/flight_seat_class.rb +1 -1
  15. data/lib/earth/air/flight_segment.rb +1 -1
  16. data/lib/earth/automobile/automobile_fuel.rb +1 -1
  17. data/lib/earth/automobile/automobile_make.rb +1 -1
  18. data/lib/earth/automobile/automobile_make_model.rb +1 -1
  19. data/lib/earth/automobile/automobile_make_model_year.rb +1 -1
  20. data/lib/earth/automobile/automobile_make_model_year_variant.rb +1 -1
  21. data/lib/earth/automobile/automobile_make_year.rb +1 -1
  22. data/lib/earth/automobile/automobile_make_year_fleet.rb +1 -1
  23. data/lib/earth/automobile/automobile_model.rb +1 -1
  24. data/lib/earth/automobile/automobile_size_class.rb +1 -1
  25. data/lib/earth/automobile/automobile_size_class_year.rb +1 -1
  26. data/lib/earth/automobile/automobile_type_fuel_control.rb +1 -1
  27. data/lib/earth/automobile/automobile_type_fuel_year.rb +1 -1
  28. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +1 -1
  29. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +1 -1
  30. data/lib/earth/automobile/automobile_type_year.rb +2 -2
  31. data/lib/earth/automobile/automobile_year.rb +1 -1
  32. data/lib/earth/bus/bus_class.rb +1 -1
  33. data/lib/earth/bus/bus_fuel.rb +2 -2
  34. data/lib/earth/bus/bus_fuel_control.rb +2 -2
  35. data/lib/earth/bus/bus_fuel_year_control.rb +2 -2
  36. data/lib/earth/computation/computation_carrier.rb +2 -2
  37. data/lib/earth/computation/computation_carrier_instance_class.rb +2 -2
  38. data/lib/earth/computation/computation_carrier_region.rb +2 -2
  39. data/lib/earth/conversions_ext.rb +26 -7
  40. data/lib/earth/diet/diet_class.rb +2 -2
  41. data/lib/earth/diet/food_group.rb +2 -2
  42. data/lib/earth/eia.rb +13 -13
  43. data/lib/earth/fuel/fuel.rb +22 -13
  44. data/lib/earth/fuel/fuel/data_miner.rb +36 -44
  45. data/lib/earth/fuel/fuel_price.rb +1 -1
  46. data/lib/earth/fuel/fuel_type.rb +2 -2
  47. data/lib/earth/fuel/fuel_year.rb +4 -2
  48. data/lib/earth/fuel/greenhouse_gas.rb +2 -2
  49. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +14 -5
  50. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +22 -1
  51. data/lib/earth/hospitality/country_lodging_class.rb +3 -3
  52. data/lib/earth/hospitality/country_lodging_class/data_miner.rb +7 -5
  53. data/lib/earth/hospitality/lodging_class.rb +1 -1
  54. data/lib/earth/hospitality/lodging_property.rb +8 -8
  55. data/lib/earth/industry/cbecs_energy_intensity.rb +59 -6
  56. data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +266 -69
  57. data/lib/earth/industry/industry.rb +1 -1
  58. data/lib/earth/industry/industry_product.rb +2 -2
  59. data/lib/earth/industry/industry_product_line.rb +2 -2
  60. data/lib/earth/industry/industry_sector.rb +2 -2
  61. data/lib/earth/industry/mecs_energy.rb +26 -15
  62. data/lib/earth/industry/mecs_energy/data_miner.rb +39 -23
  63. data/lib/earth/industry/mecs_ratio.rb +13 -10
  64. data/lib/earth/industry/mecs_ratio/data_miner.rb +14 -14
  65. data/lib/earth/industry/merchant.rb +2 -2
  66. data/lib/earth/industry/merchant_category.rb +2 -2
  67. data/lib/earth/industry/merchant_category_industry.rb +2 -2
  68. data/lib/earth/industry/product_line.rb +2 -2
  69. data/lib/earth/industry/product_line_industry_product.rb +2 -2
  70. data/lib/earth/industry/sector.rb +2 -2
  71. data/lib/earth/locality/census_division.rb +2 -2
  72. data/lib/earth/locality/census_division/data_miner.rb +4 -14
  73. data/lib/earth/locality/census_region.rb +2 -2
  74. data/lib/earth/locality/climate_division.rb +1 -17
  75. data/lib/earth/locality/country.rb +14 -28
  76. data/lib/earth/locality/country/data_miner.rb +8 -2
  77. data/lib/earth/locality/egrid_country.rb +1 -1
  78. data/lib/earth/locality/egrid_region.rb +4 -1
  79. data/lib/earth/locality/egrid_region/data_miner.rb +4 -1
  80. data/lib/earth/locality/egrid_subregion.rb +1 -1
  81. data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -0
  82. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +3 -3
  83. data/lib/earth/locality/state.rb +2 -7
  84. data/lib/earth/locality/zip_code.rb +1 -1
  85. data/lib/earth/pet/breed.rb +2 -2
  86. data/lib/earth/pet/breed_gender.rb +2 -2
  87. data/lib/earth/pet/gender.rb +2 -2
  88. data/lib/earth/pet/species.rb +2 -2
  89. data/lib/earth/pet/species/data_miner.rb +0 -9
  90. data/lib/earth/rail/country_rail_class.rb +1 -1
  91. data/lib/earth/rail/country_rail_traction.rb +1 -1
  92. data/lib/earth/rail/country_rail_traction_class.rb +1 -1
  93. data/lib/earth/rail/national_transit_database_company.rb +2 -2
  94. data/lib/earth/rail/national_transit_database_mode.rb +2 -2
  95. data/lib/earth/rail/national_transit_database_record.rb +2 -2
  96. data/lib/earth/rail/national_transit_database_record/data_miner.rb +12 -33
  97. data/lib/earth/rail/rail_class.rb +1 -1
  98. data/lib/earth/rail/rail_company.rb +1 -1
  99. data/lib/earth/rail/rail_company_traction.rb +1 -1
  100. data/lib/earth/rail/rail_company_traction_class.rb +1 -1
  101. data/lib/earth/rail/rail_fuel.rb +1 -1
  102. data/lib/earth/rail/rail_traction.rb +1 -1
  103. data/lib/earth/residence/air_conditioner_use.rb +2 -2
  104. data/lib/earth/residence/clothes_machine_use.rb +2 -2
  105. data/lib/earth/residence/dishwasher_use.rb +2 -2
  106. data/lib/earth/residence/residence_appliance.rb +2 -2
  107. data/lib/earth/residence/residence_class.rb +2 -2
  108. data/lib/earth/residence/residence_fuel_price.rb +2 -2
  109. data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -5
  110. data/lib/earth/residence/residence_fuel_type.rb +2 -2
  111. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +3 -3
  112. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -5
  113. data/lib/earth/residence/urbanity.rb +2 -2
  114. data/lib/earth/shipping/carrier.rb +3 -2
  115. data/lib/earth/shipping/carrier/data_miner.rb +1 -0
  116. data/lib/earth/shipping/carrier_mode.rb +2 -2
  117. data/lib/earth/shipping/shipment_mode.rb +2 -2
  118. data/lib/earth/version.rb +1 -1
  119. data/spec/earth/air/aircraft_spec.rb +421 -0
  120. data/spec/earth/fuel/fuel_spec.rb +35 -0
  121. data/spec/earth/hospitality/lodging_fuel_use_equation_spec.rb +96 -0
  122. data/spec/earth/industry/cbecs_energy_intensity_spec.rb +102 -0
  123. data/spec/earth/industry/mecs_energy_spec.rb +36 -44
  124. data/spec/earth/industry/mecs_ratio_spec.rb +24 -17
  125. data/spec/earth/locality/country_spec.rb +0 -9
  126. data/spec/spec_helper.rb +8 -3
  127. data/spec/support/integration.rb +17 -0
  128. data/vendor/geokit-rails/init.rb +2 -1
  129. data/vendor/geokit-rails/lib/geokit-rails.rb +1 -0
  130. metadata +63 -36
  131. data/lib/earth/hospitality/lodging_fuel_use_equation.rb +0 -26
  132. data/lib/earth/hospitality/lodging_fuel_use_equation/data_miner.rb +0 -20
  133. data/test/test_aircraft_match.rb +0 -732
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+ require 'earth/fuel/fuel'
3
+ require 'earth/fuel/fuel/data_miner'
4
+ require 'earth/fuel/fuel_year'
5
+
6
+ describe Fuel do
7
+ before :all do
8
+ Fuel.auto_upgrade!
9
+ end
10
+
11
+ describe 'when importing data', :slow => true do
12
+ it 'fetches all fuels' do
13
+ Earth.init :fuel, :load_data_miner => true
14
+ Fuel.run_data_miner!
15
+ Fuel.count.should == 22
16
+ end
17
+ end
18
+
19
+ describe 'after importing data', :sanity => true do
20
+ it 'should have a record for district heat' do
21
+ district_heat = Fuel.find 'District Heat'
22
+ district_heat.co2_emission_factor.should be_within(0.00001).of(0.0766528)
23
+ end
24
+
25
+ # TODO is there a way to check whether the value in the fuels table is NULL?
26
+ it 'should check FuelYear for any missing values' do
27
+ Earth.init :fuel_year
28
+ gasoline = Fuel.find('Motor Gasoline')
29
+ gasoline_years = FuelYear.where(:fuel_name => 'Motor Gasoline')
30
+ latest_gasoline_year = gasoline_years.find_by_year(gasoline_years.maximum(:year))
31
+ gasoline.energy_content.should == latest_gasoline_year.energy_content
32
+ gasoline.carbon_content.should == latest_gasoline_year.carbon_content
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,96 @@
1
+ require 'spec_helper'
2
+ require 'earth/hospitality'
3
+ require 'earth/hospitality/data_miner'
4
+ require 'charisma'
5
+
6
+ describe LodgingFuelUseEquation do
7
+ describe 'import', :slow => true do
8
+ it 'should import data without problems' do
9
+ LodgingFuelUseEquation.run_data_miner!
10
+ LodgingFuelUseEquation.all.count.should == 48
11
+ end
12
+ end
13
+
14
+ describe 'climate zone numbers' do
15
+ it 'should be nil or 1 through 5' do
16
+ LodgingFuelUseEquation.select('DISTINCT climate_zone_number').map(&:climate_zone_number).should == [nil, 1, 2, 3, 4, 5]
17
+ end
18
+ end
19
+
20
+ describe 'electricity factors' do
21
+ it 'should produce reasonable electricity use estimates' do
22
+ LodgingFuelUseEquation.where(:fuel => 'Electricity').each do |equation|
23
+ if equation.property_rooms == true and equation.construction_year == true
24
+ estimate = equation.rooms_factor * equation.year_factor * equation.constant
25
+ estimate.should > 0.0 and estimate.should < 1000.0
26
+
27
+ estimate = equation.rooms_factor**1000 * equation.year_factor * equation.constant
28
+ estimate.should > 0.0 and estimate.should < 1000.0
29
+
30
+ estimate = equation.rooms_factor * equation.year_factor**2020 * equation.constant
31
+ estimate.should > 0.0 and estimate.should < 1000.0
32
+
33
+ estimate = equation.rooms_factor**1000 * equation.year_factor**2020 * equation.constant
34
+ estimate.should > 0.0 and estimate.should < 1000.0
35
+ elsif equation.property_rooms == true
36
+ estimate = equation.rooms_factor * equation.constant
37
+ estimate.should > 0.0 and estimate.should < 1000.0
38
+
39
+ estimate = equation.rooms_factor**1000 * equation.constant
40
+ estimate.should > 0.0 and estimate.should < 1000.0
41
+ elsif equation.construction_year == true
42
+ estimate = equation.year_factor * equation.constant
43
+ estimate.should > 0.0 and estimate.should < 1000.0
44
+
45
+ estimate = equation.year_factor**2020 * equation.constant
46
+ estimate.should > 0.0 and estimate.should < 1000.0
47
+ else
48
+ equation.constant.should > 0.0
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ describe 'fuels factors' do
55
+ it 'should produce reasonable fuels use estimates' do
56
+ LodgingFuelUseEquation.where(:fuel => 'Fuels').each do |equation|
57
+ if equation.property_rooms == true and equation.construction_year == true
58
+ estimate = equation.rooms_factor + equation.year_factor + equation.constant
59
+ estimate.should > 0.0 and estimate.should < 1000.0
60
+
61
+ estimate = equation.rooms_factor * 1000 + equation.year_factor + equation.constant
62
+ estimate.should > 0.0 and estimate.should < 1000.0
63
+
64
+ estimate = equation.rooms_factor + equation.year_factor * 2020 + equation.constant
65
+ estimate.should > 0.0 and estimate.should < 1000.0
66
+
67
+ estimate = equation.rooms_factor * 1000 + equation.year_factor * 2020 + equation.constant
68
+ estimate.should > 0.0 and estimate.should < 1000.0
69
+ elsif equation.property_rooms == true
70
+ estimate = equation.rooms_factor + equation.constant
71
+ estimate.should > 0.0 and estimate.should < 1000.0
72
+
73
+ estimate = equation.rooms_factor * 1000 + equation.constant
74
+ estimate.should > 0.0 and estimate.should < 1000.0
75
+ elsif equation.construction_year == true
76
+ estimate = equation.year_factor + equation.constant
77
+ estimate.should > 0.0 and estimate.should < 1000.0
78
+
79
+ estimate = equation.year_factor * 2020 + equation.constant
80
+ estimate.should > 0.0 and estimate.should < 1000.0
81
+ else
82
+ equation.constant.should > 0.0
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ describe 'find_by_criteria' do
89
+ it 'should return the proper equation' do
90
+ LodgingFuelUseEquation.find_by_criteria('Fuels', {}).name.should == 'Fuels'
91
+ LodgingFuelUseEquation.find_by_criteria('Fuels', {:climate_zone_number => ::Charisma::Curator::Curation.new(2) }).name.should == 'Fuels zone 2'
92
+ LodgingFuelUseEquation.find_by_criteria('Fuels', {:climate_zone_number => ::Charisma::Curator::Curation.new(2), :property_rooms => 25}).name.should == 'Fuels zone 2 rooms'
93
+ LodgingFuelUseEquation.find_by_criteria('Fuels', {:climate_zone_number => ::Charisma::Curator::Curation.new(2), :property_rooms => 25, :property_construction_year => 1998}).name.should == 'Fuels zone 2 rooms year'
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+ require 'earth/industry/cbecs_energy_intensity'
3
+ require 'earth/industry/cbecs_energy_intensity/data_miner'
4
+
5
+ def create_cbecs(name, args)
6
+ c = CbecsEnergyIntensity.new args
7
+ c.name = name
8
+ c.save!
9
+ end
10
+
11
+ describe CbecsEnergyIntensity do
12
+ before :all do
13
+ CbecsEnergyIntensity.auto_upgrade!
14
+ end
15
+ before :each do
16
+ CbecsEnergyIntensity.delete_all
17
+ end
18
+
19
+ describe '.find_by_naics_code_and_census_division_number' do
20
+ before do
21
+ create_cbecs '1', :naics_code => '44', :census_division_number => 1
22
+ create_cbecs '2', :naics_code => '445', :census_division_number => 1
23
+ create_cbecs '3', :naics_code => '621', :census_division_number => 1
24
+ create_cbecs '4', :naics_code => '44', :census_division_number => 2
25
+ create_cbecs '5', :naics_code => '445', :census_division_number => 2
26
+ create_cbecs '6', :naics_code => '621', :census_division_number => 2
27
+ end
28
+ it 'finds an exact match' do
29
+ record = CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('445', 2)
30
+ record.naics_code.should == '445'
31
+ record.census_division_number.should == 2
32
+ end
33
+ it 'finds a parent category when exact code is not present' do
34
+ record = CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('4451', 2)
35
+ record.naics_code.should == '445'
36
+ record.census_division_number.should == 2
37
+ end
38
+ it 'does not find a sibling category' do
39
+ CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('622', 2).
40
+ should be_nil
41
+ end
42
+ it 'returns nil if no match found' do
43
+ CbecsEnergyIntensity.find_by_naics_code_and_census_division_number('8131', 1).
44
+ should be_nil
45
+ end
46
+ end
47
+
48
+ describe '#fuel_ratios' do
49
+ it 'makes ratios from fuel energies' do
50
+ cbecs = CbecsEnergyIntensity.new :name => '1', :electricity => 1000, :natural_gas => 2000, :fuel_oil => 500, :district_heat => 0
51
+ cbecs.fuel_ratios.should == {
52
+ :electricity => 0.2857142857142857,
53
+ :natural_gas => 0.5714285714285714,
54
+ :fuel_oil => 0.14285714285714285,
55
+ :district_heat => 0.0
56
+ }
57
+ end
58
+ end
59
+
60
+ describe 'import', :slow => true do
61
+ it 'fetches electric, natural gas, fuel oil, and distric heat data' do
62
+ CbecsEnergyIntensity.run_data_miner!
63
+
64
+ # check census divisions
65
+ divisionals = CbecsEnergyIntensity.divisional
66
+ divisionals.count.should == 117
67
+ spot_check(divisionals, [
68
+ [[:principal_building_activity, :census_region_number, :census_division_number], [:electricity, :natural_gas]],
69
+
70
+ [['Education', 1, 1], [:nil, :nil]],
71
+ [['Education', 1, 2], [:present, :present]],
72
+ ])
73
+
74
+ # check census regions
75
+ regionals = CbecsEnergyIntensity.regional
76
+ regionals.count.should == 52
77
+ spot_check(regionals, [
78
+ [[:principal_building_activity, :census_region_number], [:electricity, :fuel_oil]],
79
+ # Regional fuel oil
80
+ [['Education', 1], [:present, :present]],
81
+ [['Education', 2], [:present, :nil]],
82
+ [['Education', 3], [:present, :nil]],
83
+ [['Education', 4], [:present, :nil]],
84
+
85
+ [['Health Care', 1], [:present, :nil]],
86
+ [['Health Care', 2], [:present, :nil]],
87
+ [['Health Care', 3], [:present, :present]],
88
+ [['Health Care', 4], [:present, :present]],
89
+ ])
90
+
91
+ # check total us averages
92
+ nationals = CbecsEnergyIntensity.national
93
+ nationals.count.should == 13
94
+ spot_check(nationals, [
95
+ [[:principal_building_activity], [:electricity, :fuel_oil, :district_heat]],
96
+ [['Education'], [:present, :present, :present]],
97
+ [['Lodging'], [:present, :present, :nil]],
98
+ [['Office'], [:present, :present, :present]],
99
+ ])
100
+ end
101
+ end
102
+ end
@@ -8,70 +8,62 @@ describe MecsEnergy do
8
8
  MecsEnergy.auto_upgrade!
9
9
  MecsEnergy.run_data_miner!
10
10
  end
11
-
11
+
12
12
  describe 'data mining' do
13
13
  it 'retrieves Total US statistics' do
14
14
  apparel = MecsEnergy.find_by_naics_code '315'
15
- apparel.census_region.should be_nil
16
- apparel.total.should == 14
17
- apparel.net_electricity.should == 7
18
- apparel.residual_fuel_oil.should be_nil
19
- apparel.distillate_fuel_oil.should == 0
20
- apparel.natural_gas.should == 7
21
- apparel.lpg_and_ngl.should == 0
22
- apparel.coal.should == 0
23
- apparel.coke_and_breeze.should == 0
24
- apparel.other.should == 0
15
+ apparel.census_region_number.should be_nil
16
+ # apparel.energy.should == 14_770_800_000
17
+ # apparel.energy_units.should == 'megajoules'
18
+ # apparel.electricity.should == 7_385_390_000
19
+ # apparel.electricity_units.should == 'megajoules'
20
+ # apparel.residual_fuel_oil.should be_nil
21
+ # apparel.distillate_fuel_oil.should == 0
22
+ # apparel.energy_units.should == 'megajoules'
23
+ # apparel.natural_gas.should == 7
24
+ # apparel.energy_units.should == 'megajoules'
25
+ # apparel.lpg_and_ngl.should == 0
26
+ # apparel.energy_units.should == 'megajoules'
27
+ # apparel.coal.should == 0
28
+ # apparel.energy_units.should == 'megajoules'
29
+ # apparel.coke_and_breeze.should == 0
30
+ # apparel.energy_units.should == 'megajoules'
31
+ # apparel.other.should == 0
32
+ # apparel.energy_units.should == 'megajoules'
25
33
  end
26
34
  end
27
-
28
- describe '.find_by_naics_code_and_census_region' do
29
- before do
30
- MecsEnergy.create! :naics_code => '312', :census_region => '1'
31
- MecsEnergy.create! :naics_code => '3121', :census_region => '1'
32
- MecsEnergy.create! :naics_code => '3122', :census_region => '1'
33
- MecsEnergy.create! :naics_code => '312', :census_region => '2'
34
- MecsEnergy.create! :naics_code => '3121', :census_region => '2'
35
- MecsEnergy.create! :naics_code => '3122', :census_region => '2'
36
- MecsEnergy.create! :naics_code => '312211', :census_region => '2'
37
- end
35
+
36
+ describe '.find_by_naics_code_and_census_region_number' do
38
37
  it 'finds an exact match' do
39
- MecsEnergy.find_by_naics_code_and_census_region('312211', '2').
40
- naics_code.should == '312211'
38
+ MecsEnergy.find_by_naics_code_and_census_region_number('311221', 2).
39
+ name.should == '311221-2'
41
40
  end
42
- it 'finds a parent category by prefix' do
43
- MecsEnergy.find_by_naics_code_and_census_region('312199', '2').
44
- naics_code.should == '3121'
41
+ it 'finds a parent category when exact code is not present' do
42
+ MecsEnergy.find_by_naics_code_and_census_region_number('3117', 2).
43
+ name.should == '311-2'
44
+ end
45
+ it 'finds a parent category rather than a sibling category' do
46
+ MecsEnergy.find_by_naics_code_and_census_region_number('311225', 2).
47
+ name.should == '3112-2'
45
48
  end
46
49
  it 'returns nil if no match found' do
47
- MecsEnergy.find_by_naics_code_and_census_region('543211', '2').
50
+ MecsEnergy.find_by_naics_code_and_census_region_number('543211', 2).
48
51
  should be_nil
49
52
  end
50
53
  end
51
-
54
+
52
55
  describe '#fuel_ratios' do
53
56
  it 'returns a list of fuel ratios for a given NAICS' do
54
- energy = MecsEnergy.new :total => 100, :net_electricity => 20,
57
+ energy = MecsEnergy.new :energy => 100, :electricity => 20,
55
58
  :residual_fuel_oil => 1, :distillate_fuel_oil => 2,
56
59
  :natural_gas => 30, :lpg_and_ngl => 22, :coal => 22,
57
- :coke_and_breeze => 1, :other => 1
60
+ :coke_and_breeze => 1, :other_fuel => 1
58
61
  energy.fuel_ratios.should == {
59
- :net_electricity => 0.20,
62
+ :electricity => 0.20,
60
63
  :residual_fuel_oil => 0.01, :distillate_fuel_oil => 0.02,
61
64
  :natural_gas => 0.3, :lpg_and_ngl => 0.22, :coal => 0.22,
62
- :coke_and_breeze => 0.01, :other => 0.01
65
+ :coke_and_breeze => 0.01, :other_fuel => 0.01
63
66
  }
64
67
  end
65
68
  end
66
-
67
- describe '.normalize_fuels' do
68
- it 'transforms Q (witheld due to stddev error) into 0' do
69
- MecsEnergy.all.each do |energy|
70
- MecsEnergy::FUELS.each do |fuel|
71
- %w{W Q *}.should_not include(energy.send(fuel))
72
- end
73
- end
74
- end
75
- end
76
69
  end
77
-
@@ -5,29 +5,36 @@ describe MecsRatio do
5
5
  before :all do
6
6
  MecsRatio.auto_upgrade!
7
7
  end
8
-
9
- describe '.find_by_naics_code_and_census_region' do
8
+
9
+ describe '.find_by_naics_code_and_census_region_number' do
10
10
  before do
11
- MecsRatio.create! :naics_code => '312', :census_region => '1', :consumption_per_dollar_of_shipments => 11
12
- MecsRatio.create! :naics_code => '3121', :census_region => '1', :consumption_per_dollar_of_shipments => 12
13
- MecsRatio.create! :naics_code => '3122', :census_region => '1', :consumption_per_dollar_of_shipments => 13
14
- MecsRatio.create! :naics_code => '312', :census_region => '2', :consumption_per_dollar_of_shipments => 17
15
- MecsRatio.create! :naics_code => '3121', :census_region => '2', :consumption_per_dollar_of_shipments => 18
16
- MecsRatio.create! :naics_code => '3122', :census_region => '2', :consumption_per_dollar_of_shipments => 19
17
- MecsRatio.create! :naics_code => '312211', :census_region => '2', :consumption_per_dollar_of_shipments => 20
11
+ MecsRatio.create! :naics_code => '311', :census_region_number => 1, :energy_per_dollar_of_shipments => 11
12
+ MecsRatio.create! :naics_code => '3112', :census_region_number => 1, :energy_per_dollar_of_shipments => 12
13
+ MecsRatio.create! :naics_code => '311221', :census_region_number => 1, :energy_per_dollar_of_shipments => 13
14
+ MecsRatio.create! :naics_code => '31131', :census_region_number => 1, :energy_per_dollar_of_shipments => 13
15
+ MecsRatio.create! :naics_code => '311', :census_region_number => 2, :energy_per_dollar_of_shipments => 17
16
+ MecsRatio.create! :naics_code => '3112', :census_region_number => 2, :energy_per_dollar_of_shipments => 18
17
+ MecsRatio.create! :naics_code => '311221', :census_region_number => 2, :energy_per_dollar_of_shipments => 19
18
+ MecsRatio.create! :naics_code => '31131', :census_region_number => 2, :energy_per_dollar_of_shipments => 20
18
19
  end
20
+
19
21
  it 'finds an exact match' do
20
- MecsRatio.find_by_naics_code_and_census_region('312211', '2').
21
- naics_code.should == '312211'
22
+ ratio = MecsRatio.find_by_naics_code_and_census_region_number('311221', 2)
23
+ ratio.naics_code.should == '311221'
24
+ ratio.census_region_number.should == 2
25
+ end
26
+ it 'finds a parent category when exact code is not present' do
27
+ ratio = MecsRatio.find_by_naics_code_and_census_region_number('3117', 2)
28
+ ratio.naics_code.should == '311'
29
+ ratio.census_region_number.should == 2
22
30
  end
23
- it 'finds a parent category by prefix' do
24
- MecsRatio.find_by_naics_code_and_census_region('312199', '2').
25
- naics_code.should == '3121'
31
+ it 'finds a parent category rather than a sibling category' do
32
+ ratio = MecsRatio.find_by_naics_code_and_census_region_number('311225', 2)
33
+ ratio.naics_code.should == '3112'
34
+ ratio.census_region_number.should == 2
26
35
  end
27
36
  it 'returns nil if no match found' do
28
- MecsRatio.find_by_naics_code_and_census_region('543211', '2').
29
- should be_nil
37
+ MecsRatio.find_by_naics_code_and_census_region_number('543211', 2).should be_nil
30
38
  end
31
39
  end
32
40
  end
33
-
@@ -9,14 +9,5 @@ describe Country do
9
9
  Country.run_data_miner!
10
10
  Country.all.count.should == 249
11
11
  end
12
-
13
- it 'should correctly determine climate zone number' do
14
- Country.find('LT').climate_zone_number.should == 1
15
- Country.find('HU').climate_zone_number.should == 2
16
- Country.find('HR').climate_zone_number.should == 3
17
- Country.find('CY').climate_zone_number.should == 4
18
- Country.find('UZ').climate_zone_number.should == 5
19
- Country.where(:heating_degree_days => nil).first.climate_zone_number.should == nil
20
- end
21
12
  end
22
13
  end
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,9 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
8
8
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
9
9
  require 'earth'
10
10
 
11
+ require 'support/integration'
12
+ include Integration
13
+
11
14
  case ENV['EARTH_DB_ADAPTER']
12
15
  when 'mysql'
13
16
  adapter = 'mysql'
@@ -18,8 +21,8 @@ when 'mysql'
18
21
  # system %{mysql -u #{username} -p#{password} -e "DROP DATABASE #{database}"}
19
22
  # system %{mysql -u #{username} -p#{password} -e "CREATE DATABASE #{database}"}
20
23
  else
21
- adapter = 'sqlite3'
22
- database = ':memory:'
24
+ adapter = 'postgresql'
25
+ database = 'test_earth'
23
26
  username = nil
24
27
  password = nil
25
28
  end
@@ -41,5 +44,7 @@ ActiveRecord::Base.logger = logger
41
44
  DataMiner.logger = logger
42
45
 
43
46
  RSpec.configure do |c|
44
- c.filter_run_excluding :slow => true
47
+ unless ENV['ALL'] == 'true'
48
+ c.filter_run_excluding :slow => true
49
+ end
45
50
  end
@@ -0,0 +1,17 @@
1
+ module Integration
2
+ def spot_check(records, tests)
3
+ headers = tests.shift
4
+ tests.each do |test|
5
+ where_clause = {}
6
+ headers[0].each_with_index do |field, i|
7
+ where_clause[field] = test[0][i]
8
+ end
9
+ record = records.where(where_clause).first
10
+ record.should_not be_nil, "Expected to find a record with #{where_clause.inspect}"
11
+ headers[1].each_with_index do |field, i|
12
+ criterion = test[1][i]
13
+ record.send(field).should send("be_#{criterion}"), "Expecting #{field} to be #{criterion} on #{record.inspect}"
14
+ end
15
+ end
16
+ end
17
+ end