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,14 +1,14 @@
|
|
1
|
-
require 'earth/automobile/
|
2
|
-
require 'earth/fuel/
|
3
|
-
require 'earth/hospitality/
|
4
|
-
require 'earth/
|
1
|
+
require 'earth/automobile/automobile_activity_year_type_fuel'
|
2
|
+
require 'earth/fuel/greenhouse_gas'
|
3
|
+
require 'earth/hospitality/commercial_building_energy_consumption_survey_response'
|
4
|
+
require 'earth/locality/country'
|
5
|
+
require 'earth/locality/egrid_subregion'
|
6
|
+
require 'earth/locality/electricity_mix'
|
7
|
+
require 'earth/rail/rail_company'
|
8
|
+
require 'earth/rail/rail_fuel'
|
5
9
|
|
6
10
|
Country.class_eval do
|
7
11
|
data_miner do
|
8
|
-
process "Start from scratch" do
|
9
|
-
delete_all
|
10
|
-
end
|
11
|
-
|
12
12
|
# http://www.iso.org/iso/list-en1-semic-3.txt
|
13
13
|
# http://unstats.un.org/unsd/methods/m49/m49alpha.htm
|
14
14
|
import "OpenGeoCode.org's Country Codes to Country Names list",
|
@@ -1,4 +1,26 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
1
3
|
class EgridCountry < ActiveRecord::Base
|
4
|
+
extend Earth::Model
|
5
|
+
|
6
|
+
TABLE_STRUCTURE = <<-EOS
|
7
|
+
|
8
|
+
CREATE TABLE egrid_countries
|
9
|
+
(
|
10
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
11
|
+
generation FLOAT,
|
12
|
+
generation_units CHARACTER VARYING(255),
|
13
|
+
foreign_interchange FLOAT,
|
14
|
+
foreign_interchange_units CHARACTER VARYING(255),
|
15
|
+
domestic_interchange FLOAT,
|
16
|
+
domestic_interchange_units CHARACTER VARYING(255),
|
17
|
+
consumption FLOAT,
|
18
|
+
consumption_units CHARACTER VARYING(255),
|
19
|
+
loss_factor FLOAT
|
20
|
+
);
|
21
|
+
|
22
|
+
EOS
|
23
|
+
|
2
24
|
self.primary_key = "name"
|
3
25
|
|
4
26
|
class << self
|
@@ -7,16 +29,6 @@ class EgridCountry < ActiveRecord::Base
|
|
7
29
|
end
|
8
30
|
end
|
9
31
|
|
10
|
-
col :name
|
11
|
-
col :generation, :type => :float
|
12
|
-
col :generation_units
|
13
|
-
col :foreign_interchange, :type => :float
|
14
|
-
col :foreign_interchange_units
|
15
|
-
col :domestic_interchange, :type => :float
|
16
|
-
col :domestic_interchange_units
|
17
|
-
col :consumption, :type => :float
|
18
|
-
col :consumption_units
|
19
|
-
col :loss_factor, :type => :float
|
20
32
|
|
21
33
|
warn_unless_size 1
|
22
34
|
warn_if_any_nulls
|
@@ -1,6 +1,31 @@
|
|
1
|
+
require 'falls_back_on'
|
2
|
+
|
3
|
+
require 'earth/model'
|
4
|
+
|
1
5
|
require 'earth/locality/egrid_country'
|
6
|
+
require 'earth/locality/egrid_subregion'
|
2
7
|
|
3
8
|
class EgridRegion < ActiveRecord::Base
|
9
|
+
extend Earth::Model
|
10
|
+
|
11
|
+
TABLE_STRUCTURE = <<-EOS
|
12
|
+
|
13
|
+
CREATE TABLE egrid_regions
|
14
|
+
(
|
15
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
16
|
+
generation FLOAT,
|
17
|
+
generation_units CHARACTER VARYING(255),
|
18
|
+
foreign_interchange FLOAT,
|
19
|
+
foreign_interchange_units CHARACTER VARYING(255),
|
20
|
+
domestic_interchange FLOAT,
|
21
|
+
domestic_interchange_units CHARACTER VARYING(255),
|
22
|
+
consumption FLOAT,
|
23
|
+
consumption_units CHARACTER VARYING(255),
|
24
|
+
loss_factor FLOAT
|
25
|
+
);
|
26
|
+
|
27
|
+
EOS
|
28
|
+
|
4
29
|
self.primary_key = "name"
|
5
30
|
|
6
31
|
# EgridCountry must be a parent so that it automatically gets data_mined (needed for fallback calculation)
|
@@ -10,16 +35,6 @@ class EgridRegion < ActiveRecord::Base
|
|
10
35
|
falls_back_on :name => 'fallback',
|
11
36
|
:loss_factor => lambda { EgridCountry.us.loss_factor }
|
12
37
|
|
13
|
-
col :name
|
14
|
-
col :generation, :type => :float
|
15
|
-
col :generation_units
|
16
|
-
col :foreign_interchange, :type => :float
|
17
|
-
col :foreign_interchange_units
|
18
|
-
col :domestic_interchange, :type => :float
|
19
|
-
col :domestic_interchange_units
|
20
|
-
col :consumption, :type => :float
|
21
|
-
col :consumption_units
|
22
|
-
col :loss_factor, :type => :float
|
23
38
|
|
24
39
|
warn_unless_size 5
|
25
40
|
warn_if_any_nulls
|
@@ -1,6 +1,37 @@
|
|
1
|
+
require 'falls_back_on'
|
2
|
+
|
3
|
+
require 'earth/model'
|
4
|
+
|
1
5
|
require 'earth/locality/egrid_region'
|
6
|
+
require 'earth/locality/electricity_mix'
|
2
7
|
|
3
8
|
class EgridSubregion < ActiveRecord::Base
|
9
|
+
extend Earth::Model
|
10
|
+
|
11
|
+
TABLE_STRUCTURE = <<-EOS
|
12
|
+
|
13
|
+
CREATE TABLE egrid_subregions
|
14
|
+
(
|
15
|
+
abbreviation CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
16
|
+
name CHARACTER VARYING(255),
|
17
|
+
nerc_abbreviation CHARACTER VARYING(255),
|
18
|
+
egrid_region_name CHARACTER VARYING(255),
|
19
|
+
net_generation FLOAT,
|
20
|
+
net_generation_units CHARACTER VARYING(255),
|
21
|
+
co2_emission_factor FLOAT,
|
22
|
+
co2_emission_factor_units CHARACTER VARYING(255),
|
23
|
+
co2_biogenic_emission_factor FLOAT,
|
24
|
+
co2_biogenic_emission_factor_units CHARACTER VARYING(255),
|
25
|
+
ch4_emission_factor FLOAT,
|
26
|
+
ch4_emission_factor_units CHARACTER VARYING(255),
|
27
|
+
n2o_emission_factor FLOAT,
|
28
|
+
n2o_emission_factor_units CHARACTER VARYING(255),
|
29
|
+
electricity_emission_factor FLOAT,
|
30
|
+
electricity_emission_factor_units CHARACTER VARYING(255)
|
31
|
+
);
|
32
|
+
|
33
|
+
EOS
|
34
|
+
|
4
35
|
self.primary_key = "abbreviation"
|
5
36
|
|
6
37
|
belongs_to :egrid_region, :foreign_key => 'egrid_region_name'
|
@@ -19,22 +50,6 @@ class EgridSubregion < ActiveRecord::Base
|
|
19
50
|
:electricity_emission_factor => lambda { weighted_average(:electricity_emission_factor, :weighted_by => :net_generation) },
|
20
51
|
:electricity_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour'
|
21
52
|
|
22
|
-
col :abbreviation
|
23
|
-
col :name
|
24
|
-
col :nerc_abbreviation
|
25
|
-
col :egrid_region_name
|
26
|
-
col :net_generation, :type => :float
|
27
|
-
col :net_generation_units
|
28
|
-
col :co2_emission_factor, :type => :float
|
29
|
-
col :co2_emission_factor_units
|
30
|
-
col :co2_biogenic_emission_factor, :type => :float
|
31
|
-
col :co2_biogenic_emission_factor_units
|
32
|
-
col :ch4_emission_factor, :type => :float
|
33
|
-
col :ch4_emission_factor_units
|
34
|
-
col :n2o_emission_factor, :type => :float
|
35
|
-
col :n2o_emission_factor_units
|
36
|
-
col :electricity_emission_factor, :type => :float
|
37
|
-
col :electricity_emission_factor_units
|
38
53
|
|
39
54
|
warn_unless_size 26
|
40
55
|
warn_if_any_nulls
|
@@ -1,11 +1,8 @@
|
|
1
|
-
require 'earth/fuel/
|
1
|
+
require 'earth/fuel/greenhouse_gas'
|
2
|
+
require 'earth/locality/egrid_country'
|
2
3
|
|
3
4
|
EgridSubregion.class_eval do
|
4
5
|
data_miner do
|
5
|
-
process "Start from scratch" do
|
6
|
-
delete_all
|
7
|
-
end
|
8
|
-
|
9
6
|
import "eGRID 2012 subregion data",
|
10
7
|
:url => 'http://www.epa.gov/cleanenergy/documents/egridzips/eGRID2012V1_0_year09_DATA.xls',
|
11
8
|
:sheet => 'SRL09',
|
@@ -25,7 +22,11 @@ EgridSubregion.class_eval do
|
|
25
22
|
store 'egrid_region_name'
|
26
23
|
end
|
27
24
|
|
28
|
-
process "
|
25
|
+
process "Ensure EgridCountry is populated" do
|
26
|
+
EgridCountry.run_data_miner!
|
27
|
+
end
|
28
|
+
|
29
|
+
process "Ensure GreenhouseGas is populated" do
|
29
30
|
GreenhouseGas.run_data_miner!
|
30
31
|
end
|
31
32
|
|
@@ -1,4 +1,31 @@
|
|
1
|
+
require 'falls_back_on'
|
2
|
+
|
3
|
+
require 'earth/model'
|
4
|
+
|
1
5
|
class ElectricityMix < ActiveRecord::Base
|
6
|
+
extend Earth::Model
|
7
|
+
|
8
|
+
TABLE_STRUCTURE = <<-EOS
|
9
|
+
|
10
|
+
CREATE TABLE electricity_mixes
|
11
|
+
(
|
12
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
13
|
+
egrid_subregion_abbreviation CHARACTER VARYING(255),
|
14
|
+
state_postal_abbreviation CHARACTER VARYING(255),
|
15
|
+
country_iso_3166_code CHARACTER VARYING(255),
|
16
|
+
co2_emission_factor FLOAT,
|
17
|
+
co2_emission_factor_units CHARACTER VARYING(255),
|
18
|
+
co2_biogenic_emission_factor FLOAT,
|
19
|
+
co2_biogenic_emission_factor_units CHARACTER VARYING(255),
|
20
|
+
ch4_emission_factor FLOAT,
|
21
|
+
ch4_emission_factor_units CHARACTER VARYING(255),
|
22
|
+
n2o_emission_factor FLOAT,
|
23
|
+
n2o_emission_factor_units CHARACTER VARYING(255),
|
24
|
+
loss_factor FLOAT
|
25
|
+
);
|
26
|
+
|
27
|
+
EOS
|
28
|
+
|
2
29
|
self.primary_key = :name
|
3
30
|
|
4
31
|
def energy_content
|
@@ -18,19 +45,6 @@ class ElectricityMix < ActiveRecord::Base
|
|
18
45
|
:n2o_emission_factor_units => 'kilograms_co2e_per_kilowatt_hour',
|
19
46
|
:loss_factor => 0.096 # from ecometrica paper FIXME TODO calculate this
|
20
47
|
|
21
|
-
col :name
|
22
|
-
col :egrid_subregion_abbreviation
|
23
|
-
col :state_postal_abbreviation
|
24
|
-
col :country_iso_3166_code
|
25
|
-
col :co2_emission_factor, :type => :float
|
26
|
-
col :co2_emission_factor_units
|
27
|
-
col :co2_biogenic_emission_factor, :type => :float
|
28
|
-
col :co2_biogenic_emission_factor_units
|
29
|
-
col :ch4_emission_factor, :type => :float
|
30
|
-
col :ch4_emission_factor_units
|
31
|
-
col :n2o_emission_factor, :type => :float
|
32
|
-
col :n2o_emission_factor_units
|
33
|
-
col :loss_factor, :type => :float
|
34
48
|
|
35
49
|
warn_unless_size 187
|
36
50
|
warn_if_any_nulls
|
@@ -1,13 +1,17 @@
|
|
1
|
+
require 'earth/fuel/greenhouse_gas'
|
2
|
+
require 'earth/locality/egrid_subregion'
|
3
|
+
require 'earth/locality/state'
|
4
|
+
|
1
5
|
ElectricityMix.class_eval do
|
2
6
|
data_miner do
|
3
|
-
process "Start from scratch" do
|
4
|
-
delete_all
|
5
|
-
end
|
6
|
-
|
7
7
|
process "Ensure GreenhouseGas is populated" do
|
8
8
|
GreenhouseGas.run_data_miner!
|
9
9
|
end
|
10
10
|
|
11
|
+
process "Ensure EgridSubregion is populated" do
|
12
|
+
EgridSubregion.run_data_miner!
|
13
|
+
end
|
14
|
+
|
11
15
|
import "national electricity mixes from Brander et al. (2011)",
|
12
16
|
:url => "file://#{Earth::DATA_DIR}/locality/national_electricity_efs.csv" do
|
13
17
|
key :name, :synthesize => lambda { |row| [row['country_iso_3166_code'], 'national electricity'].join(' ') }
|
@@ -18,10 +22,6 @@ ElectricityMix.class_eval do
|
|
18
22
|
store :loss_factor
|
19
23
|
end
|
20
24
|
|
21
|
-
process "Ensure EgridSubregion is populated" do
|
22
|
-
EgridSubregion.run_data_miner!
|
23
|
-
end
|
24
|
-
|
25
25
|
process "Derive eGRID subregion electricity mixes" do
|
26
26
|
EgridSubregion.safe_find_each do |subregion|
|
27
27
|
mix = find_or_create_by_name [subregion.abbreviation, 'egrid subregion electricity'].join(' ')
|
@@ -1,4 +1,21 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
1
3
|
class PetroleumAdministrationForDefenseDistrict < ActiveRecord::Base
|
4
|
+
extend Earth::Model
|
5
|
+
|
6
|
+
TABLE_STRUCTURE = <<-EOS
|
7
|
+
|
8
|
+
CREATE TABLE petroleum_districts
|
9
|
+
(
|
10
|
+
code CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
11
|
+
district_code CHARACTER VARYING(255),
|
12
|
+
district_name CHARACTER VARYING(255),
|
13
|
+
subdistrict_code CHARACTER VARYING(255),
|
14
|
+
subdistrict_name CHARACTER VARYING(255)
|
15
|
+
);
|
16
|
+
|
17
|
+
EOS
|
18
|
+
|
2
19
|
self.primary_key = "code"
|
3
20
|
self.table_name = :petroleum_districts
|
4
21
|
|
@@ -8,11 +25,6 @@ class PetroleumAdministrationForDefenseDistrict < ActiveRecord::Base
|
|
8
25
|
str
|
9
26
|
end
|
10
27
|
|
11
|
-
col :code
|
12
|
-
col :district_code
|
13
|
-
col :district_name
|
14
|
-
col :subdistrict_code
|
15
|
-
col :subdistrict_name
|
16
28
|
|
17
29
|
warn_if_nulls_except(
|
18
30
|
:subdistrict_code,
|
data/lib/earth/locality/state.rb
CHANGED
@@ -1,4 +1,40 @@
|
|
1
|
+
require 'earth/model'
|
2
|
+
|
3
|
+
require 'earth/locality/census_division'
|
4
|
+
require 'earth/locality/census_region'
|
5
|
+
require 'earth/locality/climate_division'
|
6
|
+
require 'earth/locality/country'
|
7
|
+
require 'earth/locality/electricity_mix'
|
8
|
+
require 'earth/locality/petroleum_administration_for_defense_district'
|
9
|
+
require 'earth/locality/zip_code'
|
10
|
+
|
1
11
|
class State < ActiveRecord::Base
|
12
|
+
data_miner do
|
13
|
+
process "Ensure Country and ElectricityMix are imported because they're like belongs_to associations" do
|
14
|
+
Country.run_data_miner!
|
15
|
+
ElectricityMix.run_data_miner!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
extend Earth::Model
|
20
|
+
|
21
|
+
TABLE_STRUCTURE = <<-EOS
|
22
|
+
|
23
|
+
CREATE TABLE states
|
24
|
+
(
|
25
|
+
postal_abbreviation CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
26
|
+
fips_code INTEGER,
|
27
|
+
name CHARACTER VARYING(255),
|
28
|
+
census_division_number INTEGER,
|
29
|
+
petroleum_administration_for_defense_district_code CHARACTER VARYING(255),
|
30
|
+
population INTEGER,
|
31
|
+
electricity_emission_factor FLOAT,
|
32
|
+
electricity_emission_factor_units CHARACTER VARYING(255),
|
33
|
+
electricity_loss_factor FLOAT
|
34
|
+
);
|
35
|
+
|
36
|
+
EOS
|
37
|
+
|
2
38
|
self.primary_key = "postal_abbreviation"
|
3
39
|
|
4
40
|
has_many :zip_codes, :foreign_key => 'state_postal_abbreviation'
|
@@ -8,26 +44,10 @@ class State < ActiveRecord::Base
|
|
8
44
|
has_one :electricity_mix, :foreign_key => 'state_postal_abbreviation'
|
9
45
|
belongs_to :petroleum_administration_for_defense_district, :foreign_key => 'petroleum_administration_for_defense_district_code'
|
10
46
|
|
11
|
-
data_miner do
|
12
|
-
process "Ensure Country and ElectricityMix are imported because they're like belongs_to associations" do
|
13
|
-
Country.run_data_miner!
|
14
|
-
ElectricityMix.run_data_miner!
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
47
|
def country
|
19
48
|
Country.united_states
|
20
49
|
end
|
21
50
|
|
22
|
-
col :postal_abbreviation
|
23
|
-
col :fips_code, :type => :integer
|
24
|
-
col :name
|
25
|
-
col :census_division_number, :type => :integer
|
26
|
-
col :petroleum_administration_for_defense_district_code
|
27
|
-
col :population, :type => :integer
|
28
|
-
col :electricity_emission_factor, :type => :float
|
29
|
-
col :electricity_emission_factor_units
|
30
|
-
col :electricity_loss_factor, :type => :float
|
31
51
|
|
32
52
|
warn_if_nulls_except(
|
33
53
|
:census_division_number,
|
@@ -1,6 +1,39 @@
|
|
1
|
-
require
|
1
|
+
require 'earth/model'
|
2
|
+
require 'earth/loader'
|
3
|
+
Earth::Loader.load_plugins
|
4
|
+
|
5
|
+
require 'earth/locality/climate_division'
|
6
|
+
require 'earth/locality/country'
|
7
|
+
require 'earth/locality/egrid_subregion'
|
8
|
+
require 'earth/locality/state'
|
9
|
+
require 'earth/electricity/electric_market'
|
10
|
+
require 'earth/electricity/electric_utility'
|
2
11
|
|
3
12
|
class ZipCode < ActiveRecord::Base
|
13
|
+
data_miner do
|
14
|
+
process "Ensure Country is imported because it's like a belongs_to association" do
|
15
|
+
Country.run_data_miner!
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
extend Earth::Model
|
20
|
+
|
21
|
+
TABLE_STRUCTURE = <<-EOS
|
22
|
+
|
23
|
+
CREATE TABLE zip_codes
|
24
|
+
(
|
25
|
+
name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,
|
26
|
+
state_postal_abbreviation CHARACTER VARYING(255),
|
27
|
+
description CHARACTER VARYING(255),
|
28
|
+
latitude CHARACTER VARYING(255),
|
29
|
+
longitude CHARACTER VARYING(255),
|
30
|
+
egrid_subregion_abbreviation CHARACTER VARYING(255),
|
31
|
+
climate_division_name CHARACTER VARYING(255),
|
32
|
+
population INTEGER
|
33
|
+
);
|
34
|
+
|
35
|
+
EOS
|
36
|
+
|
4
37
|
self.primary_key = "name"
|
5
38
|
|
6
39
|
belongs_to :climate_division, :foreign_key => 'climate_division_name'
|
@@ -11,12 +44,6 @@ class ZipCode < ActiveRecord::Base
|
|
11
44
|
|
12
45
|
scope :known_subregion, where('egrid_subregion_abbreviation IS NOT NULL')
|
13
46
|
|
14
|
-
data_miner do
|
15
|
-
process "Ensure Country is imported because it's like a belongs_to association" do
|
16
|
-
Country.run_data_miner!
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
47
|
def country
|
21
48
|
Country.united_states
|
22
49
|
end
|
@@ -31,14 +58,6 @@ class ZipCode < ActiveRecord::Base
|
|
31
58
|
:lat_column_name => :latitude,
|
32
59
|
:lng_column_name => :longitude
|
33
60
|
|
34
|
-
col :name
|
35
|
-
col :state_postal_abbreviation
|
36
|
-
col :description
|
37
|
-
col :latitude
|
38
|
-
col :longitude
|
39
|
-
col :egrid_subregion_abbreviation
|
40
|
-
col :climate_division_name
|
41
|
-
col :population, :type => :integer
|
42
61
|
|
43
62
|
warn_unless_size 43770
|
44
63
|
warn_if_nonexistent_owner_except :egrid_subregion
|