Documentation
¶
Index ¶
- type AggregateFunc
- type BinOptions
- type DataPoint
- type EWM
- type Expanding
- func (e *Expanding) Apply(fn AggregateFunc) Transform
- func (e *Expanding) Count() Transform
- func (e *Expanding) Max() Transform
- func (e *Expanding) Mean() Transform
- func (e *Expanding) Min() Transform
- func (e *Expanding) MinPeriods(n int) *Expanding
- func (e *Expanding) Std() Transform
- func (e *Expanding) Sum() Transform
- func (e *Expanding) Var() Transform
- type GroupOptions
- type HoppingWindow
- type NormalizeOptions
- type Rolling
- func (r *Rolling) Apply(fn AggregateFunc) Transform
- func (r *Rolling) Center(center bool) *Rolling
- func (r *Rolling) Kurt() Transform
- func (r *Rolling) Max() Transform
- func (r *Rolling) Mean() Transform
- func (r *Rolling) Median() Transform
- func (r *Rolling) Min() Transform
- func (r *Rolling) MinPeriods(n int) *Rolling
- func (r *Rolling) Quantile(q float64) Transform
- func (r *Rolling) Skew() Transform
- func (r *Rolling) Std() Transform
- func (r *Rolling) Sum() Transform
- func (r *Rolling) Var() Transform
- type SessionWindow
- type SlidingWindow
- type SmoothOptions
- type SnapshotWindow
- type StackOptions
- type TimeSeriesPoint
- type TimeWindow
- type Transform
- func Abs() Transform
- func ApplyWindow(strategy WindowStrategy, fn AggregateFunc) Transform
- func Bin(opts BinOptions) Transform
- func BinCount(binSize float64) Transform
- func Clamp(min, max float64) Transform
- func Cumulative() Transform
- func Dodge(by string, padding float64) Transform
- func Downsample(n int) Transform
- func Expand() Transform
- func ExponentialSmoothing(alpha float64) Transform
- func Filter(predicate func(DataPoint) bool) Transform
- func GroupBy(opts GroupOptions) Transform
- func Histogram(thresholds ...float64) Transform
- func Interpolate() Transform
- func Loess(bandwidth float64) Transform
- func Log(base float64) Transform
- func Map(fn func(DataPoint) DataPoint) Transform
- func MovingAverage(windowSize int) Transform
- func Normalize(opts NormalizeOptions) Transform
- func NormalizeByGroup(groupBy string, method string) Transform
- func NormalizeFraction() Transform
- func NormalizeMinMax(targetMin, targetMax float64) Transform
- func NormalizePercentage() Transform
- func NormalizeZScore() Transform
- func Offset(amount float64) Transform
- func Percentile(p float64) Transform
- func Reduce(fn AggregateFunc) Transform
- func SavitzkyGolay(windowSize, polyOrder int) Transform
- func Scale(factor float64) Transform
- func Smooth(opts SmoothOptions) Transform
- func SnapshotAggregate(fn AggregateFunc) Transform
- func SnapshotCount() Transform
- func SnapshotMax() Transform
- func SnapshotMean() Transform
- func SnapshotMin() Transform
- func SnapshotSum() Transform
- func Sort(by string, ascending bool) Transform
- func Sqrt() Transform
- func Stack(opts StackOptions) Transform
- func StackCenter(by string) Transform
- func StackNormalize(by string) Transform
- func StackZero(by string) Transform
- func Top(n int) Transform
- func Unstack() Transform
- func WeightedMovingAverage(weights []float64) Transform
- func Window(size int, fn AggregateFunc) Transform
- func WindowAggregate(size int, fn AggregateFunc, strategy string) Transform
- func WindowedMax(size int, strategy string) Transform
- func WindowedMean(size int, strategy string) Transform
- func WindowedMin(size int, strategy string) Transform
- func WindowedSum(size int, strategy string) Transform
- type TumblingWindow
- type WindowStrategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AggregateFunc ¶
AggregateFunc defines how to aggregate numeric values.
var ( // Sum aggregates by summing all values Sum AggregateFunc = func(values []float64) float64 { sum := 0.0 for _, v := range values { sum += v } return sum } // Mean aggregates by calculating the mean (average) Mean AggregateFunc = func(values []float64) float64 { if len(values) == 0 { return 0 } return Sum(values) / float64(len(values)) } // Max aggregates by taking the maximum value Max AggregateFunc = func(values []float64) float64 { if len(values) == 0 { return 0 } max := values[0] for _, v := range values[1:] { if v > max { max = v } } return max } // Min aggregates by taking the minimum value Min AggregateFunc = func(values []float64) float64 { if len(values) == 0 { return 0 } min := values[0] for _, v := range values[1:] { if v < min { min = v } } return min } // Count aggregates by counting the number of values Count AggregateFunc = func(values []float64) float64 { return float64(len(values)) } // Median aggregates by calculating the median Median AggregateFunc = func(values []float64) float64 { if len(values) == 0 { return 0 } sorted := make([]float64, len(values)) copy(sorted, values) for i := 0; i < len(sorted); i++ { for j := i + 1; j < len(sorted); j++ { if sorted[i] > sorted[j] { sorted[i], sorted[j] = sorted[j], sorted[i] } } } mid := len(sorted) / 2 if len(sorted)%2 == 0 { return (sorted[mid-1] + sorted[mid]) / 2 } return sorted[mid] } )
Common aggregation functions
type BinOptions ¶
type BinOptions struct {
// Thresholds specifies explicit bin edges (overrides Count)
Thresholds []float64
// Count specifies the approximate number of bins (default: 10)
Count int
// Domain specifies the [min, max] range to bin over
Domain [2]float64
// Nice rounds bin edges to nice numbers
Nice bool
}
BinOptions configures binning behavior
type DataPoint ¶
type DataPoint struct {
X interface{} // X value (can be time.Time, float64, string, etc.)
Y float64 // Y value (numeric)
Y0 float64 // Baseline Y value (for stacking)
Y1 float64 // Top Y value (for stacking)
Label string // Category label
Value float64 // Generic numeric value
Count int // Count for aggregations
Group string // Group identifier
Index int // Original index
Data interface{} // Original data reference
}
DataPoint represents a generic data point that can be transformed. Transforms operate on slices of DataPoints and return transformed data.
func ToDataPoints ¶
func ToDataPoints(points []TimeSeriesPoint) []DataPoint
ToDataPoints converts TimeSeriesPoints to DataPoints
type EWM ¶
type EWM struct {
// contains filtered or unexported fields
}
EWM provides pandas-style exponentially weighted functions
func (*EWM) MinPeriods ¶
MinPeriods sets the minimum number of observations
type Expanding ¶
type Expanding struct {
// contains filtered or unexported fields
}
Expanding provides pandas-style expanding window operations
func NewExpanding ¶
func NewExpanding() *Expanding
NewExpanding creates a new expanding window operator
func (*Expanding) Apply ¶
func (e *Expanding) Apply(fn AggregateFunc) Transform
Apply applies a custom aggregation function
func (*Expanding) MinPeriods ¶
MinPeriods sets the minimum number of observations required
type GroupOptions ¶
type GroupOptions struct {
// By specifies the field to group by ("X", "Label", "Group")
By string
// Aggregate specifies how to aggregate Y values
Aggregate AggregateFunc
// Sort specifies whether to sort groups (by key or value)
Sort string // "key", "value", or ""
}
GroupOptions configures grouping behavior
type HoppingWindow ¶
type HoppingWindow struct {
Size int // Window size in number of points
Hop int // Hop size (step between windows)
}
HoppingWindow creates fixed-size windows with configurable hop/stride
func NewHoppingWindow ¶
func NewHoppingWindow(size, hop int) *HoppingWindow
NewHoppingWindow creates a hopping window strategy
func (*HoppingWindow) WindowBounds ¶
func (hw *HoppingWindow) WindowBounds(windowID int, data []DataPoint) (start, end int)
WindowBounds returns the bounds for a hopping window
func (*HoppingWindow) Windows ¶
func (hw *HoppingWindow) Windows(data []DataPoint) [][]int
Windows returns window assignments for hopping windows
type NormalizeOptions ¶
type NormalizeOptions struct {
// Method specifies normalization method ("percentage", "zscore", "minmax")
Method string
// By specifies the field to normalize by ("group", "all")
By string
}
NormalizeOptions configures normalization behavior
type Rolling ¶
type Rolling struct {
// contains filtered or unexported fields
}
Rolling provides pandas-style rolling window operations
func NewRolling ¶
NewRolling creates a new rolling window operator
func (*Rolling) Apply ¶
func (r *Rolling) Apply(fn AggregateFunc) Transform
Apply applies a custom aggregation function
func (*Rolling) MinPeriods ¶
MinPeriods sets the minimum number of observations required
type SessionWindow ¶
type SessionWindow struct {
GapThreshold time.Duration // Maximum gap between points in the same session
}
SessionWindow groups points based on gaps in time
func NewSessionWindow ¶
func NewSessionWindow(gapThreshold time.Duration) *SessionWindow
NewSessionWindow creates a session window strategy
func (*SessionWindow) WindowBounds ¶
func (sw *SessionWindow) WindowBounds(windowID int, data []DataPoint) (start, end int)
WindowBounds returns the bounds for a session window
func (*SessionWindow) Windows ¶
func (sw *SessionWindow) Windows(data []DataPoint) [][]int
Windows returns window assignments for session windows
type SlidingWindow ¶
type SlidingWindow struct {
Size int // Window size in number of points
Step int // Step size (default: 1 for maximum overlap)
}
SlidingWindow creates overlapping windows of fixed size
func NewSlidingWindow ¶
func NewSlidingWindow(size int) *SlidingWindow
NewSlidingWindow creates a sliding window strategy
func (*SlidingWindow) WindowBounds ¶
func (sw *SlidingWindow) WindowBounds(windowID int, data []DataPoint) (start, end int)
WindowBounds returns the bounds for a window
func (*SlidingWindow) Windows ¶
func (sw *SlidingWindow) Windows(data []DataPoint) [][]int
Windows returns window assignments for sliding windows
func (*SlidingWindow) WithStep ¶
func (sw *SlidingWindow) WithStep(step int) *SlidingWindow
WithStep sets the step size for sliding windows
type SmoothOptions ¶
type SmoothOptions struct {
// Method specifies the smoothing method ("movingAverage", "loess", "exponential")
Method string
// WindowSize specifies the window size for moving averages
WindowSize int
// Bandwidth specifies the bandwidth for LOESS smoothing (0-1)
Bandwidth float64
// Alpha specifies the smoothing factor for exponential smoothing (0-1)
Alpha float64
}
SmoothOptions configures smoothing behavior
type SnapshotWindow ¶
type SnapshotWindow struct{}
SnapshotWindow groups events that occur at the exact same timestamp Unlike other windows, snapshot windows are event-driven and fire on every event
func NewSnapshotWindow ¶
func NewSnapshotWindow() *SnapshotWindow
NewSnapshotWindow creates a snapshot window strategy
func (*SnapshotWindow) WindowBounds ¶
func (sw *SnapshotWindow) WindowBounds(windowID int, data []DataPoint) (start, end int)
WindowBounds returns the bounds for a snapshot window
func (*SnapshotWindow) Windows ¶
func (sw *SnapshotWindow) Windows(data []DataPoint) [][]int
Windows returns window assignments for snapshot windows Each unique timestamp gets its own window
type StackOptions ¶
type StackOptions struct {
// By specifies the field to group by for stacking
By string
// Order specifies the stacking order ("ascending", "descending", "none")
Order string
// Offset specifies the baseline ("zero", "center", "normalize")
Offset string
}
StackOptions configures stacking behavior
type TimeSeriesPoint ¶
TimeSeriesPoint represents a time-series data point
func FromDataPoints ¶
func FromDataPoints(points []DataPoint) []TimeSeriesPoint
FromDataPoints converts DataPoints back to TimeSeriesPoints
type TimeWindow ¶
TimeWindow partitions data by fixed time intervals
func NewTimeWindow ¶
func NewTimeWindow(interval time.Duration) *TimeWindow
NewTimeWindow creates a time-based window strategy
func (*TimeWindow) WindowBounds ¶
func (tw *TimeWindow) WindowBounds(windowID int, data []DataPoint) (start, end int)
WindowBounds returns the bounds for a time window
func (*TimeWindow) Windows ¶
func (tw *TimeWindow) Windows(data []DataPoint) [][]int
Windows returns window assignments for time-based windows
type Transform ¶
Transform is a function that transforms a slice of data points.
func ApplyWindow ¶
func ApplyWindow(strategy WindowStrategy, fn AggregateFunc) Transform
ApplyWindow applies a window strategy and aggregates each window
func Bin ¶
func Bin(opts BinOptions) Transform
Bin creates a binning transform that groups continuous data into discrete bins. Useful for creating histograms and frequency distributions.
Example:
data := []DataPoint{{Y: 1.5}, {Y: 2.3}, {Y: 5.7}, {Y: 8.1}}
binned := Bin(BinOptions{Count: 3})(data)
// Results in 3 bins with counts
func Dodge ¶
Dodge creates side-by-side positioning for grouped bars Instead of stacking, places items next to each other
func Downsample ¶
Downsample reduces the number of points by sampling every nth point
func ExponentialSmoothing ¶
ExponentialSmoothing applies exponential smoothing
func GroupBy ¶
func GroupBy(opts GroupOptions) Transform
GroupBy creates a grouping transform that aggregates data by a field. Useful for creating summary statistics grouped by category.
Example:
data := []DataPoint{
{Label: "A", Y: 10},
{Label: "A", Y: 20},
{Label: "B", Y: 15},
}
grouped := GroupBy(GroupOptions{By: "Label", Aggregate: Sum})(data)
// Results in: [{Label: "A", Y: 30}, {Label: "B", Y: 15}]
func Interpolate ¶
func Interpolate() Transform
Interpolate fills in missing values using linear interpolation
func Loess ¶
Loess applies LOESS (Locally Estimated Scatterplot Smoothing) This is a simplified version of LOESS
func MovingAverage ¶
MovingAverage creates a simple moving average transform
func Normalize ¶
func Normalize(opts NormalizeOptions) Transform
Normalize creates a normalization transform that scales values to a standard range. Useful for comparing datasets with different scales or creating percentage-based views.
Example:
data := []DataPoint{{Y: 10}, {Y: 20}, {Y: 30}}
normalized := Normalize(NormalizeOptions{Method: "percentage"})(data)
// Results in percentage of total: [16.67%, 33.33%, 50%]
func NormalizeByGroup ¶
NormalizeByGroup normalizes within each group
func NormalizeFraction ¶
func NormalizeFraction() Transform
NormalizeFraction converts values to fractions of the total (0-1)
func NormalizeMinMax ¶
NormalizeMinMax scales values to a specified range [min, max]
func NormalizePercentage ¶
func NormalizePercentage() Transform
NormalizePercentage converts values to percentages of the total
func NormalizeZScore ¶
func NormalizeZScore() Transform
NormalizeZScore converts values to z-scores (standard scores)
func Percentile ¶
Percentile calculates percentiles for the Y values
func Reduce ¶
func Reduce(fn AggregateFunc) Transform
Reduce aggregates all data points into a single value using the given function
func SavitzkyGolay ¶
SavitzkyGolay applies Savitzky-Golay smoothing (simplified)
func Smooth ¶
func Smooth(opts SmoothOptions) Transform
Smooth creates a smoothing transform that applies various smoothing algorithms. Useful for trend lines, noise reduction, and pattern identification.
Example:
data := []DataPoint{{Y: 1}, {Y: 5}, {Y: 2}, {Y: 8}, {Y: 3}}
smoothed := Smooth(SmoothOptions{Method: "movingAverage", WindowSize: 3})(data)
func SnapshotAggregate ¶
func SnapshotAggregate(fn AggregateFunc) Transform
SnapshotAggregate creates a snapshot window aggregation transform
func SnapshotCount ¶
func SnapshotCount() Transform
SnapshotCount creates a snapshot window count transform
func SnapshotMean ¶
func SnapshotMean() Transform
SnapshotMean creates a snapshot window mean transform
func Stack ¶
func Stack(opts StackOptions) Transform
Stack creates a stacking transform that computes Y0 and Y1 for stacked visualizations. Essential for stacked bar charts, area charts, and stream graphs.
Example:
data := []DataPoint{
{Label: "2020", Group: "A", Y: 10},
{Label: "2020", Group: "B", Y: 15},
{Label: "2021", Group: "A", Y: 12},
{Label: "2021", Group: "B", Y: 18},
}
stacked := Stack(StackOptions{By: "Label"})(data)
// Results in Y0 and Y1 computed for stacking
func StackCenter ¶
StackCenter creates a centered (diverging) stack
func StackNormalize ¶
StackNormalize creates a normalized (100%) stack
func WeightedMovingAverage ¶
WeightedMovingAverage applies weighted moving average with custom weights
func Window ¶
func Window(size int, fn AggregateFunc) Transform
Window applies a windowed aggregation (rolling window)
func WindowAggregate ¶
func WindowAggregate(size int, fn AggregateFunc, strategy string) Transform
WindowAggregate creates a windowed aggregation transform
func WindowedMax ¶
WindowedMax creates a windowed max transform
func WindowedMean ¶
WindowedMean creates a windowed mean transform
func WindowedMin ¶
WindowedMin creates a windowed min transform
func WindowedSum ¶
WindowedSum creates a windowed sum transform
type TumblingWindow ¶
type TumblingWindow struct {
Size int // Window size in number of points
}
TumblingWindow creates non-overlapping windows of fixed size
func NewTumblingWindow ¶
func NewTumblingWindow(size int) *TumblingWindow
NewTumblingWindow creates a tumbling window strategy
func (*TumblingWindow) WindowBounds ¶
func (tw *TumblingWindow) WindowBounds(windowID int, data []DataPoint) (start, end int)
WindowBounds returns the bounds for a tumbling window
func (*TumblingWindow) Windows ¶
func (tw *TumblingWindow) Windows(data []DataPoint) [][]int
Windows returns window assignments for tumbling windows
type WindowStrategy ¶
type WindowStrategy interface {
// Windows returns the window assignments for each data point
// Returns a slice of window IDs for each input point
Windows(data []DataPoint) [][]int
// WindowBounds returns the start and end indices for a window ID
WindowBounds(windowID int, data []DataPoint) (start, end int)
}
WindowStrategy defines how to partition data into windows