emissions

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: GPL-3.0 Imports: 18 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")
	ErrMissingInput     = errors.New("missing username/password/region for Watt Time")
	ErrMissingData      = errors.New("missing data in Watt Time response")
	ErrNoValidProviders = errors.New("no valid emission data providers found")
)

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

func Register(
	provider string,
	providerName string,
	factory func(logger *slog.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 *slog.Logger, enabled []string) (*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.

func (FactorProviders) Stop

func (e FactorProviders) Stop() error

Stop terminates tickers (when present) 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)

	// Stop updaters and release resources
	Stop() error
}

Provider is the interface a emission provider has to implement.

func NewEMapsProvider

func NewEMapsProvider(logger *slog.Logger) (Provider, error)

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

func NewGlobalProvider

func NewGlobalProvider(logger *slog.Logger) (Provider, error)

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

func NewOWIDProvider

func NewOWIDProvider(logger *slog.Logger) (Provider, error)

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

func NewRTEProvider

func NewRTEProvider(logger *slog.Logger) (Provider, error)

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

func NewWattTimeProvider

func NewWattTimeProvider(logger *slog.Logger) (Provider, error)

NewWattTimeProvider returns a new Provider that returns emission factor from WattTime data.

Jump to

Keyboard shortcuts

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