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
data/lib/earth/hospitality/commercial_building_energy_consumption_survey_response/data_miner.rb
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
CommercialBuildingEnergyConsumptionSurveyResponse.class_eval do
|
2
2
|
data_miner do
|
3
|
-
process "Start from scratch" do
|
4
|
-
delete_all
|
5
|
-
end
|
6
|
-
|
7
3
|
import 'building characteristics from the 2003 EIA CBECS - part 1',
|
8
4
|
:url => 'http://www.eia.gov/emeu/cbecs/cbecs2003/public_use_2003/data/FILE01.csv',
|
9
5
|
:skip => 1,
|
@@ -1,7 +1,19 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
1
3
|
class LodgingClass < ActiveRecord::Base
|
4
|
+
extend Earth::Model
|
5
|
+
|
6
|
+
TABLE_STRUCTURE = <<-EOS
|
7
|
+
|
8
|
+
CREATE TABLE lodging_classes
|
9
|
+
(
|
10
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY
|
11
|
+
);
|
12
|
+
|
13
|
+
EOS
|
14
|
+
|
2
15
|
self.primary_key = "name"
|
3
16
|
|
4
|
-
col :name
|
5
17
|
|
6
18
|
warn_unless_size 3
|
7
19
|
end
|
data/lib/earth/industry.rb
CHANGED
@@ -1,44 +1,55 @@
|
|
1
|
+
require 'earth/model'
|
1
2
|
require 'earth/locality'
|
2
3
|
|
3
4
|
class CbecsEnergyIntensity < ActiveRecord::Base
|
5
|
+
extend Earth::Model
|
6
|
+
|
7
|
+
TABLE_STRUCTURE = <<-EOS
|
8
|
+
|
9
|
+
CREATE TABLE cbecs_energy_intensities
|
10
|
+
(
|
11
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
12
|
+
principal_building_activity CHARACTER VARYING(255),
|
13
|
+
naics_code CHARACTER VARYING(255),
|
14
|
+
census_region_number INTEGER,
|
15
|
+
census_division_number INTEGER,
|
16
|
+
electricity FLOAT,
|
17
|
+
electricity_units CHARACTER VARYING(255),
|
18
|
+
electricity_floorspace FLOAT,
|
19
|
+
electricity_floorspace_units CHARACTER VARYING(255),
|
20
|
+
electricity_intensity FLOAT,
|
21
|
+
electricity_intensity_units CHARACTER VARYING(255),
|
22
|
+
natural_gas FLOAT,
|
23
|
+
natural_gas_units CHARACTER VARYING(255),
|
24
|
+
natural_gas_floorspace FLOAT,
|
25
|
+
natural_gas_floorspace_units CHARACTER VARYING(255),
|
26
|
+
natural_gas_intensity FLOAT,
|
27
|
+
natural_gas_intensity_units CHARACTER VARYING(255),
|
28
|
+
fuel_oil FLOAT,
|
29
|
+
fuel_oil_units CHARACTER VARYING(255),
|
30
|
+
fuel_oil_floorspace FLOAT,
|
31
|
+
fuel_oil_floorspace_units CHARACTER VARYING(255),
|
32
|
+
fuel_oil_intensity FLOAT,
|
33
|
+
fuel_oil_intensity_units CHARACTER VARYING(255),
|
34
|
+
district_heat FLOAT,
|
35
|
+
district_heat_units CHARACTER VARYING(255),
|
36
|
+
district_heat_floorspace FLOAT,
|
37
|
+
district_heat_floorspace_units CHARACTER VARYING(255),
|
38
|
+
district_heat_intensity FLOAT,
|
39
|
+
district_heat_intensity_units CHARACTER VARYING(255)
|
40
|
+
);
|
41
|
+
CREATE INDEX index_cbecs_energy_intensities_on_naics_code ON cbecs_energy_intensities (naics_code);
|
42
|
+
CREATE INDEX index_cbecs_energy_intensities_on_census_region_number ON cbecs_energy_intensities (census_region_number);
|
43
|
+
CREATE INDEX index_cbecs_energy_intensities_on_census_division_number ON cbecs_energy_intensities (census_division_number)
|
44
|
+
|
45
|
+
EOS
|
46
|
+
|
4
47
|
self.primary_key = "name"
|
5
48
|
|
6
|
-
col :name
|
7
|
-
col :principal_building_activity
|
8
|
-
col :naics_code
|
9
|
-
col :census_region_number, :type => :integer
|
10
|
-
col :census_division_number, :type => :integer
|
11
|
-
add_index :naics_code
|
12
|
-
add_index :census_region_number
|
13
|
-
add_index :census_division_number
|
14
49
|
|
15
|
-
col :electricity, :type => :float
|
16
|
-
col :electricity_units
|
17
|
-
col :electricity_floorspace, :type => :float
|
18
|
-
col :electricity_floorspace_units
|
19
|
-
col :electricity_intensity, :type => :float
|
20
|
-
col :electricity_intensity_units
|
21
50
|
|
22
|
-
col :natural_gas, :type => :float
|
23
|
-
col :natural_gas_units
|
24
|
-
col :natural_gas_floorspace, :type => :float
|
25
|
-
col :natural_gas_floorspace_units
|
26
|
-
col :natural_gas_intensity, :type => :float
|
27
|
-
col :natural_gas_intensity_units
|
28
51
|
|
29
|
-
col :fuel_oil, :type => :float
|
30
|
-
col :fuel_oil_units
|
31
|
-
col :fuel_oil_floorspace, :type => :float
|
32
|
-
col :fuel_oil_floorspace_units
|
33
|
-
col :fuel_oil_intensity, :type => :float
|
34
|
-
col :fuel_oil_intensity_units
|
35
52
|
|
36
|
-
col :district_heat, :type => :float
|
37
|
-
col :district_heat_units
|
38
|
-
col :district_heat_floorspace, :type => :float
|
39
|
-
col :district_heat_floorspace_units
|
40
|
-
col :district_heat_intensity, :type => :float
|
41
|
-
col :district_heat_intensity_units
|
42
53
|
|
43
54
|
scope :divisional, where('census_region_number IS NOT NULL AND census_division_number IS NOT NULL')
|
44
55
|
scope :regional, where('census_region_number IS NOT NULL AND census_division_number IS NULL')
|
@@ -1,5 +1,25 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry_product_line'
|
4
|
+
require 'earth/industry/industry_sector'
|
5
|
+
require 'earth/industry/merchant_category_industry'
|
6
|
+
require 'earth/industry/product_line'
|
7
|
+
require 'earth/industry/sector'
|
8
|
+
|
1
9
|
# TODO replace this with NAICS 2002?
|
2
10
|
class Industry < ActiveRecord::Base
|
11
|
+
extend Earth::Model
|
12
|
+
|
13
|
+
TABLE_STRUCTURE = <<-EOS
|
14
|
+
|
15
|
+
CREATE TABLE industries
|
16
|
+
(
|
17
|
+
naics_code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
18
|
+
description CHARACTER VARYING(255)
|
19
|
+
);
|
20
|
+
|
21
|
+
EOS
|
22
|
+
|
3
23
|
self.primary_key = "naics_code"
|
4
24
|
|
5
25
|
has_many :merchant_category_industries, :foreign_key => 'naics_code'
|
@@ -10,8 +30,6 @@ class Industry < ActiveRecord::Base
|
|
10
30
|
has_many :industry_sectors, :foreign_key => 'naics_code'
|
11
31
|
has_many :sectors, :through => :industry_sectors
|
12
32
|
|
13
|
-
col :naics_code
|
14
|
-
col :description
|
15
33
|
|
16
34
|
class << self
|
17
35
|
def format_naics_code(input)
|
@@ -1,14 +1,28 @@
|
|
1
|
-
require 'earth/
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry'
|
4
|
+
require 'earth/industry/product_line_industry_product'
|
5
|
+
|
2
6
|
class IndustryProduct < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE industry_products
|
12
|
+
(
|
13
|
+
naics_product_code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
description TEXT,
|
15
|
+
value FLOAT,
|
16
|
+
value_units CHARACTER VARYING(255),
|
17
|
+
naics_code CHARACTER VARYING(255)
|
18
|
+
);
|
19
|
+
|
20
|
+
EOS
|
21
|
+
|
3
22
|
self.primary_key = "naics_product_code"
|
4
23
|
|
5
24
|
has_many :product_line_industry_products, :foreign_key => 'naics_product_code'
|
6
25
|
|
7
26
|
belongs_to :industry, :foreign_key => 'naics_code'
|
8
27
|
|
9
|
-
col :naics_product_code
|
10
|
-
col :description, :type => :text
|
11
|
-
col :value, :type => :float
|
12
|
-
col :value_units
|
13
|
-
col :naics_code
|
14
28
|
end
|
@@ -1,12 +1,26 @@
|
|
1
|
-
require 'earth/
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry'
|
4
|
+
require 'earth/industry/product_line'
|
5
|
+
|
2
6
|
class IndustryProductLine < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE industry_product_lines
|
12
|
+
(
|
13
|
+
row_hash CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
naics_code CHARACTER VARYING(255),
|
15
|
+
ratio FLOAT,
|
16
|
+
ps_code CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
3
21
|
self.primary_key = "row_hash"
|
4
22
|
|
5
23
|
belongs_to :industry, :foreign_key => 'naics_code'
|
6
24
|
belongs_to :product_line, :foreign_key => 'ps_code'
|
7
25
|
|
8
|
-
col :row_hash
|
9
|
-
col :naics_code
|
10
|
-
col :ratio, :type => :float
|
11
|
-
col :ps_code
|
12
26
|
end
|
@@ -1,12 +1,25 @@
|
|
1
|
-
require 'earth/
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry'
|
4
|
+
require 'earth/industry/sector'
|
5
|
+
|
2
6
|
class IndustrySector < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE industry_sectors
|
12
|
+
(
|
13
|
+
row_hash CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
naics_code CHARACTER VARYING(255),
|
15
|
+
ratio FLOAT,
|
16
|
+
io_code CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
3
21
|
self.primary_key = "row_hash"
|
4
22
|
|
5
23
|
belongs_to :industry, :foreign_key => 'naics_code'
|
6
24
|
belongs_to :sector, :foreign_key => 'io_code'
|
7
|
-
|
8
|
-
col :row_hash
|
9
|
-
col :naics_code
|
10
|
-
col :ratio, :type => :float
|
11
|
-
col :io_code
|
12
25
|
end
|
@@ -1,29 +1,41 @@
|
|
1
|
-
require 'earth/
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry'
|
2
4
|
|
3
5
|
class MecsEnergy < ActiveRecord::Base
|
6
|
+
extend Earth::Model
|
7
|
+
|
8
|
+
TABLE_STRUCTURE = <<-EOS
|
9
|
+
|
10
|
+
CREATE TABLE mecs_energies
|
11
|
+
(
|
12
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
13
|
+
census_region_number INTEGER,
|
14
|
+
naics_code CHARACTER VARYING(255),
|
15
|
+
energy FLOAT,
|
16
|
+
energy_units CHARACTER VARYING(255),
|
17
|
+
electricity FLOAT,
|
18
|
+
electricity_units CHARACTER VARYING(255),
|
19
|
+
residual_fuel_oil FLOAT,
|
20
|
+
residual_fuel_oil_units CHARACTER VARYING(255),
|
21
|
+
distillate_fuel_oil FLOAT,
|
22
|
+
distillate_fuel_oil_units CHARACTER VARYING(255),
|
23
|
+
natural_gas FLOAT,
|
24
|
+
natural_gas_units CHARACTER VARYING(255),
|
25
|
+
lpg_and_ngl FLOAT,
|
26
|
+
lpg_and_ngl_units CHARACTER VARYING(255),
|
27
|
+
coal FLOAT,
|
28
|
+
coal_units CHARACTER VARYING(255),
|
29
|
+
coke_and_breeze FLOAT,
|
30
|
+
coke_and_breeze_units CHARACTER VARYING(255),
|
31
|
+
other_fuel FLOAT,
|
32
|
+
other_fuel_units CHARACTER VARYING(255)
|
33
|
+
);
|
34
|
+
|
35
|
+
EOS
|
36
|
+
|
4
37
|
self.primary_key = "name"
|
5
38
|
|
6
|
-
col :name
|
7
|
-
col :census_region_number, :type => :integer
|
8
|
-
col :naics_code
|
9
|
-
col :energy, :type => :float
|
10
|
-
col :energy_units
|
11
|
-
col :electricity, :type => :float
|
12
|
-
col :electricity_units
|
13
|
-
col :residual_fuel_oil, :type => :float
|
14
|
-
col :residual_fuel_oil_units
|
15
|
-
col :distillate_fuel_oil, :type => :float
|
16
|
-
col :distillate_fuel_oil_units
|
17
|
-
col :natural_gas, :type => :float
|
18
|
-
col :natural_gas_units
|
19
|
-
col :lpg_and_ngl, :type => :float
|
20
|
-
col :lpg_and_ngl_units
|
21
|
-
col :coal, :type => :float
|
22
|
-
col :coal_units
|
23
|
-
col :coke_and_breeze, :type => :float
|
24
|
-
col :coke_and_breeze_units
|
25
|
-
col :other_fuel, :type => :float
|
26
|
-
col :other_fuel_units
|
27
39
|
|
28
40
|
FUELS = [:electricity, :residual_fuel_oil, :distillate_fuel_oil,
|
29
41
|
:natural_gas, :lpg_and_ngl, :coal, :coke_and_breeze, :other_fuel]
|
@@ -1,16 +1,27 @@
|
|
1
|
-
require 'earth/
|
1
|
+
require 'earth/model'
|
2
|
+
|
2
3
|
require 'earth/industry/industry'
|
3
4
|
|
4
5
|
class MecsRatio < ActiveRecord::Base
|
6
|
+
extend Earth::Model
|
7
|
+
|
8
|
+
TABLE_STRUCTURE = <<-EOS
|
9
|
+
|
10
|
+
CREATE TABLE mecs_ratios
|
11
|
+
(
|
12
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
13
|
+
census_region_number INTEGER,
|
14
|
+
naics_code CHARACTER VARYING(255),
|
15
|
+
energy_per_dollar_of_shipments FLOAT,
|
16
|
+
energy_per_dollar_of_shipments_units CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
5
21
|
self.primary_key = "name"
|
6
22
|
|
7
23
|
belongs_to :industry
|
8
24
|
|
9
|
-
col :name
|
10
|
-
col :census_region_number, :type => :integer
|
11
|
-
col :naics_code
|
12
|
-
col :energy_per_dollar_of_shipments, :type => :float
|
13
|
-
col :energy_per_dollar_of_shipments_units
|
14
25
|
|
15
26
|
# Find the first record whose naics_code matches code and whose energy per dollar shipment is present.
|
16
27
|
# If no record found chop off the last character of code and try again, and so on.
|
@@ -1,4 +1,21 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry'
|
4
|
+
require 'earth/industry/merchant_category_industry'
|
5
|
+
|
1
6
|
class MerchantCategory < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE merchant_categories
|
12
|
+
(
|
13
|
+
mcc CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
description CHARACTER VARYING(255)
|
15
|
+
);
|
16
|
+
|
17
|
+
EOS
|
18
|
+
|
2
19
|
self.primary_key = "mcc"
|
3
20
|
|
4
21
|
has_many :merchant_category_industries, :foreign_key => 'mcc'
|
@@ -8,6 +25,4 @@ class MerchantCategory < ActiveRecord::Base
|
|
8
25
|
description
|
9
26
|
end
|
10
27
|
|
11
|
-
col :mcc
|
12
|
-
col :description
|
13
28
|
end
|
@@ -1,11 +1,26 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/industry/industry'
|
4
|
+
require 'earth/industry/merchant_category'
|
5
|
+
|
1
6
|
class MerchantCategoryIndustry < ActiveRecord::Base
|
7
|
+
extend Earth::Model
|
8
|
+
|
9
|
+
TABLE_STRUCTURE = <<-EOS
|
10
|
+
|
11
|
+
CREATE TABLE merchant_category_industries
|
12
|
+
(
|
13
|
+
row_hash CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
14
|
+
mcc CHARACTER VARYING(255),
|
15
|
+
ratio FLOAT,
|
16
|
+
naics_code CHARACTER VARYING(255)
|
17
|
+
);
|
18
|
+
|
19
|
+
EOS
|
20
|
+
|
2
21
|
self.primary_key = "row_hash"
|
3
22
|
|
4
23
|
belongs_to :merchant_category, :foreign_key => 'mcc'
|
5
24
|
belongs_to :industry, :foreign_key => 'naics_code'
|
6
25
|
|
7
|
-
col :row_hash
|
8
|
-
col :mcc
|
9
|
-
col :ratio, :type => :float
|
10
|
-
col :naics_code
|
11
26
|
end
|