Class: AutomobileFuel
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AutomobileFuel
- Defined in:
- lib/earth/automobile/automobile_fuel.rb
Constant Summary collapse
- CODES =
{ :electricity => 'El', :diesel => 'D' }
Class Method Summary collapse
- .fallback_annual_distance ⇒ Object
- .fallback_annual_distance_units ⇒ Object
- .fallback_blend_portion ⇒ Object
- .fallback_ch4_emission_factor ⇒ Object
- .fallback_ch4_emission_factor_units ⇒ Object
- .fallback_co2_biogenic_emission_factor ⇒ Object
- .fallback_co2_biogenic_emission_factor_units ⇒ Object
- .fallback_co2_emission_factor ⇒ Object
- .fallback_co2_emission_factor_units ⇒ Object
- .fallback_hfc_emission_factor ⇒ Object
- .fallback_hfc_emission_factor_units ⇒ Object
- .fallback_latest_type_fuel_year_ages ⇒ Object
- .fallback_latest_type_fuel_years ⇒ Object
- .fallback_n2o_emission_factor ⇒ Object
- .fallback_n2o_emission_factor_units ⇒ Object
Class Method Details
.fallback_annual_distance ⇒ Object
19 20 21 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 19 def fallback_annual_distance fallback_latest_type_fuel_year_ages.weighted_average(:annual_distance, :weighted_by => :vehicles) end |
.fallback_annual_distance_units ⇒ Object
23 24 25 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 23 def fallback_annual_distance_units fallback_latest_type_fuel_year_ages.first.annual_distance_units end |
.fallback_blend_portion ⇒ Object
27 28 29 30 31 32 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 27 def fallback_blend_portion latest_year = AutomobileTypeFuelYear.maximum('year') gas_use = AutomobileTypeFuelYear.where(:year => latest_year, :fuel_common_name => 'gasoline').sum('fuel_consumption') diesel_use = AutomobileTypeFuelYear.where(:year => latest_year, :fuel_common_name => 'diesel').sum('fuel_consumption') diesel_use / (gas_use + diesel_use) end |
.fallback_ch4_emission_factor ⇒ Object
65 66 67 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 65 def fallback_ch4_emission_factor fallback_latest_type_fuel_years.weighted_average(:ch4_emission_factor, :weighted_by => :total_travel) * GreenhouseGas[:ch4].global_warming_potential end |
.fallback_ch4_emission_factor_units ⇒ Object
69 70 71 72 73 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 69 def fallback_ch4_emission_factor_units prefix = fallback_latest_type_fuel_years.first.ch4_emission_factor_units.split("_per_")[0] suffix = fallback_latest_type_fuel_years.first.ch4_emission_factor_units.split("_per_")[1] prefix + "_co2e_per_" + suffix end |
.fallback_co2_biogenic_emission_factor ⇒ Object
52 53 54 55 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 52 def fallback_co2_biogenic_emission_factor (Fuel.find_by_name("Motor Gasoline").co2_biogenic_emission_factor * (1 - AutomobileFuel.fallback_blend_portion)) + (Fuel.find_by_name("Distillate Fuel Oil No. 2").co2_biogenic_emission_factor * AutomobileFuel.fallback_blend_portion) end |
.fallback_co2_biogenic_emission_factor_units ⇒ Object
57 58 59 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 57 def fallback_co2_biogenic_emission_factor_units Fuel.find_by_name("Motor Gasoline").co2_biogenic_emission_factor_units end |
.fallback_co2_emission_factor ⇒ Object
43 44 45 46 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 43 def fallback_co2_emission_factor (Fuel.find_by_name("Motor Gasoline").co2_emission_factor * (1 - AutomobileFuel.fallback_blend_portion)) + (Fuel.find_by_name("Distillate Fuel Oil No. 2").co2_emission_factor * AutomobileFuel.fallback_blend_portion) end |
.fallback_co2_emission_factor_units ⇒ Object
48 49 50 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 48 def fallback_co2_emission_factor_units Fuel.find_by_name("Motor Gasoline").co2_emission_factor_units end |
.fallback_hfc_emission_factor ⇒ Object
85 86 87 88 89 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 85 def fallback_hfc_emission_factor fallback_latest_type_fuel_years.map do |tfy| tfy.total_travel * tfy.type_year.hfc_emission_factor end.sum / fallback_latest_type_fuel_years.sum('total_travel') end |
.fallback_hfc_emission_factor_units ⇒ Object
91 92 93 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 91 def fallback_hfc_emission_factor_units fallback_latest_type_fuel_years.first.type_year.hfc_emission_factor_units end |
.fallback_latest_type_fuel_year_ages ⇒ Object
15 16 17 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 15 def fallback_latest_type_fuel_year_ages AutomobileTypeFuelYearAge.where(:year => AutomobileTypeFuelYearAge.maximum('year')) end |
.fallback_latest_type_fuel_years ⇒ Object
61 62 63 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 61 def fallback_latest_type_fuel_years AutomobileTypeFuelYear.where(:year => AutomobileTypeFuelYear.maximum('year')) end |
.fallback_n2o_emission_factor ⇒ Object
75 76 77 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 75 def fallback_n2o_emission_factor fallback_latest_type_fuel_years.weighted_average(:n2o_emission_factor, :weighted_by => :total_travel) * GreenhouseGas[:n2o].global_warming_potential end |
.fallback_n2o_emission_factor_units ⇒ Object
79 80 81 82 83 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 79 def fallback_n2o_emission_factor_units prefix = fallback_latest_type_fuel_years.first.n2o_emission_factor_units.split("_per_")[0] suffix = fallback_latest_type_fuel_years.first.n2o_emission_factor_units.split("_per_")[1] prefix + "_co2e_per_" + suffix end |