lib/flight/carbon_model.rb in flight-0.0.18 vs lib/flight/carbon_model.rb in flight-0.0.19
- old
+ new
@@ -1,21 +1,22 @@
-require 'leap'
require 'timeframe'
require 'weighted_average'
module BrighterPlanet
module Flight
module CarbonModel
def self.included(base)
- base.extend ::Leap::Subject
base.extend FastTimestamp
base.decide :emission, :with => :characteristics do
committee :emission do
quorum 'from fuel and passengers with coefficients',
:needs => [:fuel, :passengers, :seat_class_multiplier, :emission_factor,
:radiative_forcing_index, :freight_share, :date] do |characteristics, timeframe|
- if timeframe.include? characteristics[:date]
+ date = characteristics[:date].is_a?(Date) ?
+ characteristics[:date] :
+ Date.parse(characteristics[:date].to_s)
+ if timeframe.include? date
#( kg fuel ) * ( kg CO2 / kg fuel ) = kg CO2
(characteristics[:fuel] / characteristics[:passengers] * characteristics[:seat_class_multiplier]) * characteristics[:emission_factor] * characteristics[:radiative_forcing_index] * (1 - characteristics[:freight_share])
else
0
end
@@ -147,18 +148,18 @@
quorum 'from cohort', :needs => :cohort do |characteristics|
characteristics[:cohort].weighted_average(:load_factor, :weighted_by => :passengers)
end
quorum 'default' do
- BrighterPlanet::Flight.flight_model.fallback.andand.load_factor
+ base.fallback.andand.load_factor
end
end
committee :adjusted_distance do # returns nautical miles
quorum 'from distance', :needs => [:distance, :emplanements_per_trip] do |characteristics|
- route_inefficiency_factor = BrighterPlanet::Flight.flight_model.research(:route_inefficiency_factor)
- dogleg_factor = BrighterPlanet::Flight.flight_model.research(:dogleg_factor)
+ route_inefficiency_factor = base.research(:route_inefficiency_factor)
+ dogleg_factor = base.research(:dogleg_factor)
characteristics[:distance] * route_inefficiency_factor * ( dogleg_factor ** (characteristics[:emplanements_per_trip] - 1) )
end
end
committee :distance do # returns nautical miles
@@ -183,17 +184,17 @@
distance = characteristics[:cohort].weighted_average(:distance, :weighted_by => :passengers).to_f.kilometres.to(:nautical_miles)
distance > 0 ? distance : nil
end
quorum 'default' do
- BrighterPlanet::Flight.flight_model.fallback.distance_estimate.kilometres.to :nautical_miles
+ base.fallback.distance_estimate.kilometres.to :nautical_miles
end
end
committee :emplanements_per_trip do # per trip
quorum 'default' do
- BrighterPlanet::Flight.flight_model.fallback.emplanements_per_trip_before_type_cast
+ base.fallback.emplanements_per_trip_before_type_cast
end
end
committee :radiative_forcing_index do
quorum 'from fuel type', :needs => :fuel_type do |characteristics|
@@ -224,10 +225,10 @@
end
end
committee :trips do
quorum 'default' do
- BrighterPlanet::Flight.flight_model.fallback.andand.trips_before_type_cast
+ base.fallback.andand.trips_before_type_cast
end
end
# Disabling this for now because domesticity is pretty useless
# FIXME TODO make domesticity non-us-centric and check that data's ok