earth 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +9 -21
- data/data/rail/ntd_companies.csv +1 -0
- data/data/rail/ntd_fuel_consumption.csv +1 -0
- data/data/rail/ntd_modes.csv +1 -0
- data/data/rail/ntd_service.csv +1 -0
- data/errata/flight_segment/bts_errata.csv +6 -0
- data/lib/earth.rb +1 -0
- data/lib/earth/air/aircraft.rb +3 -5
- data/lib/earth/air/airline.rb +2 -3
- data/lib/earth/air/airport.rb +4 -5
- data/lib/earth/air/bts_aircraft.rb +1 -1
- data/lib/earth/air/flight_distance_class.rb +0 -1
- data/lib/earth/air/flight_distance_class/data_miner.rb +0 -4
- data/lib/earth/air/flight_distance_class_seat_class.rb +0 -1
- data/lib/earth/air/flight_segment.rb +12 -13
- data/lib/earth/air/flight_segment/data_miner.rb +13 -0
- data/lib/earth/automobile/automobile_activity_year.rb +0 -1
- data/lib/earth/automobile/automobile_activity_year_type.rb +4 -4
- data/lib/earth/automobile/automobile_activity_year_type_fuel.rb +1 -2
- data/lib/earth/automobile/automobile_fuel.rb +1 -2
- data/lib/earth/automobile/automobile_make.rb +0 -1
- data/lib/earth/automobile/automobile_make/data_miner.rb +2 -0
- data/lib/earth/automobile/automobile_make_model.rb +1 -2
- data/lib/earth/automobile/automobile_make_model_year_variant.rb +0 -1
- data/lib/earth/automobile/automobile_make_model_year_variant/data_miner.rb +2 -223
- data/lib/earth/automobile/automobile_make_model_year_variant/parser.rb +224 -0
- data/lib/earth/automobile/automobile_make_year_fleet.rb +0 -1
- data/lib/earth/automobile/automobile_model.rb +0 -1
- data/lib/earth/automobile/automobile_size_class.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel_control.rb +0 -1
- data/lib/earth/automobile/automobile_type_fuel_year.rb +4 -4
- data/lib/earth/automobile/automobile_type_fuel_year_control.rb +7 -15
- data/lib/earth/automobile/automobile_year.rb +0 -1
- data/lib/earth/bus/bus_class.rb +0 -1
- data/lib/earth/bus/bus_fuel.rb +1 -72
- data/lib/earth/bus/bus_fuel_control.rb +0 -1
- data/lib/earth/bus/bus_fuel_control/data_miner.rb +0 -2
- data/lib/earth/bus/bus_fuel_year_control.rb +0 -1
- data/lib/earth/bus/bus_fuel_year_control/data_miner.rb +0 -2
- data/lib/earth/computation/computation_carrier.rb +1 -11
- data/lib/earth/computation/computation_carrier_instance_class.rb +4 -25
- data/lib/earth/computation/computation_carrier_region.rb +0 -1
- data/lib/earth/computation/computation_carrier_region/data_miner.rb +0 -3
- data/lib/earth/diet/diet_class.rb +0 -1
- data/lib/earth/diet/food_group.rb +1 -1
- data/lib/earth/electricity/electric_market.rb +2 -0
- data/lib/earth/electricity/electric_utility.rb +11 -4
- data/lib/earth/electricity/electric_utility/data_miner.rb +2 -8
- data/lib/earth/electricity/green_button_adoption.rb +2 -1
- data/lib/earth/fuel/fuel.rb +20 -81
- data/lib/earth/fuel/fuel_year.rb +0 -44
- data/lib/earth/fuel/greenhouse_gas.rb +0 -40
- data/lib/earth/hospitality/lodging_class.rb +0 -1
- data/lib/earth/industry/cbecs_energy_intensity.rb +25 -29
- data/lib/earth/industry/cbecs_energy_intensity/data_miner.rb +1 -1
- data/lib/earth/industry/industry.rb +1 -2
- data/lib/earth/industry/mecs_energy.rb +9 -10
- data/lib/earth/industry/mecs_ratio.rb +2 -1
- data/lib/earth/industry/merchant_category.rb +1 -0
- data/lib/earth/industry/naics_2002.rb +2 -0
- data/lib/earth/industry/naics_2002_naics_2007_concordance.rb +1 -0
- data/lib/earth/industry/naics_2002_sic_1987_concordance.rb +1 -0
- data/lib/earth/industry/naics_2007.rb +1 -0
- data/lib/earth/industry/sic_1987.rb +1 -0
- data/lib/earth/locality/census_division.rb +1 -3
- data/lib/earth/locality/climate_division.rb +0 -1
- data/lib/earth/locality/country.rb +1 -2
- data/lib/earth/locality/country/data_miner.rb +4 -0
- data/lib/earth/locality/egrid_country.rb +0 -1
- data/lib/earth/locality/egrid_region.rb +1 -3
- data/lib/earth/locality/egrid_subregion.rb +1 -3
- data/lib/earth/locality/electricity_mix.rb +2 -4
- data/lib/earth/locality/petroleum_administration_for_defense_district.rb +0 -1
- data/lib/earth/locality/state.rb +0 -1
- data/lib/earth/locality/zip_code.rb +0 -1
- data/lib/earth/model.rb +1 -1
- data/lib/earth/pet/breed.rb +0 -1
- data/lib/earth/pet/breed_gender.rb +0 -1
- data/lib/earth/pet/gender.rb +0 -1
- data/lib/earth/pet/species.rb +1 -3
- data/lib/earth/rail/country_rail_class.rb +0 -1
- data/lib/earth/rail/country_rail_traction.rb +0 -1
- data/lib/earth/rail/country_rail_traction_class.rb +0 -1
- data/lib/earth/rail/national_transit_database_company.rb +1 -3
- data/lib/earth/rail/national_transit_database_company/data_miner.rb +1 -1
- data/lib/earth/rail/national_transit_database_mode.rb +0 -1
- data/lib/earth/rail/national_transit_database_mode/data_miner.rb +1 -1
- data/lib/earth/rail/national_transit_database_record.rb +0 -1
- data/lib/earth/rail/national_transit_database_record/data_miner.rb +2 -2
- data/lib/earth/rail/rail_class.rb +0 -1
- data/lib/earth/rail/rail_class/data_miner.rb +5 -4
- data/lib/earth/rail/rail_company.rb +0 -1
- data/lib/earth/rail/rail_fuel.rb +0 -1
- data/lib/earth/rail/rail_traction.rb +0 -1
- data/lib/earth/rail/rail_traction/data_miner.rb +2 -8
- data/lib/earth/residence/air_conditioner_use.rb +0 -1
- data/lib/earth/residence/clothes_machine_use.rb +0 -1
- data/lib/earth/residence/dishwasher_use.rb +0 -1
- data/lib/earth/residence/residence_appliance.rb +0 -1
- data/lib/earth/residence/residence_class.rb +0 -1
- data/lib/earth/residence/residence_fuel_price.rb +1 -2
- data/lib/earth/residence/urbanity.rb +0 -1
- data/lib/earth/shipping/carrier.rb +1 -52
- data/lib/earth/shipping/carrier_mode.rb +0 -34
- data/lib/earth/shipping/shipment_mode.rb +0 -26
- data/lib/earth/tasks.rb +14 -4
- data/lib/earth/version.rb +1 -1
- data/spec/earth/air/aircraft_spec.rb +9 -1
- data/spec/earth/air/airline_spec.rb +2 -2
- data/spec/earth/air/airport_spec.rb +1 -2
- data/spec/earth/air/bts_aircraft_spec.rb +2 -2
- data/spec/earth/air/flight_distance_class_seat_class_spec.rb +22 -0
- data/spec/earth/air/flight_distance_class_spec.rb +26 -18
- data/spec/earth/air/flight_seat_class_spec.rb +12 -0
- data/spec/earth/air/flight_segment_spec.rb +38 -33
- data/spec/earth/automobile/automobile_activity_year_spec.rb +20 -14
- data/spec/earth/automobile/automobile_activity_year_type_fuel_spec.rb +14 -10
- data/spec/earth/automobile/automobile_activity_year_type_spec.rb +28 -20
- data/spec/earth/automobile/automobile_fuel_spec.rb +106 -52
- data/spec/earth/automobile/automobile_make_model_spec.rb +103 -62
- data/spec/earth/automobile/automobile_make_model_year_spec.rb +69 -46
- data/spec/earth/automobile/automobile_make_model_year_variant_spec.rb +108 -109
- data/spec/earth/automobile/automobile_make_spec.rb +8 -8
- data/spec/earth/automobile/automobile_make_year_fleet_spec.rb +10 -6
- data/spec/earth/automobile/automobile_make_year_spec.rb +10 -9
- data/spec/earth/automobile/automobile_model_spec.rb +3 -0
- data/spec/earth/automobile/automobile_size_class_spec.rb +12 -11
- data/spec/earth/automobile/automobile_type_fuel_control_spec.rb +9 -9
- data/spec/earth/automobile/automobile_type_fuel_spec.rb +23 -18
- data/spec/earth/automobile/automobile_type_fuel_year_control_spec.rb +37 -29
- data/spec/earth/automobile/automobile_type_fuel_year_spec.rb +35 -36
- data/spec/earth/automobile/automobile_year_spec.rb +4 -2
- data/spec/earth/bus/bus_class_spec.rb +10 -0
- data/spec/earth/bus/bus_fuel_control_spec.rb +3 -5
- data/spec/earth/bus/bus_fuel_spec.rb +16 -8
- data/spec/earth/bus/bus_fuel_year_control_spec.rb +7 -7
- data/spec/earth/computation/computation_carrrier_instance_class_spec.rb +17 -0
- data/spec/earth/computation/computation_carrrier_region_spec.rb +10 -0
- data/spec/earth/computation/computation_carrrier_spec.rb +17 -0
- data/spec/earth/diet/diet_class_spec.rb +14 -0
- data/spec/earth/diet/food_group_spec.rb +26 -0
- data/spec/earth/electricity/electric_market_spec.rb +4 -5
- data/spec/earth/electricity/electric_utility_spec.rb +30 -19
- data/spec/earth/electricity/green_button_adoption_spec.rb +29 -7
- data/spec/earth/fuel/fuel_spec.rb +88 -14
- data/spec/earth/fuel/fuel_year_spec.rb +21 -0
- data/spec/earth/fuel/greenhouse_gas_spec.rb +23 -0
- data/spec/earth/hospitality/commercial_building_energy_consumption_survey_response_spec.rb +13 -10
- data/spec/earth/hospitality/lodging_class_spec.rb +1 -1
- data/spec/earth/industry/cbecs_energy_intensity_spec.rb +72 -72
- data/spec/earth/industry/industry_spec.rb +16 -9
- data/spec/earth/industry/mecs_energy_spec.rb +76 -72
- data/spec/earth/industry/mecs_ratio_spec.rb +35 -31
- data/spec/earth/industry/merchant_category_spec.rb +7 -5
- data/spec/earth/industry/naics_2002_naics_2007_concordance_spec.rb +10 -19
- data/spec/earth/industry/naics_2002_sic_1987_concordance_spec.rb +9 -19
- data/spec/earth/industry/naics_2002_spec.rb +1 -11
- data/spec/earth/industry/naics_2007_spec.rb +2 -11
- data/spec/earth/industry/sic_1987_spec.rb +3 -14
- data/spec/earth/locality/census_division_spec.rb +25 -0
- data/spec/earth/locality/census_region_spec.rb +8 -0
- data/spec/earth/locality/climate_division_spec.rb +13 -0
- data/spec/earth/locality/country_spec.rb +24 -23
- data/spec/earth/locality/egrid_country_spec.rb +7 -6
- data/spec/earth/locality/egrid_region_spec.rb +6 -6
- data/spec/earth/locality/egrid_subregion_spec.rb +14 -14
- data/spec/earth/locality/electricity_mix_spec.rb +17 -17
- data/spec/earth/locality/padd_spec.rb +21 -0
- data/spec/earth/locality/state_spec.rb +8 -11
- data/spec/earth/locality/zip_code_spec.rb +29 -22
- data/spec/earth/pet/breed_gender_spec.rb +8 -0
- data/spec/earth/pet/breed_spec.rb +8 -0
- data/spec/earth/pet/gender_spec.rb +8 -0
- data/spec/earth/pet/species_spec.rb +11 -5
- data/spec/earth/rail/country_rail_class_spec.rb +16 -0
- data/spec/earth/rail/country_rail_traction_class_spec.rb +14 -0
- data/spec/earth/rail/country_rail_traction_spec.rb +14 -0
- data/spec/earth/rail/national_transit_database_company_spec.rb +103 -0
- data/spec/earth/rail/national_transit_database_mode_spec.rb +21 -0
- data/spec/earth/rail/national_transit_database_record_spec.rb +31 -0
- data/spec/earth/rail/rail_class_spec.rb +8 -0
- data/spec/earth/rail/rail_company_spec.rb +20 -0
- data/spec/earth/rail/rail_fuel_spec.rb +19 -0
- data/spec/earth/rail/rail_traction_spec.rb +8 -0
- data/spec/earth/residence/air_conditioner_use_spec.rb +17 -0
- data/spec/earth/residence/clothes_machine_use_spec.rb +11 -0
- data/spec/earth/residence/dishwasher_use_spec.rb +11 -0
- data/spec/earth/residence/residence_appliance_spec.rb +19 -0
- data/spec/earth/residence/residence_class_spec.rb +15 -0
- data/spec/earth/residence/residence_fuel_price_spec.rb +12 -0
- data/spec/earth/residence/residence_fuel_type_spec.rb +18 -0
- data/spec/earth/residence/residential_energy_consumption_survey_response_spec.rb +13 -0
- data/spec/earth/residence/urbanity_spec.rb +8 -0
- data/spec/earth/shipping/carrier_mode_spec.rb +18 -0
- data/spec/earth/shipping/carrier_spec.rb +27 -0
- data/spec/earth/shipping/shipment_mode_spec.rb +16 -0
- data/spec/earth_spec.rb +1 -1
- data/spec/factories/airline.rb +0 -1
- data/spec/factories/airport.rb +0 -1
- data/spec/factories/automobile_activity_year.rb +8 -0
- data/spec/factories/automobile_activity_year_type.rb +8 -0
- data/spec/factories/automobile_activity_year_type_fuel.rb +9 -0
- data/spec/factories/automobile_fuel.rb +15 -0
- data/spec/factories/automobile_make.rb +9 -0
- data/spec/factories/automobile_make_model.rb +10 -0
- data/spec/factories/automobile_make_model_year.rb +9 -0
- data/spec/factories/automobile_model.rb +9 -0
- data/spec/factories/automobile_type_fuel.rb +7 -0
- data/spec/factories/automobile_type_fuel_control.rb +16 -0
- data/spec/factories/automobile_type_fuel_year.rb +9 -0
- data/spec/factories/automobile_type_fuel_year_control.rb +11 -0
- data/spec/factories/bus_fuel.rb +7 -0
- data/spec/factories/bus_fuel_year_control.rb +9 -0
- data/spec/factories/cbecs_energy_intensity.rb +15 -0
- data/spec/factories/commercial_building_energy_consumption_survey_response.rb +10 -0
- data/spec/factories/electric_utility.rb +8 -0
- data/spec/factories/flight_distance_class.rb +8 -0
- data/spec/factories/flight_segment.rb +0 -1
- data/spec/factories/food_group.rb +8 -0
- data/spec/factories/fuel.rb +8 -0
- data/spec/factories/fuel_year.rb +8 -0
- data/spec/factories/green_button_adoption.rb +8 -0
- data/spec/factories/greenhouse_gas.rb +7 -0
- data/spec/factories/industry.rb +9 -0
- data/spec/factories/mecs_energy.rb +15 -0
- data/spec/factories/mecs_ratio.rb +15 -0
- data/spec/factories/national_transit_database_company.rb +8 -0
- data/spec/factories/national_transit_database_mode.rb +8 -0
- data/spec/factories/national_transit_database_record.rb +9 -0
- data/spec/factories/residence_appliance.rb +7 -0
- data/spec/factories/zip_code.rb +9 -0
- data/spec/spec_helper.rb +36 -19
- metadata +346 -66
- data/lib/earth/acronyms.rb +0 -12
- data/lib/earth/rail/rail_company_traction.rb +0 -24
- data/lib/earth/rail/rail_company_traction/data_miner.rb +0 -4
- data/lib/earth/rail/rail_company_traction_class.rb +0 -26
- data/lib/earth/rail/rail_company_traction_class/data_miner.rb +0 -4
@@ -18,7 +18,5 @@ BusFuelYearControl.class_eval do
|
|
18
18
|
process "Derive bus fuel control name for association with BusFuelControl" do
|
19
19
|
update_all "bus_fuel_control_name = bus_fuel_name || ' ' || control"
|
20
20
|
end
|
21
|
-
|
22
|
-
# FIXME TODO verify that for any year the percentages sum to 1
|
23
21
|
end
|
24
22
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'falls_back_on'
|
2
|
-
|
3
1
|
require 'earth/model'
|
2
|
+
require 'falls_back_on'
|
4
3
|
|
5
4
|
class ComputationCarrier < ActiveRecord::Base
|
6
5
|
extend Earth::Model
|
@@ -20,14 +19,5 @@ EOS
|
|
20
19
|
falls_back_on :name => 'fallback',
|
21
20
|
:power_usage_effectiveness => lambda { ComputationCarrier.maximum('power_usage_effectiveness') }
|
22
21
|
|
23
|
-
|
24
|
-
# verify "Power usage effectiveness should be one or more" do
|
25
|
-
# ComputationCarrier.all.each do |carrier|
|
26
|
-
# unless carrier.power_usage_effectiveness >= 1.0
|
27
|
-
# raise "Invalid power usage effectiveness for ComputationCarrier #{carrier.name}: #{carrier.power_usage_effectiveness} (should be >= 1.0)"
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
|
32
22
|
warn_unless_size 1
|
33
23
|
end
|
@@ -1,6 +1,5 @@
|
|
1
|
-
require 'falls_back_on'
|
2
|
-
|
3
1
|
require 'earth/model'
|
2
|
+
require 'falls_back_on'
|
4
3
|
|
5
4
|
require 'earth/computation/computation_carrier'
|
6
5
|
|
@@ -24,29 +23,9 @@ EOS
|
|
24
23
|
|
25
24
|
belongs_to :carrier, :class_name => 'ComputationCarrier', :foreign_key => 'computation_carrier_name'
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
def self.fallback
|
27
|
+
find_by_name 'Amazon m1.small'
|
28
|
+
end
|
31
29
|
|
32
|
-
# FIXME TODO verify that computation carrier name appears in computation_carriers
|
33
|
-
|
34
|
-
# verify "Electricity intensity should be more than zero" do
|
35
|
-
# ComputationCarrierInstanceClass.all.each do |instance_class|
|
36
|
-
# unless instance_class.electricity_intensity > 0
|
37
|
-
# raise "Invalid electricity intensity for ComputationCarrierInstanceClass #{instance_class.name}: #{instance_class.electricity_intensity} (should be > 0)"
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
#
|
42
|
-
# verify "Electricity intensity units should be kilowatts" do
|
43
|
-
# ComputationCarrierInstanceClass.all.each do |instance_class|
|
44
|
-
# unless instance_class.electricity_intensity_units == 'kilowatts'
|
45
|
-
# raise "Invalid electricity intensity units for ComputationCarrierInstanceClass #{instance_class.name}: #{instance_class.electricity_intensity_units} (should be kilowatts)"
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
# end
|
49
|
-
|
50
|
-
|
51
30
|
warn_unless_size 8
|
52
31
|
end
|
@@ -6,8 +6,14 @@ require 'earth/locality/state'
|
|
6
6
|
require 'earth/locality/zip_code'
|
7
7
|
|
8
8
|
class ElectricUtility < ActiveRecord::Base
|
9
|
+
data_miner do
|
10
|
+
process "Data mine GreenButtonAdoption because it's like a belongs_to association" do
|
11
|
+
GreenButtonAdoption.run_data_miner!
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
9
15
|
extend Earth::Model
|
10
|
-
|
16
|
+
|
11
17
|
TABLE_STRUCTURE = <<-EOS
|
12
18
|
|
13
19
|
CREATE TABLE electric_utilities
|
@@ -28,12 +34,13 @@ EOS
|
|
28
34
|
has_many :electric_markets, :foreign_key => :electric_utility_eia_id
|
29
35
|
has_many :zip_codes, :through => :electric_markets
|
30
36
|
|
31
|
-
|
32
37
|
def green_button_implementer?
|
33
|
-
GreenButtonAdoption.implemented? name, nickname
|
38
|
+
GreenButtonAdoption.implemented? name, nickname
|
34
39
|
end
|
35
|
-
|
40
|
+
|
36
41
|
def green_button_committer?
|
37
42
|
GreenButtonAdoption.committed? name, nickname
|
38
43
|
end
|
44
|
+
|
45
|
+
warn_unless_size 3265
|
39
46
|
end
|
@@ -1,11 +1,5 @@
|
|
1
|
-
require 'earth/electricity/green_button_adoption'
|
2
|
-
|
3
1
|
ElectricUtility.class_eval do
|
4
2
|
data_miner do
|
5
|
-
process "make sure green button adoption is populated" do
|
6
|
-
GreenButtonAdoption.run_data_miner!
|
7
|
-
end
|
8
|
-
|
9
3
|
import 'EIA Form 861 records from 2010 (revised)',
|
10
4
|
:url => 'http://www.eia.gov/Ftproot/pub/electricity/f86110.zip',
|
11
5
|
:filename => 'file1_2010.xls',
|
@@ -17,8 +11,8 @@ ElectricUtility.class_eval do
|
|
17
11
|
store 'nerc_region_abbreviation', :synthesize => proc { |row| (first_nerc = row['NERC_LOCATION'].match(/^(\w+)/))? first_nerc.captures[0] : nil }
|
18
12
|
store 'second_nerc_region_abbreviation', :synthesize => proc { |row| (second_nerc = row['NERC_LOCATION'].match(/^\w+ ?[&,\/] ?(\w+)$/)) ? second_nerc.captures[0] : nil }
|
19
13
|
end
|
20
|
-
|
21
|
-
import '
|
14
|
+
|
15
|
+
import 'aliases', :url => 'https://docs.google.com/spreadsheet/pub?key=0AtyCBJLCFHlwdEM5WjVxRjBKWVJRcTJ3c1BhUnlSVXc&single=true&gid=0&output=csv' do
|
22
16
|
key 'eia_id', :field_name => 'utility_id'
|
23
17
|
store 'nickname', :field_name => 'alias'
|
24
18
|
end
|
data/lib/earth/fuel/fuel.rb
CHANGED
@@ -3,10 +3,8 @@ require 'earth/model'
|
|
3
3
|
require 'earth/fuel/fuel_year'
|
4
4
|
|
5
5
|
class Fuel < ActiveRecord::Base
|
6
|
-
# Need to ensure FuelYear gets data_mined even when pulling with taps
|
7
|
-
# b/c Fuel has instance methods to look up missing values from FuelYear
|
8
6
|
data_miner do
|
9
|
-
process "
|
7
|
+
process "Data mine FuelYear because some methods are delegated to it" do
|
10
8
|
FuelYear.run_data_miner!
|
11
9
|
end
|
12
10
|
end
|
@@ -40,88 +38,29 @@ EOS
|
|
40
38
|
has_many :fuel_years, :foreign_key => 'fuel_name'
|
41
39
|
|
42
40
|
def latest_fuel_year
|
43
|
-
fuel_years.find_by_year
|
41
|
+
fuel_years.find_by_year fuel_years.maximum(:year)
|
44
42
|
end
|
45
43
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
[
|
45
|
+
:energy_content,
|
46
|
+
:energy_content_units,
|
47
|
+
:carbon_content,
|
48
|
+
:carbon_content_units,
|
49
|
+
:oxidation_factor,
|
50
|
+
:biogenic_fraction,
|
51
|
+
:co2_emission_factor,
|
52
|
+
:co2_emission_factor_units,
|
53
|
+
:co2_biogenic_emission_factor,
|
54
|
+
:co2_biogenic_emission_factor_units
|
55
|
+
].each do |method_name|
|
56
|
+
define_method method_name do
|
57
|
+
if attribute = super()
|
58
|
+
attribute
|
59
|
+
elsif fuel_years.present?
|
60
|
+
latest_fuel_year.send method_name
|
61
|
+
end
|
51
62
|
end
|
52
63
|
end
|
53
64
|
|
54
|
-
def energy_content_units
|
55
|
-
if units = super
|
56
|
-
units
|
57
|
-
elsif fuel_years.present?
|
58
|
-
latest_fuel_year.energy_content_units
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def carbon_content
|
63
|
-
if content = super
|
64
|
-
content
|
65
|
-
elsif fuel_years.present?
|
66
|
-
latest_fuel_year.carbon_content
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def carbon_content_units
|
71
|
-
if units = super
|
72
|
-
units
|
73
|
-
elsif fuel_years.present?
|
74
|
-
latest_fuel_year.carbon_content_units
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def oxidation_factor
|
79
|
-
if oxidation_factor = super
|
80
|
-
oxidation_factor
|
81
|
-
elsif fuel_years.present?
|
82
|
-
latest_fuel_year.oxidation_factor
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def biogenic_fraction
|
87
|
-
if biogenic_fraction = super
|
88
|
-
biogenic_fraction
|
89
|
-
elsif fuel_years.present?
|
90
|
-
latest_fuel_year.biogenic_fraction
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def co2_emission_factor
|
95
|
-
if ef = super
|
96
|
-
ef
|
97
|
-
elsif fuel_years.present?
|
98
|
-
latest_fuel_year.co2_emission_factor
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def co2_emission_factor_units
|
103
|
-
if units = super
|
104
|
-
units
|
105
|
-
elsif fuel_years.present?
|
106
|
-
latest_fuel_year.co2_emission_factor_units
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
def co2_biogenic_emission_factor
|
111
|
-
if ef = super
|
112
|
-
ef
|
113
|
-
elsif fuel_years.present?
|
114
|
-
latest_fuel_year.co2_biogenic_emission_factor
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def co2_biogenic_emission_factor_units
|
119
|
-
if units = super
|
120
|
-
units
|
121
|
-
elsif fuel_years.present?
|
122
|
-
latest_fuel_year.co2_biogenic_emission_factor_units
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
65
|
warn_unless_size 23
|
127
66
|
end
|
data/lib/earth/fuel/fuel_year.rb
CHANGED
@@ -30,49 +30,5 @@ EOS
|
|
30
30
|
|
31
31
|
belongs_to :fuel, :foreign_key => 'fuel_name'
|
32
32
|
|
33
|
-
|
34
|
-
# FIXME TODO verify fuel name is in Fuel
|
35
|
-
# verify "Fuel name should never be missing" do
|
36
|
-
# FuelYear.all.each do |record|
|
37
|
-
# fuel_name = record.send(:fuel_name)
|
38
|
-
# if fuel_name.nil?
|
39
|
-
# raise "Missing fuel name for FuelYear '#{record.name}'"
|
40
|
-
# end
|
41
|
-
# end
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# verify "Year should be from 1990 to 2008" do
|
45
|
-
# FuelYear.all.each do |record|
|
46
|
-
# year = record.send(:year)
|
47
|
-
# unless year > 1989 and year < 2009
|
48
|
-
# raise "Invalid year for FuelYear '#{record.name}': #{year} (should be from 1990 to 2008)"
|
49
|
-
# end
|
50
|
-
# end
|
51
|
-
# end
|
52
|
-
#
|
53
|
-
# verify "Carbon content and energy content should be greater than zero" do
|
54
|
-
# FuelYear.all.each do |record|
|
55
|
-
# %w{ carbon_content energy_content }.each do |attribute|
|
56
|
-
# value = record.send(:"#{attribute}")
|
57
|
-
# unless value > 0
|
58
|
-
# raise "Invalid #{attribute} for FuelYear '#{record.name}': #{value} (should be > 0)"
|
59
|
-
# end
|
60
|
-
# end
|
61
|
-
# end
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# verify "Emission factors should be zero or more" do
|
65
|
-
# FuelYear.all.each do |record|
|
66
|
-
# %w{ co2_emission_factor co2_biogenic_emission_factor }.each do |attribute|
|
67
|
-
# value = record.send(:"#{attribute}")
|
68
|
-
# unless value >= 0
|
69
|
-
# raise "Invalid #{attribute} for FuelYear '#{record.name}': #{value} (should be >= 0)"
|
70
|
-
# end
|
71
|
-
# end
|
72
|
-
# end
|
73
|
-
# end
|
74
|
-
#
|
75
|
-
# FIXME TODO verify units
|
76
|
-
|
77
33
|
warn_unless_size 171
|
78
34
|
end
|
@@ -25,45 +25,5 @@ EOS
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
|
-
# verify "Abbreviation and IPCC report should never be missing" do
|
30
|
-
# GreenhouseGas.all.each do |record|
|
31
|
-
# %w{ abbreviation ipcc_report }.each do |attribute|
|
32
|
-
# value = record.send(:"#{attribute}")
|
33
|
-
# unless value.present?
|
34
|
-
# raise "Missing #{attribute} for GreenhouseGas '#{record.name}'"
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
# end
|
38
|
-
# end
|
39
|
-
#
|
40
|
-
# verify "Time horizon should be 100" do
|
41
|
-
# GreenhouseGas.all.each do |record|
|
42
|
-
# value = record.send(:time_horizon)
|
43
|
-
# unless value == 100
|
44
|
-
# raise "Invalid time horizon for GreenhouseGas '#{record.name}': #{value} (should be 100)"
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
# end
|
48
|
-
#
|
49
|
-
# verify "Time horizon units should be years" do
|
50
|
-
# GreenhouseGas.all.each do |record|
|
51
|
-
# units = record.send(:time_horizon_units)
|
52
|
-
# unless units == "years"
|
53
|
-
# raise "Invalid time horizon units for GreenhouseGas '#{record.name}': #{units} (should be years)"
|
54
|
-
# end
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
#
|
58
|
-
# verify "Global warming potential should be one or more" do
|
59
|
-
# GreenhouseGas.all.each do |record|
|
60
|
-
# value = record.send(:global_warming_potential)
|
61
|
-
# unless value >= 1
|
62
|
-
# raise "Invalid global warming potential for GreenhouseGas '#{record.name}': #{value} (should >= 1)"
|
63
|
-
# end
|
64
|
-
# end
|
65
|
-
# end
|
66
|
-
|
67
|
-
|
68
28
|
warn_unless_size 4
|
69
29
|
end
|
@@ -1,7 +1,29 @@
|
|
1
1
|
require 'earth/model'
|
2
|
-
require 'earth/locality'
|
3
2
|
|
4
3
|
class CbecsEnergyIntensity < ActiveRecord::Base
|
4
|
+
FUELS = {
|
5
|
+
:electricity => {
|
6
|
+
:consumption => :billion_kilowatt_hours,
|
7
|
+
:intensity => :kilowatt_hours_per_square_foot,
|
8
|
+
:set => 10
|
9
|
+
},
|
10
|
+
:natural_gas => {
|
11
|
+
:consumption => :billion_cubic_feet_of_natural_gas,
|
12
|
+
:intensity => :cubic_feet_of_natural_gas_per_square_foot,
|
13
|
+
:set => 11
|
14
|
+
},
|
15
|
+
:fuel_oil => {
|
16
|
+
:consumption => :million_gallons_of_fuel_oil,
|
17
|
+
:intensity => :gallons_of_fuel_oil_per_square_foot,
|
18
|
+
:set => 12
|
19
|
+
},
|
20
|
+
:district_heat => {
|
21
|
+
:consumption => :trillion_btu,
|
22
|
+
:intensity => :trillion_btu_per_million_square_feet,
|
23
|
+
:set => 13
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
5
27
|
extend Earth::Model
|
6
28
|
|
7
29
|
TABLE_STRUCTURE = <<-EOS
|
@@ -46,38 +68,10 @@ EOS
|
|
46
68
|
|
47
69
|
self.primary_key = "name"
|
48
70
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
71
|
scope :divisional, where('census_region_number IS NOT NULL AND census_division_number IS NOT NULL')
|
55
72
|
scope :regional, where('census_region_number IS NOT NULL AND census_division_number IS NULL')
|
56
73
|
scope :national, where(:census_region_number => nil, :census_division_number => nil)
|
57
74
|
|
58
|
-
FUELS = {
|
59
|
-
:electricity => {
|
60
|
-
:consumption => :billion_kilowatt_hours,
|
61
|
-
:intensity => :kilowatt_hours_per_square_foot,
|
62
|
-
:set => 10
|
63
|
-
},
|
64
|
-
:natural_gas => {
|
65
|
-
:consumption => :billion_cubic_feet_of_natural_gas,
|
66
|
-
:intensity => :cubic_feet_of_natural_gas_per_square_foot,
|
67
|
-
:set => 11
|
68
|
-
},
|
69
|
-
:fuel_oil => {
|
70
|
-
:consumption => :million_gallons_of_fuel_oil,
|
71
|
-
:intensity => :gallons_of_fuel_oil_per_square_foot,
|
72
|
-
:set => 12
|
73
|
-
},
|
74
|
-
:district_heat => {
|
75
|
-
:consumption => :trillion_btu,
|
76
|
-
:intensity => :trillion_btu_per_million_square_feet,
|
77
|
-
:set => 13
|
78
|
-
}
|
79
|
-
}
|
80
|
-
|
81
75
|
# Find the first record whose naics_code matches code.
|
82
76
|
# If no record found chop off the last character of code and try again, and so on.
|
83
77
|
def self.find_by_naics_code(code)
|
@@ -114,4 +108,6 @@ EOS
|
|
114
108
|
ratios
|
115
109
|
end
|
116
110
|
end
|
111
|
+
|
112
|
+
warn_unless_size 182
|
117
113
|
end
|