earth-ruby19 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +5 -0
- data/Gemfile.lock +138 -0
- data/LICENSE +20 -0
- data/README.markdown +38 -0
- data/lib/earth.rb +146 -0
- data/lib/earth/active_record_ext.rb +9 -0
- data/lib/earth/air.rb +13 -0
- data/lib/earth/air/aircraft.rb +21 -0
- data/lib/earth/air/aircraft/data_miner.rb +184 -0
- data/lib/earth/air/aircraft_class.rb +10 -0
- data/lib/earth/air/aircraft_class/data_miner.rb +42 -0
- data/lib/earth/air/aircraft_manufacturer.rb +9 -0
- data/lib/earth/air/aircraft_manufacturer/data_miner.rb +20 -0
- data/lib/earth/air/airline.rb +16 -0
- data/lib/earth/air/airline/data_miner.rb +57 -0
- data/lib/earth/air/airport.rb +44 -0
- data/lib/earth/air/airport/data_miner.rb +80 -0
- data/lib/earth/air/data_miner.rb +15 -0
- data/lib/earth/air/flight_configuration.rb +7 -0
- data/lib/earth/air/flight_configuration/data_miner.rb +16 -0
- data/lib/earth/air/flight_distance_class.rb +7 -0
- data/lib/earth/air/flight_distance_class/data_miner.rb +16 -0
- data/lib/earth/air/flight_domesticity.rb +6 -0
- data/lib/earth/air/flight_domesticity/data_miner.rb +57 -0
- data/lib/earth/air/flight_fuel_type.rb +12 -0
- data/lib/earth/air/flight_fuel_type/data_miner.rb +12 -0
- data/lib/earth/air/flight_propulsion.rb +7 -0
- data/lib/earth/air/flight_propulsion/data_miner.rb +16 -0
- data/lib/earth/air/flight_seat_class.rb +12 -0
- data/lib/earth/air/flight_seat_class/data_miner.rb +36 -0
- data/lib/earth/air/flight_segment.rb +29 -0
- data/lib/earth/air/flight_segment/data_miner.rb +330 -0
- data/lib/earth/air/flight_service.rb +7 -0
- data/lib/earth/air/flight_service/data_miner.rb +16 -0
- data/lib/earth/all.rb +11 -0
- data/lib/earth/automobile.rb +8 -0
- data/lib/earth/automobile/automobile_fuel_type.rb +18 -0
- data/lib/earth/automobile/automobile_fuel_type/data_miner.rb +45 -0
- data/lib/earth/automobile/automobile_make.rb +14 -0
- data/lib/earth/automobile/automobile_make/data_miner.rb +68 -0
- data/lib/earth/automobile/automobile_make_fleet_year.rb +15 -0
- data/lib/earth/automobile/automobile_make_fleet_year/data_miner.rb +29 -0
- data/lib/earth/automobile/automobile_make_year.rb +14 -0
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +45 -0
- data/lib/earth/automobile/automobile_model.rb +14 -0
- data/lib/earth/automobile/automobile_model/data_miner.rb +38 -0
- data/lib/earth/automobile/automobile_model_year.rb +15 -0
- data/lib/earth/automobile/automobile_model_year/data_miner.rb +51 -0
- data/lib/earth/automobile/automobile_size_class.rb +14 -0
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +43 -0
- data/lib/earth/automobile/automobile_variant.rb +17 -0
- data/lib/earth/automobile/automobile_variant/data_miner.rb +460 -0
- data/lib/earth/automobile/data_miner.rb +8 -0
- data/lib/earth/base.rb +7 -0
- data/lib/earth/bus.rb +1 -0
- data/lib/earth/bus/bus_class.rb +19 -0
- data/lib/earth/bus/bus_class/data_miner.rb +41 -0
- data/lib/earth/bus/data_miner.rb +1 -0
- data/lib/earth/conversions_ext.rb +45 -0
- data/lib/earth/data_miner.rb +10 -0
- data/lib/earth/diet.rb +2 -0
- data/lib/earth/diet/data_miner.rb +2 -0
- data/lib/earth/diet/diet_class.rb +15 -0
- data/lib/earth/diet/diet_class/data_miner.rb +36 -0
- data/lib/earth/diet/food_group.rb +17 -0
- data/lib/earth/diet/food_group/data_miner.rb +26 -0
- data/lib/earth/fuel.rb +2 -0
- data/lib/earth/fuel/data_miner.rb +2 -0
- data/lib/earth/fuel/fuel_price.rb +13 -0
- data/lib/earth/fuel/fuel_price/data_miner.rb +20 -0
- data/lib/earth/fuel/fuel_type.rb +18 -0
- data/lib/earth/fuel/fuel_type/data_miner.rb +37 -0
- data/lib/earth/hospitality.rb +1 -0
- data/lib/earth/hospitality/data_miner.rb +1 -0
- data/lib/earth/hospitality/lodging_class.rb +9 -0
- data/lib/earth/hospitality/lodging_class/data_miner.rb +30 -0
- data/lib/earth/industry.rb +10 -0
- data/lib/earth/industry/industry.rb +23 -0
- data/lib/earth/industry/industry_product.rb +22 -0
- data/lib/earth/industry/industry_product_line.rb +20 -0
- data/lib/earth/industry/industry_sector.rb +20 -0
- data/lib/earth/industry/merchant.rb +18 -0
- data/lib/earth/industry/merchant_category.rb +22 -0
- data/lib/earth/industry/merchant_category_industry.rb +20 -0
- data/lib/earth/industry/product_line.rb +22 -0
- data/lib/earth/industry/product_line_industry_product.rb +20 -0
- data/lib/earth/industry/sector.rb +19 -0
- data/lib/earth/inflectors.rb +9 -0
- data/lib/earth/locality.rb +10 -0
- data/lib/earth/locality/census_division.rb +22 -0
- data/lib/earth/locality/census_division/data_miner.rb +64 -0
- data/lib/earth/locality/census_region.rb +13 -0
- data/lib/earth/locality/census_region/data_miner.rb +17 -0
- data/lib/earth/locality/climate_division.rb +17 -0
- data/lib/earth/locality/climate_division/data_miner.rb +20 -0
- data/lib/earth/locality/country.rb +13 -0
- data/lib/earth/locality/country/data_miner.rb +19 -0
- data/lib/earth/locality/data_miner.rb +10 -0
- data/lib/earth/locality/egrid_region.rb +15 -0
- data/lib/earth/locality/egrid_region/data_miner.rb +35 -0
- data/lib/earth/locality/egrid_subregion.rb +16 -0
- data/lib/earth/locality/egrid_subregion/data_miner.rb +65 -0
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +13 -0
- data/lib/earth/locality/petroleum_administration_for_defense_district/data_miner.rb +21 -0
- data/lib/earth/locality/state.rb +22 -0
- data/lib/earth/locality/state/data_miner.rb +37 -0
- data/lib/earth/locality/urbanity.rb +10 -0
- data/lib/earth/locality/urbanity/data_miner.rb +15 -0
- data/lib/earth/locality/zip_code.rb +23 -0
- data/lib/earth/locality/zip_code/data_miner.rb +43 -0
- data/lib/earth/pet.rb +4 -0
- data/lib/earth/pet/breed.rb +15 -0
- data/lib/earth/pet/breed/data_miner.rb +25 -0
- data/lib/earth/pet/breed_gender.rb +14 -0
- data/lib/earth/pet/breed_gender/data_miner.rb +21 -0
- data/lib/earth/pet/data_miner.rb +4 -0
- data/lib/earth/pet/gender.rb +10 -0
- data/lib/earth/pet/gender/data_miner.rb +13 -0
- data/lib/earth/pet/species.rb +40 -0
- data/lib/earth/pet/species/data_miner.rb +42 -0
- data/lib/earth/rail.rb +1 -0
- data/lib/earth/rail/data_miner.rb +1 -0
- data/lib/earth/rail/rail_class.rb +16 -0
- data/lib/earth/rail/rail_class/data_miner.rb +36 -0
- data/lib/earth/residence.rb +8 -0
- data/lib/earth/residence/air_conditioner_use.rb +13 -0
- data/lib/earth/residence/air_conditioner_use/data_miner.rb +22 -0
- data/lib/earth/residence/clothes_machine_use.rb +10 -0
- data/lib/earth/residence/clothes_machine_use/data_miner.rb +28 -0
- data/lib/earth/residence/data_miner.rb +8 -0
- data/lib/earth/residence/dishwasher_use.rb +10 -0
- data/lib/earth/residence/dishwasher_use/data_miner.rb +28 -0
- data/lib/earth/residence/residence_appliance.rb +16 -0
- data/lib/earth/residence/residence_appliance/data_miner.rb +20 -0
- data/lib/earth/residence/residence_class.rb +16 -0
- data/lib/earth/residence/residence_class/data_miner.rb +15 -0
- data/lib/earth/residence/residence_fuel_price.rb +18 -0
- data/lib/earth/residence/residence_fuel_price/data_miner.rb +200 -0
- data/lib/earth/residence/residence_fuel_type.rb +32 -0
- data/lib/earth/residence/residence_fuel_type/data_miner.rb +18 -0
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +39 -0
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +283 -0
- data/spec/lib/earth_spec.rb +25 -0
- data/spec/spec_helper.rb +11 -0
- data/vendor/geokit-rails/CHANGELOG.rdoc +46 -0
- data/vendor/geokit-rails/MIT-LICENSE +20 -0
- data/vendor/geokit-rails/README.markdown +561 -0
- data/vendor/geokit-rails/Rakefile +18 -0
- data/vendor/geokit-rails/about.yml +9 -0
- data/vendor/geokit-rails/assets/api_keys_template +61 -0
- data/vendor/geokit-rails/init.rb +1 -0
- data/vendor/geokit-rails/install.rb +14 -0
- data/vendor/geokit-rails/lib/geokit-rails.rb +24 -0
- data/vendor/geokit-rails/lib/geokit-rails/acts_as_mappable.rb +456 -0
- data/vendor/geokit-rails/lib/geokit-rails/adapters/abstract.rb +31 -0
- data/vendor/geokit-rails/lib/geokit-rails/adapters/mysql.rb +22 -0
- data/vendor/geokit-rails/lib/geokit-rails/adapters/postgresql.rb +22 -0
- data/vendor/geokit-rails/lib/geokit-rails/adapters/sqlserver.rb +43 -0
- data/vendor/geokit-rails/lib/geokit-rails/defaults.rb +22 -0
- data/vendor/geokit-rails/lib/geokit-rails/geocoder_control.rb +16 -0
- data/vendor/geokit-rails/lib/geokit-rails/ip_geocode_lookup.rb +46 -0
- data/vendor/geokit-rails/test/acts_as_mappable_test.rb +474 -0
- data/vendor/geokit-rails/test/boot.rb +25 -0
- data/vendor/geokit-rails/test/database.yml +20 -0
- data/vendor/geokit-rails/test/fixtures/companies.yml +7 -0
- data/vendor/geokit-rails/test/fixtures/custom_locations.yml +54 -0
- data/vendor/geokit-rails/test/fixtures/locations.yml +54 -0
- data/vendor/geokit-rails/test/fixtures/mock_addresses.yml +17 -0
- data/vendor/geokit-rails/test/fixtures/mock_families.yml +2 -0
- data/vendor/geokit-rails/test/fixtures/mock_houses.yml +9 -0
- data/vendor/geokit-rails/test/fixtures/mock_organizations.yml +5 -0
- data/vendor/geokit-rails/test/fixtures/mock_people.yml +5 -0
- data/vendor/geokit-rails/test/fixtures/stores.yml +0 -0
- data/vendor/geokit-rails/test/ip_geocode_lookup_test.rb +77 -0
- data/vendor/geokit-rails/test/models/company.rb +3 -0
- data/vendor/geokit-rails/test/models/custom_location.rb +12 -0
- data/vendor/geokit-rails/test/models/location.rb +4 -0
- data/vendor/geokit-rails/test/models/mock_address.rb +4 -0
- data/vendor/geokit-rails/test/models/mock_family.rb +3 -0
- data/vendor/geokit-rails/test/models/mock_house.rb +3 -0
- data/vendor/geokit-rails/test/models/mock_organization.rb +4 -0
- data/vendor/geokit-rails/test/models/mock_person.rb +4 -0
- data/vendor/geokit-rails/test/models/store.rb +3 -0
- data/vendor/geokit-rails/test/schema.rb +60 -0
- data/vendor/geokit-rails/test/tasks.rake +31 -0
- data/vendor/geokit-rails/test/test_helper.rb +23 -0
- metadata +476 -0
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
# NOTE: the following import uses an 18 Mb zip - don't know if two imports will cause it to be downloaded twice...
|
|
9
|
+
#
|
|
10
|
+
# import "eGRID regions and loss factors derived from eGRID 2007 data",
|
|
11
|
+
# :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
|
|
12
|
+
# :filename => 'eGRID2007_Version1-1/eGRID2007V1_1_year0504_STIE_USGC.xls',
|
|
13
|
+
# :sheet => 'STIE05',
|
|
14
|
+
# :skip => 4,
|
|
15
|
+
# :select => lambda { |row| row['eGRID2007 2005 file State sequence number'].to_i.between?(1, 51) } do
|
|
16
|
+
# key 'name', :field_name => 'Grid region (E=Eastern grid, W=Western grid, AK=Alaska, HI=Hawaii, TX=Texas)'
|
|
17
|
+
# store 'loss_factor', :field_name => '2005 grid gross loss factor'
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# import "the US average grid loss factor derived eGRID 2007 data"
|
|
21
|
+
# :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
|
|
22
|
+
# :filename => 'eGRID2007_Version1-1/eGRID2007V1_1_year0504_STIE_USGC.xls',
|
|
23
|
+
# :sheet => 'USGC',
|
|
24
|
+
# :skip => 5 do
|
|
25
|
+
# key # the name should be 'US'
|
|
26
|
+
# store # store the result of (USTNGN05 + USTNFI05 - USTCON05) / USTNGN05
|
|
27
|
+
# end
|
|
28
|
+
|
|
29
|
+
import "eGRID regions and loss factors derived from eGRID 2007 data",
|
|
30
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHoydC1MdDY0YVZkRE5zN0huOUZYbnc&hl=en&single=true&gid=0&output=csv' do
|
|
31
|
+
key 'name'
|
|
32
|
+
store 'loss_factor'
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -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,65 @@
|
|
|
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 :pounds_per_megawatt_hour, :kilograms_per_kilowatt_hour, 0.00045359237
|
|
14
|
+
# Conversions.register :pounds_per_gigawatt_hour, :kilograms_per_kilowatt_hour, 0.00000045359237
|
|
15
|
+
# end
|
|
16
|
+
#
|
|
17
|
+
# NOTE: the following import uses an 18 Mb zip - don't know if two imports will cause it to be downloaded twice...
|
|
18
|
+
#
|
|
19
|
+
# import "eGRID regions and electricity emission factors derived from eGRID 2007 data",
|
|
20
|
+
# :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
|
|
21
|
+
# :filename => 'eGRID2007V1_1_year05_aggregation.xls',
|
|
22
|
+
# :sheet => 'SRL05',
|
|
23
|
+
# :skip => 3,
|
|
24
|
+
# :select => lambda { |row| row['eGRID2007 2005 file eGRID subregion location (operator)-based sequence number'].to_i.between?(1, 26) } do
|
|
25
|
+
# key 'abbreviation', :field_name => 'eGRID subregion acronym'
|
|
26
|
+
# store 'name', :field_name => 'eGRID subregion name associated with eGRID subregion acronym'
|
|
27
|
+
# store 'nerc_abbreviation', :field_name => 'NERC region acronym associated with the eGRID subregion acronym'
|
|
28
|
+
# store 'electricity_ef_co2', :field_name => 'eGRID subregion annual CO2 output emission rate (lb/MWh)', :from_units => :pounds_per_megawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
|
29
|
+
# store 'electricity_ef_ch4', :field_name => 'eGRID subregion annual CH4 output emission rate (lb/GWh)', :from_units => :pounds_per_gigawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
|
30
|
+
# store 'electricity_ef_n2o', :field_name => 'eGRID subregion annual N2O output emission rate (lb/GWh)', :from_units => :pounds_per_gigawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
|
31
|
+
# end
|
|
32
|
+
#
|
|
33
|
+
# import "US average electricity emission factors derived from eGRID 2007 data",
|
|
34
|
+
# :url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2007_Version1-1.zip',
|
|
35
|
+
# :filename => 'eGRID2007V1_1_year05_aggregation.xls',
|
|
36
|
+
# :sheet => 'US05',
|
|
37
|
+
# :skip => 3,
|
|
38
|
+
# :select => lambda { |row| row['eGRID2007 2005 file US sequence number'].to_i.is?(1) } do
|
|
39
|
+
# key # the single row should be keyed 'US'
|
|
40
|
+
# store 'name' # the single row should be named 'United States Average'
|
|
41
|
+
# store 'electricity_ef_co2', :field_name => 'US annual CO2 output emission rate (lb/MWh)', :from_units => :pounds_per_megawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
|
42
|
+
# store 'electricity_ef_ch4', :field_name => 'US annual CH4 output emission rate (lb/GWh)', :from_units => :pounds_per_gigawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
|
43
|
+
# store 'electricity_ef_n2o', :field_name => 'US annual N2O output emission rate (lb/GWh)', :from_units => :pounds_per_gigawatt_hour, :to_units => :kilograms_per_kilowatt_hour
|
|
44
|
+
# end
|
|
45
|
+
#
|
|
46
|
+
# import "the eGRID regions associated with each subregion" do
|
|
47
|
+
# :url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGRORTJNSWRMQ1puRVprYlAtZHhDaFE&hl=en&single=true&gid=0&output=csv' do
|
|
48
|
+
# key 'abbreviation'
|
|
49
|
+
# store 'egrid_region_name'
|
|
50
|
+
# end
|
|
51
|
+
#
|
|
52
|
+
# process "Calculate CO2e emission factor"
|
|
53
|
+
# # multiply each gas ef by the gas GWP and sum
|
|
54
|
+
# end
|
|
55
|
+
|
|
56
|
+
import "a list of eGRID subregions and emissions factors derived from eGRID 2007 data",
|
|
57
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGRORTJNSWRMQ1puRVprYlAtZHhDaFE&hl=en&single=true&gid=0&output=csv' do
|
|
58
|
+
key 'abbreviation'
|
|
59
|
+
store 'name'
|
|
60
|
+
store 'nerc_abbreviation'
|
|
61
|
+
store 'egrid_region_name'
|
|
62
|
+
store 'electricity_emission_factor', :units_field_name => 'electricity_emission_factor_units'
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -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,15 @@
|
|
|
1
|
+
Urbanity.class_eval do
|
|
2
|
+
data_miner do
|
|
3
|
+
schema do
|
|
4
|
+
string 'name'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
process "derive from ResidentialEnergyConsumptionSurveyResponse" do
|
|
8
|
+
ResidentialEnergyConsumptionSurveyResponse.run_data_miner!
|
|
9
|
+
connection.execute %{
|
|
10
|
+
INSERT IGNORE INTO urbanities(name)
|
|
11
|
+
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
|
|
12
|
+
}
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
data_miner do
|
|
17
|
+
tap "Brighter Planet's sanitized zip codes", Earth.taps_server
|
|
18
|
+
|
|
19
|
+
process "pull dependencies" do
|
|
20
|
+
run_data_miner_on_belongs_to_associations
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
ZipCode.class_eval do
|
|
2
|
+
# sabshere 9/20/10 this isn't called anywhere
|
|
3
|
+
# def set_latitude_and_longitude
|
|
4
|
+
# return if latitude.present? and longitude.present?
|
|
5
|
+
# a = Geokit::Geocoders::YahooGeocoder.geocode name
|
|
6
|
+
# update_attributes! :latitude => a.lat, :longitude => a.lng
|
|
7
|
+
# end
|
|
8
|
+
|
|
9
|
+
data_miner do
|
|
10
|
+
schema Earth.database_options do
|
|
11
|
+
string 'name'
|
|
12
|
+
string 'state_postal_abbreviation'
|
|
13
|
+
string 'description'
|
|
14
|
+
string 'latitude'
|
|
15
|
+
string 'longitude'
|
|
16
|
+
string 'egrid_subregion_abbreviation'
|
|
17
|
+
string 'climate_division_name'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
import 'the Mapping Hacks zipcode database',
|
|
21
|
+
:url => 'http://mappinghacks.com/data/zipcode.zip',
|
|
22
|
+
:filename => 'zipcode.csv' do
|
|
23
|
+
key 'name', :field_name => 'zip', :sprintf => '%05d'
|
|
24
|
+
store 'state_postal_abbreviation', :field_name => 'state'
|
|
25
|
+
store 'description', :field_name => 'city'
|
|
26
|
+
store 'latitude'
|
|
27
|
+
store 'longitude'
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
import 'a list of zipcodes and eGRID Subregions',
|
|
31
|
+
:url => 'http://static.brighterplanet.com/science/data/electricity/egrid/models_export/zip_subregions.csv' do
|
|
32
|
+
key 'name', :field_name => 'zip', :sprintf => '%05d'
|
|
33
|
+
store 'egrid_subregion_abbreviation', :field_name => 'primary_subregion'
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
import 'a list of zipcodes and Climate Divisions',
|
|
37
|
+
:url => 'http://static.brighterplanet.com/science/data/geography/zip_code_name-climate_division_name.csv' do
|
|
38
|
+
key 'name', :field_name => 'zip_code_name', :sprintf => '%05d'
|
|
39
|
+
store 'climate_division_name'
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
data/lib/earth/pet.rb
ADDED
|
@@ -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,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
|