Documentation ¶
Index ¶
- Constants
- func AnyCompatible(compatible []Semver, actual Semver) (isApiCompat bool)
- func BuildExchangeKey(exchangeName string, currencyPair string, interval int) string
- func Compatible(required, actual Semver) bool
- func DisableLog()
- func ExtractExchangeKey(setKey string) (exchangeName string, currencyPair string, interval int)
- func MakePowChart(charts *Manager, dates ChartUints, deviations []ChartNullUints, pools []string) ([]byte, error)
- func MakeVspChart(charts *Manager, dates ChartUints, deviations []ChartNullData, vsps []string) ([]byte, error)
- func ParseAxis(aType string) axisType
- func ParseBin(binString string) binLevel
- func UseLogger(logger slog.Logger)
- func ValidateLengths(lens ...Lengther) (int, error)
- type ChartError
- type ChartFloats
- type ChartMaker
- type ChartNullData
- type ChartNullFloats
- func (data ChartNullFloats) IsZero(index int) bool
- func (data ChartNullFloats) Length() int
- func (data ChartNullFloats) Normalize() Lengther
- func (data ChartNullFloats) Remove(index int) Lengther
- func (data ChartNullFloats) String(index int) string
- func (data ChartNullFloats) Truncate(l int) Lengther
- func (data ChartNullFloats) Valid(index int) bool
- func (data ChartNullFloats) Value(index int) interface{}
- type ChartNullUints
- func (data ChartNullUints) IsZero(index int) bool
- func (data ChartNullUints) Length() int
- func (data ChartNullUints) Normalize() Lengther
- func (data ChartNullUints) Remove(index int) Lengther
- func (data ChartNullUints) String(index int) string
- func (data ChartNullUints) ToChartString() ChartStrings
- func (data ChartNullUints) Truncate(l int) Lengther
- func (data ChartNullUints) Valid(index int) bool
- func (data ChartNullUints) Value(index int) interface{}
- type ChartStrings
- type ChartUints
- type ChartUpdater
- type Lengther
- type Manager
- func (charts *Manager) AddRetriever(chartID string, retriever Retriver)
- func (charts *Manager) AddUpdater(updater ChartUpdater)
- func (charts *Manager) AppendChartFloatsAxis(key string, set ChartFloats) error
- func (charts *Manager) AppendChartNullFloatsAxis(key string, set ChartNullFloats) error
- func (charts *Manager) AppendChartNullFloatsAxisTx(key string, set ChartNullFloats, txn *badger.Txn) error
- func (charts *Manager) AppendChartNullUintsAxis(key string, set ChartNullUints) error
- func (charts *Manager) AppendChartNullUintsAxisTx(key string, set ChartNullUints, txn *badger.Txn) error
- func (charts *Manager) AppendChartUintsAxis(key string, set ChartUints) error
- func (charts *Manager) Chart(ctx context.Context, chartID, dataType, axisString, binString string, ...) ([]byte, error)
- func (charts *Manager) ClearVLog()
- func (charts *Manager) Encode(keys []string, sets ...Lengther) ([]byte, error)
- func (charts *Manager) ExchangeSetTime(key string) uint64
- func (charts *Manager) Lengthen(tags ...string) error
- func (charts *Manager) Load(ctx context.Context) error
- func (charts *Manager) MempoolTimeTip() uint64
- func (charts *Manager) NormalizeLength(tags ...string) error
- func (charts *Manager) PowTimeTip() uint64
- func (charts *Manager) PropagationHeightTip() uint64
- func (charts *Manager) ReadVal(key string, result interface{}) error
- func (charts *Manager) ReadValTx(key string, result interface{}, txn *badger.Txn) error
- func (charts *Manager) SaveVal(key string, val interface{}) error
- func (charts *Manager) SaveValTx(key string, val interface{}, txn *badger.Txn) error
- func (charts *Manager) SaveVersion() error
- func (charts *Manager) SnapshotTip() uint64
- func (charts *Manager) TriggerUpdate(ctx context.Context, tag string) error
- func (charts *Manager) Update(ctx context.Context, tags ...string) error
- func (charts *Manager) VSPTimeTip() uint64
- type Retriver
- type Semver
Constants ¶
const ( Mempool = "mempool" Propagation = "propagation" Community = "community" PowChart = "pow" VSP = "vsp" Exchange = "exchange" Snapshot = "snapshot" )
Keys for specifying chart data type.
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.
const ( ExchangeCloseAxis axisType = "close" ExchangeHighAxis axisType = "high" ExchangeOpenAxis axisType = "open" ExchangeLowAxis axisType = "low" )
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.
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 ¶
AnyCompatible checks if the version is compatible with any versions in a slice of versions.
func BuildExchangeKey ¶
BuildExchangeKey returns exchange name, currency pair and interval joined by -
func Compatible ¶
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 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 ValidateLengths ¶
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 ChartNullFloats ¶
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 ¶
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 ¶
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 (*Manager) AppendChartNullUintsAxis ¶
func (charts *Manager) AppendChartNullUintsAxis(key string, set ChartNullUints) error
func (*Manager) AppendChartNullUintsAxisTx ¶
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) Encode ¶
Encode the slices. The set lengths are truncated to the smallest of the arguments.
func (*Manager) ExchangeSetTime ¶
func (*Manager) Load ¶
Load loads chart data from the gob file at the specified path and performs an update.
func (*Manager) MempoolTimeTip ¶
func (*Manager) NormalizeLength ¶
func (*Manager) PowTimeTip ¶
func (*Manager) PropagationHeightTip ¶
func (*Manager) SnapshotTip ¶
func (*Manager) TriggerUpdate ¶
TriggerUpdate triggers (*ChartData).Update.
func (*Manager) Update ¶
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 ¶
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 ParseVersionStr ¶
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.