Documentation ¶
Index ¶
- Constants
- func GenKeyPair() ([][]byte, error)
- func InsertCategory(context *VotingContext, name string) error
- func InsertVoters(context *VotingContext, revisionID uint, voters []*Voter) error
- func InsertVotersRevision(context *VotingContext, categoryID uint) error
- func IntMax(a, b int) int
- func IntMin(a, b int) int
- func Now() time.Time
- func ReadKeyPairs(path string) ([][]byte, error)
- func SortMedianVotes(votes []*MedianVote)
- func TimeFromScanType(val interface{}) (time.Time, error)
- func WriteKeyPairs(path string, keyPairs ...[]byte) error
- type Category
- type IntMatrix
- type MedianResult
- type MedianVote
- type MedianVoting
- type SchulzeRes
- type SchulzeVote
- type SchulzeVoting
- type SyntaxError
- type Voter
- type VotersRevision
- type VotingCollection
- type VotingContext
- type VotingGroup
Constants ¶
const InvalidID = ^uint(0)
Variables ¶
This section is empty.
Functions ¶
func GenKeyPair ¶
func InsertCategory ¶
func InsertCategory(context *VotingContext, name string) error
func InsertVoters ¶
func InsertVoters(context *VotingContext, revisionID uint, voters []*Voter) error
func InsertVotersRevision ¶
func InsertVotersRevision(context *VotingContext, categoryID uint) error
func ReadKeyPairs ¶
func SortMedianVotes ¶
func SortMedianVotes(votes []*MedianVote)
SortMedianVotes sorts the votes according to the voted value. Votes with hightest values come first.
func TimeFromScanType ¶
DefaultTimeFromScanType is the default function to return database entries to a time.Time.
func WriteKeyPairs ¶
Types ¶
type Category ¶
func ListCategories ¶
func ListCategories(context *VotingContext) ([]*Category, error)
type MedianResult ¶
type MedianResult struct { // Value is the value that has a majority. Value int // VotesRequired is the number of votes required for a majority. VotesRequired int }
MedianResult is a result type for median votings.
func EvaluateMedian ¶
func EvaluateMedian(votes []*MedianVote, percentRequired float64) *MedianResult
EvaluateMedian evalues all votes given in votes and returns the greatest value that has a majority. percentRequired is a float and should be greater than 0 and lesser than 1. It describes how many percents of all votes are required for a majority. It returns 0 for value if no value was agreed upon.
type MedianVote ¶
type MedianVote struct { // Weight is the weight of the voter. Weight int // Value is the value the voter chose. Value int }
MedianVote is used as a vote in a median procedure. It contains information about the weight of the voter and the value chosen.
func NewMedianVote ¶
func NewMedianVote(weight, value int) *MedianVote
NewMedianVote returns a new MedianVote.
type MedianVoting ¶
func (*MedianVoting) String ¶
func (voting *MedianVoting) String() string
type SchulzeRes ¶
type SchulzeRes struct { // VotesRequired is the number of votes required for a majority. VotesRequired int // D is the matrix d as described in Wikipedia. D IntMatrix // P is the matrix p as described in Wikipedia. P IntMatrix // Ranked contains the result of the ranking algorithm. // It contains a list of list of integers. // The first list contains all options that are winners, // the second list contains all options that are on the second place etc. Ranked [][]int // Percents is a list of length n - 1 containing the percentage of votes // that voted the options 0...n-1 before no (no being the last option). // So if there are three options and 50% voted option 1 before no and // 75% voted option 2 before no this slice will be [0.5, 0.75]. Percents []float64 }
SchulzeRes is the result returned by the schulze method.
func EvaluateSchulze ¶
func EvaluateSchulze(votes []*SchulzeVote, n int, percentRequired float64) (*SchulzeRes, error)
EvaluateSchulze evaluates the Schulze method. votes contains all votes to be evaluated, n is the number of options in the voting (so all votes must have a Ranking slice of length n) and percentRequired is a float and should be greater than 0 and lesser than 1. It describes how many percents of all votes are required for a majority.
type SchulzeVote ¶
type SchulzeVote struct { // Weight is the weight of the voter. Weight int // Ranking is the ordering for all options. // It must be a list of n elements if n is the number of possible options // where Ordering[i] is the value in the ranking. // Smaller values mean that the option is voted higher (comes first) in the // ranking. // For example: If there are three options and the first and third one should // be equally preferred to option two the ranking would be // [0, 1, 0]. Ranking []int }
SchulzeVote is a vote used in the Schulze procedure.
func NewSchulzeVote ¶
func NewSchulzeVote(weight int, ranking []int) *SchulzeVote
NewSchulzeVote returns a new SchulzeVote. See struct documentation for details.
type SchulzeVoting ¶
func (*SchulzeVoting) String ¶
func (voting *SchulzeVoting) String() string
type SyntaxError ¶
type SyntaxError struct {
// contains filtered or unexported fields
}
func NewSyntaxError ¶
func NewSyntaxError(lineNumber int, message string) *SyntaxError
func (*SyntaxError) Error ¶
func (err *SyntaxError) Error() string
type Voter ¶
func ListVoters ¶
func ListVoters(context *VotingContext, revisionID uint) ([]*Voter, error)
type VotersRevision ¶
func ListVotersRevision ¶
func ListVotersRevision(context *VotingContext, categoryID uint) ([]*VotersRevision, error)
type VotingCollection ¶
type VotingCollection struct { Name string Date time.Time Groups []*VotingGroup }
func ParseVotingCollection ¶
func ParseVotingCollection(r io.Reader) (*VotingCollection, error)
func (*VotingCollection) String ¶
func (collection *VotingCollection) String() string
type VotingContext ¶
type VotingContext struct { DB *sql.DB ConfigDir string Store sessions.Store Logger *logrus.Logger UserHandler goauth.UserHandler SessionController *goauth.SessionController Keys [][]byte Templates map[string]*template.Template SessionLifespan time.Duration Port int }
func ParseConfig ¶
func ParseConfig(configDir string) (*VotingContext, error)
func (*VotingContext) ReadOrCreateKeys ¶
func (context *VotingContext) ReadOrCreateKeys()
type VotingGroup ¶
type VotingGroup struct { Name string MedianVotings []*MedianVoting SchulzeVotings []*SchulzeVoting }
func (*VotingGroup) String ¶
func (group *VotingGroup) String() string