earth 0.12.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/Gemfile +0 -5
- data/README.markdown +32 -19
- data/Rakefile +4 -0
- data/bin/earth_tester.rb +66 -54
- data/earth.gemspec +6 -3
- data/lib/earth.rb +67 -114
- data/lib/earth/air.rb +1 -1
- data/lib/earth/air/aircraft.rb +37 -21
- data/lib/earth/air/aircraft/data_miner.rb +0 -4
- data/lib/earth/air/airline.rb +19 -5
- data/lib/earth/air/airline/data_miner.rb +0 -4
- data/lib/earth/air/airport.rb +23 -9
- data/lib/earth/air/airport/data_miner.rb +1 -5
- data/lib/earth/air/bts_aircraft.rb +14 -2
- data/lib/earth/air/flight_distance_class.rb +19 -7
- data/lib/earth/air/flight_distance_class_seat_class.rb +21 -4
- data/lib/earth/air/flight_seat_class.rb +13 -1
- data/lib/earth/air/flight_seat_class/data_miner.rb +2 -0
- data/lib/earth/air/flight_segment.rb +64 -59
- data/lib/earth/air/flight_segment/data_miner.rb +4 -5
- data/lib/earth/all.rb +1 -1
- data/lib/earth/automobile.rb +1 -1
- data/lib/earth/automobile/automobile_activity_year.rb +17 -3
- data/lib/earth/automobile/automobile_activity_year/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_activity_year_type.rb +21 -7
- data/lib/earth/automobile/automobile_activity_year_type/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +20 -8
- data/lib/earth/automobile/automobile_activity_year_type_fuel/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_fuel.rb +37 -23
- data/lib/earth/automobile/automobile_fuel/data_miner.rb +3 -5
- data/lib/earth/automobile/automobile_make.rb +17 -3
- data/lib/earth/automobile/automobile_make/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_make_model.rb +29 -14
- data/lib/earth/automobile/automobile_make_model/data_miner.rb +2 -5
- data/lib/earth/automobile/automobile_make_model_year.rb +31 -18
- data/lib/earth/automobile/automobile_make_model_year/data_miner.rb +3 -4
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +43 -31
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_make_year.rb +18 -7
- data/lib/earth/automobile/automobile_make_year/data_miner.rb +4 -4
- data/lib/earth/automobile/automobile_make_year_fleet.rb +19 -7
- data/lib/earth/automobile/automobile_make_year_fleet/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_model.rb +13 -1
- data/lib/earth/automobile/automobile_model/data_miner.rb +2 -4
- data/lib/earth/automobile/automobile_size_class.rb +24 -10
- data/lib/earth/automobile/automobile_size_class/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_type_fuel.rb +26 -12
- data/lib/earth/automobile/automobile_type_fuel/data_miner.rb +2 -4
- data/lib/earth/automobile/automobile_type_fuel_control.rb +20 -8
- data/lib/earth/automobile/automobile_type_fuel_control/data_miner.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel_year.rb +25 -11
- data/lib/earth/automobile/automobile_type_fuel_year/data_miner.rb +2 -4
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +21 -7
- data/lib/earth/automobile/automobile_type_fuel_year_control/data_miner.rb +0 -4
- data/lib/earth/automobile/automobile_year.rb +13 -1
- data/lib/earth/automobile/automobile_year/data_miner.rb +2 -0
- data/lib/earth/bus.rb +1 -1
- data/lib/earth/bus/bus_class.rb +38 -25
- data/lib/earth/bus/bus_class/data_miner.rb +0 -1
- data/lib/earth/bus/bus_fuel.rb +27 -13
- data/lib/earth/bus/bus_fuel/data_miner.rb +5 -1
- data/lib/earth/bus/bus_fuel_control.rb +19 -7
- data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -1
- data/lib/earth/bus/bus_fuel_year_control.rb +20 -7
- data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +2 -1
- data/lib/earth/computation.rb +1 -1
- data/lib/earth/computation/computation_carrier.rb +16 -3
- data/lib/earth/computation/computation_carrier/data_miner.rb +0 -1
- data/lib/earth/computation/computation_carrier_instance_class.rb +21 -6
- data/lib/earth/computation/computation_carrier_instance_class/data_miner.rb +0 -1
- data/lib/earth/computation/computation_carrier_region.rb +18 -5
- data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -1
- data/lib/earth/diet.rb +1 -1
- data/lib/earth/diet/diet_class.rb +25 -13
- data/lib/earth/diet/food_group.rb +18 -7
- data/lib/earth/electricity.rb +1 -1
- data/lib/earth/electricity/electric_market.rb +17 -5
- data/lib/earth/electricity/electric_market/data_miner.rb +0 -2
- data/lib/earth/electricity/electric_utility.rb +22 -7
- data/lib/earth/electricity/electric_utility/data_miner.rb +1 -1
- data/lib/earth/electricity/green_button_adoption.rb +15 -3
- data/lib/earth/fuel.rb +1 -1
- data/lib/earth/fuel/fuel.rb +32 -19
- data/lib/earth/fuel/fuel/data_miner.rb +2 -4
- data/lib/earth/fuel/fuel_price.rb +17 -3
- data/lib/earth/fuel/fuel_type.rb +23 -12
- data/lib/earth/fuel/fuel_year.rb +27 -13
- data/lib/earth/fuel/greenhouse_gas.rb +18 -6
- data/lib/earth/hospitality.rb +1 -1
- data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response.rb +68 -56
- data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb +0 -4
- data/lib/earth/hospitality/lodging_class.rb +13 -1
- data/lib/earth/industry.rb +1 -1
- data/lib/earth/industry/cbecs_energy_intensity.rb +43 -32
- data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +0 -1
- data/lib/earth/industry/industry.rb +20 -2
- data/lib/earth/industry/industry/data_miner.rb +0 -4
- data/lib/earth/industry/industry_product.rb +20 -6
- data/lib/earth/industry/industry_product_line.rb +19 -5
- data/lib/earth/industry/industry_sector.rb +19 -6
- data/lib/earth/industry/mecs_energy.rb +34 -22
- data/lib/earth/industry/mecs_ratio.rb +17 -6
- data/lib/earth/industry/mecs_ratio/data_miner.rb +1 -1
- data/lib/earth/industry/merchant_category.rb +17 -2
- data/lib/earth/industry/merchant_category/data_miner.rb +0 -4
- data/lib/earth/industry/merchant_category_industry.rb +19 -4
- data/lib/earth/industry/naics_2002.rb +20 -3
- data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +19 -4
- data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +19 -4
- data/lib/earth/industry/naics_2007.rb +17 -2
- data/lib/earth/industry/product_line.rb +20 -5
- data/lib/earth/industry/product_line_industry_product.rb +19 -5
- data/lib/earth/industry/sector.rb +18 -5
- data/lib/earth/industry/sic_1987.rb +17 -2
- data/lib/earth/loader.rb +47 -0
- data/lib/earth/locality.rb +1 -1
- data/lib/earth/locality/census_division.rb +32 -13
- data/lib/earth/locality/census_division/data_miner.rb +0 -1
- data/lib/earth/locality/census_region.rb +18 -5
- data/lib/earth/locality/climate_division.rb +21 -6
- data/lib/earth/locality/country.rb +68 -56
- data/lib/earth/locality/country/data_miner.rb +8 -8
- data/lib/earth/locality/egrid_country.rb +22 -10
- data/lib/earth/locality/egrid_region.rb +25 -10
- data/lib/earth/locality/egrid_region/data_miner.rb +0 -4
- data/lib/earth/locality/egrid_subregion.rb +31 -16
- data/lib/earth/locality/egrid_subregion/data_miner.rb +7 -6
- data/lib/earth/locality/electricity_mix.rb +27 -13
- data/lib/earth/locality/electricity_mix/data_miner.rb +8 -8
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +17 -5
- data/lib/earth/locality/state.rb +36 -16
- data/lib/earth/locality/state/data_miner.rb +0 -4
- data/lib/earth/locality/zip_code.rb +34 -15
- data/lib/earth/locality/zip_code/data_miner.rb +0 -4
- data/lib/earth/model.rb +90 -0
- data/lib/earth/pet.rb +1 -1
- data/lib/earth/pet/breed.rb +19 -4
- data/lib/earth/pet/breed_gender.rb +20 -5
- data/lib/earth/pet/gender.rb +15 -1
- data/lib/earth/pet/species.rb +30 -14
- data/lib/earth/rail.rb +1 -1
- data/lib/earth/rail/country_rail_class.rb +26 -15
- data/lib/earth/rail/country_rail_class/data_miner.rb +0 -1
- data/lib/earth/rail/country_rail_traction.rb +21 -11
- data/lib/earth/rail/country_rail_traction/data_miner.rb +2 -2
- data/lib/earth/rail/country_rail_traction_class.rb +22 -12
- data/lib/earth/rail/country_rail_traction_class/data_miner.rb +2 -2
- data/lib/earth/rail/national_transit_database_company.rb +20 -6
- data/lib/earth/rail/national_transit_database_company/data_miner.rb +0 -1
- data/lib/earth/rail/national_transit_database_mode.rb +15 -3
- data/lib/earth/rail/national_transit_database_record.rb +45 -31
- data/lib/earth/rail/national_transit_database_record/data_miner.rb +0 -1
- data/lib/earth/rail/rail_class.rb +13 -1
- data/lib/earth/rail/rail_company.rb +34 -22
- data/lib/earth/rail/rail_company/data_miner.rb +7 -2
- data/lib/earth/rail/rail_company_traction.rb +21 -10
- data/lib/earth/rail/rail_company_traction/data_miner.rb +0 -1
- data/lib/earth/rail/rail_company_traction_class.rb +22 -11
- data/lib/earth/rail/rail_company_traction_class/data_miner.rb +0 -1
- data/lib/earth/rail/rail_fuel.rb +20 -7
- data/lib/earth/rail/rail_fuel/data_miner.rb +3 -1
- data/lib/earth/rail/rail_traction.rb +13 -1
- data/lib/earth/rail/rail_traction/data_miner.rb +5 -0
- data/lib/earth/residence.rb +1 -1
- data/lib/earth/residence/air_conditioner_use.rb +19 -3
- data/lib/earth/residence/clothes_machine_use.rb +17 -3
- data/lib/earth/residence/dishwasher_use.rb +17 -3
- data/lib/earth/residence/residence_appliance.rb +15 -3
- data/lib/earth/residence/residence_appliance/data_miner.rb +2 -0
- data/lib/earth/residence/residence_class.rb +15 -1
- data/lib/earth/residence/residence_fuel_price.rb +25 -12
- data/lib/earth/residence/residence_fuel_price/data_miner.rb +0 -1
- data/lib/earth/residence/residence_fuel_type.rb +17 -6
- data/lib/earth/residence/residential_energy_consumption_survey_response.rb +110 -91
- data/lib/earth/residence/residential_energy_consumption_survey_response/data_miner.rb +0 -1
- data/lib/earth/residence/urbanity.rb +15 -1
- data/lib/earth/shipping.rb +1 -1
- data/lib/earth/shipping/carrier.rb +24 -8
- data/lib/earth/shipping/carrier_mode.rb +22 -7
- data/lib/earth/shipping/shipment_mode.rb +18 -4
- data/lib/earth/tasks.rb +62 -0
- data/lib/earth/version.rb +1 -1
- data/lib/earth/warnings.rb +12 -0
- data/spec/data_mining_spec.rb +31 -0
- data/spec/earth/air/aircraft_spec.rb +0 -10
- data/spec/earth/air/airline_spec.rb +1 -11
- data/spec/earth/air/airport_spec.rb +0 -10
- data/spec/earth/air/bts_aircraft_spec.rb +0 -10
- data/spec/earth/air/flight_distance_class_spec.rb +0 -10
- data/spec/earth/air/flight_segment_spec.rb +27 -10
- data/spec/earth/automobile/automobile_activity_year_spec.rb +0 -7
- data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +0 -7
- data/spec/earth/automobile/automobile_activity_year_type_spec.rb +0 -7
- data/spec/earth/automobile/automobile_fuel_spec.rb +0 -10
- data/spec/earth/automobile/automobile_make_model_spec.rb +0 -8
- data/spec/earth/automobile/automobile_make_model_year_spec.rb +0 -8
- data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +0 -8
- data/spec/earth/automobile/automobile_make_spec.rb +0 -11
- data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +0 -11
- data/spec/earth/automobile/automobile_make_year_spec.rb +0 -8
- data/spec/earth/automobile/automobile_model_spec.rb +0 -10
- data/spec/earth/automobile/automobile_size_class_spec.rb +0 -10
- data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +0 -7
- data/spec/earth/automobile/automobile_type_fuel_spec.rb +0 -10
- data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +0 -7
- data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +1 -8
- data/spec/earth/automobile/automobile_year_spec.rb +2 -11
- data/spec/earth/bus/bus_fuel_control_spec.rb +0 -10
- data/spec/earth/bus/bus_fuel_spec.rb +0 -10
- data/spec/earth/bus/bus_fuel_year_control_spec.rb +0 -10
- data/spec/earth/electricity/electric_market_spec.rb +0 -10
- data/spec/earth/electricity/electric_utility_spec.rb +0 -10
- data/spec/earth/electricity/green_button_adoption_spec.rb +0 -10
- data/spec/earth/fuel/fuel_spec.rb +1 -10
- data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +0 -10
- data/spec/earth/hospitality/lodging_class_spec.rb +0 -10
- data/spec/earth/industry/cbecs_energy_intensity_spec.rb +3 -11
- data/spec/earth/industry/industry_spec.rb +0 -10
- data/spec/earth/industry/mecs_energy_spec.rb +0 -9
- data/spec/earth/industry/mecs_ratio_spec.rb +0 -9
- data/spec/earth/industry/merchant_category_spec.rb +2 -7
- data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +1 -12
- data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +3 -13
- data/spec/earth/industry/naics_2002_spec.rb +0 -10
- data/spec/earth/industry/naics_2007_spec.rb +0 -10
- data/spec/earth/industry/sic_1987_spec.rb +0 -10
- data/spec/earth/locality/country_spec.rb +0 -10
- data/spec/earth/locality/egrid_country_spec.rb +0 -11
- data/spec/earth/locality/egrid_region_spec.rb +0 -10
- data/spec/earth/locality/egrid_subregion_spec.rb +0 -10
- data/spec/earth/locality/electricity_mix_spec.rb +0 -10
- data/spec/earth/locality/state_spec.rb +0 -10
- data/spec/earth/locality/zip_code_spec.rb +7 -15
- data/spec/earth/model_spec.rb +27 -0
- data/spec/earth/pet/species_spec.rb +1 -1
- data/spec/earth_spec.rb +1 -30
- data/spec/factories/airline.rb +10 -0
- data/spec/factories/airport.rb +12 -0
- data/spec/factories/flight_segment.rb +38 -0
- data/spec/spec_helper.rb +27 -36
- metadata +249 -223
- data/lib/earth/active_record_base_class_methods.rb +0 -25
- data/lib/earth/air/data_miner.rb +0 -3
- data/lib/earth/automobile/data_miner.rb +0 -3
- data/lib/earth/bus/data_miner.rb +0 -3
- data/lib/earth/computation/data_miner.rb +0 -3
- data/lib/earth/data_miner.rb +0 -3
- data/lib/earth/diet/data_miner.rb +0 -3
- data/lib/earth/fuel/data_miner.rb +0 -3
- data/lib/earth/hospitality/data_miner.rb +0 -3
- data/lib/earth/industry/data_miner.rb +0 -3
- data/lib/earth/locality/data_miner.rb +0 -3
- data/lib/earth/pet/data_miner.rb +0 -3
- data/lib/earth/rail/data_miner.rb +0 -3
- data/lib/earth/residence/data_miner.rb +0 -3
- data/lib/earth/shipping/data_miner.rb +0 -3
@@ -1,4 +1,24 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry'
|
4
|
+
require 'earth/industry/naics_2002_naics_2007_concordance'
|
5
|
+
require 'earth/industry/naics_2002_sic_1987_concordance'
|
6
|
+
require 'earth/industry/naics_2007'
|
7
|
+
require 'earth/industry/sic_1987'
|
8
|
+
|
1
9
|
class Naics2002 < ActiveRecord::Base
|
10
|
+
extend Earth::Model
|
11
|
+
|
12
|
+
TABLE_STRUCTURE = <<-EOS
|
13
|
+
|
14
|
+
CREATE TABLE naics_2002
|
15
|
+
(
|
16
|
+
code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
17
|
+
description CHARACTER VARYING(255)
|
18
|
+
);
|
19
|
+
|
20
|
+
EOS
|
21
|
+
|
2
22
|
self.primary_key = "code"
|
3
23
|
self.table_name = "naics_2002"
|
4
24
|
|
@@ -9,7 +29,4 @@ class Naics2002 < ActiveRecord::Base
|
|
9
29
|
|
10
30
|
has_many :naics_2002_naics_2007_concordances, :foreign_key => :naics_2002_code
|
11
31
|
has_many :naics_2007, :through => :naics_2002_naics_2007_concordances
|
12
|
-
|
13
|
-
col :code
|
14
|
-
col :description
|
15
32
|
end
|
@@ -1,4 +1,23 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/naics_2002'
|
4
|
+
require 'earth/industry/naics_2007'
|
5
|
+
|
1
6
|
class Naics2002Naics2007Concordance < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE naics2002_naics2007_concordances
|
12
|
+
(
|
13
|
+
row_hash CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
naics_2002_code CHARACTER VARYING(255),
|
15
|
+
naics_2007_code CHARACTER VARYING(255),
|
16
|
+
naics_2002_note CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
2
21
|
self.primary_key = "row_hash"
|
3
22
|
|
4
23
|
belongs_to :naics_2002, :foreign_key => :naics_2002_code
|
@@ -9,8 +28,4 @@ class Naics2002Naics2007Concordance < ActiveRecord::Base
|
|
9
28
|
(note = description.match(/ - (.+)/)) ? note.captures.first : nil
|
10
29
|
end
|
11
30
|
|
12
|
-
col :row_hash
|
13
|
-
col :naics_2002_code
|
14
|
-
col :naics_2007_code
|
15
|
-
col :naics_2002_note
|
16
31
|
end
|
@@ -1,4 +1,23 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/naics_2002'
|
4
|
+
require 'earth/industry/sic_1987'
|
5
|
+
|
1
6
|
class Naics2002Sic1987Concordance < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE naics2002_sic1987_concordances
|
12
|
+
(
|
13
|
+
row_hash CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
naics_2002_code CHARACTER VARYING(255),
|
15
|
+
sic_1987_code CHARACTER VARYING(255),
|
16
|
+
sic_note CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
2
21
|
self.primary_key = "row_hash"
|
3
22
|
|
4
23
|
belongs_to :naics_2002, :foreign_key => :naics_2002_code
|
@@ -9,8 +28,4 @@ class Naics2002Sic1987Concordance < ActiveRecord::Base
|
|
9
28
|
(note = description.match /.+?\((.+)\)/) ? note.captures.first : nil
|
10
29
|
end
|
11
30
|
|
12
|
-
col :row_hash
|
13
|
-
col :naics_2002_code
|
14
|
-
col :sic_1987_code
|
15
|
-
col :sic_note
|
16
31
|
end
|
@@ -1,10 +1,25 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/naics_2002_naics_2007_concordance'
|
4
|
+
require 'earth/industry/naics_2002'
|
5
|
+
|
1
6
|
class Naics2007 < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE naics_2007
|
12
|
+
(
|
13
|
+
code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
description CHARACTER VARYING(255)
|
15
|
+
);
|
16
|
+
|
17
|
+
EOS
|
18
|
+
|
2
19
|
self.primary_key = "code"
|
3
20
|
self.table_name = "naics_2007"
|
4
21
|
|
5
22
|
has_many :naics_2002_naics_2007_concordances, :foreign_key => :naics_2007_code
|
6
23
|
has_many :naics_2002, :through => :naics_2002_naics_2007_concordances
|
7
24
|
|
8
|
-
col :code
|
9
|
-
col :description
|
10
25
|
end
|
@@ -1,13 +1,28 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry_product'
|
4
|
+
require 'earth/industry/industry_product_line'
|
5
|
+
require 'earth/industry/product_line_industry_product'
|
6
|
+
|
1
7
|
class ProductLine < ActiveRecord::Base
|
8
|
+
extend Earth::Model
|
9
|
+
|
10
|
+
TABLE_STRUCTURE = <<-EOS
|
11
|
+
|
12
|
+
CREATE TABLE product_lines
|
13
|
+
(
|
14
|
+
ps_code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
15
|
+
description TEXT,
|
16
|
+
broadline CHARACTER VARYING(255), /* FIXME TODO do we need this? */
|
17
|
+
parent CHARACTER VARYING(255) /* FIXME TODO do we need this? */
|
18
|
+
);
|
19
|
+
|
20
|
+
EOS
|
21
|
+
|
2
22
|
self.primary_key = "ps_code"
|
3
23
|
|
4
24
|
has_many :industry_product_lines, :foreign_key => 'ps_code'
|
5
25
|
|
6
26
|
has_many :product_line_industry_products, :foreign_key => 'ps_code'
|
7
27
|
has_many :industry_products, :through => :product_line_industry_products
|
8
|
-
|
9
|
-
col :ps_code
|
10
|
-
col :description, :type => :text
|
11
|
-
col :broadline # FIXME TODO do we need this?
|
12
|
-
col :parent # FIXME TODO do we need this?
|
13
28
|
end
|
@@ -1,11 +1,25 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/product_line'
|
4
|
+
require 'earth/industry/industry_product'
|
5
|
+
|
1
6
|
class ProductLineIndustryProduct < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE product_line_industry_products
|
12
|
+
(
|
13
|
+
row_hash CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
ps_code CHARACTER VARYING(255),
|
15
|
+
ratio FLOAT,
|
16
|
+
naics_product_code CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
2
21
|
self.primary_key = "row_hash"
|
3
22
|
|
4
23
|
belongs_to :product_line, :foreign_key => 'ps_code'
|
5
24
|
belongs_to :industry_product, :foreign_key => 'naics_product_code'
|
6
|
-
|
7
|
-
col :row_hash
|
8
|
-
col :ps_code
|
9
|
-
col :ratio, :type => :float
|
10
|
-
col :naics_product_code
|
11
25
|
end
|
@@ -1,10 +1,23 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry_sector'
|
4
|
+
|
1
5
|
class Sector < ActiveRecord::Base
|
6
|
+
extend Earth::Model
|
7
|
+
|
8
|
+
TABLE_STRUCTURE = <<-EOS
|
9
|
+
|
10
|
+
CREATE TABLE sectors
|
11
|
+
(
|
12
|
+
io_code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
13
|
+
description TEXT,
|
14
|
+
value FLOAT,
|
15
|
+
value_units CHARACTER VARYING(255)
|
16
|
+
);
|
17
|
+
|
18
|
+
EOS
|
19
|
+
|
2
20
|
self.primary_key = "io_code"
|
3
21
|
|
4
22
|
has_many :industry_sectors, :foreign_key => 'io_code'
|
5
|
-
|
6
|
-
col :io_code
|
7
|
-
col :description, :type => :text
|
8
|
-
col :value, :type => :float
|
9
|
-
col :value_units
|
10
23
|
end
|
@@ -1,4 +1,21 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/naics_2002'
|
4
|
+
require 'earth/industry/naics_2002_sic_1987_concordance'
|
5
|
+
|
1
6
|
class Sic1987 < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE sic_1987
|
12
|
+
(
|
13
|
+
code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
description CHARACTER VARYING(255)
|
15
|
+
);
|
16
|
+
|
17
|
+
EOS
|
18
|
+
|
2
19
|
self.primary_key = "code"
|
3
20
|
self.table_name = "sic_1987"
|
4
21
|
|
@@ -10,6 +27,4 @@ class Sic1987 < ActiveRecord::Base
|
|
10
27
|
(desc = description.match /^(.+?) \(/) ? desc.captures.first : description
|
11
28
|
end
|
12
29
|
|
13
|
-
col :code
|
14
|
-
col :description
|
15
30
|
end
|
data/lib/earth/loader.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'earth'
|
2
|
+
|
3
|
+
module Earth
|
4
|
+
module Loader
|
5
|
+
def Loader.require_related(path)
|
6
|
+
path = ::File.expand_path path
|
7
|
+
raise ::ArgumentError, %{[earth gem] #{path} is not in #{LIB_DIR}} unless path.start_with?(LIB_DIR)
|
8
|
+
domain = %r{#{LIB_DIR}/([^\./]+)}.match(path).captures.first
|
9
|
+
require_domain domain, :mine_original_sources => path.include?('data_miner')
|
10
|
+
end
|
11
|
+
|
12
|
+
def Loader.require_all(options = {})
|
13
|
+
require_glob ::File.join(LIB_DIR, '**', '*.rb'), options
|
14
|
+
end
|
15
|
+
|
16
|
+
def Loader.require_domain(domain, options = {})
|
17
|
+
require_glob ::File.join(LIB_DIR, domain.to_s, '**', '*.rb'), options
|
18
|
+
end
|
19
|
+
|
20
|
+
def Loader.require_glob(glob, options = {})
|
21
|
+
@require_glob ||= []
|
22
|
+
args = [glob, options]
|
23
|
+
return if @require_glob.include?(args)
|
24
|
+
@require_glob << args
|
25
|
+
data_miner_paths = []
|
26
|
+
::Dir[glob].each do |path|
|
27
|
+
if path.include?('data_miner')
|
28
|
+
data_miner_paths << path
|
29
|
+
else
|
30
|
+
require path
|
31
|
+
end
|
32
|
+
end
|
33
|
+
# load data_miner blocks second to make sure they override
|
34
|
+
data_miner_paths.each do |path|
|
35
|
+
require path
|
36
|
+
end if options[:load_data_miner] || options[:mine_original_sources]
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def Loader.load_plugins
|
41
|
+
Dir[File.expand_path('../../../vendor/**/init.rb', __FILE__)].each do |pluginit|
|
42
|
+
$LOAD_PATH.unshift ::File.join(::File.dirname(pluginit), 'lib')
|
43
|
+
Kernel.load pluginit
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/earth/locality.rb
CHANGED
@@ -1,5 +1,36 @@
|
|
1
|
-
require '
|
1
|
+
require 'falls_back_on'
|
2
|
+
|
3
|
+
require 'earth/model'
|
4
|
+
|
5
|
+
require 'earth/locality/census_region'
|
6
|
+
require 'earth/locality/climate_division'
|
7
|
+
require 'earth/locality/state'
|
8
|
+
require 'earth/locality/zip_code'
|
9
|
+
require 'earth/residence/residential_energy_consumption_survey_response'
|
10
|
+
|
2
11
|
class CensusDivision < ActiveRecord::Base
|
12
|
+
extend Earth::Model
|
13
|
+
|
14
|
+
TABLE_STRUCTURE = <<-EOS
|
15
|
+
|
16
|
+
CREATE TABLE census_divisions
|
17
|
+
(
|
18
|
+
number INTEGER NOT NULL PRIMARY KEY,
|
19
|
+
name CHARACTER VARYING(255),
|
20
|
+
census_region_name CHARACTER VARYING(255),
|
21
|
+
census_region_number INTEGER,
|
22
|
+
meeting_building_natural_gas_intensity FLOAT,
|
23
|
+
meeting_building_natural_gas_intensity_units CHARACTER VARYING(255),
|
24
|
+
meeting_building_fuel_oil_intensity FLOAT,
|
25
|
+
meeting_building_fuel_oil_intensity_units CHARACTER VARYING(255),
|
26
|
+
meeting_building_electricity_intensity FLOAT,
|
27
|
+
meeting_building_electricity_intensity_units CHARACTER VARYING(255),
|
28
|
+
meeting_building_district_heat_intensity FLOAT,
|
29
|
+
meeting_building_district_heat_intensity_units CHARACTER VARYING(255)
|
30
|
+
);
|
31
|
+
|
32
|
+
EOS
|
33
|
+
|
3
34
|
self.primary_key = "number"
|
4
35
|
|
5
36
|
belongs_to :census_region, :foreign_key => 'census_region_number'
|
@@ -15,18 +46,6 @@ class CensusDivision < ActiveRecord::Base
|
|
15
46
|
:meeting_building_electricity_intensity => 0.0084323684 / 1.square_feet.to(:square_metres),
|
16
47
|
:meeting_building_district_heat_intensity => 0.0004776370.kbtus.to(:megajoules) / 1.square_feet.to(:square_metres)
|
17
48
|
|
18
|
-
col :number, :type => :integer
|
19
|
-
col :name
|
20
|
-
col :census_region_name
|
21
|
-
col :census_region_number, :type => :integer
|
22
|
-
col :meeting_building_natural_gas_intensity, :type => :float
|
23
|
-
col :meeting_building_natural_gas_intensity_units
|
24
|
-
col :meeting_building_fuel_oil_intensity, :type => :float
|
25
|
-
col :meeting_building_fuel_oil_intensity_units
|
26
|
-
col :meeting_building_electricity_intensity, :type => :float
|
27
|
-
col :meeting_building_electricity_intensity_units
|
28
|
-
col :meeting_building_district_heat_intensity, :type => :float
|
29
|
-
col :meeting_building_district_heat_intensity_units
|
30
49
|
|
31
50
|
warn_unless_size 9
|
32
51
|
end
|
@@ -1,14 +1,27 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/locality/census_division'
|
4
|
+
require 'earth/locality/state'
|
5
|
+
require 'earth/residence/residential_energy_consumption_survey_response'
|
6
|
+
|
1
7
|
class CensusRegion < ActiveRecord::Base
|
8
|
+
extend Earth::Model
|
9
|
+
|
10
|
+
TABLE_STRUCTURE = <<-EOS
|
11
|
+
|
12
|
+
CREATE TABLE census_regions
|
13
|
+
(
|
14
|
+
number INTEGER NOT NULL PRIMARY KEY,
|
15
|
+
name CHARACTER VARYING(255)
|
16
|
+
);
|
17
|
+
|
18
|
+
EOS
|
19
|
+
|
2
20
|
self.primary_key = "number"
|
3
21
|
|
4
22
|
has_many :census_divisions, :foreign_key => 'census_region_number'
|
5
23
|
has_many :states, :through => :census_divisions
|
6
|
-
# has_many :climate_divisions, :through => :census_divisions
|
7
|
-
# has_many :zip_codes, :through => :census_divisions
|
8
24
|
has_many :residential_energy_consumption_survey_responses, :foreign_key => 'census_region_number'
|
9
|
-
|
10
|
-
col :number, :type => :integer
|
11
|
-
col :name
|
12
25
|
|
13
26
|
warn_unless_size 4
|
14
27
|
end
|
@@ -1,4 +1,25 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/locality/state'
|
4
|
+
require 'earth/locality/zip_code'
|
5
|
+
|
1
6
|
class ClimateDivision < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE climate_divisions
|
12
|
+
(
|
13
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
heating_degree_days FLOAT,
|
15
|
+
heating_degree_days_units CHARACTER VARYING(255),
|
16
|
+
cooling_degree_days FLOAT,
|
17
|
+
cooling_degree_days_units CHARACTER VARYING(255),
|
18
|
+
state_postal_abbreviation CHARACTER VARYING(255)
|
19
|
+
);
|
20
|
+
|
21
|
+
EOS
|
22
|
+
|
2
23
|
self.primary_key = "name"
|
3
24
|
|
4
25
|
has_many :zip_codes, :foreign_key => 'climate_division_name'
|
@@ -6,12 +27,6 @@ class ClimateDivision < ActiveRecord::Base
|
|
6
27
|
|
7
28
|
RADIUS = 750
|
8
29
|
|
9
|
-
col :name
|
10
|
-
col :heating_degree_days, :type => :float
|
11
|
-
col :heating_degree_days_units
|
12
|
-
col :cooling_degree_days, :type => :float
|
13
|
-
col :cooling_degree_days_units
|
14
|
-
col :state_postal_abbreviation
|
15
30
|
|
16
31
|
warn_unless_size 359
|
17
32
|
end
|
@@ -1,18 +1,78 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'earth/
|
1
|
+
require 'falls_back_on'
|
2
|
+
|
3
|
+
require 'earth/model'
|
4
|
+
|
5
|
+
require 'earth/locality/electricity_mix'
|
6
|
+
require 'earth/rail/rail_company'
|
4
7
|
|
5
8
|
class Country < ActiveRecord::Base
|
6
|
-
self.primary_key = "iso_3166_code"
|
7
|
-
|
8
|
-
has_many :rail_companies, :foreign_key => 'country_iso_3166_code' # used to calculate rail data
|
9
|
-
has_one :electricity_mix, :foreign_key => 'country_iso_3166_code'
|
10
|
-
|
11
9
|
data_miner do
|
12
10
|
process "Ensure ElectricityMix is imported because it's like a belongs_to association" do
|
13
11
|
ElectricityMix.run_data_miner!
|
14
12
|
end
|
15
13
|
end
|
14
|
+
|
15
|
+
extend Earth::Model
|
16
|
+
|
17
|
+
TABLE_STRUCTURE = <<-EOS
|
18
|
+
|
19
|
+
CREATE TABLE countries
|
20
|
+
(
|
21
|
+
iso_3166_code CHARACTER VARYING(255) NOT NULL PRIMARY KEY, /* alpha-2 2-letter like GB */
|
22
|
+
iso_3166_numeric_code INTEGER, /* numeric like 826; aka UN M49 code */
|
23
|
+
iso_3166_alpha_3_code CHARACTER VARYING(255), /* 3-letter like GBR */
|
24
|
+
name CHARACTER VARYING(255),
|
25
|
+
heating_degree_days FLOAT,
|
26
|
+
heating_degree_days_units CHARACTER VARYING(255),
|
27
|
+
cooling_degree_days FLOAT,
|
28
|
+
cooling_degree_days_units CHARACTER VARYING(255),
|
29
|
+
automobile_urbanity FLOAT, /* float from 0 to 1 */
|
30
|
+
automobile_fuel_efficiency FLOAT,
|
31
|
+
automobile_fuel_efficiency_units CHARACTER VARYING(255),
|
32
|
+
automobile_city_speed FLOAT,
|
33
|
+
automobile_city_speed_units CHARACTER VARYING(255),
|
34
|
+
automobile_highway_speed FLOAT,
|
35
|
+
automobile_highway_speed_units CHARACTER VARYING(255),
|
36
|
+
automobile_trip_distance FLOAT,
|
37
|
+
automobile_trip_distance_units CHARACTER VARYING(255),
|
38
|
+
electricity_emission_factor FLOAT,
|
39
|
+
electricity_emission_factor_units CHARACTER VARYING(255),
|
40
|
+
electricity_co2_emission_factor FLOAT,
|
41
|
+
electricity_co2_emission_factor_units CHARACTER VARYING(255),
|
42
|
+
electricity_ch4_emission_factor FLOAT,
|
43
|
+
electricity_ch4_emission_factor_units CHARACTER VARYING(255),
|
44
|
+
electricity_n2o_emission_factor FLOAT,
|
45
|
+
electricity_n2o_emission_factor_units CHARACTER VARYING(255),
|
46
|
+
electricity_loss_factor FLOAT,
|
47
|
+
flight_route_inefficiency_factor FLOAT,
|
48
|
+
lodging_occupancy_rate FLOAT,
|
49
|
+
lodging_natural_gas_intensity FLOAT,
|
50
|
+
lodging_natural_gas_intensity_units CHARACTER VARYING(255),
|
51
|
+
lodging_fuel_oil_intensity FLOAT,
|
52
|
+
lodging_fuel_oil_intensity_units CHARACTER VARYING(255),
|
53
|
+
lodging_electricity_intensity FLOAT,
|
54
|
+
lodging_electricity_intensity_units CHARACTER VARYING(255),
|
55
|
+
lodging_district_heat_intensity FLOAT,
|
56
|
+
lodging_district_heat_intensity_units CHARACTER VARYING(255),
|
57
|
+
rail_passengers FLOAT,
|
58
|
+
rail_trip_distance FLOAT,
|
59
|
+
rail_trip_distance_units CHARACTER VARYING(255),
|
60
|
+
rail_speed FLOAT,
|
61
|
+
rail_speed_units CHARACTER VARYING(255),
|
62
|
+
rail_trip_electricity_intensity FLOAT,
|
63
|
+
rail_trip_electricity_intensity_units CHARACTER VARYING(255),
|
64
|
+
rail_trip_diesel_intensity FLOAT,
|
65
|
+
rail_trip_diesel_intensity_units CHARACTER VARYING(255),
|
66
|
+
rail_trip_co2_emission_factor FLOAT,
|
67
|
+
rail_trip_co2_emission_factor_units CHARACTER VARYING(255)
|
68
|
+
);
|
69
|
+
|
70
|
+
EOS
|
71
|
+
|
72
|
+
self.primary_key = "iso_3166_code"
|
73
|
+
|
74
|
+
has_many :rail_companies, :foreign_key => 'country_iso_3166_code' # used to calculate rail data
|
75
|
+
has_one :electricity_mix, :foreign_key => 'country_iso_3166_code'
|
16
76
|
|
17
77
|
def self.united_states
|
18
78
|
find_by_iso_3166_code('US')
|
@@ -59,54 +119,6 @@ class Country < ActiveRecord::Base
|
|
59
119
|
:rail_trip_co2_emission_factor => lambda { weighted_average(:rail_trip_co2_emission_factor, :weighted_by => :rail_passengers) },
|
60
120
|
:rail_trip_co2_emission_factor_units => 'kilograms_per_passenger_kilometre' # FIXME TODO derive this
|
61
121
|
|
62
|
-
col :iso_3166_code # alpha-2 2-letter like GB
|
63
|
-
col :iso_3166_numeric_code, :type => :integer # numeric like 826; aka UN M49 code
|
64
|
-
col :iso_3166_alpha_3_code # 3-letter like GBR
|
65
|
-
col :name
|
66
|
-
col :heating_degree_days, :type => :float
|
67
|
-
col :heating_degree_days_units
|
68
|
-
col :cooling_degree_days, :type => :float
|
69
|
-
col :cooling_degree_days_units
|
70
|
-
col :automobile_urbanity, :type => :float # float from 0 to 1
|
71
|
-
col :automobile_fuel_efficiency, :type => :float
|
72
|
-
col :automobile_fuel_efficiency_units
|
73
|
-
col :automobile_city_speed, :type => :float
|
74
|
-
col :automobile_city_speed_units
|
75
|
-
col :automobile_highway_speed, :type => :float
|
76
|
-
col :automobile_highway_speed_units
|
77
|
-
col :automobile_trip_distance, :type => :float
|
78
|
-
col :automobile_trip_distance_units
|
79
|
-
col :electricity_emission_factor, :type => :float
|
80
|
-
col :electricity_emission_factor_units
|
81
|
-
col :electricity_co2_emission_factor, :type => :float
|
82
|
-
col :electricity_co2_emission_factor_units
|
83
|
-
col :electricity_ch4_emission_factor, :type => :float
|
84
|
-
col :electricity_ch4_emission_factor_units
|
85
|
-
col :electricity_n2o_emission_factor, :type => :float
|
86
|
-
col :electricity_n2o_emission_factor_units
|
87
|
-
col :electricity_loss_factor, :type => :float
|
88
|
-
col :flight_route_inefficiency_factor, :type => :float
|
89
|
-
col :lodging_occupancy_rate, :type => :float
|
90
|
-
col :lodging_natural_gas_intensity, :type => :float
|
91
|
-
col :lodging_natural_gas_intensity_units
|
92
|
-
col :lodging_fuel_oil_intensity, :type => :float
|
93
|
-
col :lodging_fuel_oil_intensity_units
|
94
|
-
col :lodging_electricity_intensity, :type => :float
|
95
|
-
col :lodging_electricity_intensity_units
|
96
|
-
col :lodging_district_heat_intensity, :type => :float
|
97
|
-
col :lodging_district_heat_intensity_units
|
98
|
-
col :rail_passengers, :type => :float
|
99
|
-
col :rail_trip_distance, :type => :float
|
100
|
-
col :rail_trip_distance_units
|
101
|
-
col :rail_speed, :type => :float
|
102
|
-
col :rail_speed_units
|
103
|
-
col :rail_trip_electricity_intensity, :type => :float
|
104
|
-
col :rail_trip_electricity_intensity_units
|
105
|
-
col :rail_trip_diesel_intensity, :type => :float
|
106
|
-
col :rail_trip_diesel_intensity_units
|
107
|
-
col :rail_trip_co2_emission_factor, :type => :float
|
108
|
-
col :rail_trip_co2_emission_factor_units
|
109
|
-
|
110
122
|
warn_unless_size 249
|
111
123
|
warn_if_nulls_except(
|
112
124
|
/heating/,
|