Versions in this module Expand all Collapse all v0 v0.1.0 Apr 26, 2020 Changes in this version + const BasicPollType + const BasicVoteType + const DefaultCSVSeparator + const GeneralPollSkeletonType + const MedianPollType + const MedianVoteType + const MoneyPollSkeletonType + const SchulzePollType + const SchulzeVoteType + var DefaultParserTemplateMap = GenerateDefaultParserTemplateMap() + var DefaultSkeletonConverter = NewDefaultSkeletonConverter(true) + var ErrEmptyPollPolicy = NewPollTypeError("empty votes are not allowed") + var ErrInvalidEncoding = NewParserValidationError("invalid utf-8 encoding in input") + var ErrPoll = internalErrorSentinelType + var FiftyPercentMajority = big.NewRat(1, 2) + var TwoThirdsMajority = big.NewRat(2, 3) + func ComputePercentage(votes, votesSum Weight) *big.Rat + func CustomizeParsersToMap(polls PollMap, templates map[string]ParserCustomizer) (map[string]ParserCustomizer, error) + func DumpAbstractPollSkeleton(skel AbstractPollSkeleton, w io.Writer, currencyFormatter CurrencyFormatter) (int, error) + func FormatPercentage(percent *big.Rat) string + func GenerateDefaultParserTemplateMap() map[string]ParserCustomizer + func HasDuplicateVoters(voters []*Voter) (string, bool) + type AbstractPoll interface + AddVote func(vote AbstractVote) error + PollType func() string + func ConvertSkeletonsToPolls(skeletons []AbstractPollSkeleton, converterFunction SkeletonConverter) ([]AbstractPoll, error) + type AbstractPollSkeleton interface + GetName func() string + SkeletonType func() string + type AbstractVote interface + GetVoter func() *Voter + VoteType func() string + type BasicPoll struct + Votes []*BasicVote + func NewBasicPoll(votes []*BasicVote) *BasicPoll + func (poll *BasicPoll) AddVote(vote AbstractVote) error + func (poll *BasicPoll) GenerateVoteFromBasicAnswer(voter *Voter, answer BasicPollAnswer) (AbstractVote, error) + func (poll *BasicPoll) PollType() string + func (poll *BasicPoll) Tally() *BasicPollResult + func (poll *BasicPoll) TruncateVoters() []*BasicVote + type BasicPollAnswer int8 + const Abstention + const Aye + const No + func (a BasicPollAnswer) IsValid() bool + func (a BasicPollAnswer) String() string + type BasicPollCounter struct + NumAbstention Weight + NumAyes Weight + NumInvalid Weight + NumNoes Weight + func NewBasicPollCounter() *BasicPollCounter + func (counter *BasicPollCounter) Equals(other *BasicPollCounter) bool + func (counter *BasicPollCounter) Increase(choice BasicPollAnswer, inc Weight) + type BasicPollResult struct + NumberVoters *BasicPollCounter + VotersCount Weight + VotesSum Weight + WeightedVotes *BasicPollCounter + func NewBasicPollResult() *BasicPollResult + type BasicVote struct + Choice BasicPollAnswer + Voter *Voter + func NewBasicVote(voter *Voter, choice BasicPollAnswer) *BasicVote + func (vote *BasicVote) GetVoter() *Voter + func (vote *BasicVote) VoteType() string + type BasicVoteParser struct + AbstentionValues LowerStringSet + AllowRankingStyle bool + AyeValues LowerStringSet + NoValues LowerStringSet + func NewBasicVoteParser() *BasicVoteParser + func (parser *BasicVoteParser) CustomizeForPoll(poll AbstractPoll) (ParserCustomizer, error) + func (parser *BasicVoteParser) ParseFromString(s string, voter *Voter) (AbstractVote, error) + type CurrencyFormatter interface + Format func(value CurrencyValue) string + type CurrencyHandler interface + var DefaultCurrencyHandler CurrencyHandler = SimpleEuroHandler{} + type CurrencyParser interface + Parse func(s string) (CurrencyValue, error) + type CurrencyValue struct + Currency string + ValueCents int + func NewCurrencyValue(valueCents int, currency string) CurrencyValue + func (value CurrencyValue) Copy() CurrencyValue + func (value CurrencyValue) DefaultFormatString(sep string) string + func (value CurrencyValue) Equals(other CurrencyValue) bool + func (value CurrencyValue) String() string + type DuplicateError struct + Msg string + func NewDuplicateError(msg string) DuplicateError + func (err DuplicateError) Error() string + type EmptyVotePolicy int8 + const AddAsAbstentionEmptyVote + const AddAsAyeEmptyVote + const AddAsNoEmptyVote + const IgnoreEmptyVote + const RaiseErrorEmptyVote + func GeneratePoliciesList(policy EmptyVotePolicy, num int) []EmptyVotePolicy + func (policy EmptyVotePolicy) GenerateEmptyVoteForVoter(voter *Voter, poll AbstractPoll) (AbstractVote, error) + type LowerStringSet map[string]struct + func NewLowerStringSet(elements []string) LowerStringSet + func (s LowerStringSet) Contains(element string) bool + func (s LowerStringSet) ContainsLowercase(element string) bool + func (s LowerStringSet) Extend(elements []string) + func (s LowerStringSet) Insert(element string) + func (s LowerStringSet) String() string + type MedianPoll struct + Sorted bool + Value MedianUnit + Votes []*MedianVote + func NewMedianPoll(value MedianUnit, votes []*MedianVote) *MedianPoll + func (poll *MedianPoll) AddVote(vote AbstractVote) error + func (poll *MedianPoll) AssureSorted() + func (poll *MedianPoll) GenerateVoteFromBasicAnswer(voter *Voter, answer BasicPollAnswer) (AbstractVote, error) + func (poll *MedianPoll) PollType() string + func (poll *MedianPoll) SortVotes() + func (poll *MedianPoll) Tally(majority Weight) *MedianResult + func (poll *MedianPoll) TruncateVoters() []*MedianVote + func (poll *MedianPoll) WeightSum() Weight + type MedianResult struct + MajorityValue MedianUnit + RequiredMajority Weight + ValueDetails map[MedianUnit][]*Voter + WeightSum Weight + func NewMedianResult() *MedianResult + func (result *MedianResult) GetVotersForValue(referenceValue MedianUnit) []*Voter + type MedianUnit uint64 + const NoMedianUnitValue + func ParseMedianUnit(s string) (MedianUnit, error) + type MedianVote struct + Value MedianUnit + Voter *Voter + func NewMedianVote(voter *Voter, value MedianUnit) *MedianVote + func (vote *MedianVote) GetVoter() *Voter + func (vote *MedianVote) VoteType() string + type MedianVoteParser struct + func NewMedianVoteParser(currencyParser CurrencyParser) *MedianVoteParser + func (parser *MedianVoteParser) CustomizeForPoll(poll AbstractPoll) (ParserCustomizer, error) + func (parser *MedianVoteParser) ParseFromString(s string, voter *Voter) (AbstractVote, error) + func (parser *MedianVoteParser) WithMaxValue(maxValue MedianUnit) *MedianVoteParser + type MoneyPollSkeleton struct + Name string + Value CurrencyValue + func NewMoneyPollSkeleton(name string, value CurrencyValue) *MoneyPollSkeleton + func (skel *MoneyPollSkeleton) Dump(w io.Writer, currencyFormatter CurrencyFormatter) (int, error) + func (skel *MoneyPollSkeleton) GetName() string + func (skel *MoneyPollSkeleton) SkeletonType() string + type ParserCustomizer interface + CustomizeForPoll func(poll AbstractPoll) (ParserCustomizer, error) + func CustomizeParsers(polls []AbstractPoll, templates map[string]ParserCustomizer) ([]ParserCustomizer, error) + type ParserValidationError struct + Message string + func NewParserValidationError(msg string) *ParserValidationError + func (err ParserValidationError) Error() string + func (err ParserValidationError) Unwrap() error + type PolicyMap map[string]EmptyVotePolicy + func GeneratePoliciesMap(policy EmptyVotePolicy, polls PollMap) PolicyMap + type PollCollectionParser struct + MaxCurrencyValue int + MaxGroupNameLength int + MaxLineLength int + MaxNumLines int + MaxNumOptions int + MaxNumPolls int + MaxOptionLength int + MaxPollNameLength int + MaxTitleLength int + func NewPollCollectionParser() *PollCollectionParser + func (parser *PollCollectionParser) ParseCollectionSkeletons(r io.Reader, currencyParser CurrencyParser) (*PollSkeletonCollection, error) + func (parser *PollCollectionParser) ParseCollectionSkeletonsFromString(currencyParser CurrencyParser, s string) (*PollSkeletonCollection, error) + type PollError struct + func (pollErr PollError) Is(err error) bool + type PollGroup struct + Skeletons []AbstractPollSkeleton + Title string + func NewPollGroup(title string) *PollGroup + func (group *PollGroup) Dump(w io.Writer, currencyFormatter CurrencyFormatter) (int, error) + func (group *PollGroup) NumSkeletons() int + type PollMap map[string]AbstractPoll + func ConvertSkeletonMapToEmptyPolls(skeletons PollSkeletonMap, converterFunction SkeletonConverter) (PollMap, error) + type PollMatrix struct + Body [][]string + Head []string + func ReadMatrixFromCSV(r *VotesCSVReader) (*PollMatrix, error) + func (m *PollMatrix) FillPollsWithVotes(polls PollMap, voters VoterMap, parsers map[string]VoteParser, ...) (actualVoters VoterMap, actualPolls PollMap, err error) + func (m *PollMatrix) MatchEntries(voters VoterMap, polls PollMap) (matchedVoters VoterMap, matchedPolls PollMap, err error) + type PollSkeleton struct + Name string + Options []string + func NewPollSkeleton(name string) *PollSkeleton + func (skel *PollSkeleton) Dump(w io.Writer) (int, error) + func (skel *PollSkeleton) GetName() string + func (skel *PollSkeleton) SkeletonType() string + type PollSkeletonCollection struct + Groups []*PollGroup + Title string + func NewPollSkeletonCollection(title string) *PollSkeletonCollection + func (coll *PollSkeletonCollection) CollectSkeletons() []AbstractPollSkeleton + func (coll *PollSkeletonCollection) Dump(w io.Writer, currencyFormatter CurrencyFormatter) (int, error) + func (coll *PollSkeletonCollection) HasDuplicateSkeleton() (string, bool) + func (coll *PollSkeletonCollection) HasSkeleton() bool + func (coll *PollSkeletonCollection) NumGroups() int + func (coll *PollSkeletonCollection) NumSkeletons() int + func (coll *PollSkeletonCollection) SkeletonsToMap() (PollSkeletonMap, error) + type PollSkeletonMap map[string]AbstractPollSkeleton + type PollTypeError struct + Msg string + func NewPollTypeError(msg string, a ...interface{}) PollTypeError + func (err PollTypeError) Error() string + type PollingSemanticError struct + Err error + Msg string + func NewPollingSemanticError(err error, msg string, a ...interface{}) PollingSemanticError + func (err PollingSemanticError) Error() string + func (err PollingSemanticError) Unwrap() error + type PollingSyntaxError struct + Err error + LineNum int + Msg string + func NewPollingSyntaxError(err error, msg string, a ...interface{}) PollingSyntaxError + func (err PollingSyntaxError) Error() string + func (err PollingSyntaxError) Unwrap() error + func (err PollingSyntaxError) WithLineNum(lineNum int) PollingSyntaxError + type RawCentCurrencyHandler struct + func NewRawCentCurrencyParser() RawCentCurrencyHandler + func (h RawCentCurrencyHandler) Format(value CurrencyValue) string + func (h RawCentCurrencyHandler) Parse(s string) (CurrencyValue, error) + type SchulzeMatrix [][]Weight + func NewSchulzeMatrix(dimension int) SchulzeMatrix + func (m SchulzeMatrix) Equals(other SchulzeMatrix) bool + type SchulzePoll struct + NumOptions int + Votes []*SchulzeVote + func NewSchulzePoll(numOptions int, votes []*SchulzeVote) *SchulzePoll + func (poll *SchulzePoll) AddVote(vote AbstractVote) error + func (poll *SchulzePoll) GenerateVoteFromBasicAnswer(voter *Voter, answer BasicPollAnswer) (AbstractVote, error) + func (poll *SchulzePoll) PollType() string + func (poll *SchulzePoll) Tally() *SchulzeResult + func (poll *SchulzePoll) TruncateVoters() []*SchulzeVote + type SchulzeRanking []int + func NewSchulzeAbstention(numOptions int) SchulzeRanking + func NewSchulzeAye(numOptions int) SchulzeRanking + func NewSchulzeNo(numOptions int) SchulzeRanking + func NewSchulzeRanking() SchulzeRanking + func (ranking SchulzeRanking) IsAbstention() bool + type SchulzeResult struct + D SchulzeMatrix + DNonStrict SchulzeMatrix + P SchulzeMatrix + RankedGroups SchulzeWinsList + WeightSum Weight + func NewSchulzeResult(d, dNonStrict, p SchulzeMatrix, rankedGroups SchulzeWinsList, votesSum Weight) *SchulzeResult + func (schulzeRes *SchulzeResult) BetterOrEqualNo() []Weight + func (schulzeRes *SchulzeResult) StrictlyBetterThanNo() []Weight + type SchulzeVote struct + Ranking SchulzeRanking + Voter *Voter + func NewSchulzeVote(voter *Voter, ranking SchulzeRanking) *SchulzeVote + func (vote *SchulzeVote) GetVoter() *Voter + func (vote *SchulzeVote) VoteType() string + type SchulzeVoteParser struct + Length int + func NewSchulzeVoteParser(length int) *SchulzeVoteParser + func (parser *SchulzeVoteParser) CustomizeForPoll(poll AbstractPoll) (ParserCustomizer, error) + func (parser *SchulzeVoteParser) ParseFromString(s string, voter *Voter) (AbstractVote, error) + func (parser *SchulzeVoteParser) WithLength(length int) *SchulzeVoteParser + type SchulzeWinsList [][]int + type SimpleEuroHandler struct + func (h SimpleEuroHandler) Format(value CurrencyValue) string + func (h SimpleEuroHandler) Parse(s string) (CurrencyValue, error) + type SkeletonConverter func(skel AbstractPollSkeleton) (AbstractPoll, error) + func NewDefaultSkeletonConverter(convertToBasic bool) SkeletonConverter + type VoteGenerator interface + GenerateVoteFromBasicAnswer func(voter *Voter, answer BasicPollAnswer) (AbstractVote, error) + type VoteParser interface + ParseFromString func(s string, voter *Voter) (AbstractVote, error) + type Voter struct + Name string + Weight Weight + func NewVoter(name string, weight Weight) *Voter + func (voter *Voter) Equals(other *Voter) bool + func (voter *Voter) Format(indent string) string + type VoterMap map[string]*Voter + func VotersToMap(voters []*Voter) (VoterMap, error) + type VotersParser struct + MaxLineLength int + MaxNumLines int + MaxNumVoters int + MaxVotersNameLength int + MaxVotersWeight Weight + func NewVotersParser() *VotersParser + func (parser *VotersParser) ComputeDefaultMaxLineLength() + func (parser *VotersParser) ParseVoters(r io.Reader) ([]*Voter, error) + func (parser *VotersParser) ParseVotersFromString(s string) ([]*Voter, error) + func (parser *VotersParser) ParseVotersLine(s string) (*Voter, error) + type VotesCSVReader struct + MaxNumLines int + MaxPollNameLength int + MaxRecordLength int + MaxVotersNameLength int + Sep rune + func NewVotesCSVReader(r io.Reader) *VotesCSVReader + func (r *VotesCSVReader) ReadRecords() (head []string, lines [][]string, err error) + type VotesCSVWriter struct + Sep rune + func NewVotesCSVWriter(w io.Writer) *VotesCSVWriter + func (w *VotesCSVWriter) GenerateEmptyTemplate(voters []*Voter, skels []AbstractPollSkeleton) error + type Weight uint32 + const NoWeight + func ComputeMajority(majority *big.Rat, votesSum Weight) Weight + func ParseWeight(s string) (Weight, error) + func WeightMax(a, b Weight) Weight + func WeightMin(a, b Weight) Weight