impact_model.rb |
|
|---|---|
|
Copyright © 2010 Brighter Planet. See LICENSE for details. Contact Brighter Planet for dual-license arrangements. |
require 'leap'
require 'timeframe'
require 'date'
require 'weighted_average'
require 'builder' |
ElectricityUse carbon modelThis model is used by Brighter Planet’s carbon emission web service to estimate the greenhouse gas emissions of electricity use. Timeframe and dateThe model estimates the emissions that occur during a particular CalculationsThe final estimate is the result of the calculations detailed below. These calculations are performed in reverse order, starting with the last calculation listed and finishing with the MethodsTo accomodate varying client input, each calculation may have one or more methods. These are listed under each calculation in order from most to least preferred. Each method is named according to the values it requires. If any of these values is not available the method will be ignored. If all the methods for a calculation are ignored, the calculation will not return a value. “Default” methods do not require any values, and so a calculation with a default method will always return a value. Standard complianceEach method lists any established calculation standards with which it complies. When compliance with a standard is requested, all methods that do not comply with that standard are ignored. This means that any values a particular method requires will have been calculated using a compliant method, because those are the only methods available. If any value did not have a compliant method in its calculation then it would be undefined, and the current method would have been ignored. CollaborationContributions to this carbon model are actively encouraged and warmly welcomed. This library includes a comprehensive test suite to ensure that your changes do not cause regressions. All changes should include test coverage for new functionality. Please see sniff, our emitter testing framework, for more information. |
module BrighterPlanet
module ElectricityUse
module ImpactModel
def self.included(base)
base.decide :impact, :with => :characteristics do |
Emission calculationReturns the |
committee :carbon do |
Emission from date, emission factor, loss factor, and energy |
quorum 'from date, emission factor, loss factor and energy', :needs => [:date, :emission_factor, :loss_factor, :energy] do |characteristics, timeframe|
date = characteristics[:date].is_a?(Date) ?
characteristics[:date] :
Date.parse(characteristics[:date].to_s) |
|
if timeframe.include? date |
|
characteristics[:energy] / (1 - characteristics[:loss_factor]) * characteristics[:emission_factor]
else |
|
0
end
end
end
|
Emission factor calculationReturns the grid average emission factor of the area where the electricity was used (kg CO2 / kWh). |
committee :emission_factor do |
Emission factor from eGRID subregion |
quorum 'from eGRID subregion', :needs => :egrid_subregion do |characteristics| |
|
Looks up the emission factor of the |
characteristics[:egrid_subregion].electricity_emission_factor
end
end
|
Loss factor calculationReturns the average transmission and distribution loss factor for the area where the electricity was used. |
committee :loss_factor do |
Loss factor from eGRID region |
quorum 'from eGRID region', :needs => :egrid_region do |characteristics| |
|
Looks up the loss factor of the |
characteristics[:egrid_region].loss_factor
end
end
|
eGRID region calculationReturns the eGRID region where the electricity was used. |
committee :egrid_region do |
eGRID region from eGRID subregion |
quorum 'from eGRID subregion', :needs => :egrid_subregion do |characteristics| |
|
Looks up the eGRID region in which the |
characteristics[:egrid_subregion].egrid_region
end
end
|
eGRID subregion calculationReturns the eGRID subregion where the electricity was used. |
committee :egrid_subregion do |
eGRID subregion from zip code |
quorum 'from zip code', :needs => :zip_code do |characteristics| |
|
Looks up the eGRID subregion in which the |
characteristics[:zip_code].egrid_subregion
end
|
eGRID subregion from default |
quorum 'default' do |
|
Uses the average of all eGRID subregion, weighted by electricity generation. |
EgridSubregion.find_by_abbreviation 'US'
end
end
|
Energy calculationReturns the electricity used (kWh). |
committee :energy do |
Energy use from client inputUses the client-input |
|
Energy from default |
quorum 'default' do |
|
Uses the 2008 U.S. annual household average electricity use (kWh). |
11_040
end
end
|
Date calculationReturns the |
committee :date do |
Date from client inputUses the client-input |
|
Date from timeframe |
quorum 'from timeframe' do |characteristics, timeframe| |
|
Assumes the electricity was used on the first day of the |
timeframe.from
end
end
|
Zip code calculationReturns the zip code where the electricity was used. Zip code from client inputUses the client-input zip code. |
|
Timeframe calculationReturns the Timeframe from client inputUses the client-input |
end
end
end
end
end |