hashrate

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package avgcounter implements a simple EMA (Exponential Moving Average) counter. The New function creates a counter with the only parameter: avgInterval. Every Add call adds the value to the counter. The current value can be obtained using the Value method.

The counter holds the exponentially (by time) weighted average of all added values.

https://github.com/davidmz/avgcounter

Index

Constants

View Source
const MeanCounterKey = "mean"

Variables

This section is empty.

Functions

func GHSToHS

func GHSToHS(hrGHS int) float64

func GHSToJobSubmitted

func GHSToJobSubmitted(hrGHS float64) float64

func GHSToJobSubmittedV2

func GHSToJobSubmittedV2(hrGHS float64, duration time.Duration) float64

func HSToGHS

func HSToGHS(hashrateHS float64) int

func HSToJobSubmitted

func HSToJobSubmitted(hrHS float64) float64

func JobSubmittedToGHS

func JobSubmittedToGHS(jobSubmitted float64) float64

func JobSubmittedToGHSV2

func JobSubmittedToGHSV2(jobSubmitted float64, duration time.Duration) float64

func JobSubmittedToHS

func JobSubmittedToHS(jobSubmitted float64) float64

Types

type Counter

type Counter interface {
	Start()                           // sets the start time
	Add(v float64)                    // adds a measurment performed now to the counter
	Value() float64                   // returns the current value
	ValuePer(t time.Duration) float64 // returns the current value normalized to the given duration
	Reset()                           // resets counter
}

type Ema

type Ema struct {
	// contains filtered or unexported fields
}

Ema is an EMA (Exponential Moving Average) counter.

func NewEma

func NewEma(halfLife time.Duration) *Ema

NewEma creates a new Counter with the given half-life (time lag at which the exponential weights decay by one half)

func (*Ema) Add

func (c *Ema) Add(v float64)

Add adds a new value to the counter.

func (*Ema) LastValue

func (c *Ema) LastValue() float64

LastValue returns last value of a counter excluding the value decay

func (*Ema) LastValuePer

func (c *Ema) LastValuePer(interval time.Duration) float64

func (*Ema) Reset

func (c *Ema) Reset()

func (*Ema) Start

func (c *Ema) Start()

func (*Ema) Value

func (c *Ema) Value() float64

Value returns the current value of the counter.

func (*Ema) ValuePer

func (c *Ema) ValuePer(interval time.Duration) float64

ValuePer returns the current value of the counter, normalized to the given interval. It is actually a Value() * interval / avgInterval.

type GlobalHashrate

type GlobalHashrate struct {
	// contains filtered or unexported fields
}

func NewGlobalHashrate

func NewGlobalHashrate(hrFactory HashrateFactory) *GlobalHashrate

func (*GlobalHashrate) GetAll

func (t *GlobalHashrate) GetAll() map[string]time.Time

func (*GlobalHashrate) GetHashRateGHS

func (t *GlobalHashrate) GetHashRateGHS(workerName string, counterID string) (hrGHS float64, ok bool)

func (*GlobalHashrate) GetHashRateGHSAll

func (t *GlobalHashrate) GetHashRateGHSAll(workerName string) (hrGHS map[string]float64, ok bool)

func (*GlobalHashrate) GetLastSubmitTime

func (t *GlobalHashrate) GetLastSubmitTime(workerName string) (tm time.Time, ok bool)

func (*GlobalHashrate) GetTotalWork

func (t *GlobalHashrate) GetTotalWork(workerName string) (work float64, ok bool)

func (*GlobalHashrate) GetWorker

func (t *GlobalHashrate) GetWorker(workerName string) *WorkerHashrateModel

func (*GlobalHashrate) Initialize

func (t *GlobalHashrate) Initialize(workerName string)

func (*GlobalHashrate) OnConnect

func (t *GlobalHashrate) OnConnect(workerName string)

func (*GlobalHashrate) OnSubmit

func (t *GlobalHashrate) OnSubmit(workerName string, diff float64)

func (*GlobalHashrate) Range

func (t *GlobalHashrate) Range(f func(m *WorkerHashrateModel) bool)

func (*GlobalHashrate) Reset

func (t *GlobalHashrate) Reset(workerName string)

type Hashrate

type Hashrate struct {
	// contains filtered or unexported fields
}

func NewHashrate

func NewHashrate(counters map[string]Counter) *Hashrate

func (*Hashrate) GetHashrateAvgGHSAll

func (h *Hashrate) GetHashrateAvgGHSAll() map[string]float64

func (*Hashrate) GetHashrateAvgGHSCustom

func (h *Hashrate) GetHashrateAvgGHSCustom(ID string) (hrGHS float64, ok bool)

func (*Hashrate) GetLastSubmitTime

func (h *Hashrate) GetLastSubmitTime() time.Time

func (*Hashrate) GetTotalDuration

func (h *Hashrate) GetTotalDuration() time.Duration

func (*Hashrate) GetTotalShares

func (h *Hashrate) GetTotalShares() int

func (*Hashrate) GetTotalWork

func (h *Hashrate) GetTotalWork() float64

func (*Hashrate) OnSubmit

func (h *Hashrate) OnSubmit(diff float64)

func (*Hashrate) Reset

func (h *Hashrate) Reset()

func (*Hashrate) Start

func (h *Hashrate) Start()

type HashrateFactory

type HashrateFactory = func() *Hashrate

type Mean

type Mean struct {
	// contains filtered or unexported fields
}

func NewMean

func NewMean() *Mean

NewMean creates a new Mean hashrate counter, which adds all submitted work and divides it by the total duration it is also used to track the first and last submit time and total work

func (*Mean) Add

func (h *Mean) Add(diff float64)

func (*Mean) GetLastSubmitTime

func (h *Mean) GetLastSubmitTime() time.Time

func (*Mean) GetTotalDuration

func (h *Mean) GetTotalDuration() time.Duration

func (*Mean) GetTotalShares

func (h *Mean) GetTotalShares() uint32

func (*Mean) GetTotalWork

func (h *Mean) GetTotalWork() uint64

func (*Mean) Reset

func (h *Mean) Reset()

func (*Mean) Start

func (h *Mean) Start()

func (*Mean) Value

func (h *Mean) Value() float64

func (*Mean) ValuePer

func (h *Mean) ValuePer(t time.Duration) float64

type Sma

type Sma struct {
	// contains filtered or unexported fields
}

Sma is an SMA (Simple Moving Average) counter.

func NewSma

func NewSma(window time.Duration) *Sma

NewEma creates a new Counter with the given window time

func (*Sma) Add

func (c *Sma) Add(v float64)

Add adds a new value to the counter.

func (*Sma) AddWithTimestamp

func (c *Sma) AddWithTimestamp(v float64, timestamp time.Time)

Add adds a new value to the counter.

func (*Sma) Reset

func (c *Sma) Reset()

func (*Sma) Start

func (c *Sma) Start()

func (*Sma) Value

func (c *Sma) Value() float64

Value returns the current value of the counter.

func (*Sma) ValuePer

func (c *Sma) ValuePer(t time.Duration) float64

type WorkerHashrateModel

type WorkerHashrateModel struct {
	// contains filtered or unexported fields
}

func NewWorkerHashrateModel

func NewWorkerHashrateModel(id string, hr *Hashrate) *WorkerHashrateModel

func (*WorkerHashrateModel) GetHashRateGHS

func (m *WorkerHashrateModel) GetHashRateGHS(counterID string) (float64, bool)

func (*WorkerHashrateModel) GetHashrateAvgGHSAll

func (m *WorkerHashrateModel) GetHashrateAvgGHSAll() map[string]float64

func (*WorkerHashrateModel) GetHashrateCounter

func (m *WorkerHashrateModel) GetHashrateCounter(counterID string) Counter

func (*WorkerHashrateModel) GetLastSubmitTime

func (m *WorkerHashrateModel) GetLastSubmitTime() time.Time

func (*WorkerHashrateModel) GetTotalShares

func (m *WorkerHashrateModel) GetTotalShares() int

func (*WorkerHashrateModel) ID

func (m *WorkerHashrateModel) ID() string

func (*WorkerHashrateModel) OnConnect

func (m *WorkerHashrateModel) OnConnect()

func (*WorkerHashrateModel) OnSubmit

func (m *WorkerHashrateModel) OnSubmit(diff float64)

func (*WorkerHashrateModel) Reconnects

func (m *WorkerHashrateModel) Reconnects() int

Jump to

Keyboard shortcuts

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