matrix

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package matrix abstracts the source data as Plane, and then pixelates it into a matrix for display on the front end.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPartOf

func CheckPartOf(src, part []string)

CheckPartOf checks that part keys are a subset of src keys.

func CheckReduceOf

func CheckReduceOf(src, part []string)

CheckReduceOf checks that part keys are a subset of src keys and have the same StartKey and EndKey.

func GetLastKey

func GetLastKey(keys []string) string

GetLastKey gets the last element of keys.

func KeysRange

func KeysRange(keys []string, startKey string, endKey string) (start, end int, ok bool)

KeysRange finds a range that intersects [startKey, endKey) in keys.

func MakeKeys

func MakeKeys(keySet map[string]struct{}) []string

MakeKeys uses a key set to build a new Key-Axis.

func MakeKeysWithUnlimitedEnd

func MakeKeysWithUnlimitedEnd(keySet map[string]struct{}) []string

MakeKeysWithUnlimitedEnd uses a key set to build a new Key-Axis, then add a "" to the keys, indicating that the last bucket has an unlimited end.

func Max

func Max(a, b int) int

Max returns the larger of a and b.

func MemsetInt

func MemsetInt(slice []int, v int)

MemsetInt sets all elements of the int slice to v.

func MemsetUint64

func MemsetUint64(slice []uint64, v uint64)

MemsetUint64 sets all elements of the uint64 slice to v.

func Min

func Min(a, b int) int

Min returns the smaller of a and b.

Types

type Axis

type Axis struct {
	Keys       []string
	ValuesList [][]uint64
}

Axis stores consecutive buckets. Each bucket has StartKey, EndKey, and some statistics. The EndKey of each bucket is the StartKey of its next bucket. The actual data structure is stored in columns. Therefore satisfies: len(Keys) == len(ValuesList[i]) + 1. In particular, ValuesList[0] is the base column.

func CreateAxis

func CreateAxis(keys []string, valuesList [][]uint64) Axis

CreateAxis checks the given parameters and uses them to build the Axis.

func CreateEmptyAxis

func CreateEmptyAxis(startKey, endKey string, valuesListLen int) Axis

CreateEmptyAxis constructs a minimal empty Axis with the given parameters.

func (*Axis) Divide

func (axis *Axis) Divide(strategy Strategy, target int) Axis

Divide uses the base column as the chunk for the Divide operation to obtain the partitioning scheme, and uses this to reduce other columns.

func (*Axis) Focus

func (axis *Axis) Focus(strategy Strategy, threshold uint64, ratio int, target int) Axis

Focus uses the base column as the chunk for the Focus operation to obtain the partitioning scheme, and uses this to reduce other columns.

func (*Axis) Range

func (axis *Axis) Range(startKey string, endKey string) Axis

Range returns a sub Axis with specified range.

func (*Axis) Shrink

func (axis *Axis) Shrink(ratio uint64)

Shrink reduces all statistical values.

type KeyMap

type KeyMap struct {
	sync.RWMutex
	sync.Map
}

KeyMap is used for string intern

func (*KeyMap) SaveKey

func (km *KeyMap) SaveKey(key *string)

SaveKey interns a string.

func (*KeyMap) SaveKeys

func (km *KeyMap) SaveKeys(keys []string)

SaveKeys interns all strings without using mutex.

type Matrix

type Matrix struct {
	Keys     []string              `json:"-"`
	DataMap  map[string][][]uint64 `json:"data" binding:"required"`
	KeyAxis  []decorator.LabelKey  `json:"keyAxis" binding:"required"`
	TimeAxis []int64               `json:"timeAxis" binding:"required"`
}

Matrix is the front end displays the required data.

func CreateMatrix

func CreateMatrix(strategy Strategy, times []time.Time, keys []string, valuesListLen int) Matrix

CreateMatrix uses the specified times and keys to build an initial matrix with no data.

func (*Matrix) Range

func (mx *Matrix) Range(startKey, endKey string)

Range returns a sub Matrix with specified range.

type NaiveLabelStrategy

type NaiveLabelStrategy struct{}

NaiveLabelStrategy is one of the simplest LabelStrategy.

func (NaiveLabelStrategy) Background

func (s NaiveLabelStrategy) Background()

Background do nothing.

func (NaiveLabelStrategy) CrossBorder

func (s NaiveLabelStrategy) CrossBorder(startKey, endKey string) bool

CrossBorder always returns false. So NaiveLabelStrategy believes that there are no cross-border situations.

func (NaiveLabelStrategy) Label

Label only decodes the key.

type Plane

type Plane struct {
	Times []time.Time
	Axes  []Axis
}

Plane stores consecutive axes. Each axis has StartTime, EndTime. The EndTime of each axis is the StartTime of its next axis. Therefore satisfies: len(Times) == len(Axes) + 1

func CreateEmptyPlane

func CreateEmptyPlane(startTime, endTime time.Time, startKey, endKey string, valuesListLen int) Plane

CreateEmptyPlane constructs a minimal empty Plane with the given parameters.

func CreatePlane

func CreatePlane(times []time.Time, axes []Axis) Plane

CreatePlane checks the given parameters and uses them to build the Plane.

func (*Plane) Compact

func (plane *Plane) Compact(strategy Strategy) Axis

Compact compacts Plane into an axis.

func (*Plane) Pixel

func (plane *Plane) Pixel(strategy Strategy, target int, displayTags []string) Matrix

Pixel pixelates Plane into a matrix with a number of rows close to the target.

type Strategy

type Strategy interface {
	decorator.LabelStrategy
	// contains filtered or unexported methods
}

Strategy is part of the customizable strategy in Matrix generation.

func AverageStrategy

func AverageStrategy(label decorator.LabelStrategy) Strategy

AverageStrategy adopts the strategy of equal distribution when buckets are split.

func DistanceStrategy

func DistanceStrategy(ctx context.Context, wg *sync.WaitGroup, label decorator.LabelStrategy, ratio float64, level int, count int) Strategy

DistanceStrategy adopts the strategy that the closer the split time is to the current time, the more traffic is allocated, when buckets are split.

Jump to

Keyboard shortcuts

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