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,29 @@
1
+ class ZipCode < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ belongs_to :egrid_subregion, :foreign_key => 'egrid_subregion_abbreviation'
5
+ belongs_to :climate_division, :foreign_key => 'climate_division_name'
6
+ belongs_to :state, :foreign_key => 'state_postal_abbreviation'
7
+ # has_one :census_division, :through => :state
8
+ # has_one :census_region, :through => :state
9
+ has_many :residences
10
+
11
+
12
+ acts_as_mappable :default_units => :miles, # FIXME imperial
13
+ :lat_column_name => :latitude,
14
+ :lng_column_name => :longitude
15
+
16
+ def set_latitude_and_longitude
17
+ return if latitude.present? and longitude.present?
18
+ a = Geokit::Geocoders::YahooGeocoder.geocode name
19
+ update_attributes! :latitude => a.lat, :longitude => a.lng
20
+ end
21
+
22
+ data_miner do
23
+ tap "Brighter Planet's sanitized zip codes", Earth.taps_server
24
+
25
+ process "pull dependencies" do
26
+ run_data_miner_on_belongs_to_associations
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+ ZipCode.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'name'
5
+ string 'state_postal_abbreviation'
6
+ string 'description'
7
+ string 'latitude'
8
+ string 'longitude'
9
+ string 'egrid_subregion_abbreviation'
10
+ string 'climate_division_name'
11
+ end
12
+
13
+ import 'the Mapping Hacks zipcode database',
14
+ :url => 'http://mappinghacks.com/data/zipcode.zip',
15
+ :filename => 'zipcode.csv' do
16
+ key 'name', :field_name => 'zip', :sprintf => '%05d'
17
+ store 'state_postal_abbreviation', :field_name => 'state'
18
+ store 'description', :field_name => 'city'
19
+ store 'latitude'
20
+ store 'longitude'
21
+ end
22
+
23
+ import 'a list of zipcodes and eGRID Subregions',
24
+ :url => 'http://static.brighterplanet.com/science/data/electricity/egrid/models_export/zip_subregions.csv' do
25
+ key 'name', :field_name => 'zip', :sprintf => '%05d'
26
+ store 'egrid_subregion_abbreviation', :field_name => 'primary_subregion'
27
+ end
28
+
29
+ import 'a list of zipcodes and Climate Divisions',
30
+ :url => 'http://static.brighterplanet.com/science/data/geography/zip_code_name-climate_division_name.csv' do
31
+ key 'name', :field_name => 'zip_code_name', :sprintf => '%05d'
32
+ store 'climate_division_name'
33
+ end
34
+ end
35
+ end
36
+
data/lib/earth/pet.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'earth/pet/breed'
2
+ require 'earth/pet/breed_gender'
3
+ require 'earth/pet/gender'
4
+ require 'earth/pet/species'
@@ -0,0 +1,15 @@
1
+ class Breed < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ has_many :pets, :foreign_key => 'breed_id'
5
+ has_many :breed_genders, :foreign_key => 'breed_name'
6
+ belongs_to :species, :foreign_key => 'species_name'
7
+
8
+ data_miner do
9
+ tap "Brighter Planet's breed data", Earth.taps_server
10
+
11
+ process "pull dependencies" do
12
+ run_data_miner_on_belongs_to_associations
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ Breed.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'name'
5
+ string 'species_name'
6
+ float 'weight'
7
+ string 'weight_units'
8
+ end
9
+
10
+ import "Brighter Planet's list of cat and dog breeds",
11
+ :url => 'http://static.brighterplanet.com/science/data/consumables/pets/breed_genders.csv',
12
+ :encoding => 'ISO-8859-1',
13
+ :select => lambda { |row| row['gender'].blank? } do
14
+ key 'name'
15
+ store 'species_name', :field_name => 'species'
16
+ store 'weight', :from_units => :pounds, :to_units => :kilograms
17
+ end
18
+
19
+ import "a list of horse breeds", :url => 'http://www.freebase.com/type/exporttypeinstances/base/horses/horse_breed?page=0&filter_mode=type&filter_view=table&show%01p%3D%2Ftype%2Fobject%2Fname%01index=0&show%01p%3D%2Fcommon%2Ftopic%2Fimage%01index=1&show%01p%3D%2Fcommon%2Ftopic%2Farticle%01index=2&sort%01p%3D%2Ftype%2Fobject%2Ftype%01p%3Dlink%01p%3D%2Ftype%2Flink%2Ftimestamp%01index=false&=&exporttype=csv-8' do
20
+ key 'name'
21
+ store 'species_name', :static => 'horse'
22
+ end
23
+ end
24
+ end
25
+
@@ -0,0 +1,14 @@
1
+ class BreedGender < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ belongs_to :breed, :foreign_key => 'breed_name'
5
+ belongs_to :gender, :foreign_key => 'gender_name'
6
+
7
+ data_miner do
8
+ tap "Brighter Planet's breed gender data", Earth.taps_server
9
+
10
+ process "pull dependencies" do
11
+ run_data_miner_on_belongs_to_associations
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ BreedGender.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'name'
5
+ string 'breed_name'
6
+ string 'gender_name'
7
+ float 'weight'
8
+ string 'weight_units'
9
+ end
10
+
11
+ import "Brighter Planet's list of cat and dog breeds, genders, and weights",
12
+ :url => 'http://static.brighterplanet.com/science/data/consumables/pets/breed_genders.csv',
13
+ :select => lambda { |row| row['gender'].present? } do
14
+ key 'name', :synthesize => lambda { |row| row['name'] + ' ' + row['gender'] }
15
+ store 'breed_name', :field_name => 'name'
16
+ store 'gender_name', :field_name => 'gender'
17
+ store 'weight', :from_units => :pounds, :to_units => :kilograms
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,4 @@
1
+ require 'earth/pet/breed/data_miner'
2
+ require 'earth/pet/breed_gender/data_miner'
3
+ require 'earth/pet/gender/data_miner'
4
+ require 'earth/pet/species/data_miner'
@@ -0,0 +1,10 @@
1
+ class Gender < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ has_many :pets
5
+ has_many :breed_genders, :foreign_key => 'gender_name'
6
+
7
+ data_miner do
8
+ tap "Brighter Planet's gender info", Earth.taps_server
9
+ end
10
+ end
@@ -0,0 +1,13 @@
1
+ Gender.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'name'
5
+ end
6
+ import "a list of genders derived from pet breed genders",
7
+ :url => 'http://static.brighterplanet.com/science/data/consumables/pets/breed_genders.csv',
8
+ :select => lambda { |row| row['gender'].present? } do
9
+ key 'name', :field_name => 'gender'
10
+ end
11
+ end
12
+ end
13
+
@@ -0,0 +1,40 @@
1
+ class Species < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ has_many :pets
5
+
6
+ scope :thoroughly_researched, :conditions => 'marginal_dietary_requirement IS NOT NULL'
7
+
8
+ falls_back_on :diet_emission_intensity => lambda { weighted_average :diet_emission_intensity, :weighted_by => :population }, # kg CO2 / joule
9
+ :marginal_dietary_requirement => lambda { (thoroughly_researched.map(&:weighted_diet_size).sum / thoroughly_researched.sum(:population) ) / thoroughly_researched.weighted_average(:weight, :weighted_by => :population)}, # joules
10
+ :fixed_dietary_requirement => 0, # force a zero intercept to be respectful of our tiny tiny animal friends
11
+ :weight => lambda { weighted_average :weight, :weighted_by => :population } # kg
12
+
13
+ data_miner do
14
+ tap "Brighter Planet's species data", Earth.taps_server
15
+ end
16
+
17
+ class << self
18
+ def [](name)
19
+ find_by_name name.to_s
20
+ end
21
+ end
22
+
23
+ def diet_size
24
+ return unless weight and marginal_dietary_requirement and fixed_dietary_requirement
25
+ weight * marginal_dietary_requirement + fixed_dietary_requirement
26
+ end
27
+
28
+ def weighted_diet_size
29
+ return unless _diet_size = diet_size and _population = population
30
+ _diet_size * _population
31
+ end
32
+
33
+ def to_s
34
+ name
35
+ end
36
+
37
+ def cat?
38
+ eql? self.class[:cat]
39
+ end
40
+ end
@@ -0,0 +1,42 @@
1
+ Species.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'name'
5
+ integer 'population'
6
+ float 'diet_emission_intensity'
7
+ string 'diet_emission_intensity_units'
8
+ float 'weight'
9
+ string 'weight_units'
10
+ float 'marginal_dietary_requirement'
11
+ string 'marginal_dietary_requirement_units'
12
+ float 'fixed_dietary_requirement'
13
+ string 'fixed_dietary_requirement_units'
14
+ float 'minimum_weight'
15
+ string 'minimum_weight_units'
16
+ float 'maximum_weight'
17
+ string 'maximum_weight_units'
18
+ end
19
+
20
+ process "Define some unit conversions" do
21
+ # 1 (kilocalories per pound) = 9 224.14105 joules per kilogram
22
+ Conversions.register :kilocalories_per_pound, :joules_per_kilogram, 9_224.14105
23
+ # 1 (grams per kilocalories) = 2.39005736 × 10-7 kilograms per joules
24
+ Conversions.register :grams_per_kilocalorie, :kilograms_per_joule, 2.39005736e-7
25
+ # 1 joule = 0.000239005736 kilocalories
26
+ Conversions.register :joules, :kilocalories, 0.000239005736
27
+ end
28
+
29
+ import "a list of pet species weights, dietary requirements, and diet emissions intensities",
30
+ :url => 'http://static.brighterplanet.com/science/data/consumables/pets/species.csv' do
31
+ key 'name', :field_name => 'species'
32
+ store 'population'
33
+ store 'weight', :from_units => :pounds, :to_units => :kilograms
34
+ store 'marginal_dietary_requirement', :from_units => :kilocalories_per_pound, :to_units => :joules_per_kilogram
35
+ store 'fixed_dietary_requirement', :from_units => :kilocalories, :to_units => :joules
36
+ store 'diet_emission_intensity', :from_units => :grams_per_kilocalorie, :to_units => :kilograms_per_joule
37
+ store 'minimum_weight', :from_units => :pounds, :to_units => :kilograms
38
+ store 'maximum_weight', :from_units => :pounds, :to_units => :kilograms
39
+ end
40
+ end
41
+ end
42
+
data/lib/earth/rail.rb ADDED
@@ -0,0 +1 @@
1
+ require 'earth/rail/rail_class'
@@ -0,0 +1 @@
1
+ require 'earth/rail/rail_class/data_miner'
@@ -0,0 +1,16 @@
1
+ class RailClass < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ has_many :rail_trips
5
+
6
+ data_miner do
7
+ tap "Brighter Planet's rail class data", Earth.taps_server
8
+ end
9
+
10
+ # speed is missing
11
+ # https://brighterplanet.sifterapp.com/projects/30/issues/455
12
+ falls_back_on :passengers => 25.06,
13
+ :distance => 8.57.miles.to(:kilometres),
14
+ :diesel_intensity => 0.05.gallons_per_mile.to(:litres_per_kilometre),
15
+ :electricity_intensity => 8.89.miles.to(:kilometres)
16
+ end
@@ -0,0 +1,36 @@
1
+ RailClass.class_eval do
2
+ data_miner do
3
+ schema Earth.database_options do
4
+ string 'name'
5
+ float 'distance'
6
+ string 'distance_units'
7
+ float 'passengers'
8
+ float 'speed'
9
+ string 'speed_units'
10
+ float 'duration'
11
+ string 'duration_units'
12
+ float 'electricity_intensity'
13
+ string 'electricity_intensity_units'
14
+ float 'diesel_intensity'
15
+ string 'diesel_intensity_units'
16
+ string 'description'
17
+ end
18
+
19
+ process "Define some unit conversions" do
20
+ Conversions.register :gallons_per_mile, :litres_per_kilometre, 2.35214583
21
+ end
22
+
23
+ import "a list of rail classes and pre-calculated trip and fuel use characteristics",
24
+ :url => 'http://static.brighterplanet.com/science/data/transport/rail/rail_classes.csv' do
25
+ key 'name'
26
+ store 'description'
27
+ store 'distance', :from_units => :miles, :to_units => :kilometres
28
+ store 'speed', :from_units => :miles, :to_units => :kilometres
29
+ store 'duration'
30
+ store 'passengers'
31
+ store 'electricity_intensity', :field_name => 'electricity_per_vehicle_mile', :from_units => :miles, :to_units => :kilometres
32
+ store 'diesel_intensity', :field_name => 'diesel_per_vehicle_mile', :from_units => :gallons_per_mile, :to_units => :litres_per_kilometre
33
+ end
34
+ end
35
+ end
36
+
@@ -0,0 +1,8 @@
1
+ require 'earth/residence/air_conditioner_use'
2
+ require 'earth/residence/clothes_machine_use'
3
+ require 'earth/residence/dishwasher_use'
4
+ require 'earth/residence/residence_appliance'
5
+ require 'earth/residence/residence_class'
6
+ require 'earth/residence/residence_fuel_price'
7
+ require 'earth/residence/residence_fuel_type'
8
+ require 'earth/residence/residential_energy_consumption_survey_response'
@@ -0,0 +1,30 @@
1
+ class AirConditionerUse < ActiveRecord::Base
2
+ set_primary_key :name
3
+
4
+ has_many :residences
5
+ has_many :residential_energy_consumption_survey_responses
6
+
7
+ falls_back_on :fugitive_emission => 0.102295.pounds_per_square_foot.to(:kilograms_per_square_metre), # https://brighterplanet.sifterapp.com/projects/30/issues/430
8
+ :fugitive_emission_units => 'kilograms_per_square_metre'
9
+
10
+ data_miner do
11
+ schema do
12
+ string 'name'
13
+ float 'fugitive_emission'
14
+ string 'fugitive_emission_units'
15
+ end
16
+
17
+ process "derive from ResidentialEnergyConsumptionSurveyResponse" do
18
+ ResidentialEnergyConsumptionSurveyResponse.run_data_miner!
19
+ connection.execute %{
20
+ INSERT IGNORE INTO air_conditioner_uses(name)
21
+ SELECT DISTINCT residential_energy_consumption_survey_responses.central_ac_use FROM residential_energy_consumption_survey_responses WHERE LENGTH(residential_energy_consumption_survey_responses.central_ac_use) > 0
22
+ }
23
+ end
24
+
25
+ import "Ian's precalculated fugitive emissions values", :url => 'http://spreadsheets.google.com/pub?key=ri_380yQZAqBKeqie_TECgg' do
26
+ key 'name', :field_name => 'air_conditioner_use_name'
27
+ store 'fugitive_emission', :units_field_name => 'unit', :to_units => :kilograms_per_square_metre
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ AirConditionerUse.class_eval do
2
+ # data_miner do
3
+ #...
4
+ end
@@ -0,0 +1,33 @@
1
+ class ClothesMachineUse < 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
+ float 'annual_energy_from_electricity_for_clothes_driers'
11
+ string 'annual_energy_from_electricity_for_clothes_driers_units'
12
+ end
13
+
14
+ process "derive from ResidentialEnergyConsumptionSurveyResponse" do
15
+ ResidentialEnergyConsumptionSurveyResponse.run_data_miner!
16
+ connection.execute %{
17
+ INSERT IGNORE INTO clothes_machine_uses(name)
18
+ SELECT DISTINCT residential_energy_consumption_survey_responses.clothes_washer_use FROM residential_energy_consumption_survey_responses WHERE LENGTH(residential_energy_consumption_survey_responses.clothes_washer_use) > 0
19
+ }
20
+ end
21
+
22
+ # sabshere 5/20/10 weird that this uses cohort
23
+ process "precalculate annual energy use" do
24
+ find_in_batches do |batch|
25
+ batch.each do |record|
26
+ record.annual_energy_from_electricity_for_clothes_driers = ResidentialEnergyConsumptionSurveyResponse.big_cohort(:clothes_machine_use => record).weighted_average :annual_energy_from_electricity_for_clothes_driers
27
+ record.annual_energy_from_electricity_for_clothes_driers_units = 'joules'
28
+ record.save!
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,4 @@
1
+ ClothesMachineUse.class_eval do
2
+ # data_miner do
3
+ #...
4
+ end
@@ -0,0 +1,8 @@
1
+ require 'earth/residence/air_conditioner_use/data_miner'
2
+ require 'earth/residence/clothes_machine_use/data_miner'
3
+ require 'earth/residence/dishwasher_use/data_miner'
4
+ require 'earth/residence/residence_appliance/data_miner'
5
+ require 'earth/residence/residence_class/data_miner'
6
+ require 'earth/residence/residence_fuel_price/data_miner'
7
+ require 'earth/residence/residence_fuel_type/data_miner'
8
+ require 'earth/residence/residential_energy_consumption_survey_response/data_miner'
@@ -0,0 +1,33 @@
1
+ class DishwasherUse < 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
+ float 'annual_energy_from_electricity_for_dishwashers'
11
+ string 'annual_energy_from_electricity_for_dishwashers_units'
12
+ end
13
+
14
+ process "derive from ResidentialEnergyConsumptionSurveyResponse" do
15
+ ResidentialEnergyConsumptionSurveyResponse.run_data_miner!
16
+ connection.execute %{
17
+ INSERT IGNORE INTO dishwasher_uses(name)
18
+ SELECT DISTINCT residential_energy_consumption_survey_responses.dishwasher_use_id FROM residential_energy_consumption_survey_responses WHERE LENGTH(residential_energy_consumption_survey_responses.dishwasher_use_id) > 0
19
+ }
20
+ end
21
+
22
+ # sabshere 5/25/10 weird that this uses cohort
23
+ process "precalculate annual energy" do
24
+ find_in_batches do |batch|
25
+ batch.each do |record|
26
+ record.annual_energy_from_electricity_for_dishwashers = ResidentialEnergyConsumptionSurveyResponse.big_cohort(:dishwasher_use => record).weighted_average :annual_energy_from_electricity_for_dishwashers
27
+ record.annual_energy_from_electricity_for_dishwashers_units = 'joules'
28
+ record.save!
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end