earth 0.11.7 → 0.11.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. data/README.markdown +30 -0
  2. data/bin/earth_tester.rb +1 -1
  3. data/earth.gemspec +3 -3
  4. data/lib/earth.rb +105 -90
  5. data/lib/earth/air.rb +3 -12
  6. data/lib/earth/air/aircraft.rb +9 -9
  7. data/lib/earth/air/airport.rb +3 -0
  8. data/lib/earth/air/airport/data_miner.rb +2 -0
  9. data/lib/earth/air/data_miner.rb +3 -10
  10. data/lib/earth/air/flight_segment.rb +3 -1
  11. data/lib/earth/air/flight_segment/data_miner.rb +2 -0
  12. data/lib/earth/all.rb +3 -13
  13. data/lib/earth/automobile.rb +3 -18
  14. data/lib/earth/automobile/automobile_fuel.rb +1 -3
  15. data/lib/earth/automobile/automobile_fuel/data_miner.rb +1 -0
  16. data/lib/earth/automobile/automobile_make.rb +1 -0
  17. data/lib/earth/automobile/automobile_make/data_miner.rb +1 -0
  18. data/lib/earth/automobile/automobile_make_model.rb +1 -0
  19. data/lib/earth/automobile/automobile_make_model/data_miner.rb +1 -0
  20. data/lib/earth/automobile/automobile_make_model_year.rb +1 -0
  21. data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +1 -0
  22. data/lib/earth/automobile/automobile_make_model_year_variant.rb +1 -0
  23. data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +1 -0
  24. data/lib/earth/automobile/automobile_make_year.rb +1 -0
  25. data/lib/earth/automobile/automobile_make_year/data_miner.rb +1 -0
  26. data/lib/earth/automobile/automobile_make_year_fleet.rb +1 -0
  27. data/lib/earth/automobile/automobile_make_year_fleet/data_miner.rb +1 -0
  28. data/lib/earth/automobile/automobile_model.rb +1 -0
  29. data/lib/earth/automobile/automobile_model/data_miner.rb +1 -0
  30. data/lib/earth/automobile/automobile_size_class.rb +1 -0
  31. data/lib/earth/automobile/automobile_size_class/data_miner.rb +1 -0
  32. data/lib/earth/automobile/automobile_size_class_year.rb +1 -0
  33. data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +1 -0
  34. data/lib/earth/automobile/automobile_type_fuel_control.rb +1 -0
  35. data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +1 -0
  36. data/lib/earth/automobile/automobile_type_fuel_year.rb +1 -0
  37. data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -0
  38. data/lib/earth/automobile/automobile_type_fuel_year_age.rb +1 -0
  39. data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +1 -0
  40. data/lib/earth/automobile/automobile_type_fuel_year_control.rb +1 -0
  41. data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +1 -0
  42. data/lib/earth/automobile/automobile_type_year.rb +1 -0
  43. data/lib/earth/automobile/automobile_type_year/data_miner.rb +1 -0
  44. data/lib/earth/automobile/automobile_year.rb +1 -0
  45. data/lib/earth/automobile/automobile_year/data_miner.rb +1 -0
  46. data/lib/earth/automobile/data_miner.rb +3 -18
  47. data/lib/earth/bus.rb +3 -6
  48. data/lib/earth/bus/bus_class.rb +1 -0
  49. data/lib/earth/bus/bus_class/data_miner.rb +1 -0
  50. data/lib/earth/bus/bus_fuel.rb +1 -0
  51. data/lib/earth/bus/bus_fuel/data_miner.rb +1 -0
  52. data/lib/earth/bus/bus_fuel_control.rb +1 -0
  53. data/lib/earth/bus/bus_fuel_control/data_miner.rb +1 -0
  54. data/lib/earth/bus/bus_fuel_year_control.rb +1 -0
  55. data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +1 -0
  56. data/lib/earth/bus/data_miner.rb +3 -6
  57. data/lib/earth/computation.rb +3 -5
  58. data/lib/earth/computation/computation_carrier.rb +1 -0
  59. data/lib/earth/computation/computation_carrier/data_miner.rb +1 -1
  60. data/lib/earth/computation/computation_carrier_instance_class.rb +1 -0
  61. data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +1 -0
  62. data/lib/earth/computation/computation_carrier_region.rb +1 -0
  63. data/lib/earth/computation/computation_carrier_region/data_miner.rb +1 -0
  64. data/lib/earth/computation/data_miner.rb +3 -5
  65. data/lib/earth/data_miner.rb +3 -13
  66. data/lib/earth/diet.rb +3 -2
  67. data/lib/earth/diet/data_miner.rb +3 -2
  68. data/lib/earth/eia.rb +11 -13
  69. data/lib/earth/fuel.rb +3 -5
  70. data/lib/earth/fuel/data_miner.rb +3 -5
  71. data/lib/earth/fuel/fuel_price.rb +1 -1
  72. data/lib/earth/hospitality.rb +3 -5
  73. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +2 -0
  74. data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +13 -7
  75. data/lib/earth/hospitality/country_lodging_class.rb +1 -0
  76. data/lib/earth/hospitality/country_lodging_class/data_miner.rb +4 -2
  77. data/lib/earth/hospitality/data_miner.rb +3 -4
  78. data/lib/earth/hospitality/lodging_class.rb +1 -10
  79. data/lib/earth/hospitality/lodging_class/data_miner.rb +7 -30
  80. data/lib/earth/hospitality/lodging_property.rb +1 -0
  81. data/lib/earth/industry.rb +3 -13
  82. data/lib/earth/industry/cbecs_energy_intensity.rb +5 -49
  83. data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +94 -42
  84. data/lib/earth/industry/data_miner.rb +3 -4
  85. data/lib/earth/industry/industry.rb +1 -0
  86. data/lib/earth/industry/industry/data_miner.rb +1 -0
  87. data/lib/earth/industry/industry_product.rb +1 -0
  88. data/lib/earth/industry/industry_product_line.rb +1 -0
  89. data/lib/earth/industry/industry_sector.rb +1 -0
  90. data/lib/earth/industry/mecs_energy.rb +3 -24
  91. data/lib/earth/industry/mecs_energy/data_miner.rb +34 -11
  92. data/lib/earth/industry/mecs_ratio.rb +6 -24
  93. data/lib/earth/industry/mecs_ratio/data_miner.rb +24 -1
  94. data/lib/earth/locality.rb +3 -15
  95. data/lib/earth/locality/census_division.rb +1 -0
  96. data/lib/earth/locality/census_division/data_miner.rb +1 -0
  97. data/lib/earth/locality/country.rb +3 -0
  98. data/lib/earth/locality/country/data_miner.rb +5 -1
  99. data/lib/earth/locality/data_miner.rb +3 -15
  100. data/lib/earth/locality/egrid_subregion.rb +1 -0
  101. data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -0
  102. data/lib/earth/locality/state/data_miner.rb +11 -11
  103. data/lib/earth/locality/zip_code.rb +6 -0
  104. data/lib/earth/pet.rb +3 -4
  105. data/lib/earth/pet/data_miner.rb +3 -4
  106. data/lib/earth/rail.rb +3 -15
  107. data/lib/earth/rail/country_rail_class.rb +1 -0
  108. data/lib/earth/rail/country_rail_class/data_miner.rb +1 -0
  109. data/lib/earth/rail/country_rail_traction.rb +2 -0
  110. data/lib/earth/rail/country_rail_traction/data_miner.rb +2 -0
  111. data/lib/earth/rail/country_rail_traction_class.rb +2 -0
  112. data/lib/earth/rail/country_rail_traction_class/data_miner.rb +2 -0
  113. data/lib/earth/rail/data_miner.rb +3 -16
  114. data/lib/earth/rail/national_transit_database_company.rb +1 -0
  115. data/lib/earth/rail/national_transit_database_company/data_miner.rb +1 -0
  116. data/lib/earth/rail/national_transit_database_record.rb +1 -0
  117. data/lib/earth/rail/national_transit_database_record/data_miner.rb +1 -0
  118. data/lib/earth/rail/rail_company.rb +2 -0
  119. data/lib/earth/rail/rail_company/data_miner.rb +2 -0
  120. data/lib/earth/rail/rail_company_traction.rb +1 -0
  121. data/lib/earth/rail/rail_company_traction/data_miner.rb +1 -0
  122. data/lib/earth/rail/rail_company_traction_class.rb +1 -0
  123. data/lib/earth/rail/rail_company_traction_class/data_miner.rb +1 -0
  124. data/lib/earth/rail/rail_fuel.rb +1 -0
  125. data/lib/earth/rail/rail_fuel/data_miner.rb +1 -0
  126. data/lib/earth/residence.rb +3 -11
  127. data/lib/earth/residence/data_miner.rb +3 -11
  128. data/lib/earth/residence/residence_fuel_price.rb +1 -0
  129. data/lib/earth/residence/residence_fuel_price/data_miner.rb +1 -0
  130. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +1 -0
  131. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +1 -0
  132. data/lib/earth/shipping.rb +3 -3
  133. data/lib/earth/shipping/data_miner.rb +3 -3
  134. data/lib/earth/version.rb +1 -1
  135. data/spec/earth/industry/mecs_energy_spec.rb +18 -0
  136. data/spec/earth_spec.rb +18 -29
  137. data/test/test_aircraft_match.rb +142 -142
  138. data/vendor/geokit-rails/.gitignore +2 -0
  139. data/vendor/geokit-rails/CHANGELOG.rdoc +4 -1
  140. data/vendor/geokit-rails/README.markdown +11 -3
  141. data/vendor/geokit-rails/about.yml +2 -0
  142. data/vendor/geokit-rails/lib/geokit-rails.rb +7 -4
  143. data/vendor/geokit-rails/lib/geokit-rails/acts_as_mappable.rb +15 -2
  144. data/vendor/geokit-rails/lib/geokit-rails/adapters/abstract.rb +1 -1
  145. data/vendor/geokit-rails/lib/geokit-rails/adapters/mysql2.rb +22 -0
  146. data/vendor/geokit-rails/test/database.yml +5 -0
  147. data/vendor/geokit-rails/test/ip_geocode_lookup_test.rb +1 -1
  148. data/vendor/geokit-rails/test/tasks.rake +2 -2
  149. metadata +179 -191
  150. data/lib/earth/hospitality/census_region_lodging_class.rb +0 -16
  151. data/lib/earth/hospitality/census_region_lodging_class/data_miner.rb +0 -40
data/lib/earth/fuel.rb CHANGED
@@ -1,5 +1,3 @@
1
- require 'earth/fuel/fuel'
2
- require 'earth/fuel/fuel_price'
3
- require 'earth/fuel/fuel_type'
4
- require 'earth/fuel/fuel_year'
5
- require 'earth/fuel/greenhouse_gas'
1
+ # lib/earth/fuel.rb
2
+ require 'earth'
3
+ Earth.require_related __FILE__
@@ -1,5 +1,3 @@
1
- require 'earth/fuel/fuel/data_miner'
2
- require 'earth/fuel/fuel_price/data_miner'
3
- require 'earth/fuel/fuel_type/data_miner'
4
- require 'earth/fuel/fuel_year/data_miner'
5
- require 'earth/fuel/greenhouse_gas/data_miner'
1
+ # lib/earth/fuel/data_miner.rb
2
+ require 'earth'
3
+ Earth.require_related __FILE__
@@ -6,4 +6,4 @@ class FuelPrice < ActiveRecord::Base
6
6
  col :name
7
7
  col :price, :type => :float
8
8
  col :price_units
9
- end
9
+ end
@@ -1,5 +1,3 @@
1
- require 'earth/hospitality/census_region_lodging_class'
2
- require 'earth/hospitality/commercial_building_energy_consumption_survey_response'
3
- require 'earth/hospitality/country_lodging_class'
4
- require 'earth/hospitality/lodging_class'
5
- require 'earth/hospitality/lodging_property'
1
+ # lib/earth/hospitality.rb
2
+ require 'earth'
3
+ Earth.require_related __FILE__
@@ -1,3 +1,4 @@
1
+ require 'earth/locality'
1
2
  class CommercialBuildingEnergyConsumptionSurveyResponse < ActiveRecord::Base
2
3
  set_primary_key :id
3
4
  set_table_name :cbecs_responses
@@ -8,6 +9,7 @@ class CommercialBuildingEnergyConsumptionSurveyResponse < ActiveRecord::Base
8
9
  col :id, :type => :integer
9
10
  col :census_region_number, :type => :integer
10
11
  col :census_division_number, :type => :integer
12
+ col :climate_zone_number, :type => :integer
11
13
  col :heating_degree_days, :type => :integer
12
14
  col :cooling_degree_days, :type => :integer
13
15
  col :construction_year, :type => :integer
@@ -1,5 +1,10 @@
1
+ require 'earth/locality/data_miner'
1
2
  CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
2
3
  data_miner do
4
+ process 'Define some unit conversions' do
5
+ Conversions.register :hundred_cubic_feet, :cubic_metres, 2.83168466
6
+ end
7
+
3
8
  import 'building characteristics from the 2003 EIA Commercial Building Energy Consumption Survey',
4
9
  :url => 'http://www.eia.gov/emeu/cbecs/cbecs2003/public_use_2003/data/FILE01.csv',
5
10
  :skip => 1,
@@ -7,6 +12,7 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
7
12
  key 'id', :field_name => 'PUBID8'
8
13
  store 'census_region_number', :field_name => 'REGION8'
9
14
  store 'census_division_number', :field_name => 'CENDIV8'
15
+ store 'climate_zone_number', :synthesize => Proc.new { |row| row['CLIMATE8'].to_i == 7 ? nil : row['CLIMATE8'].to_i }
10
16
  store 'area', :field_name => 'SQFT8', :from_units => :square_feet, :to_units => :square_metres
11
17
  store 'principal_activity', :field_name => 'PBA8', :dictionary => { :input => 'principal_activity_code', :output => 'principal_activity', :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=2&output=csv' }
12
18
  store 'floors', :field_name => 'NFLOOR8', :dictionary => { :input => 'floors_code', :output => 'floors', :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=0&output=csv' }
@@ -27,9 +33,9 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
27
33
  store 'first_activity', :field_name => 'ACT18', :dictionary => { :input => 'activity_code', :output => 'activity', :url => 'https://docs.google.com/spreadsheet/pub?&key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=4&output=csv' }
28
34
  store 'second_activity', :field_name => 'ACT28', :dictionary => { :input => 'activity_code', :output => 'activity', :url => 'https://docs.google.com/spreadsheet/pub?&key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=4&output=csv' }
29
35
  store 'third_activity', :field_name => 'ACT38', :dictionary => { :input => 'activity_code', :output => 'activity', :url => 'https://docs.google.com/spreadsheet/pub?&key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=4&output=csv' }
30
- store 'first_activity_share', :synthesize => lambda { |row| row['ACT1PCT8'].blank? ? nil : row['ACT1PCT8'].to_f / 100.0 }
31
- store 'second_activity_share', :synthesize => lambda { |row| row['ACT2PCT8'].blank? ? nil : row['ACT2PCT8'].to_f / 100.0 }
32
- store 'third_activity_share', :synthesize => lambda { |row| row['ACT3PCT8'].blank? ? nil : row['ACT3PCT8'].to_f / 100.0 }
36
+ store 'first_activity_share', :synthesize => Proc.new { |row| row['ACT1PCT8'].blank? ? nil : row['ACT1PCT8'].to_f / 100.0 }
37
+ store 'second_activity_share', :synthesize => Proc.new { |row| row['ACT2PCT8'].blank? ? nil : row['ACT2PCT8'].to_f / 100.0 }
38
+ store 'third_activity_share', :synthesize => Proc.new { |row| row['ACT3PCT8'].blank? ? nil : row['ACT3PCT8'].to_f / 100.0 }
33
39
  store 'lodging_rooms', :field_name => 'LODGRM8'
34
40
  end
35
41
 
@@ -40,7 +46,7 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
40
46
  key 'id', :field_name => 'PUBID8'
41
47
  store 'heating_degree_days', :field_name => 'HDD658'
42
48
  store 'cooling_degree_days', :field_name => 'CDD658'
43
- store 'electricity_use', :field_name => 'ELCNS8', :units => :kilowatt_hours
49
+ store 'electricity_use', :synthesize => Proc.new { |row| row['ELCNS8'].to_i }, :units => :kilowatt_hours
44
50
  end
45
51
 
46
52
  import 'fuel use characteristics from the 2003 EIA Commercial Building Energy Consumption Survey',
@@ -48,9 +54,9 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
48
54
  :skip => 1,
49
55
  :headers => ["PUBID8", "REGION8", "CENDIV8", "SQFT8", "SQFTC8", "YRCONC8", "PBA8", "ELUSED8", "NGUSED8", "FKUSED8", "PRUSED8", "STUSED8", "HWUSED8", "ADJWT8", "STRATUM8", "PAIR8", "NGCNS8", "NGBTU8", "NGEXP8", "ZNGCNS8", "ZNGEXP8", "FKCNS8", "FKBTU8", "FKEXP8", "ZFKCNS8", "ZFKEXP8", "DHUSED8", "DHHT18", "DHHT28", "DHCOOL8", "DHWATR8", "DHCOOK8", "DHMANU8", "DHOTH8", "DHCNS8", "DHBTU8", "DHEXP8", "ZDHCNS8", "ZDHEXP8"] do
50
56
  key 'id', :field_name => 'PUBID8'
51
- store 'natural_gas_use', :synthesize => lambda { |row| row['NGCNS8'].to_i == 0 ? nil : (row['NGCNS8'].to_f * 100.0).cubic_feet.to(:cubic_metres) }, :units => :cubic_metres
52
- store 'fuel_oil_use', :synthesize => lambda { |row| row['FKCNS8'].to_i == 0 ? nil : row['FKCNS8'].to_f.gallons.to(:litres) }, :units => :litres
53
- store 'district_heat_use', :synthesize => lambda { |row| row['DHBTU8'].to_i == 0 ? nil : row['DHBTU8'].to_f.kbtus.to(:megajoules) }, :units => :megajoules
57
+ store 'natural_gas_use', :field_name => 'NGCNS8', :from_units => :hundred_cubic_feet, :to_units => :cubic_metres #!!!!!!!!!!!!
58
+ store 'fuel_oil_use', :field_name => 'FKCNS8', :from_units => :gallons, :to_units => :litres
59
+ store 'district_heat_use', :field_name => 'DHBTU8', :from_units => :kbtus, :to_units => :megajoules
54
60
  end
55
61
  end
56
62
  end
@@ -1,3 +1,4 @@
1
+ require 'earth/locality'
1
2
  class CountryLodgingClass < ActiveRecord::Base
2
3
  set_primary_key :name
3
4
 
@@ -1,3 +1,4 @@
1
+ require 'earth/locality/data_miner'
1
2
  CountryLodgingClass.class_eval do
2
3
  data_miner do
3
4
  import "a curated list of country lodging classes",
@@ -18,11 +19,12 @@ CountryLodgingClass.class_eval do
18
19
  intensities = {}
19
20
 
20
21
  [:natural_gas, :fuel_oil, :electricity, :district_heat].each do |fuel|
21
- intensities[fuel] = cbecs_responses.inject(0) do |sum, response|
22
+ intensity = cbecs_responses.inject(0) do |sum, response|
22
23
  next sum unless response.send("#{fuel}_use").present?
23
24
  occupied_room_nights = 365.0 / 7.0 / 12.0 * response.months_used * response.weekly_hours / 24.0 * response.lodging_rooms * 0.59
24
25
  sum + (response.weighting * response.send("#{fuel}_use") / occupied_room_nights)
25
- end / cbecs_responses.sum(:weighting)
26
+ end
27
+ intensities[fuel] = intensity / cbecs_responses.sum(:weighting)
26
28
  end
27
29
 
28
30
  lodging_class.natural_gas_intensity = intensities[:natural_gas]
@@ -1,4 +1,3 @@
1
- require 'earth/hospitality/census_region_lodging_class/data_miner'
2
- require 'earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner'
3
- require 'earth/hospitality/country_lodging_class/data_miner'
4
- require 'earth/hospitality/lodging_class/data_miner'
1
+ # lib/earth/hospitality/data_miner.rb
2
+ require 'earth'
3
+ Earth.require_related __FILE__
@@ -1,15 +1,6 @@
1
+ require 'earth/locality'
1
2
  class LodgingClass < ActiveRecord::Base
2
3
  set_primary_key :name
3
4
 
4
5
  col :name
5
-
6
- # DEPRECATED - cut once new Lodging has been phased in
7
- col :electricity_intensity, :type => :float
8
- col :electricity_intensity_units
9
- col :natural_gas_intensity, :type => :float
10
- col :natural_gas_intensity_units
11
- col :fuel_oil_intensity, :type => :float
12
- col :fuel_oil_intensity_units
13
- col :district_heat_intensity, :type => :float
14
- col :district_heat_intensity_units
15
6
  end
@@ -1,37 +1,14 @@
1
+ require 'earth/locality/data_miner'
1
2
  LodgingClass.class_eval do
2
3
  data_miner do
3
- # DEPRECATED - once new Lodging is phased in replace this with an import of lodging class names from the CountryLodgingClass google doc
4
- import "a list of lodging classes and pre-calculated energy intensities",
5
- :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdGZZWmZtWEJlYzhRNXlPdWpBTldlcUE&output=csv' do
6
- key 'name'
7
- store 'electricity_intensity', :units_field_name => 'electricity_intensity_units'
8
- store 'natural_gas_intensity', :units_field_name => 'natural_gas_intensity_units'
9
- store 'fuel_oil_intensity', :units_field_name => 'fuel_oil_intensity_units'
10
- store 'district_heat_intensity', :units_field_name => 'district_heat_intensity_units'
4
+ process "Ensure CountryLodgingClass is populated" do
5
+ CountryLodgingClass.run_data_miner!
11
6
  end
12
7
 
13
- process "Convert natural gas intensities to metric units" do
14
- conversion_factor = 2.83168466 # Google: 2.83168466 cubic m / 100 cubic ft
15
- where(:natural_gas_intensity_units => 'hundred_cubic_feet_per_room_night').update_all(%{
16
- natural_gas_intensity = 1.0 * natural_gas_intensity * #{conversion_factor},
17
- natural_gas_intensity_units = 'cubic_metres_per_room_night'
18
- })
19
- end
20
-
21
- process "Convert fuel oil intensities to metric units" do
22
- conversion_factor = 3.78541178 # Google: 3.78541178 l / gal
23
- where(:fuel_oil_intensity_units => 'gallons_per_room_night').update_all(%{
24
- fuel_oil_intensity = 1.0 * fuel_oil_intensity * #{conversion_factor},
25
- fuel_oil_intensity_units = 'litres_per_room_night'
26
- })
27
- end
28
-
29
- process "Convert district heat intensities to metric units" do
30
- conversion_factor = 1.05505585 # Google: 1.05505585 MJ / 1000 Btu
31
- where(:district_heat_intensity_units => 'thousand_btu_per_room_night').update_all(%{
32
- district_heat_intensity = 1.0 * district_heat_intensity * #{conversion_factor},
33
- district_heat_intensity_units = 'megajoules_per_room_night'
34
- })
8
+ process "Derive lodging classes from CountryLodgingClass" do
9
+ connection.select_values("SELECT DISTINCT lodging_class_name FROM #{CountryLodgingClass.quoted_table_name}").each do |lodging_class_name|
10
+ find_or_create_by_name lodging_class_name
11
+ end
35
12
  end
36
13
  end
37
14
  end
@@ -1,3 +1,4 @@
1
+ require 'earth/locality'
1
2
  # Copyright 2011 Brighter Planet, Inc.
2
3
  class LodgingProperty < ActiveRecord::Base
3
4
  set_primary_key :northstar_id
@@ -1,13 +1,3 @@
1
- require 'earth/industry/cbecs_energy_intensity'
2
- require 'earth/industry/industry_product_line'
3
- require 'earth/industry/industry_sector'
4
- require 'earth/industry/industry'
5
- require 'earth/industry/industry_product'
6
- require 'earth/industry/mecs_energy'
7
- require 'earth/industry/mecs_ratio'
8
- require 'earth/industry/merchant'
9
- require 'earth/industry/merchant_category_industry'
10
- require 'earth/industry/merchant_category'
11
- require 'earth/industry/product_line'
12
- require 'earth/industry/product_line_industry_product'
13
- require 'earth/industry/sector'
1
+ # lib/earth/industry.rb
2
+ require 'earth'
3
+ Earth.require_related __FILE__
@@ -1,55 +1,11 @@
1
+ require 'earth/locality'
1
2
  class CbecsEnergyIntensity < ActiveRecord::Base
2
- col :naics_code, :type => :string
3
+ set_primary_key :name
4
+
5
+ col :name
6
+ col :naics_code
3
7
  col :census_division_number, :type => :integer
4
8
  col :total_electricity_consumption, :type => :float
5
9
  col :total_floorspace, :type => :float
6
10
  col :electricity_intensity, :type => :float
7
-
8
- CENSUS_DIVISIONS = {
9
- 'New England Division' => {
10
- :column => 0,
11
- :code => 1,
12
- :table => 'c17'
13
- },
14
- 'Middle Atlantic Division' => {
15
- :column => 1,
16
- :code => 2,
17
- :table => 'c17'
18
- },
19
- 'East North Central Division' => {
20
- :column => 2,
21
- :code => 3,
22
- :table => 'c17'
23
- },
24
- 'West North Central Division' => {
25
- :column => 0,
26
- :code => 4,
27
- :table => 'c18'
28
- },
29
- 'South Atlantic Division' => {
30
- :column => 1,
31
- :code => 5,
32
- :table => 'c18'
33
- },
34
- 'East South Central Division' => {
35
- :column => 2,
36
- :code => 6,
37
- :table => 'c18'
38
- },
39
- 'West South Central Division' => {
40
- :column => 0,
41
- :code => 7,
42
- :table => 'c19'
43
- },
44
- 'Mountain Division' => {
45
- :column => 1,
46
- :code => 8,
47
- :table => 'c19'
48
- },
49
- 'Pacific Division' => {
50
- :column => 2,
51
- :code => 9,
52
- :table => 'c19'
53
- }
54
- }
55
11
  end
@@ -1,48 +1,100 @@
1
+ require 'earth/eia'
2
+ require 'earth/locality/data_miner'
1
3
  CbecsEnergyIntensity.class_eval do
2
- data_miner do
3
- NAICS_CODE_SYNTHESIZER = Proc.new do |row|
4
- case row[0].gsub(/\./, '')
5
- when 'Education' then
6
- 611110
7
- when 'Food Sales' then
8
- 445
9
- when 'Food Service' then
10
- 722
11
- when 'Health Care' then
12
- 622110
13
- when 'Inpatient' then
14
- 622110
15
- when 'Outpatient' then
16
- 622111
17
- when 'Lodging' then
18
- 721
19
- when 'Retail (Other Than Mall)' then
20
- 44
21
- when 'Office' then
22
- #TODO
23
- when 'Public Assembly' then
24
- #TODO
25
- when 'Public Order and Safety' then
26
- 922120
27
- when 'Religious Worship' then
28
- 813110
29
- when 'Service' then
30
- #TODO
31
- when 'Warehouse and Storage' then
32
- 493110
33
- when 'Other' then
34
- #TODO
35
- when 'Vacant' then
36
- #TODO
37
- end
4
+ const_set(:CENSUS_DIVISIONS, {
5
+ 'New England Division' => {
6
+ :column => 0,
7
+ :code => 1,
8
+ :table => 'c17'
9
+ },
10
+ 'Middle Atlantic Division' => {
11
+ :column => 1,
12
+ :code => 2,
13
+ :table => 'c17'
14
+ },
15
+ 'East North Central Division' => {
16
+ :column => 2,
17
+ :code => 3,
18
+ :table => 'c17'
19
+ },
20
+ 'West North Central Division' => {
21
+ :column => 0,
22
+ :code => 4,
23
+ :table => 'c18'
24
+ },
25
+ 'South Atlantic Division' => {
26
+ :column => 1,
27
+ :code => 5,
28
+ :table => 'c18'
29
+ },
30
+ 'East South Central Division' => {
31
+ :column => 2,
32
+ :code => 6,
33
+ :table => 'c18'
34
+ },
35
+ 'West South Central Division' => {
36
+ :column => 0,
37
+ :code => 7,
38
+ :table => 'c19'
39
+ },
40
+ 'Mountain Division' => {
41
+ :column => 1,
42
+ :code => 8,
43
+ :table => 'c19'
44
+ },
45
+ 'Pacific Division' => {
46
+ :column => 2,
47
+ :code => 9,
48
+ :table => 'c19'
49
+ }
50
+ })
51
+
52
+ const_set(:NAICS_CODE_SYNTHESIZER, lambda { |row|
53
+ case row[0].to_s
54
+ when /Education/
55
+ 611110
56
+ when /Food Sales/
57
+ 445
58
+ when /Food Service/
59
+ 722
60
+ when /Health Care/
61
+ 622110
62
+ when /Inpatient/
63
+ 622110
64
+ when /Outpatient/
65
+ 622111
66
+ when /Lodging/
67
+ 721
68
+ when /Retail (Other Than Mall)/
69
+ 44
70
+ when /Office/
71
+ #TODO
72
+ when /Public Assembly/
73
+ #TODO
74
+ when /Public Order and Safety/
75
+ 922120
76
+ when /Religious Worship/
77
+ 813110
78
+ when /Service/
79
+ #TODO
80
+ when /Warehouse and Storage/
81
+ 493110
82
+ when /Other/
83
+ #TODO
84
+ when /Vacant/
85
+ #TODO
38
86
  end
39
-
87
+ })
88
+
89
+ data_miner do
40
90
  CbecsEnergyIntensity::CENSUS_DIVISIONS.each do |division, data|
41
- import "2003 CBECS #{data[:table].capitalize} - Electricity Consumption and Intensity - #{division}",
91
+ import "2003 CBECS #{data[:table].upcase} - Electricity Consumption and Intensity - #{division}",
42
92
  :url => "http://www.eia.gov/emeu/cbecs/cbecs2003/detailed_tables_2003/2003set10/2003excel/#{data[:table]}.xls",
43
- :crop => (21..36) do
44
- key :name, :synthesize => Proc.new { |row| "#{Industry.format_naics_code(row[0])}-#{data[:code]}" }
45
- store :naics_code, :synthesize => NAICS_CODE_SYNTHESIZER
93
+ :headers => false,
94
+ :select => ::Proc.new { |row| CbecsEnergyIntensity::NAICS_CODE_SYNTHESIZER.call(row) },
95
+ :crop => (21..37) do
96
+ key :name, :synthesize => ::Proc.new { |row| "#{Industry.format_naics_code(CbecsEnergyIntensity::NAICS_CODE_SYNTHESIZER.call(row))}-#{data[:code]}" }
97
+ store :naics_code, :synthesize => CbecsEnergyIntensity::NAICS_CODE_SYNTHESIZER
46
98
  store :census_division_number, :static => data[:code]
47
99
  store :total_electricity_consumption, :field_number => data[:column] + 1
48
100
  store :total_floorspace, :field_number => data[:column] + 4
@@ -51,7 +103,7 @@ CbecsEnergyIntensity.class_eval do
51
103
  end
52
104
 
53
105
  process :normalize_fuels do
54
- EIA.normalize(CbecsEnergyIntensity, [:total_electricity_consumption, :total_floorspace, :electricity_intensity])
106
+ Earth::EIA.normalize(CbecsEnergyIntensity, [:total_electricity_consumption, :total_floorspace, :electricity_intensity])
55
107
  end
56
108
  end
57
109
  end
@@ -1,4 +1,3 @@
1
- require 'earth/industry/cbecs_energy_intensity/data_miner'
2
- require 'earth/industry/industry/data_miner'
3
- require 'earth/industry/mecs_energy/data_miner'
4
- require 'earth/industry/mecs_ratio/data_miner'
1
+ # lib/earth/industry/data_miner.rb
2
+ require 'earth'
3
+ Earth.require_related __FILE__