vote

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: Apache-2.0, BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ConflictType defines an object type conflict.
	ConflictType = iota
	// TimestampType defines an object type timestamp.
	TimestampType
)

Variables

View Source
var ErrVotingNotFound = errors.New("no voting found")

ErrVotingNotFound is returned when a voting for a given id wasn't found.

Functions

func OpinionCaller

func OpinionCaller(handler interface{}, params ...interface{})

OpinionCaller calls the given handler with an OpinionEvent (containing its opinions, its associated ID and context).

func RoundStatsCaller

func RoundStatsCaller(handler interface{}, params ...interface{})

RoundStatsCaller calls the given handler with a RoundStats.

Types

type Context

type Context struct {
	ID   string
	Type ObjectType
	// The percentage of OpinionGivers who liked this item on the last query.
	ProportionLiked float64
	// The number of voting rounds performed.
	Rounds int
	// Append-only list of opinions formed after each round.
	// the first opinion is the initial opinion when this vote context was created.
	Opinions []opinion.Opinion
	// Weights used for voting
	Weights VotingWeights
	// ConflictCreationTime points to time when the context has been created
	ConflictCreationTime time.Time
}

Context is the context of votes from multiple rounds about a given item.

func NewContext

func NewContext(id string, objectType ObjectType, initOpn opinion.Opinion) *Context

NewContext creates a new vote context.

func (*Context) AddOpinion

func (vc *Context) AddOpinion(opn opinion.Opinion)

AddOpinion adds the given opinion to this vote context.

func (*Context) HadFirstRound

func (vc *Context) HadFirstRound() bool

HadFirstRound tells whether the vote context just had its first round.

func (*Context) HadFixedRound added in v0.5.5

func (vc *Context) HadFixedRound(coolingOffPeriod, totalRoundsFinalization, totalRoundsFixedThreshold int) bool

HadFixedRound tells whether the vote context is in the last l2 rounds of fixed threshold

func (*Context) IsFinalized

func (vc *Context) IsFinalized(coolingOffPeriod, totalRoundsFinalization int) bool

IsFinalized tells whether this vote context is finalized by checking whether the opinion was held for totalRoundsFinalization number of rounds.

func (*Context) IsNew

func (vc *Context) IsNew() bool

IsNew tells whether the vote context is new.

func (*Context) LastOpinion

func (vc *Context) LastOpinion() opinion.Opinion

LastOpinion returns the last formed opinion.

type DRNGRoundBasedVoter

type DRNGRoundBasedVoter interface {
	Voter
	// Round starts a new round.
	Round(rand float64, delayedRoundStart ...time.Duration) error
}

DRNGRoundBasedVoter is a Voter which votes in rounds and uses random numbers which were generated in a decentralized fashion.

type Events

type Events struct {
	// Fired when an Opinion has been finalized.
	Finalized *events.Event
	// Fired when an Opinion couldn't be finalized.
	Failed *events.Event
	// Fired when a DRNGRoundBasedVoter has executed a round.
	RoundExecuted *events.Event
	// Fired when internal errors occur.
	Error *events.Event
}

Events defines events which happen on a Voter.

type ObjectType added in v0.3.2

type ObjectType uint8

ObjectType is the object type of a voting (e.g., conflict or timestamp)

type OpinionEvent

type OpinionEvent struct {
	// ID is the of the conflict.
	ID string
	// Opinion is an opinion about a conflict.
	Opinion opinion.Opinion
	// Ctx contains all relevant infos regarding the conflict.
	Ctx Context
}

OpinionEvent is the struct containing data to be passed around with Finalized and Failed events.

type RoundStats

type RoundStats struct {
	// The time it took to complete a round.
	Duration time.Duration `json:"duration"`
	// The rand number used during the round.
	RandUsed float64 `json:"rand_used"`
	// The vote contexts on which opinions were formed and queried.
	// This list does not include the vote contexts which were finalized/aborted
	// during the execution of the round.
	// Create a copy of this map if you need to modify any of its elements.
	ActiveVoteContexts map[string]*Context `json:"active_vote_contexts"`
	// The opinions which were queried during the round per opinion giver.
	QueriedOpinions []opinion.QueriedOpinions `json:"queried_opinions"`
}

RoundStats encapsulates data about an executed round.

type Voter

type Voter interface {
	// Vote submits the given ID for voting with its initial Opinion.
	Vote(id string, objectType ObjectType, initOpn opinion.Opinion) error
	// IntermediateOpinion gets intermediate Opinion about the given ID.
	IntermediateOpinion(id string) (opinion.Opinion, error)
	// Events returns the Events instance of the given Voter.
	Events() Events
}

Voter votes on hashes.

type VotingWeights added in v0.5.5

type VotingWeights struct {
	// Total base mana of opinion givers from the last query
	TotalWeights float64
	// Own mana from the last query
	OwnWeight float64
}

VotingWeights stores parameters used for weighted voting calculation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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