earth 0.11.7 → 0.11.8
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +30 -0
- data/bin/earth_tester.rb +1 -1
- data/earth.gemspec +3 -3
- data/lib/earth.rb +105 -90
- data/lib/earth/air.rb +3 -12
- data/lib/earth/air/aircraft.rb +9 -9
- data/lib/earth/air/airport.rb +3 -0
- data/lib/earth/air/airport/data_miner.rb +2 -0
- data/lib/earth/air/data_miner.rb +3 -10
- data/lib/earth/air/flight_segment.rb +3 -1
- data/lib/earth/air/flight_segment/data_miner.rb +2 -0
- data/lib/earth/all.rb +3 -13
- data/lib/earth/automobile.rb +3 -18
- data/lib/earth/automobile/automobile_fuel.rb +1 -3
- data/lib/earth/automobile/automobile_fuel/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_make.rb +1 -0
- data/lib/earth/automobile/automobile_make/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_make_model.rb +1 -0
- data/lib/earth/automobile/automobile_make_model/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_make_model_year.rb +1 -0
- data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +1 -0
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_make_year.rb +1 -0
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_make_year_fleet.rb +1 -0
- data/lib/earth/automobile/automobile_make_year_fleet/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_model.rb +1 -0
- data/lib/earth/automobile/automobile_model/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_size_class.rb +1 -0
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_size_class_year.rb +1 -0
- data/lib/earth/automobile/automobile_size_class_year/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_type_fuel_control.rb +1 -0
- data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_type_fuel_year.rb +1 -0
- data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_type_fuel_year_age.rb +1 -0
- data/lib/earth/automobile/automobile_type_fuel_year_age/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +1 -0
- data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_type_year.rb +1 -0
- data/lib/earth/automobile/automobile_type_year/data_miner.rb +1 -0
- data/lib/earth/automobile/automobile_year.rb +1 -0
- data/lib/earth/automobile/automobile_year/data_miner.rb +1 -0
- data/lib/earth/automobile/data_miner.rb +3 -18
- data/lib/earth/bus.rb +3 -6
- data/lib/earth/bus/bus_class.rb +1 -0
- data/lib/earth/bus/bus_class/data_miner.rb +1 -0
- data/lib/earth/bus/bus_fuel.rb +1 -0
- data/lib/earth/bus/bus_fuel/data_miner.rb +1 -0
- data/lib/earth/bus/bus_fuel_control.rb +1 -0
- data/lib/earth/bus/bus_fuel_control/data_miner.rb +1 -0
- data/lib/earth/bus/bus_fuel_year_control.rb +1 -0
- data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +1 -0
- data/lib/earth/bus/data_miner.rb +3 -6
- data/lib/earth/computation.rb +3 -5
- data/lib/earth/computation/computation_carrier.rb +1 -0
- data/lib/earth/computation/computation_carrier/data_miner.rb +1 -1
- data/lib/earth/computation/computation_carrier_instance_class.rb +1 -0
- data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +1 -0
- data/lib/earth/computation/computation_carrier_region.rb +1 -0
- data/lib/earth/computation/computation_carrier_region/data_miner.rb +1 -0
- data/lib/earth/computation/data_miner.rb +3 -5
- data/lib/earth/data_miner.rb +3 -13
- data/lib/earth/diet.rb +3 -2
- data/lib/earth/diet/data_miner.rb +3 -2
- data/lib/earth/eia.rb +11 -13
- data/lib/earth/fuel.rb +3 -5
- data/lib/earth/fuel/data_miner.rb +3 -5
- data/lib/earth/fuel/fuel_price.rb +1 -1
- data/lib/earth/hospitality.rb +3 -5
- data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +2 -0
- data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +13 -7
- data/lib/earth/hospitality/country_lodging_class.rb +1 -0
- data/lib/earth/hospitality/country_lodging_class/data_miner.rb +4 -2
- data/lib/earth/hospitality/data_miner.rb +3 -4
- data/lib/earth/hospitality/lodging_class.rb +1 -10
- data/lib/earth/hospitality/lodging_class/data_miner.rb +7 -30
- data/lib/earth/hospitality/lodging_property.rb +1 -0
- data/lib/earth/industry.rb +3 -13
- data/lib/earth/industry/cbecs_energy_intensity.rb +5 -49
- data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +94 -42
- data/lib/earth/industry/data_miner.rb +3 -4
- data/lib/earth/industry/industry.rb +1 -0
- data/lib/earth/industry/industry/data_miner.rb +1 -0
- data/lib/earth/industry/industry_product.rb +1 -0
- data/lib/earth/industry/industry_product_line.rb +1 -0
- data/lib/earth/industry/industry_sector.rb +1 -0
- data/lib/earth/industry/mecs_energy.rb +3 -24
- data/lib/earth/industry/mecs_energy/data_miner.rb +34 -11
- data/lib/earth/industry/mecs_ratio.rb +6 -24
- data/lib/earth/industry/mecs_ratio/data_miner.rb +24 -1
- data/lib/earth/locality.rb +3 -15
- data/lib/earth/locality/census_division.rb +1 -0
- data/lib/earth/locality/census_division/data_miner.rb +1 -0
- data/lib/earth/locality/country.rb +3 -0
- data/lib/earth/locality/country/data_miner.rb +5 -1
- data/lib/earth/locality/data_miner.rb +3 -15
- data/lib/earth/locality/egrid_subregion.rb +1 -0
- data/lib/earth/locality/egrid_subregion/data_miner.rb +1 -0
- data/lib/earth/locality/state/data_miner.rb +11 -11
- data/lib/earth/locality/zip_code.rb +6 -0
- data/lib/earth/pet.rb +3 -4
- data/lib/earth/pet/data_miner.rb +3 -4
- data/lib/earth/rail.rb +3 -15
- data/lib/earth/rail/country_rail_class.rb +1 -0
- data/lib/earth/rail/country_rail_class/data_miner.rb +1 -0
- data/lib/earth/rail/country_rail_traction.rb +2 -0
- data/lib/earth/rail/country_rail_traction/data_miner.rb +2 -0
- data/lib/earth/rail/country_rail_traction_class.rb +2 -0
- data/lib/earth/rail/country_rail_traction_class/data_miner.rb +2 -0
- data/lib/earth/rail/data_miner.rb +3 -16
- data/lib/earth/rail/national_transit_database_company.rb +1 -0
- data/lib/earth/rail/national_transit_database_company/data_miner.rb +1 -0
- data/lib/earth/rail/national_transit_database_record.rb +1 -0
- data/lib/earth/rail/national_transit_database_record/data_miner.rb +1 -0
- data/lib/earth/rail/rail_company.rb +2 -0
- data/lib/earth/rail/rail_company/data_miner.rb +2 -0
- data/lib/earth/rail/rail_company_traction.rb +1 -0
- data/lib/earth/rail/rail_company_traction/data_miner.rb +1 -0
- data/lib/earth/rail/rail_company_traction_class.rb +1 -0
- data/lib/earth/rail/rail_company_traction_class/data_miner.rb +1 -0
- data/lib/earth/rail/rail_fuel.rb +1 -0
- data/lib/earth/rail/rail_fuel/data_miner.rb +1 -0
- data/lib/earth/residence.rb +3 -11
- data/lib/earth/residence/data_miner.rb +3 -11
- data/lib/earth/residence/residence_fuel_price.rb +1 -0
- data/lib/earth/residence/residence_fuel_price/data_miner.rb +1 -0
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +1 -0
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +1 -0
- data/lib/earth/shipping.rb +3 -3
- data/lib/earth/shipping/data_miner.rb +3 -3
- data/lib/earth/version.rb +1 -1
- data/spec/earth/industry/mecs_energy_spec.rb +18 -0
- data/spec/earth_spec.rb +18 -29
- data/test/test_aircraft_match.rb +142 -142
- data/vendor/geokit-rails/.gitignore +2 -0
- data/vendor/geokit-rails/CHANGELOG.rdoc +4 -1
- data/vendor/geokit-rails/README.markdown +11 -3
- data/vendor/geokit-rails/about.yml +2 -0
- data/vendor/geokit-rails/lib/geokit-rails.rb +7 -4
- data/vendor/geokit-rails/lib/geokit-rails/acts_as_mappable.rb +15 -2
- data/vendor/geokit-rails/lib/geokit-rails/adapters/abstract.rb +1 -1
- data/vendor/geokit-rails/lib/geokit-rails/adapters/mysql2.rb +22 -0
- data/vendor/geokit-rails/test/database.yml +5 -0
- data/vendor/geokit-rails/test/ip_geocode_lookup_test.rb +1 -1
- data/vendor/geokit-rails/test/tasks.rake +2 -2
- metadata +179 -191
- data/lib/earth/hospitality/census_region_lodging_class.rb +0 -16
- data/lib/earth/hospitality/census_region_lodging_class/data_miner.rb +0 -40
data/lib/earth/fuel.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'earth
|
3
|
-
|
4
|
-
require 'earth/fuel/fuel_year/data_miner'
|
5
|
-
require 'earth/fuel/greenhouse_gas/data_miner'
|
1
|
+
# lib/earth/fuel/data_miner.rb
|
2
|
+
require 'earth'
|
3
|
+
Earth.require_related __FILE__
|
data/lib/earth/hospitality.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'earth
|
3
|
-
|
4
|
-
require 'earth/hospitality/lodging_class'
|
5
|
-
require 'earth/hospitality/lodging_property'
|
1
|
+
# lib/earth/hospitality.rb
|
2
|
+
require 'earth'
|
3
|
+
Earth.require_related __FILE__
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'earth/locality'
|
1
2
|
class CommercialBuildingEnergyConsumptionSurveyResponse < ActiveRecord::Base
|
2
3
|
set_primary_key :id
|
3
4
|
set_table_name :cbecs_responses
|
@@ -8,6 +9,7 @@ class CommercialBuildingEnergyConsumptionSurveyResponse < ActiveRecord::Base
|
|
8
9
|
col :id, :type => :integer
|
9
10
|
col :census_region_number, :type => :integer
|
10
11
|
col :census_division_number, :type => :integer
|
12
|
+
col :climate_zone_number, :type => :integer
|
11
13
|
col :heating_degree_days, :type => :integer
|
12
14
|
col :cooling_degree_days, :type => :integer
|
13
15
|
col :construction_year, :type => :integer
|
data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
require 'earth/locality/data_miner'
|
1
2
|
CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
|
2
3
|
data_miner do
|
4
|
+
process 'Define some unit conversions' do
|
5
|
+
Conversions.register :hundred_cubic_feet, :cubic_metres, 2.83168466
|
6
|
+
end
|
7
|
+
|
3
8
|
import 'building characteristics from the 2003 EIA Commercial Building Energy Consumption Survey',
|
4
9
|
:url => 'http://www.eia.gov/emeu/cbecs/cbecs2003/public_use_2003/data/FILE01.csv',
|
5
10
|
:skip => 1,
|
@@ -7,6 +12,7 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
|
|
7
12
|
key 'id', :field_name => 'PUBID8'
|
8
13
|
store 'census_region_number', :field_name => 'REGION8'
|
9
14
|
store 'census_division_number', :field_name => 'CENDIV8'
|
15
|
+
store 'climate_zone_number', :synthesize => Proc.new { |row| row['CLIMATE8'].to_i == 7 ? nil : row['CLIMATE8'].to_i }
|
10
16
|
store 'area', :field_name => 'SQFT8', :from_units => :square_feet, :to_units => :square_metres
|
11
17
|
store 'principal_activity', :field_name => 'PBA8', :dictionary => { :input => 'principal_activity_code', :output => 'principal_activity', :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=2&output=csv' }
|
12
18
|
store 'floors', :field_name => 'NFLOOR8', :dictionary => { :input => 'floors_code', :output => 'floors', :url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=0&output=csv' }
|
@@ -27,9 +33,9 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
|
|
27
33
|
store 'first_activity', :field_name => 'ACT18', :dictionary => { :input => 'activity_code', :output => 'activity', :url => 'https://docs.google.com/spreadsheet/pub?&key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=4&output=csv' }
|
28
34
|
store 'second_activity', :field_name => 'ACT28', :dictionary => { :input => 'activity_code', :output => 'activity', :url => 'https://docs.google.com/spreadsheet/pub?&key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=4&output=csv' }
|
29
35
|
store 'third_activity', :field_name => 'ACT38', :dictionary => { :input => 'activity_code', :output => 'activity', :url => 'https://docs.google.com/spreadsheet/pub?&key=0AoQJbWqPrREqdHRGVHczYXRoU2dFLV90aDdET0dQLUE&single=true&gid=4&output=csv' }
|
30
|
-
store 'first_activity_share', :synthesize =>
|
31
|
-
store 'second_activity_share', :synthesize =>
|
32
|
-
store 'third_activity_share', :synthesize =>
|
36
|
+
store 'first_activity_share', :synthesize => Proc.new { |row| row['ACT1PCT8'].blank? ? nil : row['ACT1PCT8'].to_f / 100.0 }
|
37
|
+
store 'second_activity_share', :synthesize => Proc.new { |row| row['ACT2PCT8'].blank? ? nil : row['ACT2PCT8'].to_f / 100.0 }
|
38
|
+
store 'third_activity_share', :synthesize => Proc.new { |row| row['ACT3PCT8'].blank? ? nil : row['ACT3PCT8'].to_f / 100.0 }
|
33
39
|
store 'lodging_rooms', :field_name => 'LODGRM8'
|
34
40
|
end
|
35
41
|
|
@@ -40,7 +46,7 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
|
|
40
46
|
key 'id', :field_name => 'PUBID8'
|
41
47
|
store 'heating_degree_days', :field_name => 'HDD658'
|
42
48
|
store 'cooling_degree_days', :field_name => 'CDD658'
|
43
|
-
store 'electricity_use', :
|
49
|
+
store 'electricity_use', :synthesize => Proc.new { |row| row['ELCNS8'].to_i }, :units => :kilowatt_hours
|
44
50
|
end
|
45
51
|
|
46
52
|
import 'fuel use characteristics from the 2003 EIA Commercial Building Energy Consumption Survey',
|
@@ -48,9 +54,9 @@ CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
|
|
48
54
|
:skip => 1,
|
49
55
|
:headers => ["PUBID8", "REGION8", "CENDIV8", "SQFT8", "SQFTC8", "YRCONC8", "PBA8", "ELUSED8", "NGUSED8", "FKUSED8", "PRUSED8", "STUSED8", "HWUSED8", "ADJWT8", "STRATUM8", "PAIR8", "NGCNS8", "NGBTU8", "NGEXP8", "ZNGCNS8", "ZNGEXP8", "FKCNS8", "FKBTU8", "FKEXP8", "ZFKCNS8", "ZFKEXP8", "DHUSED8", "DHHT18", "DHHT28", "DHCOOL8", "DHWATR8", "DHCOOK8", "DHMANU8", "DHOTH8", "DHCNS8", "DHBTU8", "DHEXP8", "ZDHCNS8", "ZDHEXP8"] do
|
50
56
|
key 'id', :field_name => 'PUBID8'
|
51
|
-
store 'natural_gas_use', :
|
52
|
-
store 'fuel_oil_use', :
|
53
|
-
store 'district_heat_use', :
|
57
|
+
store 'natural_gas_use', :field_name => 'NGCNS8', :from_units => :hundred_cubic_feet, :to_units => :cubic_metres #!!!!!!!!!!!!
|
58
|
+
store 'fuel_oil_use', :field_name => 'FKCNS8', :from_units => :gallons, :to_units => :litres
|
59
|
+
store 'district_heat_use', :field_name => 'DHBTU8', :from_units => :kbtus, :to_units => :megajoules
|
54
60
|
end
|
55
61
|
end
|
56
62
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'earth/locality/data_miner'
|
1
2
|
CountryLodgingClass.class_eval do
|
2
3
|
data_miner do
|
3
4
|
import "a curated list of country lodging classes",
|
@@ -18,11 +19,12 @@ CountryLodgingClass.class_eval do
|
|
18
19
|
intensities = {}
|
19
20
|
|
20
21
|
[:natural_gas, :fuel_oil, :electricity, :district_heat].each do |fuel|
|
21
|
-
|
22
|
+
intensity = cbecs_responses.inject(0) do |sum, response|
|
22
23
|
next sum unless response.send("#{fuel}_use").present?
|
23
24
|
occupied_room_nights = 365.0 / 7.0 / 12.0 * response.months_used * response.weekly_hours / 24.0 * response.lodging_rooms * 0.59
|
24
25
|
sum + (response.weighting * response.send("#{fuel}_use") / occupied_room_nights)
|
25
|
-
end
|
26
|
+
end
|
27
|
+
intensities[fuel] = intensity / cbecs_responses.sum(:weighting)
|
26
28
|
end
|
27
29
|
|
28
30
|
lodging_class.natural_gas_intensity = intensities[:natural_gas]
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'earth
|
3
|
-
|
4
|
-
require 'earth/hospitality/lodging_class/data_miner'
|
1
|
+
# lib/earth/hospitality/data_miner.rb
|
2
|
+
require 'earth'
|
3
|
+
Earth.require_related __FILE__
|
@@ -1,15 +1,6 @@
|
|
1
|
+
require 'earth/locality'
|
1
2
|
class LodgingClass < ActiveRecord::Base
|
2
3
|
set_primary_key :name
|
3
4
|
|
4
5
|
col :name
|
5
|
-
|
6
|
-
# DEPRECATED - cut once new Lodging has been phased in
|
7
|
-
col :electricity_intensity, :type => :float
|
8
|
-
col :electricity_intensity_units
|
9
|
-
col :natural_gas_intensity, :type => :float
|
10
|
-
col :natural_gas_intensity_units
|
11
|
-
col :fuel_oil_intensity, :type => :float
|
12
|
-
col :fuel_oil_intensity_units
|
13
|
-
col :district_heat_intensity, :type => :float
|
14
|
-
col :district_heat_intensity_units
|
15
6
|
end
|
@@ -1,37 +1,14 @@
|
|
1
|
+
require 'earth/locality/data_miner'
|
1
2
|
LodgingClass.class_eval do
|
2
3
|
data_miner do
|
3
|
-
|
4
|
-
|
5
|
-
:url => 'https://docs.google.com/spreadsheet/pub?key=0AoQJbWqPrREqdGZZWmZtWEJlYzhRNXlPdWpBTldlcUE&output=csv' do
|
6
|
-
key 'name'
|
7
|
-
store 'electricity_intensity', :units_field_name => 'electricity_intensity_units'
|
8
|
-
store 'natural_gas_intensity', :units_field_name => 'natural_gas_intensity_units'
|
9
|
-
store 'fuel_oil_intensity', :units_field_name => 'fuel_oil_intensity_units'
|
10
|
-
store 'district_heat_intensity', :units_field_name => 'district_heat_intensity_units'
|
4
|
+
process "Ensure CountryLodgingClass is populated" do
|
5
|
+
CountryLodgingClass.run_data_miner!
|
11
6
|
end
|
12
7
|
|
13
|
-
process "
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
natural_gas_intensity_units = 'cubic_metres_per_room_night'
|
18
|
-
})
|
19
|
-
end
|
20
|
-
|
21
|
-
process "Convert fuel oil intensities to metric units" do
|
22
|
-
conversion_factor = 3.78541178 # Google: 3.78541178 l / gal
|
23
|
-
where(:fuel_oil_intensity_units => 'gallons_per_room_night').update_all(%{
|
24
|
-
fuel_oil_intensity = 1.0 * fuel_oil_intensity * #{conversion_factor},
|
25
|
-
fuel_oil_intensity_units = 'litres_per_room_night'
|
26
|
-
})
|
27
|
-
end
|
28
|
-
|
29
|
-
process "Convert district heat intensities to metric units" do
|
30
|
-
conversion_factor = 1.05505585 # Google: 1.05505585 MJ / 1000 Btu
|
31
|
-
where(:district_heat_intensity_units => 'thousand_btu_per_room_night').update_all(%{
|
32
|
-
district_heat_intensity = 1.0 * district_heat_intensity * #{conversion_factor},
|
33
|
-
district_heat_intensity_units = 'megajoules_per_room_night'
|
34
|
-
})
|
8
|
+
process "Derive lodging classes from CountryLodgingClass" do
|
9
|
+
connection.select_values("SELECT DISTINCT lodging_class_name FROM #{CountryLodgingClass.quoted_table_name}").each do |lodging_class_name|
|
10
|
+
find_or_create_by_name lodging_class_name
|
11
|
+
end
|
35
12
|
end
|
36
13
|
end
|
37
14
|
end
|
data/lib/earth/industry.rb
CHANGED
@@ -1,13 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'earth
|
3
|
-
|
4
|
-
require 'earth/industry/industry'
|
5
|
-
require 'earth/industry/industry_product'
|
6
|
-
require 'earth/industry/mecs_energy'
|
7
|
-
require 'earth/industry/mecs_ratio'
|
8
|
-
require 'earth/industry/merchant'
|
9
|
-
require 'earth/industry/merchant_category_industry'
|
10
|
-
require 'earth/industry/merchant_category'
|
11
|
-
require 'earth/industry/product_line'
|
12
|
-
require 'earth/industry/product_line_industry_product'
|
13
|
-
require 'earth/industry/sector'
|
1
|
+
# lib/earth/industry.rb
|
2
|
+
require 'earth'
|
3
|
+
Earth.require_related __FILE__
|
@@ -1,55 +1,11 @@
|
|
1
|
+
require 'earth/locality'
|
1
2
|
class CbecsEnergyIntensity < ActiveRecord::Base
|
2
|
-
|
3
|
+
set_primary_key :name
|
4
|
+
|
5
|
+
col :name
|
6
|
+
col :naics_code
|
3
7
|
col :census_division_number, :type => :integer
|
4
8
|
col :total_electricity_consumption, :type => :float
|
5
9
|
col :total_floorspace, :type => :float
|
6
10
|
col :electricity_intensity, :type => :float
|
7
|
-
|
8
|
-
CENSUS_DIVISIONS = {
|
9
|
-
'New England Division' => {
|
10
|
-
:column => 0,
|
11
|
-
:code => 1,
|
12
|
-
:table => 'c17'
|
13
|
-
},
|
14
|
-
'Middle Atlantic Division' => {
|
15
|
-
:column => 1,
|
16
|
-
:code => 2,
|
17
|
-
:table => 'c17'
|
18
|
-
},
|
19
|
-
'East North Central Division' => {
|
20
|
-
:column => 2,
|
21
|
-
:code => 3,
|
22
|
-
:table => 'c17'
|
23
|
-
},
|
24
|
-
'West North Central Division' => {
|
25
|
-
:column => 0,
|
26
|
-
:code => 4,
|
27
|
-
:table => 'c18'
|
28
|
-
},
|
29
|
-
'South Atlantic Division' => {
|
30
|
-
:column => 1,
|
31
|
-
:code => 5,
|
32
|
-
:table => 'c18'
|
33
|
-
},
|
34
|
-
'East South Central Division' => {
|
35
|
-
:column => 2,
|
36
|
-
:code => 6,
|
37
|
-
:table => 'c18'
|
38
|
-
},
|
39
|
-
'West South Central Division' => {
|
40
|
-
:column => 0,
|
41
|
-
:code => 7,
|
42
|
-
:table => 'c19'
|
43
|
-
},
|
44
|
-
'Mountain Division' => {
|
45
|
-
:column => 1,
|
46
|
-
:code => 8,
|
47
|
-
:table => 'c19'
|
48
|
-
},
|
49
|
-
'Pacific Division' => {
|
50
|
-
:column => 2,
|
51
|
-
:code => 9,
|
52
|
-
:table => 'c19'
|
53
|
-
}
|
54
|
-
}
|
55
11
|
end
|
@@ -1,48 +1,100 @@
|
|
1
|
+
require 'earth/eia'
|
2
|
+
require 'earth/locality/data_miner'
|
1
3
|
CbecsEnergyIntensity.class_eval do
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
4
|
+
const_set(:CENSUS_DIVISIONS, {
|
5
|
+
'New England Division' => {
|
6
|
+
:column => 0,
|
7
|
+
:code => 1,
|
8
|
+
:table => 'c17'
|
9
|
+
},
|
10
|
+
'Middle Atlantic Division' => {
|
11
|
+
:column => 1,
|
12
|
+
:code => 2,
|
13
|
+
:table => 'c17'
|
14
|
+
},
|
15
|
+
'East North Central Division' => {
|
16
|
+
:column => 2,
|
17
|
+
:code => 3,
|
18
|
+
:table => 'c17'
|
19
|
+
},
|
20
|
+
'West North Central Division' => {
|
21
|
+
:column => 0,
|
22
|
+
:code => 4,
|
23
|
+
:table => 'c18'
|
24
|
+
},
|
25
|
+
'South Atlantic Division' => {
|
26
|
+
:column => 1,
|
27
|
+
:code => 5,
|
28
|
+
:table => 'c18'
|
29
|
+
},
|
30
|
+
'East South Central Division' => {
|
31
|
+
:column => 2,
|
32
|
+
:code => 6,
|
33
|
+
:table => 'c18'
|
34
|
+
},
|
35
|
+
'West South Central Division' => {
|
36
|
+
:column => 0,
|
37
|
+
:code => 7,
|
38
|
+
:table => 'c19'
|
39
|
+
},
|
40
|
+
'Mountain Division' => {
|
41
|
+
:column => 1,
|
42
|
+
:code => 8,
|
43
|
+
:table => 'c19'
|
44
|
+
},
|
45
|
+
'Pacific Division' => {
|
46
|
+
:column => 2,
|
47
|
+
:code => 9,
|
48
|
+
:table => 'c19'
|
49
|
+
}
|
50
|
+
})
|
51
|
+
|
52
|
+
const_set(:NAICS_CODE_SYNTHESIZER, lambda { |row|
|
53
|
+
case row[0].to_s
|
54
|
+
when /Education/
|
55
|
+
611110
|
56
|
+
when /Food Sales/
|
57
|
+
445
|
58
|
+
when /Food Service/
|
59
|
+
722
|
60
|
+
when /Health Care/
|
61
|
+
622110
|
62
|
+
when /Inpatient/
|
63
|
+
622110
|
64
|
+
when /Outpatient/
|
65
|
+
622111
|
66
|
+
when /Lodging/
|
67
|
+
721
|
68
|
+
when /Retail (Other Than Mall)/
|
69
|
+
44
|
70
|
+
when /Office/
|
71
|
+
#TODO
|
72
|
+
when /Public Assembly/
|
73
|
+
#TODO
|
74
|
+
when /Public Order and Safety/
|
75
|
+
922120
|
76
|
+
when /Religious Worship/
|
77
|
+
813110
|
78
|
+
when /Service/
|
79
|
+
#TODO
|
80
|
+
when /Warehouse and Storage/
|
81
|
+
493110
|
82
|
+
when /Other/
|
83
|
+
#TODO
|
84
|
+
when /Vacant/
|
85
|
+
#TODO
|
38
86
|
end
|
39
|
-
|
87
|
+
})
|
88
|
+
|
89
|
+
data_miner do
|
40
90
|
CbecsEnergyIntensity::CENSUS_DIVISIONS.each do |division, data|
|
41
|
-
import "2003 CBECS #{data[:table].
|
91
|
+
import "2003 CBECS #{data[:table].upcase} - Electricity Consumption and Intensity - #{division}",
|
42
92
|
:url => "http://www.eia.gov/emeu/cbecs/cbecs2003/detailed_tables_2003/2003set10/2003excel/#{data[:table]}.xls",
|
43
|
-
:
|
44
|
-
|
45
|
-
|
93
|
+
:headers => false,
|
94
|
+
:select => ::Proc.new { |row| CbecsEnergyIntensity::NAICS_CODE_SYNTHESIZER.call(row) },
|
95
|
+
:crop => (21..37) do
|
96
|
+
key :name, :synthesize => ::Proc.new { |row| "#{Industry.format_naics_code(CbecsEnergyIntensity::NAICS_CODE_SYNTHESIZER.call(row))}-#{data[:code]}" }
|
97
|
+
store :naics_code, :synthesize => CbecsEnergyIntensity::NAICS_CODE_SYNTHESIZER
|
46
98
|
store :census_division_number, :static => data[:code]
|
47
99
|
store :total_electricity_consumption, :field_number => data[:column] + 1
|
48
100
|
store :total_floorspace, :field_number => data[:column] + 4
|
@@ -51,7 +103,7 @@ CbecsEnergyIntensity.class_eval do
|
|
51
103
|
end
|
52
104
|
|
53
105
|
process :normalize_fuels do
|
54
|
-
EIA.normalize(CbecsEnergyIntensity, [:total_electricity_consumption, :total_floorspace, :electricity_intensity])
|
106
|
+
Earth::EIA.normalize(CbecsEnergyIntensity, [:total_electricity_consumption, :total_floorspace, :electricity_intensity])
|
55
107
|
end
|
56
108
|
end
|
57
109
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
|
-
require 'earth
|
3
|
-
|
4
|
-
require 'earth/industry/mecs_ratio/data_miner'
|
1
|
+
# lib/earth/industry/data_miner.rb
|
2
|
+
require 'earth'
|
3
|
+
Earth.require_related __FILE__
|