Documentation
¶
Index ¶
- func Append(path string, res speedtest.Result) error
- func CSV(w io.Writer, records []speedtest.Result) error
- func DefaultPath() (string, error)
- func Filter(records []speedtest.Result, since, until time.Time) []speedtest.Result
- func JSON(w io.Writer, records []speedtest.Result) error
- func LastN(records []speedtest.Result, n int) []speedtest.Result
- func Load(path string) ([]speedtest.Result, int, error)
- func Median(values []float64) float64
- func ParseBound(s string, end bool, now time.Time) (time.Time, error)
- func RenderCompare(w io.Writer, c Comparison, plan PlanInfo, st *output.Styler)
- func RenderCompareJSON(w io.Writer, c Comparison, plan PlanInfo) error
- func RenderSummary(w io.Writer, s Summary, st *output.Styler)
- func Table(w io.Writer, records []speedtest.Result, total int, st *output.Styler)
- type Comparison
- type MetricCompare
- type MetricStatus
- type PlanInfo
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶
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
CSV writes records as CSV with a header row. Empty input writes just the header.
func DefaultPath ¶
DefaultPath returns the default history file location under the user's home.
func Filter ¶ added in v0.1.8
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
JSON writes records as a 2-space-indented JSON array. Empty input writes [].
func LastN ¶ added in v0.1.7
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
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
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
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
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
RenderSummary renders the avg/min/max stats block from a computed Summary.
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.
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
PlanInfo carries optional ISP-plan targets for the comparison output.