earth-ruby19 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- 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,8 @@
|
|
1
|
+
require 'earth/automobile/automobile_fuel_type/data_miner'
|
2
|
+
require 'earth/automobile/automobile_make/data_miner'
|
3
|
+
require 'earth/automobile/automobile_make_fleet_year/data_miner'
|
4
|
+
require 'earth/automobile/automobile_make_year/data_miner'
|
5
|
+
require 'earth/automobile/automobile_model/data_miner'
|
6
|
+
require 'earth/automobile/automobile_model_year/data_miner'
|
7
|
+
require 'earth/automobile/automobile_size_class/data_miner'
|
8
|
+
require 'earth/automobile/automobile_variant/data_miner'
|
data/lib/earth/base.rb
ADDED
data/lib/earth/bus.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'earth/bus/bus_class'
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class BusClass < ActiveRecord::Base
|
2
|
+
set_primary_key :name
|
3
|
+
|
4
|
+
has_many :bus_trips
|
5
|
+
|
6
|
+
# https://brighterplanet.sifterapp.com/projects/30/issues/454
|
7
|
+
falls_back_on :distance => 5.45.miles.to(:kilometres),
|
8
|
+
:passengers => 8.25,
|
9
|
+
:speed => 19.67.miles.to(:kilometres),
|
10
|
+
:duration => 0.277,
|
11
|
+
:diesel_intensity => 0.143.gallons_per_mile.to(:litres_per_kilometre),
|
12
|
+
:gasoline_intensity => 0.000123.gallons_per_mile.to(:litres_per_kilometre),
|
13
|
+
:alternative_fuels_intensity => 0.0517.gallons_per_mile.to(:litres_per_kilometre),
|
14
|
+
:fugitive_air_conditioning_emission => 0.0203.pounds_per_mile.to(:kilograms_per_kilometre)
|
15
|
+
|
16
|
+
data_miner do
|
17
|
+
tap "Brighter Planet's sanitized bus class data", Earth.taps_server
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
BusClass.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 'diesel_intensity'
|
13
|
+
string 'diesel_intensity_units'
|
14
|
+
float 'gasoline_intensity'
|
15
|
+
string 'gasoline_intensity_units'
|
16
|
+
float 'alternative_fuels_intensity'
|
17
|
+
string 'alternative_fuels_intensity_units'
|
18
|
+
float 'fugitive_air_conditioning_emission'
|
19
|
+
string 'fugitive_air_conditioning_emission_units'
|
20
|
+
end
|
21
|
+
|
22
|
+
process "Define some necessary conversions" do
|
23
|
+
Conversions.register :gallons_per_mile, :litres_per_kilometre, 2.35214583
|
24
|
+
Conversions.register :pounds_per_mile, :kilograms_per_kilometre, 0.281849232
|
25
|
+
end
|
26
|
+
|
27
|
+
import "a list of bus classes and pre-calculated trip and fuel use characteristics",
|
28
|
+
:url => 'http://static.brighterplanet.com/science/data/transport/bus/bus_classes.csv' do
|
29
|
+
key 'name'
|
30
|
+
store 'distance', :from_units => :miles, :to_units => :kilometres
|
31
|
+
store 'passengers'
|
32
|
+
store 'speed', :from_units => :miles, :to_units => :kilometres
|
33
|
+
store 'duration', :units => :minutes
|
34
|
+
store 'diesel_intensity', :field_name => 'diesel_per_vehicle_mile', :from_units => :gallons_per_mile, :to_units => :litres_per_kilometre
|
35
|
+
store 'gasoline_intensity', :field_name => 'gasoline_per_vehicle_mile', :from_units => :gallons_per_mile, :to_units => :litres_per_kilometre
|
36
|
+
store 'alternative_fuels_intensity', :field_name => 'alternative_fuels_per_vehicle_mile', :from_units => :gallons_per_mile, :to_units => :litres_per_kilometre
|
37
|
+
store 'fugitive_air_conditioning_emission', :field_name => 'fugitive_air_conditioning_emission_per_vehicle_mile', :from_units => :pounds_per_mile, :to_units => :kilograms_per_kilometre
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'earth/bus/bus_class/data_miner'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'conversions'
|
2
|
+
Conversions.register(:miles, :nautical_miles, 0.868976242)
|
3
|
+
Conversions.register(:kilometres, :nautical_miles, 0.539956803)
|
4
|
+
Conversions.register(:pounds_per_gallon, :kilograms_per_litre, 0.119826427)
|
5
|
+
Conversions.register(:inches, :meters, 0.0254)
|
6
|
+
Conversions.register(:kilowatt_hours, :watt_hours, 1_000.0)
|
7
|
+
Conversions.register(:kilowatt_hours, :btus, 3_412.14163) # obsolete?
|
8
|
+
Conversions.register(:watt_hours, :btus, 3.4121414799) # obsolete?
|
9
|
+
Conversions.register(:watt_hours, :joules, 3_600.0)
|
10
|
+
Conversions.register(:kilowatt_hours, :joules, 3_600_000.0)
|
11
|
+
|
12
|
+
# Conversions.register(:btus, :gallons_of_kerosene, 0.000007419521097)
|
13
|
+
Conversions.register(:joules, :litres_of_kerosene, 1.0 / (135_000.0 * 3.78541178 * 1_055.05585)) # should only be used for RECS 2005
|
14
|
+
|
15
|
+
# Conversions.register(:btus, :gallons_of_propane, 0.000010471204188)
|
16
|
+
Conversions.register(:joules, :litres_of_propane, 1.0 / (91_333.0 * 3.78541178 * 1_055.05585)) # should only be used for RECS 2005
|
17
|
+
|
18
|
+
# Conversions.register(:btus, :therms, 0.000010002388121)
|
19
|
+
Conversions.register(:therms, :joules, 105_505_585.0) # should only be used for RECS 2005
|
20
|
+
|
21
|
+
# Conversions.register(:btus, :gallons_of_fuel_oil, 0.0000072007637183)
|
22
|
+
Conversions.register(:joules, :litres_of_fuel_oil, 1.0 / (138_690.0 * 3.78541178 * 1_055.05585)) # should only be used for RECS 2005
|
23
|
+
|
24
|
+
# Conversions.register(:tons_of_coal, :btus, 20_169_000.0)
|
25
|
+
Conversions.register(:joules, :kilograms_of_coal, 1.0 / (22_342_000.0 * 0.00110231131 * 1_055.05585)) # should only be used for RECS 2005
|
26
|
+
|
27
|
+
Conversions.register(:kilograms, :lbs, 2.20462262)
|
28
|
+
Conversions.register(:kbtus, :btus, 1_000.0)
|
29
|
+
Conversions.register(:square_feet, :square_metres, 0.09290304)
|
30
|
+
Conversions.register(:pounds_per_square_foot, :kilograms_per_square_metre, 4.88242764)
|
31
|
+
Conversions.register(:kilograms_per_kilowatt_hour, :kilograms_per_megawatt_hour, 1_000.0)
|
32
|
+
Conversions.register(:btus, :joules, 1_055.05585)
|
33
|
+
Conversions.register(:kbtus, :joules, 1_000.0 * 1_055.05585)
|
34
|
+
Conversions.register(:cords, :joules, 2.11011171e10)
|
35
|
+
|
36
|
+
Conversions.register(:gallons_per_mile, :litres_per_kilometre, 2.35214583)
|
37
|
+
Conversions.register(:pounds_per_mile, :kilograms_per_kilometre, 0.281849232)
|
38
|
+
Conversions.register(:dollars, :cents, 100)
|
39
|
+
Conversions.register(:cubic_feet, :cubic_metres, 0.0283168466)
|
40
|
+
# 1 (kilocalories per pound) = 9 224.14105 joules per kilogram
|
41
|
+
Conversions.register :kilocalories_per_pound, :joules_per_kilogram, 9_224.14105
|
42
|
+
# 1 (grams per kilocalories) = 2.39005736 × 10-7 kilograms per joules
|
43
|
+
Conversions.register :grams_per_kilocalorie, :kilograms_per_joule, 2.39005736e-7
|
44
|
+
# 1 joule = 0.000239005736 kilocalories
|
45
|
+
Conversions.register :joules, :kilocalories, 0.000239005736
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'earth/air/data_miner'
|
2
|
+
require 'earth/automobile/data_miner'
|
3
|
+
require 'earth/bus/data_miner'
|
4
|
+
require 'earth/diet/data_miner'
|
5
|
+
require 'earth/fuel/data_miner'
|
6
|
+
require 'earth/hospitality/data_miner'
|
7
|
+
require 'earth/locality/data_miner'
|
8
|
+
require 'earth/pet/data_miner'
|
9
|
+
require 'earth/rail/data_miner'
|
10
|
+
require 'earth/residence/data_miner'
|
data/lib/earth/diet.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
DietClass.class_eval do
|
2
|
+
data_miner do
|
3
|
+
schema Earth.database_options do
|
4
|
+
string 'name'
|
5
|
+
float 'intensity'
|
6
|
+
string 'intensity_units'
|
7
|
+
float 'red_meat_share'
|
8
|
+
float 'poultry_share'
|
9
|
+
float 'fish_share'
|
10
|
+
float 'eggs_share'
|
11
|
+
float 'nuts_share'
|
12
|
+
float 'dairy_share'
|
13
|
+
float 'cereals_and_grains_share'
|
14
|
+
float 'fruit_share'
|
15
|
+
float 'vegetables_share'
|
16
|
+
float 'oils_and_sugars_share'
|
17
|
+
end
|
18
|
+
|
19
|
+
import "a Brighter Planet-defined list of diet classes and food group caloric distributions",
|
20
|
+
:url => 'http://static.brighterplanet.com/science/data/consumables/diets/diet_classes.csv' do
|
21
|
+
key 'name'
|
22
|
+
store 'intensity'
|
23
|
+
store 'red_meat_share'
|
24
|
+
store 'poultry_share'
|
25
|
+
store 'fish_share'
|
26
|
+
store 'eggs_share'
|
27
|
+
store 'nuts_share'
|
28
|
+
store 'dairy_share'
|
29
|
+
store 'cereals_and_grains_share'
|
30
|
+
store 'fruit_share'
|
31
|
+
store 'vegetables_share'
|
32
|
+
store 'oils_and_sugars_share'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class FoodGroup < ActiveRecord::Base
|
2
|
+
set_primary_key :name
|
3
|
+
|
4
|
+
class << self
|
5
|
+
def names
|
6
|
+
connection.select_values arel_table.project(:name).to_sql
|
7
|
+
end
|
8
|
+
|
9
|
+
def [](name)
|
10
|
+
find_by_name name.to_s
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
data_miner do
|
15
|
+
tap "Brighter Planet's food group data", Earth.taps_server
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
FoodGroup.class_eval do
|
2
|
+
data_miner do
|
3
|
+
schema Earth.database_options do
|
4
|
+
string 'name'
|
5
|
+
float 'intensity'
|
6
|
+
string 'intensity_units'
|
7
|
+
float 'energy'
|
8
|
+
string 'energy_units'
|
9
|
+
string 'suggested_imperial_measurement' # ?
|
10
|
+
end
|
11
|
+
|
12
|
+
import "a list of food groups and their emissions intensities",
|
13
|
+
:url => 'http://static.brighterplanet.com/science/data/consumables/diets/food_groups.csv' do
|
14
|
+
key 'name'
|
15
|
+
store 'intensity', :units => :grams_per_kilocalorie #FIXME TODO make sure diet expects kg / joule and then do :from_units => :grams_per_kilocalorie, :to_units => :kilograms_per_joule
|
16
|
+
end
|
17
|
+
|
18
|
+
import "energy and units",
|
19
|
+
:url => 'http://spreadsheets.google.com/pub?key=trkBEq5oFnUQE76gQ6VpQgw' do
|
20
|
+
key 'name'
|
21
|
+
store 'energy', :units => 'unknown' #FIXME this needs to be "kilocalories per" and then whatever the suggested imperial measurement is
|
22
|
+
store 'suggested_imperial_measurement', :field_name => 'friendly_units'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
data/lib/earth/fuel.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class FuelPrice < ActiveRecord::Base
|
2
|
+
set_primary_key :name
|
3
|
+
|
4
|
+
belongs_to :fuel_type, :foreign_key => 'name' # weird
|
5
|
+
|
6
|
+
data_miner do
|
7
|
+
tap "Brighter Planet's fuel price data", Earth.taps_server
|
8
|
+
|
9
|
+
process "pull dependencies" do
|
10
|
+
run_data_miner_on_belongs_to_associations
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
FuelPrice.class_eval do
|
2
|
+
# FIXME TODO phase 2
|
3
|
+
# location
|
4
|
+
# month/year
|
5
|
+
|
6
|
+
data_miner do
|
7
|
+
schema Earth.database_options do
|
8
|
+
string 'name'
|
9
|
+
float 'price'
|
10
|
+
string 'price_units'
|
11
|
+
end
|
12
|
+
|
13
|
+
import 'fuel prices derived from the EIA',
|
14
|
+
:url => 'http://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdHlSdXJoOFB5aEpHenJQbTVJdS1pMVE',
|
15
|
+
:select => lambda { |row| row['fuel_type_name'].present? } do
|
16
|
+
key 'name', :field_name => 'fuel_type_name'
|
17
|
+
store 'price', :units_field_name => 'price_units'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class FuelType < ActiveRecord::Base
|
2
|
+
set_primary_key :name
|
3
|
+
|
4
|
+
has_many :prices, :class_name => 'FuelPrice', :foreign_key => 'name' # weird
|
5
|
+
|
6
|
+
falls_back_on :emission_factor => 1.0, #FIXME TODO put a real value here - also do we want to do emission factors in kg / kj?
|
7
|
+
:emission_factor_units => 'FIXME',
|
8
|
+
:average_purchase_volume => 100, #FIXME TODO put a real value here - also do we want to do volumes in kJ?
|
9
|
+
:average_purchase_volume_units => 'FIXME'
|
10
|
+
|
11
|
+
data_miner do
|
12
|
+
tap "Brighter Planet's fuel types data", Earth.taps_server
|
13
|
+
end
|
14
|
+
|
15
|
+
def price
|
16
|
+
prices.average :price
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
FuelType.class_eval do
|
2
|
+
# FIXME TODO phase 2
|
3
|
+
# annual emissions factors
|
4
|
+
# annual energy contents
|
5
|
+
# gas-specific emissions factors
|
6
|
+
|
7
|
+
data_miner do
|
8
|
+
schema Earth.database_options do
|
9
|
+
string 'name'
|
10
|
+
float 'emission_factor'
|
11
|
+
string 'emission_factor_units'
|
12
|
+
float 'average_purchase_volume'
|
13
|
+
string 'average_purchase_volume_units'
|
14
|
+
# float 'energy_content'
|
15
|
+
# string 'energy_content_units'
|
16
|
+
# float 'carbon_content'
|
17
|
+
# string 'carbon_content_units'
|
18
|
+
end
|
19
|
+
|
20
|
+
# process "Define some necessary conversions" do
|
21
|
+
# Conversions.register :teragrams_per_quadrillion_british_thermal_units, :kilograms_per_joule, 0.000000000947817123
|
22
|
+
# Conversions.register :million_british_thermal_units_per_short_ton, :joules_per_kilogram, 1.16300000
|
23
|
+
# Conversions.register :million_british_thermal_units_per_cubic_foot, :joules_per_cubic_metre, 37_258.9457
|
24
|
+
# Conversions.register :million_british_thermal_units_per_barrel, :joules_per_litre, 6.63610165
|
25
|
+
# Conversions.register :carbon, :carbon_dioxide, 3.66666667
|
26
|
+
# end
|
27
|
+
|
28
|
+
import "a list of fuels and their emissions factors",
|
29
|
+
:url => 'http://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdDR3RjlTcWlsLTc2TzQ0cERTMElJbHc' do
|
30
|
+
key 'name', :field_name => 'fuel'
|
31
|
+
store 'emission_factor', :units_field_name => 'emission_factor_units'
|
32
|
+
store 'average_purchase_volume', :units_field_name => 'average_purchase_volume_units'
|
33
|
+
# store 'energy_content', :field_name => 'energy_content', :units_field_name => 'energy_content_units', :to_units => 'FIXME' # FIXME need different conversions for different rows...
|
34
|
+
# store 'carbon_content', :field_name => 'carbon_content', :units_field_name => 'carbon_content_units', :to_units => :kilograms_per_joule
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'earth/hospitality/lodging_class'
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'earth/hospitality/lodging_class/data_miner'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
LodgingClass.class_eval do
|
2
|
+
data_miner do
|
3
|
+
schema Earth.database_options do
|
4
|
+
string 'name'
|
5
|
+
float 'natural_gas_intensity'
|
6
|
+
string 'natural_gas_intensity_units'
|
7
|
+
float 'fuel_oil_intensity'
|
8
|
+
string 'fuel_oil_intensity_units'
|
9
|
+
float 'electricity_intensity'
|
10
|
+
string 'electricity_intensity_units'
|
11
|
+
float 'district_heat_intensity'
|
12
|
+
string 'district_heat_intensity_units'
|
13
|
+
end
|
14
|
+
|
15
|
+
process "Define some unit conversions" do
|
16
|
+
Conversions.register :hundred_cubic_feet_per_room_night, :cubic_metres_per_room_night, 2.831685
|
17
|
+
Conversions.register :gallons_per_room_night, :litres_per_room_night, 3.785412
|
18
|
+
Conversions.register :thousand_btu_per_room_night, :joules_per_room_night, 1_055_056
|
19
|
+
end
|
20
|
+
|
21
|
+
import "a list of lodging classes and pre-calculated emission factors",
|
22
|
+
:url => 'https://spreadsheets.google.com/pub?key=0AoQJbWqPrREqdGZZWmZtWEJlYzhRNXlPdWpBTldlcUE&hl=en&output=csv' do
|
23
|
+
key 'name'
|
24
|
+
store 'natural_gas_intensity', :from_units => :hundred_cubic_feet_per_room_night, :to_units => :cubic_metres_per_room_night
|
25
|
+
store 'fuel_oil_intensity', :from_units => :gallons_per_room_night, :to_units => :litres_per_room_night
|
26
|
+
store 'electricity_intensity', :units_field_name => 'electricity_intensity_units'
|
27
|
+
store 'district_heat_intensity', :from_units => :thousand_btu_per_room_night, :to_units => :joules_per_room_night
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'earth/industry/industry_product_line'
|
2
|
+
require 'earth/industry/industry_sector'
|
3
|
+
require 'earth/industry/industry'
|
4
|
+
require 'earth/industry/industry_product'
|
5
|
+
require 'earth/industry/merchant'
|
6
|
+
require 'earth/industry/merchant_category_industry'
|
7
|
+
require 'earth/industry/merchant_category'
|
8
|
+
require 'earth/industry/product_line'
|
9
|
+
require 'earth/industry/product_line_industry_product'
|
10
|
+
require 'earth/industry/sector'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Industry < ActiveRecord::Base
|
2
|
+
extend Earth::Base
|
3
|
+
set_primary_key :naics_code
|
4
|
+
|
5
|
+
has_many :merchant_category_industries, :foreign_key => 'naics_code'
|
6
|
+
|
7
|
+
has_many :industry_product_lines, :foreign_key => 'naics_code'
|
8
|
+
has_many :product_lines, :through => :industry_product_lines
|
9
|
+
|
10
|
+
has_many :industry_sectors, :foreign_key => 'naics_code'
|
11
|
+
has_many :sectors, :through => :industry_sectors
|
12
|
+
|
13
|
+
def self.schema_definition
|
14
|
+
lambda do
|
15
|
+
string 'naics_code'
|
16
|
+
string 'description'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
data_miner do
|
21
|
+
Industry.define_schema(self)
|
22
|
+
end
|
23
|
+
end
|