earth 0.0.18

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. data/.document +5 -0
  2. data/.gitignore +22 -0
  3. data/.rvmrc +8 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE +20 -0
  6. data/README.markdown +38 -0
  7. data/Rakefile +71 -0
  8. data/VERSION +1 -0
  9. data/earth.gemspec +265 -0
  10. data/lib/earth.rb +169 -0
  11. data/lib/earth/air.rb +13 -0
  12. data/lib/earth/air/aircraft.rb +32 -0
  13. data/lib/earth/air/aircraft/data_miner.rb +171 -0
  14. data/lib/earth/air/aircraft_class.rb +10 -0
  15. data/lib/earth/air/aircraft_class/data_miner.rb +42 -0
  16. data/lib/earth/air/aircraft_manufacturer.rb +9 -0
  17. data/lib/earth/air/aircraft_manufacturer/data_miner.rb +20 -0
  18. data/lib/earth/air/airline.rb +16 -0
  19. data/lib/earth/air/airline/data_miner.rb +57 -0
  20. data/lib/earth/air/airport.rb +44 -0
  21. data/lib/earth/air/airport/data_miner.rb +80 -0
  22. data/lib/earth/air/data_miner.rb +15 -0
  23. data/lib/earth/air/flight_configuration.rb +18 -0
  24. data/lib/earth/air/flight_configuration/data_miner.rb +4 -0
  25. data/lib/earth/air/flight_distance_class.rb +7 -0
  26. data/lib/earth/air/flight_distance_class/data_miner.rb +16 -0
  27. data/lib/earth/air/flight_domesticity.rb +6 -0
  28. data/lib/earth/air/flight_domesticity/data_miner.rb +57 -0
  29. data/lib/earth/air/flight_fuel_type.rb +17 -0
  30. data/lib/earth/air/flight_fuel_type/data_miner.rb +4 -0
  31. data/lib/earth/air/flight_propulsion.rb +18 -0
  32. data/lib/earth/air/flight_propulsion/data_miner.rb +4 -0
  33. data/lib/earth/air/flight_seat_class.rb +12 -0
  34. data/lib/earth/air/flight_seat_class/data_miner.rb +36 -0
  35. data/lib/earth/air/flight_segment.rb +38 -0
  36. data/lib/earth/air/flight_segment/data_miner.rb +334 -0
  37. data/lib/earth/air/flight_service.rb +18 -0
  38. data/lib/earth/air/flight_service/data_miner.rb +4 -0
  39. data/lib/earth/all.rb +10 -0
  40. data/lib/earth/automobile.rb +8 -0
  41. data/lib/earth/automobile/automobile_fuel_type.rb +18 -0
  42. data/lib/earth/automobile/automobile_fuel_type/data_miner.rb +45 -0
  43. data/lib/earth/automobile/automobile_make.rb +14 -0
  44. data/lib/earth/automobile/automobile_make/data_miner.rb +68 -0
  45. data/lib/earth/automobile/automobile_make_fleet_year.rb +15 -0
  46. data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +29 -0
  47. data/lib/earth/automobile/automobile_make_year.rb +14 -0
  48. data/lib/earth/automobile/automobile_make_year/data_miner.rb +45 -0
  49. data/lib/earth/automobile/automobile_model.rb +14 -0
  50. data/lib/earth/automobile/automobile_model/data_miner.rb +38 -0
  51. data/lib/earth/automobile/automobile_model_year.rb +15 -0
  52. data/lib/earth/automobile/automobile_model_year/data_miner.rb +51 -0
  53. data/lib/earth/automobile/automobile_size_class.rb +14 -0
  54. data/lib/earth/automobile/automobile_size_class/data_miner.rb +43 -0
  55. data/lib/earth/automobile/automobile_variant.rb +17 -0
  56. data/lib/earth/automobile/automobile_variant/data_miner.rb +464 -0
  57. data/lib/earth/automobile/data_miner.rb +8 -0
  58. data/lib/earth/bus.rb +1 -0
  59. data/lib/earth/bus/bus_class.rb +19 -0
  60. data/lib/earth/bus/bus_class/data_miner.rb +41 -0
  61. data/lib/earth/bus/data_miner.rb +1 -0
  62. data/lib/earth/conversions_ext.rb +45 -0
  63. data/lib/earth/data_miner.rb +10 -0
  64. data/lib/earth/diet.rb +2 -0
  65. data/lib/earth/diet/data_miner.rb +2 -0
  66. data/lib/earth/diet/diet_class.rb +15 -0
  67. data/lib/earth/diet/diet_class/data_miner.rb +36 -0
  68. data/lib/earth/diet/food_group.rb +17 -0
  69. data/lib/earth/diet/food_group/data_miner.rb +26 -0
  70. data/lib/earth/fuel.rb +2 -0
  71. data/lib/earth/fuel/data_miner.rb +2 -0
  72. data/lib/earth/fuel/fuel_price.rb +13 -0
  73. data/lib/earth/fuel/fuel_price/data_miner.rb +20 -0
  74. data/lib/earth/fuel/fuel_type.rb +18 -0
  75. data/lib/earth/fuel/fuel_type/data_miner.rb +37 -0
  76. data/lib/earth/industry.rb +10 -0
  77. data/lib/earth/industry/data_miner.rb +2 -0
  78. data/lib/earth/industry/industries_product_lines.rb +6 -0
  79. data/lib/earth/industry/industries_sectors.rb +6 -0
  80. data/lib/earth/industry/industry.rb +12 -0
  81. data/lib/earth/industry/industry/data_miner.rb +21 -0
  82. data/lib/earth/industry/merchant.rb +5 -0
  83. data/lib/earth/industry/merchant_categories_industries.rb +8 -0
  84. data/lib/earth/industry/merchant_category.rb +6 -0
  85. data/lib/earth/industry/product_line.rb +10 -0
  86. data/lib/earth/industry/product_line/data_miner.rb +18 -0
  87. data/lib/earth/industry/product_lines_sectors.rb +6 -0
  88. data/lib/earth/industry/sector.rb +3 -0
  89. data/lib/earth/inflectors.rb +9 -0
  90. data/lib/earth/locality.rb +10 -0
  91. data/lib/earth/locality/census_division.rb +17 -0
  92. data/lib/earth/locality/census_division/data_miner.rb +21 -0
  93. data/lib/earth/locality/census_region.rb +13 -0
  94. data/lib/earth/locality/census_region/data_miner.rb +17 -0
  95. data/lib/earth/locality/climate_division.rb +17 -0
  96. data/lib/earth/locality/climate_division/data_miner.rb +20 -0
  97. data/lib/earth/locality/country.rb +13 -0
  98. data/lib/earth/locality/country/data_miner.rb +19 -0
  99. data/lib/earth/locality/data_miner.rb +10 -0
  100. data/lib/earth/locality/egrid_region.rb +15 -0
  101. data/lib/earth/locality/egrid_region/data_miner.rb +19 -0
  102. data/lib/earth/locality/egrid_subregion.rb +16 -0
  103. data/lib/earth/locality/egrid_subregion/data_miner.rb +26 -0
  104. data/lib/earth/locality/petroleum_administration_for_defense_district.rb +13 -0
  105. data/lib/earth/locality/petroleum_administration_for_defense_district/data_miner.rb +21 -0
  106. data/lib/earth/locality/state.rb +22 -0
  107. data/lib/earth/locality/state/data_miner.rb +37 -0
  108. data/lib/earth/locality/urbanity.rb +20 -0
  109. data/lib/earth/locality/urbanity/data_miner.rb +4 -0
  110. data/lib/earth/locality/zip_code.rb +29 -0
  111. data/lib/earth/locality/zip_code/data_miner.rb +36 -0
  112. data/lib/earth/pet.rb +4 -0
  113. data/lib/earth/pet/breed.rb +15 -0
  114. data/lib/earth/pet/breed/data_miner.rb +25 -0
  115. data/lib/earth/pet/breed_gender.rb +14 -0
  116. data/lib/earth/pet/breed_gender/data_miner.rb +21 -0
  117. data/lib/earth/pet/data_miner.rb +4 -0
  118. data/lib/earth/pet/gender.rb +10 -0
  119. data/lib/earth/pet/gender/data_miner.rb +13 -0
  120. data/lib/earth/pet/species.rb +40 -0
  121. data/lib/earth/pet/species/data_miner.rb +42 -0
  122. data/lib/earth/rail.rb +1 -0
  123. data/lib/earth/rail/data_miner.rb +1 -0
  124. data/lib/earth/rail/rail_class.rb +16 -0
  125. data/lib/earth/rail/rail_class/data_miner.rb +36 -0
  126. data/lib/earth/residence.rb +8 -0
  127. data/lib/earth/residence/air_conditioner_use.rb +30 -0
  128. data/lib/earth/residence/air_conditioner_use/data_miner.rb +4 -0
  129. data/lib/earth/residence/clothes_machine_use.rb +33 -0
  130. data/lib/earth/residence/clothes_machine_use/data_miner.rb +4 -0
  131. data/lib/earth/residence/data_miner.rb +8 -0
  132. data/lib/earth/residence/dishwasher_use.rb +33 -0
  133. data/lib/earth/residence/dishwasher_use/data_miner.rb +4 -0
  134. data/lib/earth/residence/residence_appliance.rb +7 -0
  135. data/lib/earth/residence/residence_appliance/data_miner.rb +19 -0
  136. data/lib/earth/residence/residence_class.rb +26 -0
  137. data/lib/earth/residence/residence_class/data_miner.rb +4 -0
  138. data/lib/earth/residence/residence_fuel_price.rb +18 -0
  139. data/lib/earth/residence/residence_fuel_price/data_miner.rb +200 -0
  140. data/lib/earth/residence/residence_fuel_type.rb +33 -0
  141. data/lib/earth/residence/residence_fuel_type/data_miner.rb +18 -0
  142. data/lib/earth/residence/residential_energy_consumption_survey_response.rb +67 -0
  143. data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +264 -0
  144. data/lib/earth/schema.rb +8 -0
  145. data/spec/lib/earth_spec.rb +25 -0
  146. data/spec/spec_helper.rb +11 -0
  147. data/vendor/geokit-rails/CHANGELOG.rdoc +46 -0
  148. data/vendor/geokit-rails/MIT-LICENSE +20 -0
  149. data/vendor/geokit-rails/README.markdown +561 -0
  150. data/vendor/geokit-rails/Rakefile +18 -0
  151. data/vendor/geokit-rails/about.yml +9 -0
  152. data/vendor/geokit-rails/assets/api_keys_template +61 -0
  153. data/vendor/geokit-rails/init.rb +1 -0
  154. data/vendor/geokit-rails/install.rb +14 -0
  155. data/vendor/geokit-rails/lib/geokit-rails.rb +24 -0
  156. data/vendor/geokit-rails/lib/geokit-rails/acts_as_mappable.rb +456 -0
  157. data/vendor/geokit-rails/lib/geokit-rails/adapters/abstract.rb +31 -0
  158. data/vendor/geokit-rails/lib/geokit-rails/adapters/mysql.rb +22 -0
  159. data/vendor/geokit-rails/lib/geokit-rails/adapters/postgresql.rb +22 -0
  160. data/vendor/geokit-rails/lib/geokit-rails/adapters/sqlserver.rb +43 -0
  161. data/vendor/geokit-rails/lib/geokit-rails/defaults.rb +22 -0
  162. data/vendor/geokit-rails/lib/geokit-rails/geocoder_control.rb +16 -0
  163. data/vendor/geokit-rails/lib/geokit-rails/ip_geocode_lookup.rb +46 -0
  164. data/vendor/geokit-rails/test/acts_as_mappable_test.rb +474 -0
  165. data/vendor/geokit-rails/test/boot.rb +25 -0
  166. data/vendor/geokit-rails/test/database.yml +20 -0
  167. data/vendor/geokit-rails/test/fixtures/companies.yml +7 -0
  168. data/vendor/geokit-rails/test/fixtures/custom_locations.yml +54 -0
  169. data/vendor/geokit-rails/test/fixtures/locations.yml +54 -0
  170. data/vendor/geokit-rails/test/fixtures/mock_addresses.yml +17 -0
  171. data/vendor/geokit-rails/test/fixtures/mock_families.yml +2 -0
  172. data/vendor/geokit-rails/test/fixtures/mock_houses.yml +9 -0
  173. data/vendor/geokit-rails/test/fixtures/mock_organizations.yml +5 -0
  174. data/vendor/geokit-rails/test/fixtures/mock_people.yml +5 -0
  175. data/vendor/geokit-rails/test/fixtures/stores.yml +0 -0
  176. data/vendor/geokit-rails/test/ip_geocode_lookup_test.rb +77 -0
  177. data/vendor/geokit-rails/test/models/company.rb +3 -0
  178. data/vendor/geokit-rails/test/models/custom_location.rb +12 -0
  179. data/vendor/geokit-rails/test/models/location.rb +4 -0
  180. data/vendor/geokit-rails/test/models/mock_address.rb +4 -0
  181. data/vendor/geokit-rails/test/models/mock_family.rb +3 -0
  182. data/vendor/geokit-rails/test/models/mock_house.rb +3 -0
  183. data/vendor/geokit-rails/test/models/mock_organization.rb +4 -0
  184. data/vendor/geokit-rails/test/models/mock_person.rb +4 -0
  185. data/vendor/geokit-rails/test/models/store.rb +3 -0
  186. data/vendor/geokit-rails/test/schema.rb +60 -0
  187. data/vendor/geokit-rails/test/tasks.rake +31 -0
  188. data/vendor/geokit-rails/test/test_helper.rb +23 -0
  189. metadata +444 -0
@@ -0,0 +1,10 @@
1
+ class ProductLine < ActiveRecord::Base
2
+ set_primary_key :ps_code
3
+
4
+ has_many :product_lines_sectors, :foreign_key => 'ps_code'
5
+ has_many :sectors, :through => :product_lines_sectors
6
+
7
+ data_miner do
8
+ tap "Brighter Planet's product line data", Earth.taps_server
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ ProductLine.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'ps_code'
5
+ string 'description'
6
+ string 'broadline' # FIXME TODO do we need this?
7
+ string 'parent' # FIXME TODO do we need this?
8
+ end
9
+
10
+ import "the U.S. Census list of Products and Services codes for the wholesale and retail trade sectors",
11
+ :url => 'http://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGxOUzBId0VuWTB0U0dOUHExOVlWTlE&hl=en&single=true&gid=0&output=csv' do
12
+ key 'ps_code'
13
+ store 'description'
14
+ store 'broadline'
15
+ store 'parent'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ class ProductLinesSectors < ActiveRecord::Base
2
+ set_primary_key :row_hash
3
+
4
+ belongs_to :product_line, :foreign_key => 'ps_code'
5
+ belongs_to :sector, :foreign_key => 'io_code'
6
+ end
@@ -0,0 +1,3 @@
1
+ class Sector < ActiveRecord::Base
2
+ set_primary_key :io_code
3
+ 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,17 @@
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
+ data_miner do
11
+ tap "Brighter Planet's sanitized census divisions", Earth.taps_server
12
+
13
+ process "pull dependencies" do
14
+ run_data_miner_on_belongs_to_associations
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,21 @@
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
+ end
9
+
10
+ import 'the U.S. Census Geographic Terms and Definitions',
11
+ :url => 'http://www.census.gov/popest/geographic/codes02.csv',
12
+ :skip => 9,
13
+ :select => lambda { |row| row['Division'].to_s.strip != 'X' and row['FIPS CODE STATE'].to_s.strip == 'X'} do
14
+ key 'number', :field_name => 'Division'
15
+ store 'name', :field_name => 'Name'
16
+ store 'census_region_number', :field_name => 'Region'
17
+ store 'census_region_name', :field_name => 'Region', :dictionary => { :input => 'number', :output => 'name', :url => 'http://data.brighterplanet.com/census_regions.csv' }
18
+ end
19
+ end
20
+ end
21
+
@@ -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
@@ -0,0 +1,19 @@
1
+ EgridRegion.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'name'
5
+ float 'loss_factor'
6
+ end
7
+
8
+ import "eGRID regions and loss factors derived from eGRID 2007 data",
9
+ :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
10
+ :filename => 'eGRID2007_Version1-1/eGRID2007V1_1_year0504_STIE_USGC.xls',
11
+ :sheet => 'STIE05',
12
+ :select => lambda { |row| row['eGRID2007 2005 file State sequence number'].to_i.between?(1, 51) },
13
+ :skip => 4 do
14
+ key 'name', :field_name => 'Grid region (E=Eastern grid, W=Western grid, AK=Alaska, HI=Hawaii, TX=Texas)'
15
+ store 'loss_factor', :field_name => '2005 grid gross loss factor'
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,16 @@
1
+ class EgridSubregion < ActiveRecord::Base
2
+ set_primary_key :abbreviation
3
+
4
+ has_many :zip_codes, :foreign_key => 'egrid_subregion_abbreviation'
5
+ belongs_to :egrid_region, :foreign_key => 'egrid_region_name'
6
+
7
+ falls_back_on :electricity_emission_factor => 1.404.pounds.to(:kilograms) # kg CO2 / kWh https://brighterplanet.sifterapp.com/projects/30/issues/437?return_uri=%2Fprojects%2F30%2Fissues%3Fa%3D79%26s%3D1-2
8
+
9
+ data_miner do
10
+ tap "Brighter Planet's egrid subregion data", Earth.taps_server
11
+
12
+ process "pull dependencies" do
13
+ run_data_miner_on_belongs_to_associations
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ EgridSubregion.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'abbreviation'
5
+ string 'name'
6
+ float 'electricity_emission_factor'
7
+ string 'electricity_emission_factor_units'
8
+ string 'nerc_abbreviation'
9
+ string 'egrid_region_name'
10
+ end
11
+
12
+ process "Define some unit conversions" do
13
+ Conversions.register :kilograms_per_kilowatt_hour, :kilograms_per_megawatt_hour, 1_000.0
14
+ end
15
+
16
+ import "a list of eGRID subregions and pre-calculated emissions factors",
17
+ :url => 'http://static.brighterplanet.com/science/data/electricity/egrid/models_export/egrid_subregions.csv' do
18
+ key 'abbreviation'
19
+ store 'name'
20
+ store 'electricity_emission_factor', :from_units => :kilograms_per_megawatt_hour, :to_units => :kilograms_per_kilowatt_hour
21
+ store 'nerc_abbreviation'
22
+ store 'egrid_region_name'
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,13 @@
1
+ class PetroleumAdministrationForDefenseDistrict < ActiveRecord::Base
2
+ set_primary_key :code
3
+
4
+ data_miner do
5
+ tap "Brighter Planet's PADD info", Earth.taps_server
6
+ end
7
+
8
+ def name
9
+ str = "PAD District #{district_code} (#{district_name})"
10
+ str << " Subdistrict #{district_code}#{subdistrict_code} (#{subdistrict_name})" if subdistrict_code
11
+ str
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ PetroleumAdministrationForDefenseDistrict.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'code'
5
+ string 'district_code'
6
+ string 'district_name'
7
+ string 'subdistrict_code'
8
+ string 'subdistrict_name'
9
+ end
10
+
11
+ import "a list of PADD districts and states derived from the EIA PADD definitions",
12
+ :url => 'http://spreadsheets.google.com/pub?key=t5HM1KbaRngmTUbntg8JwPA' do
13
+ key 'code', :field_name => 'Code'
14
+ store 'district_code', :field_name => 'PAD district code'
15
+ store 'subdistrict_code', :field_name => 'PAD subdistrict code'
16
+ store 'district_name', :field_name => 'PAD district name'
17
+ store 'subdistrict_name', :field_name => 'PAD subdistrict name'
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,22 @@
1
+ class State < ActiveRecord::Base
2
+ set_primary_key :postal_abbreviation
3
+
4
+ has_many :climate_divisions, :foreign_key => 'state_postal_abbreviation'
5
+ has_many :zip_codes, :foreign_key => 'state_postal_abbreviation'
6
+ belongs_to :census_division, :foreign_key => 'census_division_number'
7
+ belongs_to :petroleum_administration_for_defense_district, :foreign_key => 'petroleum_administration_for_defense_district_code'
8
+ has_one :census_region, :through => :census_division
9
+
10
+ def country
11
+ Country.united_states
12
+ end
13
+
14
+ data_miner do
15
+ tap "Brighter Planet's sanitized states", Earth.taps_server
16
+
17
+ process "pull dependencies" do
18
+ run_data_miner_on_belongs_to_associations
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,37 @@
1
+ State.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'postal_abbreviation'
5
+ integer 'fips_code'
6
+ string 'name'
7
+ string 'census_division_number'
8
+ string 'petroleum_administration_for_defense_district_code'
9
+ end
10
+
11
+ # state names, ansi codes, and postal abbreviations
12
+ import 'the U.S. Census State ANSI Code file',
13
+ :url => 'http://www.census.gov/geo/www/ansi/state.txt',
14
+ :delimiter => '|' do
15
+ key 'postal_abbreviation', :field_name => 'STUSAB'
16
+ store 'fips_code', :field_name => 'STATE'
17
+ store 'name', :field_name => 'STATE_NAME'
18
+ end
19
+
20
+ # census divisions
21
+ import 'the U.S. Census Geographic Terms and Definitions',
22
+ :url => 'http://www.census.gov/popest/geographic/codes02.csv',
23
+ :skip => 9,
24
+ :select => lambda { |row| row['FIPS CODE STATE'].to_s.strip != 'X' and row['FIPS CODE COUNTY'].to_s.strip == 'X'} do
25
+ key 'fips_code', :field_name => 'FIPS CODE STATE'
26
+ store 'census_division_number', :field_name => 'Division'
27
+ end
28
+
29
+ # PADD
30
+ import 'a list of state Petroleum Administration for Defense Districts',
31
+ :url => 'http://spreadsheets.google.com/pub?key=t5HM1KbaRngmTUbntg8JwPA' do
32
+ key 'postal_abbreviation', :field_name => 'State'
33
+ store 'petroleum_administration_for_defense_district_code', :field_name => 'Code'
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,20 @@
1
+ class Urbanity < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ has_many :residences
5
+ has_many :residential_energy_consumption_survey_responses
6
+
7
+ data_miner do
8
+ schema do
9
+ string :name
10
+ end
11
+
12
+ process "derive from ResidentialEnergyConsumptionSurveyResponse" do
13
+ ResidentialEnergyConsumptionSurveyResponse.run_data_miner!
14
+ connection.execute %{
15
+ INSERT IGNORE INTO urbanities(name)
16
+ SELECT DISTINCT residential_energy_consumption_survey_responses.urbanity_id FROM residential_energy_consumption_survey_responses WHERE LENGTH(residential_energy_consumption_survey_responses.urbanity_id) > 0
17
+ }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ Urbanity.class_eval do
2
+ # data_miner do
3
+ #...
4
+ end