Class: CbecsEnergyIntensity
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- CbecsEnergyIntensity
- Extended by:
- Earth::Model
- Defined in:
- lib/earth/industry/cbecs_energy_intensity.rb
Constant Summary collapse
- FUELS =
{ :electricity => { :consumption => :billion_kilowatt_hours, :intensity => :kilowatt_hours_per_square_foot, :set => 10 }, :natural_gas => { :consumption => :billion_cubic_feet_of_natural_gas, :intensity => :cubic_feet_of_natural_gas_per_square_foot, :set => 11 }, :fuel_oil => { :consumption => :million_gallons_of_fuel_oil, :intensity => :gallons_of_fuel_oil_per_square_foot, :set => 12 }, :district_heat => { :consumption => :trillion_btu, :intensity => :trillion_btu_per_million_square_feet, :set => 13 } }
- TABLE_STRUCTURE =
"\nCREATE TABLE cbecs_energy_intensities\n (\n name CHARACTER VARYING(255) NOT NULL PRIMARY KEY,\n principal_building_activity CHARACTER VARYING(255),\n naics_code CHARACTER VARYING(255),\n census_region_number INTEGER,\n census_division_number INTEGER,\n electricity FLOAT,\n electricity_units CHARACTER VARYING(255),\n electricity_floorspace FLOAT,\n electricity_floorspace_units CHARACTER VARYING(255),\n electricity_intensity FLOAT,\n electricity_intensity_units CHARACTER VARYING(255),\n natural_gas FLOAT,\n natural_gas_units CHARACTER VARYING(255),\n natural_gas_floorspace FLOAT,\n natural_gas_floorspace_units CHARACTER VARYING(255),\n natural_gas_intensity FLOAT,\n natural_gas_intensity_units CHARACTER VARYING(255),\n fuel_oil FLOAT,\n fuel_oil_units CHARACTER VARYING(255),\n fuel_oil_floorspace FLOAT,\n fuel_oil_floorspace_units CHARACTER VARYING(255),\n fuel_oil_intensity FLOAT,\n fuel_oil_intensity_units CHARACTER VARYING(255),\n district_heat FLOAT,\n district_heat_units CHARACTER VARYING(255),\n district_heat_floorspace FLOAT,\n district_heat_floorspace_units CHARACTER VARYING(255),\n district_heat_intensity FLOAT,\n district_heat_intensity_units CHARACTER VARYING(255)\n );\nCREATE INDEX index_cbecs_energy_intensities_on_naics_code ON cbecs_energy_intensities (naics_code);\nCREATE INDEX index_cbecs_energy_intensities_on_census_region_number ON cbecs_energy_intensities (census_region_number);\nCREATE INDEX index_cbecs_energy_intensities_on_census_division_number ON cbecs_energy_intensities (census_division_number)\n\n"
Class Method Summary collapse
-
.find_by_naics_code(code) ⇒ Object
Find the first record whose naics_code matches code.
-
.find_by_naics_code_and_census_division_number(code, number) ⇒ Object
Find the first record whose census_division_number matches number and whose naics_code matches code.
- .find_by_naics_code_and_census_field(code, field, number) ⇒ Object
-
.find_by_naics_code_and_census_region_number(code, number) ⇒ Object
Find the first record whose census_region_number matches number and whose naics_code matches code.
Instance Method Summary collapse
Methods included from Earth::Model
extend_mining, extended, registry
Class Method Details
.find_by_naics_code(code) ⇒ Object
Find the first record whose naics_code matches code. If no record found chop off the last character of code and try again, and so on.
77 78 79 |
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 77 def self.find_by_naics_code(code) find_by_naics_code_and_census_field(code, :census_region_number, nil) end |
.find_by_naics_code_and_census_division_number(code, number) ⇒ Object
Find the first record whose census_division_number matches number and whose naics_code matches code. If no record found chop off the last character of code and try again, and so on.
89 90 91 |
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 89 def self.find_by_naics_code_and_census_division_number(code, number) find_by_naics_code_and_census_field(code, :census_division_number, number) end |
.find_by_naics_code_and_census_field(code, field, number) ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 93 def self.find_by_naics_code_and_census_field(code, field, number) if code.blank? record = nil else record = where(field => number, :naics_code => code).first record ||= find_by_naics_code_and_census_field(code[0..-2], field, number) end record end |
.find_by_naics_code_and_census_region_number(code, number) ⇒ Object
Find the first record whose census_region_number matches number and whose naics_code matches code. If no record found chop off the last character of code and try again, and so on.
83 84 85 |
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 83 def self.find_by_naics_code_and_census_region_number(code, number) find_by_naics_code_and_census_field(code, :census_region_number, number) end |
Instance Method Details
#fuel_ratios ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'lib/earth/industry/cbecs_energy_intensity.rb', line 103 def fuel_ratios energy = 0 FUELS.keys.each { |fuel| energy += send(fuel).to_f } FUELS.keys.inject({}) do |ratios, fuel| ratios[fuel] = send(fuel).to_f / energy.to_f ratios end end |