Skip to content

Grid Generation restructures raw API responses into a clearer, easier-to-use format, improving readability and overall usability for developers without changing the underlying result data.

License

Notifications You must be signed in to change notification settings

LewisRandles/Grid-Generation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid Generation API Repacker

Explore electricity generation mix trends and forecasts using UK power grid data.

Badge Badge Badge Badge Badge

Introduction

Grid Generation is a free, no-auth, user-friendly API library that provides access to real-time and forecasted electricity generation mix data from the Carbon Intensity API. This project makes it easy to explore energy contributions from different fuel sources. It’s designed for everyone from energy analysts and students to educators and planners who want to study generation trends and carbon intensity impacts without complex software or specialized expertise.


Table of Contents


Downloading

Different Versions

Each release provides two configuations of the project.

  • The bundled, minified format known as "production".
  • The unbundled, unminified format known as "development".

Download Page

https://github.com/LewisRandles/Grid-Generation/releases


Installing

In your JavaScript file

	// Using the unbundled version needs to be kept with the internal files.
	import gridGeneration from './scripts/gridGeneration_unbundled.js';

	// Using the bundled version is standalone and has no internal files.
	import gridGeneration from './gridGeneration_bundled.js';

Usage

No Parameters

Providing no parameters will result in the default information being set.

await gridGeneration();

First Parameter

The first parameter is providing the desired mode. The format is case-insensitive.

First Parameter Type Description
mode string Supported mode formats include current and custom.
Usage Type Description
current string Get generation mix for current half hour. All times provided in UTC (+00:00).
custom string Get generation mix between startDate and endDate times. All times provided in UTC (+00:00).
// Argument object.
await gridGeneration({"mode": "current"});
// External object.
const apiConfig = {
	"mode": "current"
}

await gridGeneration(apiConfig);

Second Parameter

The second parameter is providing the desired startDate The format is case-insensitive.

Second Parameter Type Description
startDate string Supported startDate formats include DD-MM-YYYY and YYYY-MM-DD.
Usage Type Description
startDate string startDate is in ISO8601 format.
// Argument object.
await gridGeneration({"mode": "current", "startDate": "2025-01-01"});
// External object.
const apiConfig = {
	"mode": "current",
	"startDate": "2025-01-01"
}

await gridGeneration(apiConfig);

Third Parameter

The third parameter is providing the desired endDate The format is case-insensitive.

Third Parameter Type Description
endDate string Supported endDate formats include DD-MM-YYYY and YYYY-MM-DD.
Usage Type Description
endDate string endDate is in ISO8601 format.
// Argument object.
await gridGeneration({"mode": "current", "startDate": "2025-01-01", "endDate": "2025-01-02"});
// External object.
const apiConfig = {
	"mode": "current",
	"startDate": "2025-01-01",
	"endDate": "2025-01-02"
}

await gridGeneration(apiConfig);

Processing

Normalisation

During normalization, raw API fields such as [{"fuel":"biomass","perc":2.4},{"fuel":"coal","perc":0},{"fuel":"imports","perc":10.2}] are converted into a processed object such as {biomass: "2.4", coal: "0", imports: "11.8"}. Objects provide more reliable and consistent access than arrays while enabling easier manipulation and processing of nested data structures. Nested objects are flattened, redundant metadata and overlapping identifiers are removed, empty or missing fields are normalized, boolean and encoded values are standardized, and all data is organized into a uniform, consistent key-value JSON structure to produce a clean and predictable final result.

Sanitization

During sanitization, instead of leaving object values as null or undefined, missing or empty fields are filled with a placeholder such as "no value" to ensure that every key in the final result has a valid string; this prevents errors in downstream processing, makes the dataset fully predictable, and allows client applications to safely read and display all values without additional null checks.


Customisation

This JSON serves as a configuration layer that lets you enable or disable individual parent and child fields and rename them through altName, giving you full control over which properties appear in the final output. Some values from the raw API return are intentionally omitted because they are considered unnecessary or not useful.

Parent Names

The parents group defines the top-level fields that can be enabled, disabled, or renamed, allowing you to control which main object properties appear in the output.

"parents": {

	"item1": {
		"name": {
			"original": "defaultName",
			"altName": "customName"
		},
		"used": true
	},

	...

}

Child Names

The children group manages the nested fields within those parent objects, giving similar control over which sub-properties are included and how they are labeled.

"children": {
	
	"item1": {
		"name": {
			"original": "defaultName",
			"altName": "customName"
		},
		"used": true,
		"validate": "checkGeneration"
	},

	...

}

Demo

Live Demo

Try the hosted demo via GitHub Pages Demo


Authors


Credit


License

MIT License

About

Grid Generation restructures raw API responses into a clearer, easier-to-use format, improving readability and overall usability for developers without changing the underlying result data.

Resources

License

Stars

Watchers

Forks

Packages

No packages published