history

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 14 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 Median added in v0.1.9

func Median(values []float64) float64

Median returns the middle value of values (the mean of the two middles for an even count). An empty slice returns 0.

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 RenderCompare added in v0.1.9

func RenderCompare(w io.Writer, c Comparison, plan PlanInfo, st *output.Styler)

RenderCompare writes the human-readable comparison to w.

func RenderCompareJSON added in v0.1.9

func RenderCompareJSON(w io.Writer, c Comparison, plan PlanInfo) error

RenderCompareJSON writes the comparison as a JSON object to w. baseline is null and delta omitted when there is no baseline; undefined metric deltas and plan percentages are emitted as null.

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 Comparison added in v0.1.9

type Comparison struct {
	Current     speedtest.Result
	HasBaseline bool
	SampleSize  int
	Download    MetricCompare // higher is better
	Upload      MetricCompare // higher is better
	Ping        MetricCompare // lower is better
	Jitter      MetricCompare // lower is better
	Verdict     string        // excellent|normal|degraded|unstable, optionally +_high_latency
	Summary     string        // human sentence
}

Comparison is the full current-vs-baseline result.

func Compare added in v0.1.9

func Compare(current speedtest.Result, baseline []speedtest.Result) Comparison

Compare computes the comparison of current against the baseline records.

type MetricCompare added in v0.1.9

type MetricCompare struct {
	Current  float64
	Baseline float64 // median of the baseline
	DeltaPct float64 // (current-baseline)/baseline*100; valid only when Defined
	Defined  bool    // false when the baseline median is 0
	Status   MetricStatus
}

MetricCompare is one metric's current value, baseline median, and change.

type MetricStatus added in v0.1.9

type MetricStatus int

MetricStatus classifies a metric versus its baseline.

const (
	StatusNormal MetricStatus = iota
	StatusBetter
	StatusWorse
)

type PlanInfo added in v0.1.9

type PlanInfo struct {
	Set      bool
	Download float64
	Upload   float64
}

PlanInfo carries optional ISP-plan targets for the comparison output.

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