history

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(path string, res speedtest.Result) error

Append writes the result as one JSON line to the file at path, creating parent directories and the file if needed.

func CSV added in v0.1.7

func CSV(w io.Writer, records []speedtest.Result) error

CSV writes records as CSV with a header row. Empty input writes just the header.

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the default history file location under the user's home.

func Filter added in v0.1.8

func Filter(records []speedtest.Result, since, until time.Time) []speedtest.Result

Filter returns the records whose Timestamp falls within [since, until], inclusive. A zero since or until means unbounded on that side. The result is a new slice preserving the original order.

func JSON added in v0.1.7

func JSON(w io.Writer, records []speedtest.Result) error

JSON writes records as a 2-space-indented JSON array. Empty input writes [].

func LastN added in v0.1.7

func LastN(records []speedtest.Result, n int) []speedtest.Result

LastN returns the most recent n records (records are oldest-first, so the tail). n <= 0 or n >= len returns all records.

func Load added in v0.1.7

func Load(path string) ([]speedtest.Result, int, error)

Load reads the history file at path, returning the records in file order (oldest first) and the number of malformed lines skipped. A missing file returns (nil, 0, nil); a genuine read error is returned. Parsing is best-effort: a bad line is counted and skipped, never fatal.

func ParseBound added in v0.1.8

func ParseBound(s string, end bool, now time.Time) (time.Time, error)

ParseBound parses a date-range bound. An empty string returns the zero time (unbounded). Relative durations (7d/24h/30m) return now minus that duration. "YYYY-MM-DD HH:MM" returns that exact local time. "YYYY-MM-DD" returns the start of that day for a lower bound (end=false) or the end of that day (end=true), so a bare --until date includes the whole day. Local time is used.

func RenderSummary added in v0.1.7

func RenderSummary(w io.Writer, s Summary, st *output.Styler)

RenderSummary renders the avg/min/max stats block from a computed Summary.

func Table added in v0.1.7

func Table(w io.Writer, records []speedtest.Result, total int, st *output.Styler)

Table renders records newest-first as an aligned table. total is the full record count before any --last window, used for the footer. The header is colored and the footer dimmed via st; a disabled styler emits plain text.

Types

type Summary added in v0.1.7

type Summary struct {
	Count    int
	First    time.Time
	Last     time.Time
	Download metricStats // Mbps
	Upload   metricStats // Mbps
	Ping     metricStats // ms
	Jitter   metricStats // ms
}

Summary is the aggregate view of a set of recorded runs.

func Summarize added in v0.1.7

func Summarize(records []speedtest.Result) Summary

Summarize computes the count, time range, and avg/min/max per metric. An empty slice yields the zero Summary (Count 0), which callers treat as "no data".

Jump to

Keyboard shortcuts

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