rating

package
v0.0.0-...-55ecaa8 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScorerNameDefault = "default"
)

Variables

View Source
var (
	ErrUnknownAlgorithm = errors.New("unknown rating algorithm")
	ErrAlgorithmParams  = errors.New("invalid algorithm params")
)
View Source
var ErrInvalidWeights = errors.New("weights must sum to 1")

Functions

This section is empty.

Types

type Rating

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

Filters bids based on the config, uses the scorer to rate the bids and sorts them

func NewRating

func NewRating(scorer Scorer, providerAllowList []common.Address, log lib.ILogger) *Rating

func NewRatingFromConfig

func NewRatingFromConfig(config json.RawMessage, log lib.ILogger) (*Rating, error)

func (*Rating) RateBids

func (r *Rating) RateBids(scoreInputs []RatingInput, log lib.ILogger) []RatingRes

type RatingConfig

type RatingConfig struct {
	Algorithm         string           `json:"algorithm"`
	Params            json.RawMessage  `json:"params"`
	ProviderAllowList []common.Address `json:"providerAllowlist"`
}

type RatingInput

type RatingInput struct {
	ScoreInput
	BidID      common.Hash
	ModelID    common.Hash
	ProviderID common.Address
}

type RatingRes

type RatingRes struct {
	BidID common.Hash
	Score float64
}

type ScoreInput

type ScoreInput struct {
	ProviderModel  *s.IStatsStorageProviderModelStats // stats of the provider specific to the model
	Model          *s.IStatsStorageModelStats         // stats of the model across providers
	PricePerSecond *big.Int
	ProviderStake  *big.Int
	MinStake       *big.Int
}

ScoreInput is a struct that holds the input data for the rating algorithm of a bid

func NewScoreArgs

func NewScoreArgs() *ScoreInput

type Scorer

type Scorer interface {
	// GetScore returns the score of a bid. Returns -Inf if the bid should be skipped
	GetScore(args *ScoreInput) float64
}

type ScorerDefault

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

func NewScorerDefault

func NewScorerDefault(weights ScorerDefaultParams) *ScorerDefault

func NewScorerDefaultFromJSON

func NewScorerDefaultFromJSON(data json.RawMessage) (*ScorerDefault, error)

func (*ScorerDefault) GetScore

func (r *ScorerDefault) GetScore(args *ScoreInput) float64

type ScorerDefaultParams

type ScorerDefaultParams struct {
	Weights struct {
		TPS      float64 `json:"tps"`
		TTFT     float64 `json:"ttft"`
		Duration float64 `json:"duration"`
		Success  float64 `json:"success"`
		Stake    float64 `json:"stake"`
	} `json:"weights"`
}

func ScorerDefaultParamsMock

func ScorerDefaultParamsMock() ScorerDefaultParams

func (*ScorerDefaultParams) Validate

func (w *ScorerDefaultParams) Validate() bool

type ScorerMock

type ScorerMock struct {
}

func NewScorerMock

func NewScorerMock() *ScorerMock

func (*ScorerMock) GetScore

func (m *ScorerMock) GetScore(args *ScoreInput) float64

Jump to

Keyboard shortcuts

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