emissions

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package emissions implements clients to fetch emission factors from different sources

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMissingAPIToken = errors.New("api token missing for Electricity Maps")
)

Custom errors.

Functions

func ISO23Map

func ISO23Map() map[string]string

ISO23Map returns a ISO-2 code to ISO-3 code map.

func ISO32Map

func ISO32Map() map[string]string

ISO32Map returns a ISO-3 code to ISO-2 code map.

func Register added in v0.2.0

func Register(
	provider string,
	providerName string,
	factory func(logger log.Logger) (Provider, error),
)

Register registers a emission factor provider.

Types

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
}

Client interface.

type ContextKey

type ContextKey struct{}

ContextKey is the struct key to set values in context.

type ContextValues

type ContextValues struct {
	CountryCodeAlpha2 string
	CountryCodeAlpha3 string
}

ContextValues contains the values to be set in context.

type CountryCode

type CountryCode struct {
	IsoCode []CountryCodeFields `json:"3166-1"`
}

CountryCode contains data of countries ISO codes.

var CountryCodes CountryCode

type CountryCodeFields

type CountryCodeFields struct {
	Alpha2Code    string `json:"alpha_2"`
	Alpha3Code    string `json:"alpha_3"`
	Name          string `json:"name"`
	NumericalCode string `json:"numeric"`
}

CountryCodeFields contains different ISO codes of a given country.

type EmissionFactor

type EmissionFactor struct {
	Name   string
	Factor float64
}

EmissionFactor is the container for emission factor value. The name can be country name or zone name based on the provider used.

type EmissionFactors

type EmissionFactors map[string]EmissionFactor

EmissionFactors returns a map of country code in ISO-2 with latest emission factor.

type FactorProviders

type FactorProviders struct {
	Providers     map[string]Provider
	ProviderNames map[string]string
	// contains filtered or unexported fields
}

FactorProviders implements the interface to collect emission factors from different sources.

func NewFactorProviders

func NewFactorProviders(logger log.Logger) (*FactorProviders, error)

NewFactorProviders creates a new EmissionProviders.

func (FactorProviders) Collect

func (e FactorProviders) Collect() map[string]PayLoad

Collect implements collection of emission factors from different providers.

type PayLoad

type PayLoad struct {
	Factor EmissionFactors
	Name   string
}

PayLoad contains emissions factor.

type Provider

type Provider interface {
	// Update current emission factor
	Update() (EmissionFactors, error)
}

Provider is the interface a emission provider has to implement.

func NewEMapsProvider

func NewEMapsProvider(logger log.Logger) (Provider, error)

NewEMapsProvider returns a new Provider that returns emission factor from electricity maps data.

func NewGlobalProvider

func NewGlobalProvider(logger log.Logger) (Provider, error)

NewGlobalProvider returns a new Provider that returns a constant global average emission factor.

func NewOWIDProvider

func NewOWIDProvider(logger log.Logger) (Provider, error)

NewOWIDProvider returns a new Provider that returns emission factor from OWID data.

func NewRTEProvider

func NewRTEProvider(logger log.Logger) (Provider, error)

NewRTEProvider returns a new Provider that returns emission factor from RTE eCO2 mix.

Jump to

Keyboard shortcuts

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