cache

package
v0.0.0-...-05b8940 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2020 License: ISC Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Mempool     = "mempool"
	Propagation = "propagation"
	Community   = "community"
	PowChart    = "pow"
	VSP         = "vsp"
	Exchange    = "exchange"
	Snapshot    = "snapshot"
)

Keys for specifying chart data type.

View Source
const (
	HeightAxis axisType = "height"
	TimeAxis   axisType = "time"

	HashrateAxis axisType = "hashrate"
	WorkerAxis   axisType = "workers"

	MempoolSize    = "size"
	MempoolFees    = "fees"
	MempoolTxCount = "tx-count"

	BlockPropagation = "block-propagation"
	BlockTimestamp   = "block-timestamp"
	VotesReceiveTime = "votes-receive-time"

	ImmatureAxis         axisType = "immature"
	LiveAxis             axisType = "live"
	VotedAxis            axisType = "voted"
	MissedAxis           axisType = "missed"
	PoolFeesAxis         axisType = "pool-fees"
	ProportionLiveAxis   axisType = "proportion-live"
	ProportionMissedAxis axisType = "proportion-missed"
	UserCountAxis        axisType = "user-count"
	UsersActiveAxis      axisType = "users-active"

	SnapshotNodes          axisType = "nodes"
	SnapshotReachableNodes axisType = "reachable-nodes"
	SnapshotLocations      axisType = "locations"
	SnapshotNodeVersions   axisType = "node-versions"
)

These are the recognized binLevel and axisType values.

View Source
const (
	ExchangeCloseAxis axisType = "close"
	ExchangeHighAxis  axisType = "high"
	ExchangeOpenAxis  axisType = "open"
	ExchangeLowAxis   axisType = "low"
)
View Source
const InvalidBinErr = ChartError("invalid bin")

InvalidBinErr is returned when a ChartMaker receives an unknown BinLevel. In practice, this should be impossible, since ParseBin returns a default if a supplied bin specifier is invalid, and window-binned ChartMakers ignore the bin flag.

View Source
const UnknownChartErr = ChartError("unknown chart")

UnknownChartErr is returned when a chart key is provided that does not match any known chart type constant.

Variables

This section is empty.

Functions

func AnyCompatible

func AnyCompatible(compatible []Semver, actual Semver) (isApiCompat bool)

AnyCompatible checks if the version is compatible with any versions in a slice of versions.

func BuildExchangeKey

func BuildExchangeKey(exchangeName string, currencyPair string, interval int) string

BuildExchangeKey returns exchange name, currency pair and interval joined by -

func Compatible

func Compatible(required, actual Semver) bool

Compatible decides if the actual version is compatible with the required one.

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func ExtractExchangeKey

func ExtractExchangeKey(setKey string) (exchangeName string, currencyPair string, interval int)

func MakePowChart

func MakePowChart(charts *Manager, dates ChartUints, deviations []ChartNullUints, pools []string) ([]byte, error)

func MakeVspChart

func MakeVspChart(charts *Manager, dates ChartUints, deviations []ChartNullData, vsps []string) ([]byte, error)

func ParseAxis

func ParseAxis(aType string) axisType

ParseAxis returns the matching axis type, else the default of time axis.

func ParseBin

func ParseBin(binString string) binLevel

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

func ValidateLengths

func ValidateLengths(lens ...Lengther) (int, error)

Check that the length of all arguments is equal.

Types

type ChartError

type ChartError string

ChartError is an Error interface for use with constant errors.

func (ChartError) Error

func (e ChartError) Error() string

type ChartFloats

type ChartFloats []float64

ChartFloats is a slice of floats. It satisfies the lengther interface, and provides methods for taking averages or sums of segments.

func (ChartFloats) Avg

func (data ChartFloats) Avg(s, e int) float64

Avg is the average value of a segment of the dataset.

func (ChartFloats) IsZero

func (data ChartFloats) IsZero(index int) bool

func (ChartFloats) Length

func (data ChartFloats) Length() int

Length returns the length of data. Satisfies the lengther interface.

func (ChartFloats) Normalize

func (charts ChartFloats) Normalize() Lengther

func (ChartFloats) Remove

func (data ChartFloats) Remove(index int) Lengther

func (ChartFloats) Truncate

func (data ChartFloats) Truncate(l int) Lengther

Truncate makes a subset of the underlying dataset. It satisfies the lengther interface.

type ChartMaker

type ChartMaker func(ctx context.Context, charts *Manager, dataType, axis axisType, bin binLevel, sources ...string) ([]byte, error)

ChartMaker is a function that accepts a chart type and BinLevel, and returns a JSON-encoded chartResponse.

type ChartNullData

type ChartNullData interface {
	Lengther
	Value(index int) interface{}
	Valid(index int) bool
	String(index int) string
}

type ChartNullFloats

type ChartNullFloats []*null.Float64

ChartNullFloats is a slice of null.float64. It satisfies the lengther interface.

func (ChartNullFloats) IsZero

func (data ChartNullFloats) IsZero(index int) bool

func (ChartNullFloats) Length

func (data ChartNullFloats) Length() int

Length returns the length of data. Satisfies the lengther interface.

func (ChartNullFloats) Normalize

func (data ChartNullFloats) Normalize() Lengther

func (ChartNullFloats) Remove

func (data ChartNullFloats) Remove(index int) Lengther

func (ChartNullFloats) String

func (data ChartNullFloats) String(index int) string

func (ChartNullFloats) Truncate

func (data ChartNullFloats) Truncate(l int) Lengther

Truncate makes a subset of the underlying dataset. It satisfies the lengther interface.

func (ChartNullFloats) Valid

func (data ChartNullFloats) Valid(index int) bool

func (ChartNullFloats) Value

func (data ChartNullFloats) Value(index int) interface{}

type ChartNullUints

type ChartNullUints []*null.Uint64

ChartNullUints is a slice of null.uints. It satisfies the lengther interface.

func (ChartNullUints) IsZero

func (data ChartNullUints) IsZero(index int) bool

func (ChartNullUints) Length

func (data ChartNullUints) Length() int

Length returns the length of data. Satisfies the lengther interface.

func (ChartNullUints) Normalize

func (data ChartNullUints) Normalize() Lengther

func (ChartNullUints) Remove

func (data ChartNullUints) Remove(index int) Lengther

func (ChartNullUints) String

func (data ChartNullUints) String(index int) string

func (ChartNullUints) ToChartString

func (data ChartNullUints) ToChartString() ChartStrings

Truncate makes a subset of the underlying dataset. It satisfies the lengther interface.

func (ChartNullUints) Truncate

func (data ChartNullUints) Truncate(l int) Lengther

Truncate makes a subset of the underlying dataset. It satisfies the lengther interface.

func (ChartNullUints) Valid

func (data ChartNullUints) Valid(index int) bool

func (ChartNullUints) Value

func (data ChartNullUints) Value(index int) interface{}

type ChartStrings

type ChartStrings []string

ChartStrings is a slice of strings. It satisfies the lengther interface, and provides methods for taking averages or sums of segments.

func (ChartStrings) IsZero

func (data ChartStrings) IsZero(index int) bool

func (ChartStrings) Length

func (data ChartStrings) Length() int

Length returns the length of data. Satisfies the lengther interface.

func (ChartStrings) Remove

func (data ChartStrings) Remove(index int) Lengther

func (ChartStrings) Truncate

func (data ChartStrings) Truncate(l int) Lengther

Truncate makes a subset of the underlying dataset. It satisfies the lengther interface.

type ChartUints

type ChartUints []uint64

ChartUints is a slice of uints. It satisfies the lengther interface, and provides methods for taking averages or sums of segments.

func (ChartUints) Avg

func (data ChartUints) Avg(s, e int) uint64

Avg is the average value of a segment of the dataset.

func (ChartUints) IsZero

func (data ChartUints) IsZero(index int) bool

func (ChartUints) Length

func (data ChartUints) Length() int

Length returns the length of data. Satisfies the lengther interface.

func (ChartUints) Normalize

func (data ChartUints) Normalize() Lengther

func (ChartUints) Remove

func (data ChartUints) Remove(index int) Lengther

func (ChartUints) Truncate

func (data ChartUints) Truncate(l int) Lengther

Truncate makes a subset of the underlying dataset. It satisfies the lengther interface.

type ChartUpdater

type ChartUpdater struct {
	Tag string
	// In addition to the sql.Rows and an error, the fetcher should return a
	// context.CancelFunc if appropriate, else a dummy. A done value should be
	// returned to tell if the result is the last page
	Fetcher func(ctx context.Context, charts *Manager, page int) (interface{}, func(), bool, error)
	// The Appender will be run under mutex lock.
	Appender func(charts *Manager, recordSlice interface{}) error
}

ChartUpdater is a pair of functions for fetching and appending chart data. The two steps are divided so that ChartData can check whether another thread has updated the data during the query, and abandon an update with appropriate messaging.

type Lengther

type Lengther interface {
	Length() int
	Truncate(int) Lengther
	IsZero(index int) bool
	Remove(index int) Lengther
}

An interface for reading and setting the length of datasets.

type Manager

type Manager struct {
	EnableCache bool

	DB *badger.DB

	VSPSources    []string
	PowSources    []string
	ExchangeKeys  []string
	NodeVersion   []string
	NodeLocations []string
	// contains filtered or unexported fields
}

Manager is the entry point chart cache

func NewChartData

func NewChartData(ctx context.Context, enableCache bool, syncSources,
	poolSources, vsps, nodeLocations, nodeVersion []string, chainParams *chaincfg.Params, db *badger.DB) *Manager

NewChartData constructs a new ChartData.

func (*Manager) AddRetriever

func (charts *Manager) AddRetriever(chartID string, retriever Retriver)

AddRetriever adds a Retriever to the Retrievers slice.

func (*Manager) AddUpdater

func (charts *Manager) AddUpdater(updater ChartUpdater)

AddUpdater adds a ChartUpdater to the Updaters slice. Updaters are run sequentially during (*ChartData).Update.

func (*Manager) AppendChartFloatsAxis

func (charts *Manager) AppendChartFloatsAxis(key string, set ChartFloats) error

func (*Manager) AppendChartNullFloatsAxis

func (charts *Manager) AppendChartNullFloatsAxis(key string, set ChartNullFloats) error

func (*Manager) AppendChartNullFloatsAxisTx

func (charts *Manager) AppendChartNullFloatsAxisTx(key string, set ChartNullFloats, txn *badger.Txn) error

func (*Manager) AppendChartNullUintsAxis

func (charts *Manager) AppendChartNullUintsAxis(key string, set ChartNullUints) error

func (*Manager) AppendChartNullUintsAxisTx

func (charts *Manager) AppendChartNullUintsAxisTx(key string, set ChartNullUints, txn *badger.Txn) error

func (*Manager) AppendChartUintsAxis

func (charts *Manager) AppendChartUintsAxis(key string, set ChartUints) error

func (*Manager) Chart

func (charts *Manager) Chart(ctx context.Context, chartID, dataType, axisString, binString string, extras ...string) ([]byte, error)

Chart will return a JSON-encoded chartResponse of the provided type and BinLevel.

func (*Manager) ClearVLog

func (charts *Manager) ClearVLog()

func (*Manager) Encode

func (charts *Manager) Encode(keys []string, sets ...Lengther) ([]byte, error)

Encode the slices. The set lengths are truncated to the smallest of the arguments.

func (*Manager) ExchangeSetTime

func (charts *Manager) ExchangeSetTime(key string) uint64

func (*Manager) Lengthen

func (charts *Manager) Lengthen(tags ...string) error

Lengthen performs data validation, the cacheID will be incremented.

func (*Manager) Load

func (charts *Manager) Load(ctx context.Context) error

Load loads chart data from the gob file at the specified path and performs an update.

func (*Manager) MempoolTimeTip

func (charts *Manager) MempoolTimeTip() uint64

func (*Manager) NormalizeLength

func (charts *Manager) NormalizeLength(tags ...string) error

func (*Manager) PowTimeTip

func (charts *Manager) PowTimeTip() uint64

func (*Manager) PropagationHeightTip

func (charts *Manager) PropagationHeightTip() uint64

func (*Manager) ReadVal

func (charts *Manager) ReadVal(key string, result interface{}) error

func (*Manager) ReadValTx

func (charts *Manager) ReadValTx(key string, result interface{}, txn *badger.Txn) error

func (*Manager) SaveVal

func (charts *Manager) SaveVal(key string, val interface{}) error

func (*Manager) SaveValTx

func (charts *Manager) SaveValTx(key string, val interface{}, txn *badger.Txn) error

func (*Manager) SaveVersion

func (charts *Manager) SaveVersion() error

chart version

func (*Manager) SnapshotTip

func (charts *Manager) SnapshotTip() uint64

func (*Manager) TriggerUpdate

func (charts *Manager) TriggerUpdate(ctx context.Context, tag string) error

TriggerUpdate triggers (*ChartData).Update.

func (*Manager) Update

func (charts *Manager) Update(ctx context.Context, tags ...string) error

Update refreshes chart data by calling the ChartUpdaters sequentially. The Update is abandoned with a warning if stateID changes while running a Fetcher (likely due to a new update starting during a query).

func (*Manager) VSPTimeTip

func (charts *Manager) VSPTimeTip() uint64

type Retriver

type Retriver func(ctx context.Context, charts *Manager, dataType, axisString string, bin string, extras ...string) ([]byte, error)

Retriver provides a function for directly getting a specific chart data from a store

type Semver

type Semver struct {
	Major, Minor, Patch uint32
}

Semver models a semantic version (semver) major.minor.patch

func NewSemver

func NewSemver(major, minor, patch uint32) Semver

NewSemver returns a new Semver with the version major.minor.patch

func ParseVersionStr

func ParseVersionStr(ver string) (*Semver, error)

ParseVersionStr makes a *Semver from a version string (e.g. v3.1.0, 5.3.2, 7.3, etc.). The "v" prefix is optional, as are the minor and patch versions.

func (*Semver) Split

func (s *Semver) Split() (uint32, uint32, uint32)

Split returns the major, minor and patch version.

func (Semver) String

func (s Semver) String() string

Jump to

Keyboard shortcuts

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