Module: BrighterPlanet::FuelPurchase::CarbonModel

Defined in:
lib/fuel_purchase/carbon_model.rb

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/fuel_purchase/carbon_model.rb', line 6

def self.included(base)
  base.extend ::Leap::Subject
  base.decide :emission, :with => :characteristics do
    committee :emission do
      quorum 'from volume and emission factor', :needs => [:volume, :emission_factor] do |characteristics|
        #     variable units                variable units          FIXME TODO should we make volumes energy contents to avoid unit mismatches?
        characteristics[:volume] * characteristics[:emission_factor]
      end
      
      quorum 'default' do
        raise "The fuel purchase's default emission quorum should never be called"
      end
    end
    
    committee :emission_factor do # FIXME TODO add date-based lookup once we have timeseries of emission factors
      quorum 'from fuel type', :needs => :fuel_type do |characteristics|
        characteristics[:fuel_type].emission_factor
      end
      
      quorum 'default' do
        ::FuelType.fallback.emission_factor
      end
    end
    
    committee :volume do
      quorum 'from cost and price', :needs => [:cost, :price] do |characteristics|
        #       dollars          dollars / variable unit          FIXME TODO should we make prices $ / kJ to avoid unit mismatches?
        characteristics[:cost] / characteristics[:price]
      end
      
      quorum 'from fuel type', :needs => :fuel_type do |characteristics|
        #      variable units
        characteristics[:fuel_type].average_purchase_volume
      end
      
      quorum 'default' do # FIXME TODO get rid of this if we ever make a fallback fuel_type
        #      variable units
        FuelType.fallback.average_purchase_volume
      end
    end
    
    committee :price do
      # FIXME TODO fill in location- and date-based quorums
      # quorum :from_fuel_type_and_state_and_date, :needs => [:fuel_type, :state, :date] do |characteristics, timeframe|
      # end
      # 
      # quorum :from_fuel_type_and_petroleum_administration_for_defense_district_and_date, :needs => [:fuel_type, :petroleum_administration_for_defense_district, :date] do |characteristics, timeframe|
      # end
      # 
      # quorum :from_fuel_type_and_state, :needs => [:fuel_type, :state] do |characteristics, timeframe|
      # end
      # 
      # quorum :from_fuel_type_and_petroleum_administration_for_defense_district, :needs => [:fuel_type, :petroleum_administration_for_defense_district] do |characteristics, timeframe|
      # end
      # 
      # quorum :from_fuel_type_and_date, :needs [:fuel_type, :date] do |characteristics, timeframe|
      # end
      quorum 'from fuel type', :needs => :fuel_type do |characteristics|
        #    dollars / variable unit
        characteristics[:fuel_type].price
      end
    end
    
    committee :petroleum_administration_for_defense_district do
      quorum 'from state', :needs => :state do |characteristics|
        characteristics[:state].petroleum_administration_for_defense_district
      end
    end
    
    committee :state do
      quorum 'from zip code', :needs => :zip_code do |characteristics|
        characteristics[:zip_code].state
      end
    end
    
    # FIXME TODO should this be only user-supplied, or should we specify a fallback?
    # committee :fuel_type do |characteristics, timeframe|
    #   FuelType.fallback.fuel_type
    # end
  end
end