Documentation ¶
Index ¶
- func CreateDefaultPalette(amountOfColors int) color.Palette
- func DumpColorHexString(c color.Color, prefix string, withAlpha bool) string
- func DumpPaletteHexString(palette color.Palette, separator string, quote string) string
- type DeliberatorInterface
- type MajorityJudgment
- type PollResult
- type PollTally
- type ProposalAnalysis
- type ProposalResult
- type ProposalTally
- func (proposalTally *ProposalTally) Analyze() (_ *ProposalAnalysis)
- func (proposalTally *ProposalTally) Copy() (_ *ProposalTally)
- func (proposalTally *ProposalTally) CountAvailableGrades() (_ uint8)
- func (proposalTally *ProposalTally) CountJudgments() (_ uint64)
- func (proposalTally *ProposalTally) FillWithMedianDefault(upToAmount uint64) (err error)
- func (proposalTally *ProposalTally) FillWithStaticDefault(upToAmount uint64, defaultGrade uint8) (err error)
- func (proposalTally *ProposalTally) RegradeJudgments(fromGrade uint8, intoGrade uint8) (err error)
- type ProposalsResults
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateDefaultPalette ¶ added in v0.3.0
CreateDefaultPalette returns a Palette of amountOfColors colors. 7 colors we use, red to green: "#df3222", "#ed6f01", "#fab001", "#c5d300", "#7bbd3e", "#00a249", "#017a36" When requiring more than 7, we interpolate in HSV space. This tries to be fault-tolerant, and returns an empty palette upon trouble.
func DumpColorHexString ¶ added in v0.3.0
DumpColorHexString outputs strings like #ff3399 or #ff3399ff with alpha Be mindful that PRECISION IS LOST because hex format has less bits
Types ¶
type DeliberatorInterface ¶
type DeliberatorInterface interface {
Deliberate(tally *PollTally) (result *PollResult, err error)
}
DeliberatorInterface ought to be implemented by all deliberators ; not overly useful for now, but hey.
type MajorityJudgment ¶
type MajorityJudgment struct {
// contains filtered or unexported fields
}
MajorityJudgment is one of the deliberators ; it implements DeliberatorInterface.
func (*MajorityJudgment) ComputeScore ¶
func (mj *MajorityJudgment) ComputeScore(tally *ProposalTally, favorContestation bool) (_ string, err error)
ComputeScore is the heart of our MajorityJudgment Deliberator. Not sure it should be exported, though. See docs/score-calculus-flowchart.png
func (*MajorityJudgment) Deliberate ¶
func (mj *MajorityJudgment) Deliberate(tally *PollTally) (_ *PollResult, err error)
Deliberate is part of the DeliberatorInterface
type PollResult ¶
type PollResult struct { Proposals ProposalsResults `json:"proposals"` // matches the order of the input proposals' tallies ProposalsSorted ProposalsResults `json:"proposalsSorted"` // same Results, but sorted by Rank this time }
PollResult holds the result for each proposal, in the original proposal order, or sorted by Rank.
type PollTally ¶
type PollTally struct { AmountOfJudges uint64 `json:"amountOfJudges"` // Helps balancing tallies using default judgments. Proposals []*ProposalTally `json:"proposals"` // Tallies of each proposal. Its order is preserved in the result. }
PollTally describes the amount of judgments received by each proposal on each grade.
func (*PollTally) BalanceWithMedianDefault ¶
BalanceWithMedianDefault mutates the PollTally
func (*PollTally) BalanceWithStaticDefault ¶
BalanceWithStaticDefault makes sure all proposals received the same amount of judgments, by filling the gaps with judgments of the specified default grade. This method mutates the PollTally
func (*PollTally) GuessAmountOfJudges ¶ added in v0.2.0
GuessAmountOfJudges returns the guess and mutates the PollTally by filling the AmountOfJudges property
type ProposalAnalysis ¶
type ProposalAnalysis struct { TotalSize uint64 `json:"totalSize"` // total amount of judges|judgments across all grades MedianGrade uint8 `json:"medianGrade"` // 0 == "worst" grade, goes up to the amount of grades - 1 MedianGroupSize uint64 `json:"medianGroupSize"` // in judges|judgments SecondMedianGrade uint8 `json:"secondMedianGrade"` // used in Majority Judgment deliberation SecondGroupSize uint64 `json:"secondGroupSize"` // either adhesion or contestation, whichever is bigger SecondGroupSign int `json:"secondGroupSign"` // -1 for contestation group, +1 for adhesion group AdhesionGroupGrade uint8 `json:"adhesionGroupGrade"` AdhesionGroupSize uint64 `json:"adhesionGroupSize"` ContestationGroupGrade uint8 `json:"contestationGroupGrade"` ContestationGroupSize uint64 `json:"contestationGroupSize"` }
ProposalAnalysis holds some data we need to compute the Score of a Proposal, and hence its Rank.
func (*ProposalAnalysis) Reset ¶
func (analysis *ProposalAnalysis) Reset()
Reset the ProposalAnalysis to default values.
func (*ProposalAnalysis) Run ¶
func (analysis *ProposalAnalysis) Run(proposalTally *ProposalTally, favorContestation bool)
Run MUTATES THE ANALYSIS, but leaves the proposalTally intact, unchanged. MJ uses the low median by default (favors contestation), but there's a parameter if need be. This method is deemed complex by gocyclo ; there's no way around it.
type ProposalResult ¶
type ProposalResult struct { Index int `json:"index"` // Index of the proposal in the input proposals' tallies. Useful with ProposalSorted. Rank int `json:"rank"` // Rank starts at 1 (best) and goes upwards. Equal Proposals share the same rank. Score string `json:"score"` // Higher Score lexicographically → better Rank. Analysis *ProposalAnalysis `json:"analysis"` Tally *ProposalTally `json:"tally"` // The tally of grades that generated this result. }
ProposalResult holds the computed Rank for a proposal, as well as analysis data.
type ProposalTally ¶
type ProposalTally struct {
Tally []uint64 `json:"tally"` // Amount of judgments received for each grade, from "worst" grade to "best" grade.
}
ProposalTally holds the amount of judgments received per Grade for a single Proposal
func (*ProposalTally) Analyze ¶
func (proposalTally *ProposalTally) Analyze() (_ *ProposalAnalysis)
Analyze a ProposalTally and return its ProposalAnalysis
func (*ProposalTally) Copy ¶
func (proposalTally *ProposalTally) Copy() (_ *ProposalTally)
Copy a ProposalTally (deeply)
func (*ProposalTally) CountAvailableGrades ¶
func (proposalTally *ProposalTally) CountAvailableGrades() (_ uint8)
CountAvailableGrades returns the amount of available grades in the poll (usually 7 or so).
func (*ProposalTally) CountJudgments ¶
func (proposalTally *ProposalTally) CountJudgments() (_ uint64)
CountJudgments tallies the received judgments by a Proposal
func (*ProposalTally) FillWithMedianDefault ¶
func (proposalTally *ProposalTally) FillWithMedianDefault(upToAmount uint64) (err error)
FillWithMedianDefault adds ballots of the majority grade so that the tally grows up to the specified amount This method mutates the proposalTally
func (*ProposalTally) FillWithStaticDefault ¶
func (proposalTally *ProposalTally) FillWithStaticDefault(upToAmount uint64, defaultGrade uint8) (err error)
FillWithStaticDefault adds ballots of the specified grade so that the tally grows up to the specified amount This method mutates the proposalTally
func (*ProposalTally) RegradeJudgments ¶
func (proposalTally *ProposalTally) RegradeJudgments(fromGrade uint8, intoGrade uint8) (err error)
RegradeJudgments mutates the proposalTally by moving judgments from one grade to another. Useful when computing the score ; perhaps this method should not be exported, though.
type ProposalsResults ¶
type ProposalsResults []*ProposalResult
ProposalsResults implements sort.Interface based on the Score field.
func (ProposalsResults) Less ¶
func (a ProposalsResults) Less(i, j int) bool
Less is part of sort.Interface
func (ProposalsResults) Swap ¶
func (a ProposalsResults) Swap(i, j int)
Swap is part of sort.Interface