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
@@ -1,6 +1,6 @@
1
1
  require 'earth/locality'
2
2
  class Industry < ActiveRecord::Base
3
- set_primary_key :naics_code
3
+ self.primary_key = "naics_code"
4
4
 
5
5
  has_many :merchant_category_industries, :foreign_key => 'naics_code'
6
6
 
@@ -1,6 +1,6 @@
1
1
  require 'earth/locality'
2
2
  class IndustryProduct < ActiveRecord::Base
3
- set_primary_key :naics_product_code
3
+ self.primary_key = "naics_product_code"
4
4
 
5
5
  has_many :product_line_industry_products, :foreign_key => 'naics_product_code'
6
6
 
@@ -11,4 +11,4 @@ class IndustryProduct < ActiveRecord::Base
11
11
  col :value, :type => :float
12
12
  col :value_units
13
13
  col :naics_code
14
- end
14
+ end
@@ -1,6 +1,6 @@
1
1
  require 'earth/locality'
2
2
  class IndustryProductLine < ActiveRecord::Base
3
- set_primary_key :row_hash
3
+ self.primary_key = "row_hash"
4
4
 
5
5
  belongs_to :industry, :foreign_key => 'naics_code'
6
6
  belongs_to :product_line, :foreign_key => 'ps_code'
@@ -9,4 +9,4 @@ class IndustryProductLine < ActiveRecord::Base
9
9
  col :naics_code
10
10
  col :ratio, :type => :float
11
11
  col :ps_code
12
- end
12
+ end
@@ -1,6 +1,6 @@
1
1
  require 'earth/locality'
2
2
  class IndustrySector < ActiveRecord::Base
3
- set_primary_key :row_hash
3
+ self.primary_key = "row_hash"
4
4
 
5
5
  belongs_to :industry, :foreign_key => 'naics_code'
6
6
  belongs_to :sector, :foreign_key => 'io_code'
@@ -9,4 +9,4 @@ class IndustrySector < ActiveRecord::Base
9
9
  col :naics_code
10
10
  col :ratio, :type => :float
11
11
  col :io_code
12
- end
12
+ end
@@ -1,38 +1,49 @@
1
1
  require 'earth/locality'
2
2
 
3
3
  class MecsEnergy < ActiveRecord::Base
4
- set_primary_key :name
4
+ self.primary_key = "name"
5
5
 
6
6
  col :name
7
- col :census_region
7
+ col :census_region_number, :type => :integer
8
8
  col :naics_code
9
- col :total, :type => :float
10
- col :net_electricity, :type => :float
9
+ col :energy, :type => :float
10
+ col :energy_units
11
+ col :electricity, :type => :float
12
+ col :electricity_units
11
13
  col :residual_fuel_oil, :type => :float
14
+ col :residual_fuel_oil_units
12
15
  col :distillate_fuel_oil, :type => :float
16
+ col :distillate_fuel_oil_units
13
17
  col :natural_gas, :type => :float
18
+ col :natural_gas_units
14
19
  col :lpg_and_ngl, :type => :float
20
+ col :lpg_and_ngl_units
15
21
  col :coal, :type => :float
22
+ col :coal_units
16
23
  col :coke_and_breeze, :type => :float
17
- col :other, :type => :float
18
-
19
- FUELS = [:net_electricity, :residual_fuel_oil, :distillate_fuel_oil,
20
- :natural_gas, :lpg_and_ngl, :coal, :coke_and_breeze, :other]
21
-
22
- def self.find_by_naics_code_and_census_region(code, census_region)
24
+ col :coke_and_breeze_units
25
+ col :other_fuel, :type => :float
26
+ col :other_fuel_units
27
+
28
+ FUELS = [:electricity, :residual_fuel_oil, :distillate_fuel_oil,
29
+ :natural_gas, :lpg_and_ngl, :coal, :coke_and_breeze, :other_fuel]
30
+
31
+ # Find the first record whose census_region_number matches number and whose naics_code matches code.
32
+ # If no record found chop off the last character of code and try again, and so on.
33
+ def self.find_by_naics_code_and_census_region_number(code, number)
23
34
  if code.blank?
24
- record = nil
35
+ record = nil
25
36
  else
26
37
  code = Industry.format_naics_code code
27
- record = where('census_region = ? AND naics_code LIKE ?', census_region, "#{code}%").first
28
- record ||= find_by_naics_code_and_census_region(code[0..-2], census_region)
38
+ record = where('census_region_number = ? AND naics_code = ?', number, code).first
39
+ record ||= find_by_naics_code_and_census_region_number(code[0..-2], number)
29
40
  end
30
41
  record
31
42
  end
32
-
43
+
33
44
  def fuel_ratios
34
45
  FUELS.inject({}) do |ratios, fuel|
35
- ratios[fuel] = send(fuel).to_f / total.to_f
46
+ ratios[fuel] = send("#{fuel}").to_f / energy.to_f
36
47
  ratios
37
48
  end
38
49
  end
@@ -1,51 +1,67 @@
1
1
  require 'earth/eia'
2
2
  require 'earth/locality'
3
+
3
4
  MecsEnergy.class_eval do
4
5
  const_set(:CENSUS_REGIONS, {
5
6
  'Total US' => {
6
- :crop => (15..93),
7
+ :crop => (15..94),
7
8
  :code => nil
8
9
  },
9
10
  'Northeast' => {
10
- :crop => (99..177),
11
+ :crop => (99..178),
11
12
  :code => 1
12
13
  },
13
14
  'Midwest' => {
14
- :crop => (184..262),
15
+ :crop => (183..262),
15
16
  :code => 2
16
17
  },
17
18
  'South' => {
18
- :crop => (267..345),
19
+ :crop => (267..346),
19
20
  :code => 3
20
21
  },
21
22
  'West' => {
22
- :crop => (351..429),
23
+ :crop => (351..430),
23
24
  :code => 4
24
25
  }
25
26
  })
26
-
27
+
27
28
  data_miner do
28
29
  MecsEnergy::CENSUS_REGIONS.each do |region, data|
29
30
  import("MECS table 3.2 #{region}",
30
31
  :url => "http://205.254.135.24/emeu/mecs/mecs2006/excel/Table3_2.xls",
31
- :crop => data[:crop], :headers => false, :skip => 1) do
32
- key 'name', :synthesize => Proc.new { |row| "#{Industry.format_naics_code(row[0])}-#{data[:code]}" }
33
- store 'naics_code', :field_number => 0
34
- store :total, :field_number => 2
35
- store :net_electricity, :field_number => 4
36
- store :residual_fuel_oil, :field_number => 5
37
- store :distillate_fuel_oil, :field_number => 6
38
- store :natural_gas, :field_number => 8
39
- store :lpg_and_ngl, :field_number => 10
40
- store :coal, :field_number => 12
41
- store :coke_and_breeze, :field_number => 13
42
- store :other, :field_number => 14
43
- store 'census_region', :static => data[:code]
32
+ :crop => data[:crop],
33
+ :headers => ["NAICS Code", "Subsector and Industry", "Total", "BLANK", "Net Electricity", "BLANK", "Residual Fuel Oil", "Distillate Fuel Oil", "Natural Gas", "BLANK", "LPG and NGL", "BLANK", "Coal", "Coke and Breeze", "Other"]) do
34
+ key :name, :synthesize => Proc.new { |row| "#{Industry.format_naics_code(row['NAICS Code'])}-#{data[:code]}" }
35
+ store :census_region_number, :static => data[:code]
36
+ store :naics_code, :field_name => 'NAICS Code'
37
+ store :energy, :units => :megajoules, :synthesize => Proc.new { |row|
38
+ Earth::EIA.convert_value(row['Total'], :from => :trillion_btus, :to => :megajoules)
39
+ }
40
+ store :electricity, :units => :megajoules, :synthesize => Proc.new { |row|
41
+ Earth::EIA.convert_value(row['Net Electricity'], :from => :trillion_btus, :to => :megajoules)
42
+ }
43
+ store :residual_fuel_oil, :units => :megajoules, :synthesize => Proc.new { |row|
44
+ Earth::EIA.convert_value(row['Residual Fuel Oil'], :from => :trillion_btus, :to => :megajoules)
45
+ }
46
+ store :distillate_fuel_oil, :units => :megajoules, :synthesize => Proc.new { |row|
47
+ Earth::EIA.convert_value(row['Distillate Fuel Oil'], :from => :trillion_btus, :to => :megajoules)
48
+ }
49
+ store :natural_gas, :units => :megajoules, :synthesize => Proc.new { |row|
50
+ Earth::EIA.convert_value(row['Natural Gas'], :from => :trillion_btus, :to => :megajoules)
51
+ }
52
+ store :lpg_and_ngl, :units => :megajoules, :synthesize => Proc.new { |row|
53
+ Earth::EIA.convert_value(row['LPG and NGL'], :from => :trillion_btus, :to => :megajoules)
54
+ }
55
+ store :coal, :units => :megajoules, :synthesize => Proc.new { |row|
56
+ Earth::EIA.convert_value(row['Coal'], :from => :trillion_btus, :to => :megajoules)
57
+ }
58
+ store :coke_and_breeze, :units => :megajoules, :synthesize => Proc.new { |row|
59
+ Earth::EIA.convert_value(row['Coke and Breeze'], :from => :trillion_btus, :to => :megajoules)
60
+ }
61
+ store :other_fuel, :units => :megajoules, :synthesize => Proc.new { |row|
62
+ Earth::EIA.convert_value(row['Other'], :from => :trillion_btus, :to => :megajoules)
63
+ }
44
64
  end
45
65
  end
46
-
47
- process :normalize_fuels do
48
- Earth::EIA.normalize(MecsEnergy, MecsEnergy::FUELS)
49
- end
50
66
  end
51
67
  end
@@ -2,22 +2,25 @@ require 'earth/locality'
2
2
  require 'earth/industry/industry'
3
3
 
4
4
  class MecsRatio < ActiveRecord::Base
5
- set_primary_key :name
6
-
5
+ self.primary_key = "name"
6
+
7
+ belongs_to :industry
8
+
7
9
  col :name
8
- col :census_region
10
+ col :census_region_number, :type => :integer
9
11
  col :naics_code
10
- col :consumption_per_dollar_of_shipments, :type => :float
12
+ col :energy_per_dollar_of_shipments, :type => :float
13
+ col :energy_per_dollar_of_shipments_units
11
14
 
12
- belongs_to :industry
13
-
14
- def self.find_by_naics_code_and_census_region(code, census_region)
15
+ # Find the first MecsRatio whose census_region_number matches number and whose naics_code matches code.
16
+ # If none found, chop off the last character of code and try again, and so on.
17
+ def self.find_by_naics_code_and_census_region_number(code, number)
15
18
  if code.blank?
16
- record = nil
19
+ record = nil
17
20
  else
18
21
  code = Industry.format_naics_code code
19
- record = where('census_region = ? AND naics_code LIKE ?', census_region, "#{code}%").first
20
- record ||= find_by_naics_code_and_census_region(code[0..-2], census_region)
22
+ record = where('census_region_number = ? AND naics_code = ?', number, code).first
23
+ record ||= find_by_naics_code_and_census_region_number(code[0..-2], number)
21
24
  end
22
25
  record
23
26
  end
@@ -1,25 +1,26 @@
1
1
  require 'earth/eia'
2
2
  require 'earth/locality/data_miner'
3
+
3
4
  MecsRatio.class_eval do
4
5
  const_set(:CENSUS_REGIONS, {
5
6
  'Total US' => {
6
- :crop => (16..94),
7
+ :crop => (16..95),
7
8
  :code => nil
8
9
  },
9
10
  'Northeast' => {
10
- :crop => (100..178),
11
+ :crop => (100..179),
11
12
  :code => 1
12
13
  },
13
14
  'Midwest' => {
14
- :crop => (184..262),
15
+ :crop => (184..263),
15
16
  :code => 2
16
17
  },
17
18
  'South' => {
18
- :crop => (268..346),
19
+ :crop => (268..347),
19
20
  :code => 3
20
21
  },
21
22
  'West' => {
22
- :crop => (352..430),
23
+ :crop => (352..431),
23
24
  :code => 4
24
25
  }
25
26
  })
@@ -28,16 +29,15 @@ MecsRatio.class_eval do
28
29
  MecsRatio::CENSUS_REGIONS.each do |region, data|
29
30
  import( "MECS table 6.1 #{region}",
30
31
  :url => "http://205.254.135.24/emeu/mecs/mecs2006/excel/Table6_1.xls",
31
- :crop => data[:crop]) do
32
- key 'name', :synthesize => Proc.new { |row| "#{Industry.format_naics_code(row[0])}-#{data[:code]}" }
33
- store 'naics_code', :synthesize => Proc.new { |row| Industry.format_naics_code row[0] }
34
- store 'consumption_per_dollar_of_shipments', :field_number => 4
35
- store 'census_region', :static => data[:code]
32
+ :crop => data[:crop],
33
+ :headers => ["NAICS Code", "Subsector and Industry", "Consumption per Employee", "Consumption per Dollar of Value Added", "Consumption per Dollar of Value of Shipments"]) do
34
+ key :name, :synthesize => Proc.new { |row| "#{Industry.format_naics_code(row["NAICS Code"])}-#{data[:code]}" }
35
+ store :census_region_number, :static => data[:code]
36
+ store :naics_code, :synthesize => Proc.new { |row| Industry.format_naics_code row["NAICS Code"] }
37
+ store :energy_per_dollar_of_shipments, :units => :megajoules, :synthesize => Proc.new { |row|
38
+ Earth::EIA.convert_value(row['Consumption per Dollar of Value of Shipments'], :from => :kbtus, :to => :megajoules)
39
+ }
36
40
  end
37
41
  end
38
-
39
- process :normalize_fuels do
40
- Earth::EIA.normalize(MecsRatio, [:consumption_per_dollar_of_shipments])
41
- end
42
42
  end
43
43
  end
@@ -1,9 +1,9 @@
1
1
  class Merchant < ActiveRecord::Base
2
- set_primary_key :id
2
+ self.primary_key = "id"
3
3
 
4
4
  belongs_to :merchant_category, :foreign_key => 'mcc'
5
5
 
6
6
  col :id
7
7
  col :name
8
8
  col :mcc
9
- end
9
+ end
@@ -1,5 +1,5 @@
1
1
  class MerchantCategory < ActiveRecord::Base
2
- set_primary_key :mcc
2
+ self.primary_key = "mcc"
3
3
 
4
4
  has_many :merchant_category_industries, :foreign_key => 'mcc'
5
5
  has_many :industries, :through => :merchant_category_industries
@@ -10,4 +10,4 @@ class MerchantCategory < ActiveRecord::Base
10
10
 
11
11
  col :mcc
12
12
  col :description
13
- end
13
+ end
@@ -1,5 +1,5 @@
1
1
  class MerchantCategoryIndustry < ActiveRecord::Base
2
- set_primary_key :row_hash
2
+ self.primary_key = "row_hash"
3
3
 
4
4
  belongs_to :merchant_category, :foreign_key => 'mcc'
5
5
  belongs_to :industry, :foreign_key => 'naics_code'
@@ -8,4 +8,4 @@ class MerchantCategoryIndustry < ActiveRecord::Base
8
8
  col :mcc
9
9
  col :ratio, :type => :float
10
10
  col :naics_code
11
- end
11
+ end
@@ -1,5 +1,5 @@
1
1
  class ProductLine < ActiveRecord::Base
2
- set_primary_key :ps_code
2
+ self.primary_key = "ps_code"
3
3
 
4
4
  has_many :industry_product_lines, :foreign_key => 'ps_code'
5
5
 
@@ -10,4 +10,4 @@ class ProductLine < ActiveRecord::Base
10
10
  col :description, :type => :text
11
11
  col :broadline # FIXME TODO do we need this?
12
12
  col :parent # FIXME TODO do we need this?
13
- end
13
+ end
@@ -1,5 +1,5 @@
1
1
  class ProductLineIndustryProduct < ActiveRecord::Base
2
- set_primary_key :row_hash
2
+ self.primary_key = "row_hash"
3
3
 
4
4
  belongs_to :product_line, :foreign_key => 'ps_code'
5
5
  belongs_to :industry_product, :foreign_key => 'naics_product_code'
@@ -8,4 +8,4 @@ class ProductLineIndustryProduct < ActiveRecord::Base
8
8
  col :ps_code
9
9
  col :ratio, :type => :float
10
10
  col :naics_product_code
11
- end
11
+ end
@@ -1,5 +1,5 @@
1
1
  class Sector < ActiveRecord::Base
2
- set_primary_key :io_code
2
+ self.primary_key = "io_code"
3
3
 
4
4
  has_many :industry_sectors, :foreign_key => 'io_code'
5
5
 
@@ -7,4 +7,4 @@ class Sector < ActiveRecord::Base
7
7
  col :description, :type => :text
8
8
  col :value, :type => :float
9
9
  col :value_units
10
- end
10
+ end
@@ -1,6 +1,6 @@
1
1
  require 'earth/fuel'
2
2
  class CensusDivision < ActiveRecord::Base
3
- set_primary_key :number
3
+ self.primary_key = "number"
4
4
 
5
5
  belongs_to :census_region, :foreign_key => 'census_region_number'
6
6
  has_many :states, :foreign_key => 'census_division_number'
@@ -26,4 +26,4 @@ class CensusDivision < ActiveRecord::Base
26
26
  col :meeting_building_electricity_intensity_units
27
27
  col :meeting_building_district_heat_intensity, :type => :float
28
28
  col :meeting_building_district_heat_intensity_units
29
- end
29
+ end
@@ -1,16 +1,6 @@
1
1
  require 'earth/fuel/data_miner'
2
2
  CensusDivision.class_eval do
3
3
  data_miner do
4
- process 'Define some unit conversions' do
5
- Conversions.register :hundred_cubic_feet_per_square_foot_hour, :cubic_metres_per_square_metre_hour, 30.48
6
- Conversions.register :gallons_per_square_foot_hour, :litres_per_square_metre_hour, 40.7458333
7
- Conversions.register :kilowatt_hours_per_square_foot_hour, :kilowatt_hours_per_square_metre_hour, 10.7639104
8
- Conversions.register :thousand_btu_per_square_foot_hour, :megajoules_per_square_metre_hour, 11.3565267
9
- Conversions.register :hundred_cubic_feet_per_room_night, :cubic_metres_per_room_night, 2.83168466
10
- Conversions.register :gallons_per_room_night, :litres_per_room_night, 3.78541178
11
- Conversions.register :thousand_btu_per_room_night, :megajoules_per_room_night, 1.05505585
12
- end
13
-
14
4
  # http://www.census.gov/popest/geographic/codes02.csv
15
5
  import('the U.S. Census Geographic Terms and Definitions',
16
6
  :url => 'http://www.census.gov/popest/about/geo/state_geocodes_v2009.txt',
@@ -26,10 +16,10 @@ CensusDivision.class_eval do
26
16
  import 'meeting building fuel intensities calculated from CBECS 2003',
27
17
  :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGotdjgtUEk0eUU0R3lxM1hHdlF1V0E&hl=en&gid=0&output=csv' do
28
18
  key 'number', :field_name => 'census_division'
29
- store 'meeting_building_natural_gas_intensity', :from_units => :hundred_cubic_feet_per_square_foot_hour, :to_units => :cubic_metres_per_square_metre_hour
30
- store 'meeting_building_fuel_oil_intensity', :from_units => :gallons_per_square_foot_hour, :to_units => :litres_per_square_metre_hour
31
- store 'meeting_building_electricity_intensity', :from_units => :kilowatt_hours_per_square_foot_hour, :to_units => :kilowatt_hours_per_square_metre_hour
32
- store 'meeting_building_district_heat_intensity', :from_units => :thousand_btu_per_square_foot_hour, :to_units => :megajoules_per_square_metre_hour
19
+ store 'meeting_building_natural_gas_intensity', :from_units => :hundred_cubic_feet_per_square_foot_hour, :to_units => :cubic_metres_per_square_metre_hour
20
+ store 'meeting_building_fuel_oil_intensity', :from_units => :gallons_per_square_foot_hour, :to_units => :litres_per_square_metre_hour
21
+ store 'meeting_building_electricity_intensity', :from_units => :kilowatt_hours_per_square_foot_hour, :to_units => :kilowatt_hours_per_square_metre_hour
22
+ store 'meeting_building_district_heat_intensity', :from_units => :kbtus_per_square_foot_hour, :to_units => :megajoules_per_square_metre_hour
33
23
  end
34
24
  end
35
25
  end
@@ -1,5 +1,5 @@
1
1
  class CensusRegion < ActiveRecord::Base
2
- set_primary_key :number
2
+ self.primary_key = "number"
3
3
 
4
4
  has_many :census_divisions, :foreign_key => 'census_region_number'
5
5
  has_many :states, :through => :census_divisions
@@ -9,4 +9,4 @@ class CensusRegion < ActiveRecord::Base
9
9
 
10
10
  col :number, :type => :integer
11
11
  col :name
12
- end
12
+ end
@@ -1,27 +1,11 @@
1
1
  class ClimateDivision < ActiveRecord::Base
2
- set_primary_key :name
2
+ self.primary_key = "name"
3
3
 
4
4
  has_many :zip_codes, :foreign_key => 'climate_division_name'
5
5
  belongs_to :state, :foreign_key => 'state_postal_abbreviation'
6
6
 
7
7
  RADIUS = 750
8
8
 
9
- def climate_zone_number
10
- if cooling_degree_days < 2000.degrees_fahrenheit.to(:degrees_celsius)
11
- if heating_degree_days > 7000.degrees_fahrenheit.to(:degrees_celsius)
12
- 1
13
- elsif heating_degree_days > 5499.degrees_fahrenheit.to(:degrees_celsius)
14
- 2
15
- elsif heating_degree_days > 3999.degrees_fahrenheit.to(:degrees_celsius)
16
- 3
17
- else
18
- 4
19
- end
20
- else
21
- 5
22
- end
23
- end
24
-
25
9
  col :name
26
10
  col :heating_degree_days, :type => :float
27
11
  col :heating_degree_days_units