streak

package
v0.0.0-...-531a2f0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Factor

type Factor struct {
	After time.Duration
	Value int64
}

Factor indicates which value should be returned after a streak lasted the given duration

type Streaker

type Streaker struct {
	MaxDelayBetweenHits time.Duration
	Factors             []Factor
	// contains filtered or unexported fields
}

Streaker contains the streaker parameters Factors must be sorted

func New

func New(maxDelayBetweenHits time.Duration, factors ...Factor) Streaker

New creates a new Streaker A streaker returns a given Factor.Value after the Factor.Delay has passed (since the start of the streak) The value is reset to 1 when two hits are more than maxDelayBetweenHits apart. The factors will be automatically sorted.

func (Streaker) Factor

func (s Streaker) Factor(streakDuration time.Duration) (value int64)

Factor returns the factor for a given streak duration

func (*Streaker) Hit

func (s *Streaker) Hit() time.Duration

Hit considers a hit it returns the current streak duration

func (*Streaker) UpdatedFactor

func (s *Streaker) UpdatedFactor() (value int64)

UpdatedFactor returns the factor after considering a hit

Jump to

Keyboard shortcuts

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