pivot

package
v0.0.0-...-3c98ef5 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package pivot provides the ability to pivot dataframes.

That is, given a set of traces:

types.TraceSet{
  ",arch=arm,config=8888,":   types.Trace{1, 0, 0},
  ",arch=arm,config=565,":    types.Trace{0, 2, 0},
  ",arch=arm,config=gles,":   types.Trace{0, 0, 3},
  ",arch=intel,config=8888,": types.Trace{1, 2, 3},
  ",arch=intel,config=565,":  types.Trace{1, 2, 3},
  ",arch=intel,config=gles,": types.Trace{1, 2, 3},
}

You may want to compare how 'arm' machines compare to 'intel' machines. If the traces were stored in a spreadsheet then answering that question would require a pivot table, where you would pivot over the 'arch' key. This is also similar to a GROUP BY operation in SQL, and for such queries you also need to supply the type of operation to apply to all the values that appear in each group.

So if we created a pivot Request of the form:

req := Request {
  GroupBy:   []string{"arch"},
  Operation: Sum,
}

it would pivot those traces and return summary traces:

types.TraceSet{
  ",arch=arm,":   types.Trace{1, 2, 3},
  ",arch=intel,": types.Trace{3, 6, 9},
}

Note how the trace ids only contain keys that appear in the GroupBy list, as these new traces represent each group.

The above set of generated traces could be plotted. But we may want to summarize the data further into a table, so we can optionally apply Summary operations that will be applied to the resulting traces:

req := Request {
  GroupBy:   []string{"arch"},
  Operation: Sum,
  Summary: []Operation{Avg},
}

Applied to the same traces above we now get:

types.TraceSet{
  ",arch=arm,":   types.Trace{2}, // (1+2+3)/3
  ",arch=intel,": types.Trace{6}, // (3+6+9)/3
}

Note that muliple Summary operations can be applied, and each one will generate its own column in the resulting TraceSet.

Index

Constants

This section is empty.

Variables

View Source
var AllOperations = []Operation{Sum, Avg, Geo, Std, Count, Min, Max}

AllOperations for exporting to TypeScript.

Functions

func Pivot

Pivot returns a new Dataframe with the pivot described in Request applied.

Types

type Operation

type Operation string

Operation that can be applied to pivot values.

const (
	Sum   Operation = "sum"
	Avg   Operation = "avg"
	Geo   Operation = "geo"
	Std   Operation = "std"
	Count Operation = "count"
	Min   Operation = "min"
	Max   Operation = "max"
)

Operation constants.

type Request

type Request struct {
	// Which keys to group by.
	GroupBy []string `json:"group_by"`

	// Operation to apply when grouping.
	Operation Operation `json:"operation"`

	// If Summary is the empty slice then the Summary is commits, i.e. a plot.
	// otherwise produce one column for each Operation in Summary.
	Summary []Operation `json:"summary"`
}

Request controls how a pivot is done.

func (Request) Valid

func (o Request) Valid() error

Valid returns an error if the Request is not valid.

Jump to

Keyboard shortcuts

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