decor

package
v3.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2018 License: BSD-3-Clause Imports: 10 Imported by: 581

Documentation

Overview

 Package decor contains common decorators used by "github.com/vbauerster/mpb" package.

 Some decorators returned by this package might have a closure state. It is ok to use
 decorators concurrently, unless you share the same decorator among multiple
 *mpb.Bar instances. To avoid data races, create new decorator per *mpb.Bar instance.

 Don't:

	 p := mpb.New()
	 eta := decor.ETA(decor.ET_STYLE_GO, 0, startBlock)
	 p.AddBar(100, mpb.AppendDecorators(eta))
	 p.AddBar(100, mpb.AppendDecorators(eta))

 Do:

	p := mpb.New()
	p.AddBar(100, mpb.AppendDecorators(decor.ETA(decor.ET_STYLE_GO, 0, startBlock)))
	p.AddBar(100, mpb.AppendDecorators(decor.ETA(decor.ET_STYLE_GO, 0, startBlock)))

Index

Constants

View Source
const (
	KiB = 1 << (iota * 10)
	MiB
	GiB
	TiB
)
View Source
const (
	KB = 1000
	MB = KB * 1000
	GB = MB * 1000
	TB = GB * 1000
)
View Source
const (
	UnitKiB
	UnitKB
)
View Source
const (
	// DidentRight bit specifies identation direction.
	// |foo   |b     | With DidentRight
	// |   foo|     b| Without DidentRight
	DidentRight = 1 << iota

	// DextraSpace bit adds extra space, makes sense with DSyncWidth only.
	// When DidentRight bit set, the space will be added to the right,
	// otherwise to the left.
	DextraSpace

	// DSyncWidth bit enables same column width synchronization.
	// Effective with multiple bars only.
	DSyncWidth

	// DSyncWidthR is shortcut for DSyncWidth|DidentRight
	DSyncWidthR = DSyncWidth | DidentRight

	// DSyncSpace is shortcut for DSyncWidth|DextraSpace
	DSyncSpace = DSyncWidth | DextraSpace

	// DSyncSpaceR is shortcut for DSyncWidth|DextraSpace|DidentRight
	DSyncSpaceR = DSyncWidth | DextraSpace | DidentRight
)
View Source
const (
	ET_STYLE_GO = iota
	ET_STYLE_HHMMSS
	ET_STYLE_HHMM
	ET_STYLE_MMSS
)

Variables

View Source
var (
	WCSyncWidth  = WC{C: DSyncWidth}
	WCSyncWidthR = WC{C: DSyncWidthR}
	WCSyncSpace  = WC{C: DSyncSpace}
	WCSyncSpaceR = WC{C: DSyncSpaceR}
)

Global convenience shortcuts

Functions

This section is empty.

Types

type AmountReceiver

type AmountReceiver interface {
	NextAmount(int)
}

type CounterKB

type CounterKB int64

func (CounterKB) Format

func (c CounterKB) Format(st fmt.State, verb rune)

type CounterKiB

type CounterKiB int64

func (CounterKiB) Format

func (c CounterKiB) Format(st fmt.State, verb rune)

type Decorator

type Decorator interface {
	Decor(*Statistics, chan<- int, <-chan int) string
}

Decorator is an interface with one method:

Decor(st *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string

All decorators in this package implement this interface.

func CountersKibiByte

func CountersKibiByte(pairFormat string, wcc ...WC) Decorator

CountersKibiByte returns human friendly byte counters decorator, where counters unit is multiple by 1024.

`pairFormat` printf compatible verbs for current and total, like "%f" or "%d"

`wcc` optional WC config

pairFormat example:

"%.1f / %.1f" = "1.0MiB / 12.0MiB" or "% .1f / % .1f" = "1.0 MiB / 12.0 MiB"

func CountersKiloByte

func CountersKiloByte(pairFormat string, wcc ...WC) Decorator

CountersKiloByte returns human friendly byte counters decorator, where counters unit is multiple by 1000.

`pairFormat` printf compatible verbs for current and total, like "%f" or "%d"

`wcc` optional WC config

pairFormat example:

"%.1f / %.1f" = "1.0MB / 12.0MB" or "% .1f / % .1f" = "1.0 MB / 12.0 MB"

func CountersNoUnit

func CountersNoUnit(pairFormat string, wcc ...WC) Decorator

CountersNoUnit returns raw counters decorator

`pairFormat` printf compatible verbs for current and total, like "%f" or "%d"

`wcc` optional WC config

func ETA

func ETA(style int, age float64, sb chan time.Time, wcc ...WC) Decorator

ETA returns exponential-weighted-moving-average ETA decorator.

`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]

`age` is the previous N samples to average over.
 If zero value provided, it defaults to 30.

`sb` is a start block receive channel. User suppose to send time.Now()
 to this channel on each iteration of a start block, right before actual job.
 The channel will be auto closed on bar shutdown event, so there is no need
 to close from user side.

`wcc` optional WC config

func Elapsed

func Elapsed(style int, wcc ...WC) Decorator

Elapsed returns elapsed time decorator.

`style` one of [ET_STYLE_GO|ET_STYLE_HHMMSS|ET_STYLE_HHMM|ET_STYLE_MMSS]

`wcc` optional WC config

func MovingAverageETA

func MovingAverageETA(style int, average MovingAverage, sb chan time.Time, wcc ...WC) Decorator

MovingAverageETA returns ETA decorator, which relies on MovingAverage implementation to calculate average. Default ETA decorator relies on ewma implementation. However you're free to provide your own implementation or use alternative one, which is provided by decor package:

decor.MovingAverageETA(decor.ET_STYLE_GO, decor.NewMedian(), sb)

func MovingAverageSpeed

func MovingAverageSpeed(unit int, unitFormat string, average MovingAverage, sb chan time.Time, wcc ...WC) Decorator

MovingAverageSpeed returns Speed decorator, which relies on MovingAverage implementation to calculate average. Default Speed decorator relies on ewma implementation. However you're free to provide your own implementation or use alternative one, which is provided by decor package:

decor.MovingAverageSpeed(decor.UnitKiB, "% .2f", decor.NewMedian(), sb)

func Name

func Name(name string, wcc ...WC) Decorator

Name returns name decorator.

`name` string to display

`wcc` optional WC config

func OnComplete

func OnComplete(decorator Decorator, message string, wcc ...WC) Decorator

OnComplete returns decorator, which wraps provided decorator, with sole purpose to display provided message on complete event.

`decorator` Decorator to wrap

`message` message to display on complete event

`wcc` optional WC config

func Percentage

func Percentage(wcc ...WC) Decorator

Percentage returns percentage decorator.

`wcc` optional WC config

func SpeedKibiByte

func SpeedKibiByte(unitFormat string, age float64, sb chan time.Time, wcc ...WC) Decorator

SpeedKibiByte returns human friendly I/O operation speed decorator,

`unitFormat` printf compatible verb for value, like "%f" or "%d"

`age` is the previous N samples to average over.
 If zero value provided, it defaults to 30.

`sb` is a start block receive channel. User suppose to send time.Now()
 to this channel on each iteration of a start block, right before actual job.
 The channel will be auto closed on bar shutdown event, so there is no need
 to close from user side.

`wcc` optional WC config

unitFormat example:

"%.1f" = "1.0MiB/s" or "% .1f" = "1.0 MiB/s"

func SpeedKiloByte

func SpeedKiloByte(unitFormat string, age float64, sb chan time.Time, wcc ...WC) Decorator

SpeedKiloByte returns human friendly I/O operation speed decorator,

`unitFormat` printf compatible verb for value, like "%f" or "%d"

`age` is the previous N samples to average over.
 If zero value provided, it defaults to 30.

`sb` is a start block receive channel. User suppose to send time.Now()
 to this channel on each iteration of a start block, right before actual job.
 The channel will be auto closed on bar shutdown event, so there is no need
 to close from user side.

`wcc` optional WC config

unitFormat example:

"%.1f" = "1.0MB/s" or "% .1f" = "1.0 MB/s"

func SpeedNoUnit

func SpeedNoUnit(unitFormat string, age float64, sb chan time.Time, wcc ...WC) Decorator

SpeedNoUnit returns raw I/O operation speed decorator.

`unitFormat` printf compatible verb for value, like "%f" or "%d"

`age` is the previous N samples to average over.
 If zero value provided, it defaults to 30.

`sb` is a start block receive channel. User suppose to send time.Now()
 to this channel on each iteration of a start block, right before actual job.
 The channel will be auto closed on bar shutdown event, so there is no need
 to close from user side.

`wcc` optional WC config

unitFormat example:

"%.1f" = "1.0" or "% .1f" = "1.0"

func StaticName

func StaticName(name string, wcc ...WC) Decorator

StaticName returns name decorator.

`name` string to display

`wcc` optional WC config

type DecoratorFunc

type DecoratorFunc func(*Statistics, chan<- int, <-chan int) string

DecoratorFunc is an adapter for Decorator interface

func (DecoratorFunc) Decor

func (f DecoratorFunc) Decor(s *Statistics, widthAccumulator chan<- int, widthDistributor <-chan int) string

type MovingAverage

type MovingAverage interface {
	Add(float64)
	Value() float64
	Set(float64)
}

MovingAverage is the interface that computes a moving average over a time- series stream of numbers. The average may be over a window or exponentially decaying.

func NewMedian

func NewMedian() MovingAverage

NewMedian is fixed last 3 samples median MovingAverage.

func NewMedianEwma

func NewMedianEwma(age ...float64) MovingAverage

NewMedianEwma is ewma based MovingAverage, which gets its values from median MovingAverage.

type OnCompleteMessenger

type OnCompleteMessenger interface {
	OnCompleteMessage(string, ...WC)
}

OnCompleteMessenger is an interface with one method:

OnCompleteMessage(message string, wc ...WC)

Decorators implementing this interface suppose to return provided string on complete event.

type ShutdownListener

type ShutdownListener interface {
	Shutdown()
}

type SpeedKB

type SpeedKB float64

func (SpeedKB) Format

func (s SpeedKB) Format(st fmt.State, verb rune)

type SpeedKiB

type SpeedKiB float64

func (SpeedKiB) Format

func (s SpeedKiB) Format(st fmt.State, verb rune)

type Statistics

type Statistics struct {
	ID        int
	Completed bool
	Total     int64
	Current   int64
}

Statistics is a struct, which gets passed to a Decorator.

type WC

type WC struct {
	W int
	C int
	// contains filtered or unexported fields
}

WC is a struct with two public fields W and C, both of int type. W represents width and C represents bit set of width related config.

func (*WC) BuildFormat

func (wc *WC) BuildFormat()

BuildFormat builds initial format according to WC.C

func (WC) FormatMsg

func (wc WC) FormatMsg(msg string, widthAccumulator chan<- int, widthDistributor <-chan int) string

FormatMsg formats final message according to WC.W and WC.C. Should be called by any Decorator implementation.

Jump to

Keyboard shortcuts

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