emissions

package
v0.1.0-rc.6 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: BSD-3-Clause Imports: 13 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 (
	StaticEmissionData = make(map[string]float64)
)

Functions

func RegisterProvider

func RegisterProvider(
	provider string,
	providerName string,
	factory func(ctx context.Context, logger log.Logger) (Provider, error))

RegisterProvider 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 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(ctx context.Context, 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 float64
	Name   string
}

PayLoad contains emissions factor

type Provider

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

Provider is the interface a emission provider has to implement.

func NewEMapsProvider

func NewEMapsProvider(ctx context.Context, logger log.Logger) (Provider, error)

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

func NewGlobalProvider

func NewGlobalProvider(ctx context.Context, logger log.Logger) (Provider, error)

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

func NewOWIDProvider

func NewOWIDProvider(ctx context.Context, logger log.Logger) (Provider, error)

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

func NewRTEProvider

func NewRTEProvider(ctx context.Context, 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