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
Instance Method Summary collapse
-
#annual_distance ⇒ Object
FIXME TODO should I run data miner on other classes we need? Fuel => FuelYear GreenhouseGas.
-
#ch4_emission_factor ⇒ Object
returns kg co2e / litre.
-
#co2_biogenic_emission_factor ⇒ Object
returns kg co2 / litre.
-
#co2_emission_factor ⇒ Object
returns kg co2 / litre.
-
#hfc_emission_factor ⇒ Object
returns kg co2e / litre (hfc emission factor is already in co2e).
- #latest_type_fuel_years ⇒ Object
-
#n2o_emission_factor ⇒ Object
returns kg co2e / litre.
Class Method Details
.fallback_blend_portion ⇒ Object
15 16 17 18 19 20 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 15 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 |
Instance Method Details
#annual_distance ⇒ Object
FIXME TODO should I run data miner on other classes we need? Fuel
> FuelYear
GreenhouseGas
49 50 51 52 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 49 def annual_distance # returns km scope = type_fuel_year_ages.any? ? type_fuel_year_ages : AutomobileTypeFuelYearAge scope.where(:year => scope.maximum('year')).weighted_average(:annual_distance, :weighted_by => :vehicles) end |
#ch4_emission_factor ⇒ Object
returns kg co2e / litre
75 76 77 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 75 def ch4_emission_factor # returns kg co2e / litre latest_type_fuel_years.weighted_average(:ch4_emission_factor, :weighted_by => :total_travel) * GreenhouseGas[:ch4].global_warming_potential end |
#co2_biogenic_emission_factor ⇒ Object
returns kg co2 / litre
62 63 64 65 66 67 68 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 62 def co2_biogenic_emission_factor # returns kg co2 / litre if blend_fuel.present? (base_fuel.co2_biogenic_emission_factor * (1 - blend_portion)) + (blend_fuel.co2_biogenic_emission_factor * blend_portion) else base_fuel.co2_biogenic_emission_factor end end |
#co2_emission_factor ⇒ Object
returns kg co2 / litre
54 55 56 57 58 59 60 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 54 def co2_emission_factor # returns kg co2 / litre if blend_fuel.present? (base_fuel.co2_emission_factor * (1 - blend_portion)) + (blend_fuel.co2_emission_factor * blend_portion) else base_fuel.co2_emission_factor end end |
#hfc_emission_factor ⇒ Object
returns kg co2e / litre (hfc emission factor is already in co2e)
83 84 85 86 87 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 83 def hfc_emission_factor # returns kg co2e / litre (hfc emission factor is already in co2e) latest_type_fuel_years.map do |type_fuel_year| type_fuel_year.total_travel * type_fuel_year.type_year.hfc_emission_factor end.sum / latest_type_fuel_years.sum('total_travel') end |
#latest_type_fuel_years ⇒ Object
70 71 72 73 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 70 def latest_type_fuel_years scope = type_fuel_years.any? ? type_fuel_years : AutomobileTypeFuelYear scope.where(:year => scope.maximum('year')) end |
#n2o_emission_factor ⇒ Object
returns kg co2e / litre
79 80 81 |
# File 'lib/earth/automobile/automobile_fuel.rb', line 79 def n2o_emission_factor # returns kg co2e / litre latest_type_fuel_years.weighted_average(:n2o_emission_factor, :weighted_by => :total_travel) * GreenhouseGas[:n2o].global_warming_potential end |