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) Avg(s, e int) *null.Float64
- 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) Avg(s, e int) *null.Uint64
- 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) Chart(ctx context.Context, chartID, dataType, axisString, binString string, ...) ([]byte, error)
- func (charts *Manager) Encode(keys []string, sets ...Lengther) ([]byte, error)
- func (charts *Manager) Trim(sets ...Lengther) []Lengther
- type Retriver
- type Semver
Constants ¶
const ( Mempool = "mempool" Propagation = "propagation" Community = "community" PowChart = "pow" VSP = "vsp" Exchange = "exchange" Snapshot = "snapshot" // ADay defines the number of seconds in a day. ADay = 86400 AnHour = ADay / 24 )
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" DefaultBin binLevel = "default" HourBin binLevel = "hour" DayBin binLevel = "day" )
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) Avg ¶
func (data ChartNullFloats) Avg(s, e int) *null.Float64
Avg is the average value of a segment of the dataset.
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) Avg ¶
func (data ChartNullUints) Avg(s, e int) *null.Uint64
Avg is the average value of a segment of the dataset.
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 GenerateDayBin ¶
func GenerateDayBin(dates, heights ChartUints) (days, dayHeights ChartUints, dayIntervals [][2]int)
GenerateDayBin returns slice of the first time of each day within the supplied dates with the correspounding heights if not nil. The dayIntervals holds the start and end index for each day
func GenerateHourBin ¶
func GenerateHourBin(dates, heights ChartUints) (hours, hourHeights ChartUints, hourIntervals [][2]int)
GenerateHourBin returns slice of the first time of each hour within the supplied dates with the correspounding heights if not nil. The hourIntervals holds the start and end index for each day
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 { VSPSources []string PowSources []string ExchangeKeys []string NodeVersion []string NodeLocations []string EnableCache bool // 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, dir string) *Manager
NewChartData constructs a new ChartData.
func (*Manager) AddRetriever ¶
AddRetriever adds a Retriever to the Retrievers slice.
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.
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.