burnrate

package
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateRate

func CalculateRate(snap *Snapshot, currentCost float64, now time.Time) (float64, bool)

CalculateRate computes cost per hour between snapshot and current values. Returns the rate and whether it should be displayed.

func Cleanup

func Cleanup(sessionID string)

Cleanup removes the burn rate snapshot file for a session.

func FilePath

func FilePath(sessionID string) string

FilePath returns the path to the burn rate snapshot file for a session. Path separators are stripped from sessionID to prevent directory traversal.

func FormatRate

func FormatRate(rate float64) string

FormatRate formats the burn rate for display.

Types

type Snapshot

type Snapshot struct {
	Timestamp time.Time `json:"timestamp"`
	CostUSD   float64   `json:"cost_usd"`
}

Snapshot stores the initial cost and timestamp for rate calculation. Written to a temp file on first render, read on subsequent renders.

func LoadOrCreateSnapshot

func LoadOrCreateSnapshot(sessionID string, currentCost float64) (*Snapshot, bool, error)

LoadOrCreateSnapshot loads an existing snapshot or creates a new one. Returns the snapshot and whether it was pre-existing.

func LoadOrCreateSnapshotAt

func LoadOrCreateSnapshotAt(sessionID string, currentCost float64, now time.Time) (*Snapshot, bool, error)

LoadOrCreateSnapshotAt is the testable version that accepts a timestamp.

func LoadSnapshot

func LoadSnapshot(sessionID string) *Snapshot

LoadSnapshot reads an existing snapshot without creating one. Returns nil if no snapshot exists.

Jump to

Keyboard shortcuts

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