report

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package report turns silk's persisted tag history into FameView-style 报表 (interval reports): it slices a time range into fixed buckets, reduces each tag's samples in every bucket with a chosen aggregate, and renders the grid as CSV or HTML. A screen operator picks tags, a window, an interval and an aggregate; Build fills the table one Query per tag per bucket.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aggregate

type Aggregate int

Aggregate names the reducer applied to the samples inside one bucket.

const (
	Avg   Aggregate = iota // arithmetic mean of the bucket's values
	Min                    // smallest value
	Max                    // largest value
	Sum                    // running total
	Count                  // number of samples
	First                  // earliest sample (Query returns ascending ts)
	Last                   // latest sample
)

func (Aggregate) String

func (a Aggregate) String() string

String renders the aggregate's display name (report column/title text).

type Bucket

type Bucket struct {
	From, To time.Time
	Values   map[string]float64
}

Bucket is one report row: a half-open time slice [From, To) and, per tag, the aggregated value of that tag's samples in the slice. A tag with no samples in the bucket is absent from Values (renders as an empty cell), never stored as NaN.

type Report

type Report struct {
	Tags    []string
	Buckets []Bucket
}

Report is the finished grid: the ordered tag columns and the ordered buckets.

func Build

func Build(h *historian.Historian, tags []string, from, to time.Time, interval time.Duration, a Aggregate) (*Report, error)

Build aggregates history for tags over [from, to), one bucket per interval. For each bucket it Queries each tag's samples in the half-open slice, reduces them with a, and stores the result under Values[tag]; a bucket with no samples for a tag omits that tag (empty cell). The final bucket is clamped so the report covers exactly [from, to). interval must be positive.

func (*Report) WriteCSV

func (r *Report) WriteCSV(w io.Writer) error

WriteCSV writes the report as CSV: a "time" + tag-names header, then one row per bucket keyed by the bucket start. Absent tag values render as empty cells.

func (*Report) WriteHTML

func (r *Report) WriteHTML(w io.Writer) error

WriteHTML writes the report as an HTML <table>: a "time" + tag-names header row, then one row per bucket keyed by the bucket start. Absent tag values render as empty cells.

Jump to

Keyboard shortcuts

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