emission

package
v1.98.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// B is a Val constructor function with byte (B) dimension.
	B = ValMaker(byteLabel)
	// KB is a Val constructor function with kilobyte (KB) dimension.
	KB = B(decimalMultiplier).Maker()
	// MB is a Val constructor function with megabyte (MB) dimension.
	MB = KB(decimalMultiplier).Maker()
	// GB is a Val constructor function with gigabyte (GB) dimension.
	GB = MB(decimalMultiplier).Maker()
	// TB is a Val constructor function with terabyte (TB) dimension.
	TB = GB(decimalMultiplier).Maker()

	// W is a Val constructor function with watt (W) dimension.
	W = ValMaker(wattLabel)

	// H is a Val constructor function with hour (H) dimension.
	H = ValMaker(hourLabel)
	// Y is a Val constructor function with year (Y) dimension.
	Y = H(dayHours * yearDays).Maker()
)
View Source
var Error = errs.Class("emission service")

Error describes internal emission service error.

View Source
var Q = ValMaker("")

Q is a Val constructor function without any dimension.

Functions

func ValMaker

func ValMaker(unit string) func(val float64) *Val

ValMaker creates new Val constructor function by given string representation of the unit e.g. kg. By providing amount value to a constructor function we create a value instance. kg := ValMaker("kg") - kg is a constructor function here. kg(1) is a 1 kilogram Val.

Types

type Config

type Config struct {
	WriteEnergy                    float64 `help:"energy needed to write 1GB of data, in W-hours/GB" default:"0.005"`
	CO2PerEnergy                   float64 `help:"amount of carbon emission per unit of energy, in kg/kW-hours" default:"0.2826"`
	ShortenedDriveLife             float64 `help:"shortened hard drive life period, in years" default:"3"`
	StandardDriveLife              float64 `help:"standard hard drive life period, in years" default:"4"`
	ExtendedDriveLife              float64 `help:"extended hard drive life period, in years" default:"6"`
	NewDriveEmbodiedCarbon         float64 `help:"carbon footprint of producing 1TB HDD, in kg/TB" default:"20"`
	CarbonFromDrivePowering        float64 `help:"carbon from power per year of operations, in kg/TB-year" default:"15.9"`
	RepairedData                   float64 `help:"amount of repaired data, in TB" default:"667"`
	ExpandedData                   float64 `help:"amount of expanded data, in TB" default:"48689"`
	StorjGCPCarbon                 float64 `help:"amount of carbon emission from storj GCP, in kg" default:"3600"`
	StorjCRDBCarbon                float64 `help:"amount of carbon emission from storj CRDB, in kg" default:"2650"`
	StorjEdgeCarbon                float64 `help:"amount of carbon emission from storj Edge, in kg" default:"10924"`
	StorjExpandedNetworkStorage    float64 `help:"amount of expanded network storage, in TB" default:"18933"`
	HyperscalerExpansionFactor     float64 `help:"expansion factor of hyperscaler networks" default:"3"`
	CorporateDCExpansionFactor     float64 `help:"expansion factor of corporate data center networks" default:"4"`
	StorjExpansionFactor           float64 `help:"expansion factor of storj network" default:"2.7"`
	HyperscalerRegionCount         float64 `help:"region count of hyperscaler networks" default:"2"`
	CorporateDCRegionCount         float64 `help:"region count of corporate data center networks" default:"2"`
	StorjRegionCount               float64 `help:"region count of storj network" default:"1"`
	StorjStandardNetworkWeighting  float64 `help:"network weighting of already provisioned, powered drives, in fraction" default:"0.21"`
	StorjNewNetworkWeighting       float64 `help:"network weighting of new nodes, in fraction" default:"0.582"`
	HyperscalerUtilizationFraction float64 `help:"utilization fraction of hyperscaler networks, in fraction" default:"0.75"`
	CorporateDCUtilizationFraction float64 `help:"utilization fraction of corporate data center networks, in fraction" default:"0.40"`
	StorjUtilizationFraction       float64 `help:"utilization fraction of storj network, in fraction" default:"0.85"`
}

Config contains configurable values for emission service.

type Impact

type Impact struct {
	EstimatedKgCO2eStorj                       float64
	EstimatedKgCO2eHyperscaler                 float64
	EstimatedKgCO2eCorporateDC                 float64
	EstimatedFractionSavingsAgainstHyperscaler float64
	EstimatedFractionSavingsAgainstCorporateDC float64
}

Impact represents emission impact from different sources.

type Row

type Row [modalityCount]*Val

Row holds data row of predefined number of values.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is an emission service. Performs emissions impact calculations.

architecture: Service

func NewService

func NewService(config Config) *Service

NewService creates a new Service with the given configuration.

func (*Service) CalculateImpact

func (sv *Service) CalculateImpact(amountOfDataInTB float64, duration time.Duration) (*Impact, error)

CalculateImpact calculates emission impact coming from different sources e.g. Storj, hyperscaler or corporateDC.

type Val

type Val struct {
	Amount float64
	Num    []string
	Denom  []string
}

Val represents a value which consists of the numeric value itself and it's dimensions e.g. 1 kW. It may be used to represent a really complex value e.g. 1 kW / H or 0.005 W * H / GB.

func (*Val) Add

func (v *Val) Add(rhs *Val) (*Val, error)

Add sums two Val instances with the same dimensions.

func (*Val) Div

func (v *Val) Div(rhs *Val) *Val

Div divides one Val by a given one and returns new Val. It adjusts both the amount and the dimensions accordingly. Q := ValMaker("") - Q is a constructor function which has no dimension. Q(0.005) returns 0.005 Val. Q(0.005).Mul(W(1)) means 0.005 * 1 W = 0.005 W. Q(0.005).Mul(W(1)).Div(H(1)) means 0.005 * 1 W / 1 H = 0.005 W / 1 H = 0.005 W / H.

func (*Val) InUnits

func (v *Val) InUnits(units *Val) (float64, error)

InUnits converts a Val into the specified units, if possible.

func (*Val) Maker

func (v *Val) Maker() func(val float64) *Val

Maker creates a new Val constructor function from already existing Val. This is used to handle dimension factor differences. B := ValMaker("B") - B is a constructor function here. B(1) returns 1 byte Val. KB := B(1000).Maker() returns a construction function for a KB value. KB(1) returns 1 kilobyte Val but under the hood it's still 1000 B value.

func (*Val) Mul

func (v *Val) Mul(rhs *Val) *Val

Mul multiplies existing Val with a given one and returns new Val. It adjusts both the amount and the dimensions accordingly. Q := ValMaker("") - Q is a constructor function which has no dimension. Q(0.005) returns 0.005 Val. Q(0.005).Mul(W(1)) means 0.005 * 1 W = 0.005 W. Q(0.005).Mul(W(1)).Mul(H(1)) means 0.005 * 1 W * 1 H = 0.005 W * 1 H = 0.005 W * H.

func (*Val) String

func (v *Val) String() string

String returns string representation of the Val. Q := ValMaker("") - Q is a constructor function which has no dimension. Q(0.005).String is just 0.005. Q(0.005).Mul(W(1)).Mul(H(1)).Div(MB(1)).String() is 0.005 W * H / MB. KB(1).String() returns 1000 B because KB Val was created from a B Val.

func (*Val) Sub

func (v *Val) Sub(rhs *Val) (*Val, error)

Sub subtracts one Val from another if they have the same dimensions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL