earth-ruby19 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. data/Gemfile +5 -0
  2. data/Gemfile.lock +138 -0
  3. data/LICENSE +20 -0
  4. data/README.markdown +38 -0
  5. data/lib/earth.rb +146 -0
  6. data/lib/earth/active_record_ext.rb +9 -0
  7. data/lib/earth/air.rb +13 -0
  8. data/lib/earth/air/aircraft.rb +21 -0
  9. data/lib/earth/air/aircraft/data_miner.rb +184 -0
  10. data/lib/earth/air/aircraft_class.rb +10 -0
  11. data/lib/earth/air/aircraft_class/data_miner.rb +42 -0
  12. data/lib/earth/air/aircraft_manufacturer.rb +9 -0
  13. data/lib/earth/air/aircraft_manufacturer/data_miner.rb +20 -0
  14. data/lib/earth/air/airline.rb +16 -0
  15. data/lib/earth/air/airline/data_miner.rb +57 -0
  16. data/lib/earth/air/airport.rb +44 -0
  17. data/lib/earth/air/airport/data_miner.rb +80 -0
  18. data/lib/earth/air/data_miner.rb +15 -0
  19. data/lib/earth/air/flight_configuration.rb +7 -0
  20. data/lib/earth/air/flight_configuration/data_miner.rb +16 -0
  21. data/lib/earth/air/flight_distance_class.rb +7 -0
  22. data/lib/earth/air/flight_distance_class/data_miner.rb +16 -0
  23. data/lib/earth/air/flight_domesticity.rb +6 -0
  24. data/lib/earth/air/flight_domesticity/data_miner.rb +57 -0
  25. data/lib/earth/air/flight_fuel_type.rb +12 -0
  26. data/lib/earth/air/flight_fuel_type/data_miner.rb +12 -0
  27. data/lib/earth/air/flight_propulsion.rb +7 -0
  28. data/lib/earth/air/flight_propulsion/data_miner.rb +16 -0
  29. data/lib/earth/air/flight_seat_class.rb +12 -0
  30. data/lib/earth/air/flight_seat_class/data_miner.rb +36 -0
  31. data/lib/earth/air/flight_segment.rb +29 -0
  32. data/lib/earth/air/flight_segment/data_miner.rb +330 -0
  33. data/lib/earth/air/flight_service.rb +7 -0
  34. data/lib/earth/air/flight_service/data_miner.rb +16 -0
  35. data/lib/earth/all.rb +11 -0
  36. data/lib/earth/automobile.rb +8 -0
  37. data/lib/earth/automobile/automobile_fuel_type.rb +18 -0
  38. data/lib/earth/automobile/automobile_fuel_type/data_miner.rb +45 -0
  39. data/lib/earth/automobile/automobile_make.rb +14 -0
  40. data/lib/earth/automobile/automobile_make/data_miner.rb +68 -0
  41. data/lib/earth/automobile/automobile_make_fleet_year.rb +15 -0
  42. data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +29 -0
  43. data/lib/earth/automobile/automobile_make_year.rb +14 -0
  44. data/lib/earth/automobile/automobile_make_year/data_miner.rb +45 -0
  45. data/lib/earth/automobile/automobile_model.rb +14 -0
  46. data/lib/earth/automobile/automobile_model/data_miner.rb +38 -0
  47. data/lib/earth/automobile/automobile_model_year.rb +15 -0
  48. data/lib/earth/automobile/automobile_model_year/data_miner.rb +51 -0
  49. data/lib/earth/automobile/automobile_size_class.rb +14 -0
  50. data/lib/earth/automobile/automobile_size_class/data_miner.rb +43 -0
  51. data/lib/earth/automobile/automobile_variant.rb +17 -0
  52. data/lib/earth/automobile/automobile_variant/data_miner.rb +460 -0
  53. data/lib/earth/automobile/data_miner.rb +8 -0
  54. data/lib/earth/base.rb +7 -0
  55. data/lib/earth/bus.rb +1 -0
  56. data/lib/earth/bus/bus_class.rb +19 -0
  57. data/lib/earth/bus/bus_class/data_miner.rb +41 -0
  58. data/lib/earth/bus/data_miner.rb +1 -0
  59. data/lib/earth/conversions_ext.rb +45 -0
  60. data/lib/earth/data_miner.rb +10 -0
  61. data/lib/earth/diet.rb +2 -0
  62. data/lib/earth/diet/data_miner.rb +2 -0
  63. data/lib/earth/diet/diet_class.rb +15 -0
  64. data/lib/earth/diet/diet_class/data_miner.rb +36 -0
  65. data/lib/earth/diet/food_group.rb +17 -0
  66. data/lib/earth/diet/food_group/data_miner.rb +26 -0
  67. data/lib/earth/fuel.rb +2 -0
  68. data/lib/earth/fuel/data_miner.rb +2 -0
  69. data/lib/earth/fuel/fuel_price.rb +13 -0
  70. data/lib/earth/fuel/fuel_price/data_miner.rb +20 -0
  71. data/lib/earth/fuel/fuel_type.rb +18 -0
  72. data/lib/earth/fuel/fuel_type/data_miner.rb +37 -0
  73. data/lib/earth/hospitality.rb +1 -0
  74. data/lib/earth/hospitality/data_miner.rb +1 -0
  75. data/lib/earth/hospitality/lodging_class.rb +9 -0
  76. data/lib/earth/hospitality/lodging_class/data_miner.rb +30 -0
  77. data/lib/earth/industry.rb +10 -0
  78. data/lib/earth/industry/industry.rb +23 -0
  79. data/lib/earth/industry/industry_product.rb +22 -0
  80. data/lib/earth/industry/industry_product_line.rb +20 -0
  81. data/lib/earth/industry/industry_sector.rb +20 -0
  82. data/lib/earth/industry/merchant.rb +18 -0
  83. data/lib/earth/industry/merchant_category.rb +22 -0
  84. data/lib/earth/industry/merchant_category_industry.rb +20 -0
  85. data/lib/earth/industry/product_line.rb +22 -0
  86. data/lib/earth/industry/product_line_industry_product.rb +20 -0
  87. data/lib/earth/industry/sector.rb +19 -0
  88. data/lib/earth/inflectors.rb +9 -0
  89. data/lib/earth/locality.rb +10 -0
  90. data/lib/earth/locality/census_division.rb +22 -0
  91. data/lib/earth/locality/census_division/data_miner.rb +64 -0
  92. data/lib/earth/locality/census_region.rb +13 -0
  93. data/lib/earth/locality/census_region/data_miner.rb +17 -0
  94. data/lib/earth/locality/climate_division.rb +17 -0
  95. data/lib/earth/locality/climate_division/data_miner.rb +20 -0
  96. data/lib/earth/locality/country.rb +13 -0
  97. data/lib/earth/locality/country/data_miner.rb +19 -0
  98. data/lib/earth/locality/data_miner.rb +10 -0
  99. data/lib/earth/locality/egrid_region.rb +15 -0
  100. data/lib/earth/locality/egrid_region/data_miner.rb +35 -0
  101. data/lib/earth/locality/egrid_subregion.rb +16 -0
  102. data/lib/earth/locality/egrid_subregion/data_miner.rb +65 -0
  103. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +13 -0
  104. data/lib/earth/locality/petroleum_administration_for_defense_district/data_miner.rb +21 -0
  105. data/lib/earth/locality/state.rb +22 -0
  106. data/lib/earth/locality/state/data_miner.rb +37 -0
  107. data/lib/earth/locality/urbanity.rb +10 -0
  108. data/lib/earth/locality/urbanity/data_miner.rb +15 -0
  109. data/lib/earth/locality/zip_code.rb +23 -0
  110. data/lib/earth/locality/zip_code/data_miner.rb +43 -0
  111. data/lib/earth/pet.rb +4 -0
  112. data/lib/earth/pet/breed.rb +15 -0
  113. data/lib/earth/pet/breed/data_miner.rb +25 -0
  114. data/lib/earth/pet/breed_gender.rb +14 -0
  115. data/lib/earth/pet/breed_gender/data_miner.rb +21 -0
  116. data/lib/earth/pet/data_miner.rb +4 -0
  117. data/lib/earth/pet/gender.rb +10 -0
  118. data/lib/earth/pet/gender/data_miner.rb +13 -0
  119. data/lib/earth/pet/species.rb +40 -0
  120. data/lib/earth/pet/species/data_miner.rb +42 -0
  121. data/lib/earth/rail.rb +1 -0
  122. data/lib/earth/rail/data_miner.rb +1 -0
  123. data/lib/earth/rail/rail_class.rb +16 -0
  124. data/lib/earth/rail/rail_class/data_miner.rb +36 -0
  125. data/lib/earth/residence.rb +8 -0
  126. data/lib/earth/residence/air_conditioner_use.rb +13 -0
  127. data/lib/earth/residence/air_conditioner_use/data_miner.rb +22 -0
  128. data/lib/earth/residence/clothes_machine_use.rb +10 -0
  129. data/lib/earth/residence/clothes_machine_use/data_miner.rb +28 -0
  130. data/lib/earth/residence/data_miner.rb +8 -0
  131. data/lib/earth/residence/dishwasher_use.rb +10 -0
  132. data/lib/earth/residence/dishwasher_use/data_miner.rb +28 -0
  133. data/lib/earth/residence/residence_appliance.rb +16 -0
  134. data/lib/earth/residence/residence_appliance/data_miner.rb +20 -0
  135. data/lib/earth/residence/residence_class.rb +16 -0
  136. data/lib/earth/residence/residence_class/data_miner.rb +15 -0
  137. data/lib/earth/residence/residence_fuel_price.rb +18 -0
  138. data/lib/earth/residence/residence_fuel_price/data_miner.rb +200 -0
  139. data/lib/earth/residence/residence_fuel_type.rb +32 -0
  140. data/lib/earth/residence/residence_fuel_type/data_miner.rb +18 -0
  141. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +39 -0
  142. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +283 -0
  143. data/spec/lib/earth_spec.rb +25 -0
  144. data/spec/spec_helper.rb +11 -0
  145. data/vendor/geokit-rails/CHANGELOG.rdoc +46 -0
  146. data/vendor/geokit-rails/MIT-LICENSE +20 -0
  147. data/vendor/geokit-rails/README.markdown +561 -0
  148. data/vendor/geokit-rails/Rakefile +18 -0
  149. data/vendor/geokit-rails/about.yml +9 -0
  150. data/vendor/geokit-rails/assets/api_keys_template +61 -0
  151. data/vendor/geokit-rails/init.rb +1 -0
  152. data/vendor/geokit-rails/install.rb +14 -0
  153. data/vendor/geokit-rails/lib/geokit-rails.rb +24 -0
  154. data/vendor/geokit-rails/lib/geokit-rails/acts_as_mappable.rb +456 -0
  155. data/vendor/geokit-rails/lib/geokit-rails/adapters/abstract.rb +31 -0
  156. data/vendor/geokit-rails/lib/geokit-rails/adapters/mysql.rb +22 -0
  157. data/vendor/geokit-rails/lib/geokit-rails/adapters/postgresql.rb +22 -0
  158. data/vendor/geokit-rails/lib/geokit-rails/adapters/sqlserver.rb +43 -0
  159. data/vendor/geokit-rails/lib/geokit-rails/defaults.rb +22 -0
  160. data/vendor/geokit-rails/lib/geokit-rails/geocoder_control.rb +16 -0
  161. data/vendor/geokit-rails/lib/geokit-rails/ip_geocode_lookup.rb +46 -0
  162. data/vendor/geokit-rails/test/acts_as_mappable_test.rb +474 -0
  163. data/vendor/geokit-rails/test/boot.rb +25 -0
  164. data/vendor/geokit-rails/test/database.yml +20 -0
  165. data/vendor/geokit-rails/test/fixtures/companies.yml +7 -0
  166. data/vendor/geokit-rails/test/fixtures/custom_locations.yml +54 -0
  167. data/vendor/geokit-rails/test/fixtures/locations.yml +54 -0
  168. data/vendor/geokit-rails/test/fixtures/mock_addresses.yml +17 -0
  169. data/vendor/geokit-rails/test/fixtures/mock_families.yml +2 -0
  170. data/vendor/geokit-rails/test/fixtures/mock_houses.yml +9 -0
  171. data/vendor/geokit-rails/test/fixtures/mock_organizations.yml +5 -0
  172. data/vendor/geokit-rails/test/fixtures/mock_people.yml +5 -0
  173. data/vendor/geokit-rails/test/fixtures/stores.yml +0 -0
  174. data/vendor/geokit-rails/test/ip_geocode_lookup_test.rb +77 -0
  175. data/vendor/geokit-rails/test/models/company.rb +3 -0
  176. data/vendor/geokit-rails/test/models/custom_location.rb +12 -0
  177. data/vendor/geokit-rails/test/models/location.rb +4 -0
  178. data/vendor/geokit-rails/test/models/mock_address.rb +4 -0
  179. data/vendor/geokit-rails/test/models/mock_family.rb +3 -0
  180. data/vendor/geokit-rails/test/models/mock_house.rb +3 -0
  181. data/vendor/geokit-rails/test/models/mock_organization.rb +4 -0
  182. data/vendor/geokit-rails/test/models/mock_person.rb +4 -0
  183. data/vendor/geokit-rails/test/models/store.rb +3 -0
  184. data/vendor/geokit-rails/test/schema.rb +60 -0
  185. data/vendor/geokit-rails/test/tasks.rake +31 -0
  186. data/vendor/geokit-rails/test/test_helper.rb +23 -0
  187. metadata +476 -0
@@ -0,0 +1,22 @@
1
+ class IndustryProduct < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :naics_product_code
4
+
5
+ has_many :product_line_industry_products, :foreign_key => 'naics_product_code'
6
+
7
+ belongs_to :industry, :foreign_key => 'naics_code'
8
+
9
+ def self.schema_definition
10
+ lambda do
11
+ string 'naics_product_code'
12
+ string 'description'
13
+ float 'value'
14
+ string 'value_units'
15
+ string 'naics_code'
16
+ end
17
+ end
18
+
19
+ data_miner do
20
+ IndustryProduct.define_schema(self)
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ class IndustryProductLine < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :row_hash
4
+
5
+ belongs_to :industry, :foreign_key => 'naics_code'
6
+ belongs_to :product_line, :foreign_key => 'ps_code'
7
+
8
+ def self.schema_definition
9
+ lambda do
10
+ string 'row_hash'
11
+ string 'naics_code'
12
+ float 'ratio'
13
+ string 'ps_code'
14
+ end
15
+ end
16
+
17
+ data_miner do
18
+ IndustryProductLine.define_schema(self)
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ class IndustrySector < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :row_hash
4
+
5
+ belongs_to :industry, :foreign_key => 'naics_code'
6
+ belongs_to :sector, :foreign_key => 'io_code'
7
+
8
+ def self.schema_definition
9
+ lambda do
10
+ string 'row_hash'
11
+ string 'naics_code'
12
+ float 'ratio'
13
+ string 'io_code'
14
+ end
15
+ end
16
+
17
+ data_miner do
18
+ IndustrySector.define_schema(self)
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ class Merchant < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :id
4
+
5
+ belongs_to :merchant_category, :foreign_key => 'mcc'
6
+
7
+ def self.schema_definition
8
+ lambda do
9
+ string 'id'
10
+ string 'name'
11
+ string 'mcc'
12
+ end
13
+ end
14
+
15
+ data_miner do
16
+ Merchant.define_schema(self)
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ class MerchantCategory < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :mcc
4
+
5
+ has_many :merchant_category_industries, :foreign_key => 'mcc'
6
+ has_many :industries, :through => :merchant_category_industries
7
+
8
+ def name
9
+ description
10
+ end
11
+
12
+ def self.schema_definition
13
+ lambda do
14
+ string 'mcc'
15
+ string 'description'
16
+ end
17
+ end
18
+
19
+ data_miner do
20
+ MerchantCategory.define_schema(self)
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ class MerchantCategoryIndustry < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :row_hash
4
+
5
+ belongs_to :merchant_category, :foreign_key => 'mcc'
6
+ belongs_to :industry, :foreign_key => 'naics_code'
7
+
8
+ def self.schema_definition
9
+ lambda do
10
+ string 'row_hash'
11
+ string 'mcc'
12
+ float 'ratio'
13
+ string 'naics_code'
14
+ end
15
+ end
16
+
17
+ data_miner do
18
+ MerchantCategoryIndustry.define_schema(self)
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ class ProductLine < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :ps_code
4
+
5
+ has_many :industry_product_lines, :foreign_key => 'ps_code'
6
+
7
+ has_many :product_line_industry_products, :foreign_key => 'ps_code'
8
+ has_many :industry_products, :through => :product_line_industry_products
9
+
10
+ def self.schema_definition
11
+ lambda do
12
+ string 'ps_code'
13
+ string 'description'
14
+ string 'broadline' # FIXME TODO do we need this?
15
+ string 'parent' # FIXME TODO do we need this?
16
+ end
17
+ end
18
+
19
+ data_miner do
20
+ ProductLine.define_schema(self)
21
+ end
22
+ end
@@ -0,0 +1,20 @@
1
+ class ProductLineIndustryProduct < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :row_hash
4
+
5
+ belongs_to :product_line, :foreign_key => 'ps_code'
6
+ belongs_to :industry_product, :foreign_key => 'naics_product_code'
7
+
8
+ def self.schema_definition
9
+ lambda do
10
+ string 'row_hash'
11
+ string 'ps_code'
12
+ float 'ratio'
13
+ string 'naics_product_code'
14
+ end
15
+ end
16
+
17
+ data_miner do
18
+ ProductLineIndustryProduct.define_schema(self)
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ class Sector < ActiveRecord::Base
2
+ extend Earth::Base
3
+ set_primary_key :io_code
4
+
5
+ has_many :industry_sectors, :foreign_key => 'io_code'
6
+
7
+ def self.schema_definition
8
+ lambda do
9
+ string 'io_code'
10
+ string 'description'
11
+ float 'value'
12
+ string 'value_units'
13
+ end
14
+ end
15
+
16
+ data_miner do
17
+ Sector.define_schema(self)
18
+ end
19
+ end
@@ -0,0 +1,9 @@
1
+ ActiveSupport::Inflector.inflections do |inflect|
2
+ inflect.uncountable %w(aircraft aircraft Aircraft airline_aircraft AirlineAircraft)
3
+ inflect.uncountable 'commons'
4
+ inflect.uncountable 'food'
5
+ inflect.uncountable 'shelter'
6
+ inflect.uncountable 'transportation'
7
+ inflect.uncountable 'press_coverage'
8
+ inflect.irregular 'foot', 'feet'
9
+ end
@@ -0,0 +1,10 @@
1
+ require 'earth/locality/census_division'
2
+ require 'earth/locality/census_region'
3
+ require 'earth/locality/climate_division'
4
+ require 'earth/locality/country'
5
+ require 'earth/locality/egrid_region'
6
+ require 'earth/locality/egrid_subregion'
7
+ require 'earth/locality/petroleum_administration_for_defense_district'
8
+ require 'earth/locality/state'
9
+ require 'earth/locality/urbanity'
10
+ require 'earth/locality/zip_code'
@@ -0,0 +1,22 @@
1
+ class CensusDivision < ActiveRecord::Base
2
+ set_primary_key :number
3
+
4
+ belongs_to :census_region, :foreign_key => 'census_region_number'
5
+ has_many :states, :foreign_key => 'census_division_number'
6
+ has_many :zip_codes, :through => :states
7
+ has_many :climate_divisions, :through => :states
8
+ has_many :residential_energy_consumption_survey_responses, :foreign_key => 'census_division_number'
9
+
10
+ falls_back_on :meeting_building_natural_gas_intensity => 0.011973,
11
+ :meeting_building_fuel_oil_intensity => 0.0037381,
12
+ :meeting_building_electricity_intensity => 0.072444,
13
+ :meeting_building_district_heat_intensity => 3458.7
14
+
15
+ data_miner do
16
+ tap "Brighter Planet's sanitized census divisions", Earth.taps_server
17
+
18
+ process "pull dependencies" do
19
+ run_data_miner_on_belongs_to_associations
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,64 @@
1
+ CensusDivision.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ integer 'number'
5
+ string 'name'
6
+ string 'census_region_name'
7
+ integer 'census_region_number'
8
+ float 'meeting_building_natural_gas_intensity'
9
+ string 'meeting_building_natural_gas_intensity_units'
10
+ float 'meeting_building_fuel_oil_intensity'
11
+ string 'meeting_building_fuel_oil_intensity_units'
12
+ float 'meeting_building_electricity_intensity'
13
+ string 'meeting_building_electricity_intensity_units'
14
+ float 'meeting_building_district_heat_intensity'
15
+ string 'meeting_building_district_heat_intensity_units'
16
+ float 'lodging_building_natural_gas_intensity'
17
+ string 'lodging_building_natural_gas_intensity_units'
18
+ float 'lodging_building_fuel_oil_intensity'
19
+ string 'lodging_building_fuel_oil_intensity_units'
20
+ float 'lodging_building_electricity_intensity'
21
+ string 'lodging_building_electricity_intensity_units'
22
+ float 'lodging_building_district_heat_intensity'
23
+ string 'lodging_building_district_heat_intensity_units'
24
+ end
25
+
26
+ process 'Define some unit conversions' do
27
+ Conversions.register :hundred_cubic_feet_per_square_foot_hour, :cubic_metres_per_square_metre_hour, 30.48
28
+ Conversions.register :gallons_per_square_foot_hour, :litres_per_square_metre_hour, 40.745833
29
+ Conversions.register :kilowatt_hours_per_square_foot_hour, :kilowatt_hours_per_square_metre_hour, 10.76391
30
+ Conversions.register :thousand_btu_per_square_foot_hour, :joules_per_square_metre_hour, 11_356_527
31
+ Conversions.register :hundred_cubic_feet_per_room_night, :cubic_metres_per_room_night, 2.8317
32
+ Conversions.register :gallons_per_room_night, :litres_per_room_night, 3.7854
33
+ Conversions.register :thousand_btu_per_room_night, :joules_per_room_night, 1_055_056
34
+ end
35
+
36
+ import 'the U.S. Census Geographic Terms and Definitions',
37
+ :url => 'http://www.census.gov/popest/geographic/codes02.csv',
38
+ :skip => 9,
39
+ :select => lambda { |row| row['Division'].to_s.strip != 'X' and row['FIPS CODE STATE'].to_s.strip == 'X'} do
40
+ key 'number', :field_name => 'Division'
41
+ store 'name', :field_name => 'Name'
42
+ store 'census_region_number', :field_name => 'Region'
43
+ store 'census_region_name', :field_name => 'Region', :dictionary => { :input => 'number', :output => 'name', :url => 'http://data.brighterplanet.com/census_regions.csv' }
44
+ end
45
+
46
+ import 'meeting building fuel intensities calculated from CBECS 2003',
47
+ :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGotdjgtUEk0eUU0R3lxM1hHdlF1V0E&hl=en&output=csv' do
48
+ key 'number', :field_name => 'census_division'
49
+ store 'meeting_building_natural_gas_intensity', :from_units => :hundred_cubic_feet_per_square_foot_hour, :to_units => :cubic_metres_per_square_metre_hour
50
+ store 'meeting_building_fuel_oil_intensity', :from_units => :gallons_per_square_foot_hour, :to_units => :litres_per_square_metre_hour
51
+ store 'meeting_building_electricity_intensity', :from_units => :kilowatt_hours_per_square_foot_hour, :to_units => :kilowatt_hours_per_square_metre_hour
52
+ store 'meeting_building_district_heat_intensity', :from_units => :thousand_btu_per_square_foot_hour, :to_units => :joules_per_square_metre_hour
53
+ end
54
+
55
+ import 'lodging building fuel intensities calculated from CBECS 2003',
56
+ :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHZ1QjdNTGVpbWxmZDVLbjlpTHlFVHc&hl=en&output=csv' do
57
+ key 'number', :field_name => 'census_division'
58
+ store 'lodging_building_natural_gas_intensity', :from_units => :hundred_cubic_feet_per_room_night, :to_units => :cubic_metres_per_room_night
59
+ store 'lodging_building_fuel_oil_intensity', :from_units => :gallons_per_room_night, :to_units => :litres_per_room_night
60
+ store 'lodging_building_electricity_intensity', :units_field_name => 'lodging_building_electricity_intensity_units'
61
+ store 'lodging_building_district_heat_intensity', :from_units => :thousand_btu_per_room_night, :to_units => :joules_per_room_night
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,13 @@
1
+ class CensusRegion < ActiveRecord::Base
2
+ set_primary_key :number
3
+
4
+ has_many :census_divisions, :foreign_key => 'census_region_number'
5
+ has_many :states, :through => :census_divisions
6
+ # has_many :climate_divisions, :through => :census_divisions
7
+ # has_many :zip_codes, :through => :census_divisions
8
+ has_many :residential_energy_consumption_survey_responses, :foreign_key => 'census_region_number'
9
+
10
+ data_miner do
11
+ tap "Brighter Planet's sanitized census regions", Earth.taps_server
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ CensusRegion.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ integer 'number'
5
+ string 'name'
6
+ end
7
+
8
+ import 'the U.S. Census Geographic Terms and Definitions',
9
+ :url => 'http://www.census.gov/popest/geographic/codes02.csv',
10
+ :skip => 9,
11
+ :select => lambda { |row| row['Region'].to_i > 0 and row['Division'].to_s.strip == 'X'} do
12
+ key 'number', :field_name => 'Region'
13
+ store 'name', :field_name => 'Name'
14
+ end
15
+ end
16
+ end
17
+
@@ -0,0 +1,17 @@
1
+ class ClimateDivision < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ has_many :zip_codes, :foreign_key => 'climate_division_name'
5
+ belongs_to :state, :foreign_key => 'state_postal_abbreviation'
6
+
7
+ RADIUS = 750
8
+
9
+ data_miner do
10
+ tap "Brighter Planet's sanitized climate divisions", Earth.taps_server
11
+
12
+ process "pull dependencies" do
13
+ run_data_miner_on_belongs_to_associations
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,20 @@
1
+ ClimateDivision.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'name'
5
+ float 'heating_degree_days'
6
+ float 'cooling_degree_days'
7
+ string 'state_postal_abbreviation'
8
+ end
9
+
10
+ import "a list of climate divisions and their average heating and cooling degree days",
11
+ :url => 'http://static.brighterplanet.com/science/data/climate/climate_divisions/climate_divisions.csv' do
12
+ key 'name'
13
+ store 'heating_degree_days'
14
+ store 'cooling_degree_days'
15
+ store 'state_postal_abbreviation'
16
+ end
17
+ #associate :state, :key => :state_postal_abbreviation, :foreign_key => :postal_abbreviation
18
+ end
19
+ end
20
+
@@ -0,0 +1,13 @@
1
+ class Country < ActiveRecord::Base
2
+ set_primary_key :iso_3166_code
3
+
4
+ data_miner do
5
+ tap "Brighter Planet's sanitized countries list", Earth.taps_server
6
+ end
7
+
8
+ class << self
9
+ def united_states
10
+ find_by_iso_3166_code('US')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ Country.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'iso_3166_code'
5
+ string 'name'
6
+ end
7
+
8
+ import 'the official ISO country list',
9
+ :url => 'http://www.iso.org/iso/list-en1-semic-3.txt',
10
+ :skip => 2,
11
+ :headers => false,
12
+ :delimiter => ';',
13
+ :encoding => 'ISO-8859-1' do
14
+ key 'iso_3166_code', :field_number => 1
15
+ store 'name', :field_number => 0
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,10 @@
1
+ require 'earth/locality/census_division/data_miner'
2
+ require 'earth/locality/census_region/data_miner'
3
+ require 'earth/locality/climate_division/data_miner'
4
+ require 'earth/locality/country/data_miner'
5
+ require 'earth/locality/egrid_region/data_miner'
6
+ require 'earth/locality/egrid_subregion/data_miner'
7
+ require 'earth/locality/petroleum_administration_for_defense_district/data_miner'
8
+ require 'earth/locality/state/data_miner'
9
+ require 'earth/locality/urbanity/data_miner'
10
+ require 'earth/locality/zip_code/data_miner'
@@ -0,0 +1,15 @@
1
+ class EgridRegion < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ has_many :egrid_subregions, :foreign_key => 'egrid_region_name'
5
+
6
+ data_miner do
7
+ tap "Brighter Planet's egrid region data", Earth.taps_server
8
+
9
+ process "pull dependencies" do
10
+ run_data_miner_on_belongs_to_associations
11
+ end
12
+ end
13
+
14
+ falls_back_on :loss_factor => 0.061311 # Ian
15
+ end