ngeso

package
v0.0.0-...-0dad8b8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ngeso implements the carbonintensity.org.uk Grid CO2 tracking service, which provides CO2 forecasting for the UK at a national and regional level. This service is provided by the National Grid Electricity System Operator (NGESO).

Index

Constants

View Source
const BaseURI = "https://api.carbonintensity.org.uk/"

BaseURI is the root path that the API is accessed from.

View Source
const ForecastNationalURI = BaseURI + "intensity/%s/fw48h"

ForecastNationalURI defines the location of the national forecast. Replace the first %s with the RFC3339 timestamp to fetch from.

View Source
const ForecastRegionalByIdURI = BaseURI + "regional/intensity/%s/fw48h/regionid/%s"

ForecastRegionalByIdURI defines the location of the regional forecast determined by Region ID. Replace the first %s with the RFC3339 timestamp to fetch from, and the second with the appropriate Region ID.

View Source
const ForecastRegionalByPostcodeURI = BaseURI + "regional/intensity/%s/fw48h/postcode/%s"

ForecastRegionalByPostcodeURI defines the location of the regional forecast determined by a given postcode. Replace the first %s with the RFC3339 timestamp to fetch from, and the second with the appropriate postcode.

Variables

View Source
var ErrRegionalRequestInvalidFormat = errors.New("regional request object missing region")

Functions

This section is empty.

Types

type CarbonForecastNationalRequest

type CarbonForecastNationalRequest struct{}

func ConstructNationalForecastRequest

func ConstructNationalForecastRequest() *CarbonForecastNationalRequest

ConstructNationalForecastRequest returns a request object to be used when calling the national API.

func (*CarbonForecastNationalRequest) DoRequest

func (*CarbonForecastNationalRequest) URI

type CarbonForecastRegionalRequest

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

func ConstructRegionalForecastByIDRequest

func ConstructRegionalForecastByIDRequest(r string) *CarbonForecastRegionalRequest

ConstructRegionalForecastByIDRequest returns a validly formatted, fully qualified URI to the forecast valid for the given region.

func ConstructRegionalForecastByPostcodeRequest

func ConstructRegionalForecastByPostcodeRequest(p string) *CarbonForecastRegionalRequest

ConstructRegionalForecastByPostcodeRequest returns a validly formatted, fully qualified URI to the forecast valid for the given postcode.

func (*CarbonForecastRegionalRequest) DoRequest

func (*CarbonForecastRegionalRequest) URI

type CarbonForecastRequest

type CarbonForecastRequest interface {
	URI() (string, error)
	DoRequest(helper *request.Helper) (CarbonForecastResponse, error)
}

type CarbonForecastResponse

type CarbonForecastResponse interface {
	Results() []CarbonIntensityForecastEntry
}

type CarbonIntensity

type CarbonIntensity struct {
	// The forecasted rate in gCO2/kWh
	Forecast float64 `json:"forecast"`
	// The rate recorded when this slot occurred - only available historically, otherwise nil
	Actual float64 `json:"actual"`
	// A human-readable representation of the level of emissions (e.g "low", "moderate")
	Index string `json:"index"`
}

type CarbonIntensityForecastEntry

type CarbonIntensityForecastEntry struct {
	ValidityStart shortrfc3339.Timestamp `json:"from"`
	ValidityEnd   shortrfc3339.Timestamp `json:"to"`
	Intensity     CarbonIntensity        `json:"intensity"`
}

type NationalIntensityResult

type NationalIntensityResult struct {
	Rates []CarbonIntensityForecastEntry `json:"data"`
}

NationalIntensityResult is returned either as a sub-element of a Regional request, or as the main result of a National request.

func (NationalIntensityResult) Results

Results is a helper / interface function to return the current rate data.

type RegionalIntensityResult

type RegionalIntensityResult struct {
	Data RegionalIntensityResultData `json:"data"`
}

RegionalIntensityResult is returned by Regional requests. It wraps all data inside a data element. Because that makes sense, and makes all of this SO much easier. /s

func (RegionalIntensityResult) Results

type RegionalIntensityResultData

type RegionalIntensityResultData struct {
	RegionId  int                            `json:"regionid"`
	DNORegion string                         `json:"dnoregion"`
	ShortName string                         `json:"shortname"`
	Rates     []CarbonIntensityForecastEntry `json:"data"`
}

RegionalIntensityResultData is returned by Regional requests. It includes a bit of extra data.

Jump to

Keyboard shortcuts

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