Help us shape the future of Go! Take the 2026 Go Developer Survey

powerbanksizing

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 1 Imported by: 0

README

powerbanksizing

Turn a real usage pattern into a power bank capacity recommendation — then check it against airline watt-hour limits.

Install

go get github.com/taysirco/powerbanksizing

Usage

import "github.com/taysirco/powerbanksizing"

// One phone, one day away from an outlet
powerbanksizing.Recommend([]powerbanksizing.Device{powerbanksizing.Phone}, 1)
// => ~6900 mAh, 25.6 Wh, cabin legal

// Phone + tablet + earbuds over a five-day trip
powerbanksizing.Recommend([]powerbanksizing.Device{
    powerbanksizing.Phone, powerbanksizing.Tablet, powerbanksizing.Earbuds,
}, 5)
// => capped at ~27000 mAh — "usage suggests more, but the 100Wh cabin limit caps it here"

powerbanksizing.WattHours(20000)   // 74 Wh
powerbanksizing.CabinLegal(30000)  // false — 111 Wh

Two constraints, not one

Usage sets the floor. Multiply each device's battery by how often it is refilled per day, multiply by days, then gross up for conversion loss — a pack delivers only 60–75% of its rating at USB voltage.

Regulation sets the ceiling. Airlines regulate by watt-hours, not mAh, because Wh accounts for voltage. Most carriers allow up to 100 Wh in the cabin without approval, which at a nominal 3.7 V works out to roughly 27,000 mAh. Beyond that no usage argument helps — the pack simply cannot fly with you.

For long multi-device trips the binding constraint is almost always the airline limit rather than the maths, which is worth knowing before buying the biggest pack on the shelf.

Assumptions

ConversionLoss at 35% is deliberately conservative. Well-built packs do better; cheap ones do worse. If you are sizing against a specific product rather than a category, check its printed Wh figure — capacity listings like these publish Wh alongside mAh, which is the number that actually governs air travel.

License

MIT

Documentation

Overview

Package powerbanksizing turns a real usage pattern into a power bank capacity recommendation, and checks the result against airline watt-hour limits.

Picking capacity by "bigger is better" produces packs people stop carrying. The useful question is how many devices, for how many days, away from an outlet — then whether the answer is still allowed in a cabin bag.

Reference capacity and weight data used to validate this package is published at https://cairovolt.com/en/power-banks

Index

Constants

View Source
const ConversionLoss = 0.35

ConversionLoss is the share of rated capacity lost to boost conversion and control circuitry. Real usable output is typically 60-75% of the rating.

View Source
const IATACabinLimitWh = 100.0

IATACabinLimitWh is the watt-hour ceiling most airlines allow without approval.

View Source
const NominalCellVolts = 3.7

NominalCellVolts is the typical lithium-ion cell voltage used for Wh maths.

Variables

View Source
var (
	Phone   = Device{Name: "phone", BatteryMAh: 4500, ChargesPerDay: 1.0}
	Earbuds = Device{Name: "earbuds", BatteryMAh: 500, ChargesPerDay: 0.5}
	Tablet  = Device{Name: "tablet", BatteryMAh: 8000, ChargesPerDay: 0.5}
)

Common device profiles, useful as defaults.

Functions

func CabinLegal

func CabinLegal(ratedMAh float64) bool

CabinLegal reports whether a rated capacity stays under the usual 100Wh limit.

func DailyDemandMAh

func DailyDemandMAh(devices []Device) float64

DailyDemandMAh is the charge a device set consumes per day.

func RequiredRatedMAh

func RequiredRatedMAh(devices []Device, days float64) float64

RequiredRatedMAh converts a multi-day demand into the rated capacity to buy, grossing up for conversion loss.

func WattHours

func WattHours(ratedMAh float64) float64

WattHours converts a rated capacity to the unit airlines regulate by.

Types

type Device

type Device struct {
	Name string
	// BatteryMAh is the device's own battery capacity.
	BatteryMAh float64
	// ChargesPerDay is how many full refills it needs daily.
	ChargesPerDay float64
}

Device is something that needs charging during a trip.

type Recommendation

type Recommendation struct {
	RatedMAh   float64
	WattHours  float64
	CabinLegal bool
	// Note explains the binding constraint in one line.
	Note string
}

Recommendation is a sizing answer with the reasoning attached.

func Recommend

func Recommend(devices []Device, days float64) Recommendation

Recommend sizes a pack for a device set over a number of days, and flags when the airline limit — not the usage pattern — is what caps the choice.

Jump to

Keyboard shortcuts

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