|
|
|
@ -11,21 +11,16 @@ import (
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type PollDeliberator interface {
|
|
|
|
|
// Deliberate ranks Candidates and gathers statistics into a PollResult
|
|
|
|
|
Deliberate(poll *Poll) (result *PollResult, err error)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// _ _ _
|
|
|
|
|
// | \ | | __ _(_)_ _____
|
|
|
|
|
// | \| |/ _` | \ \ / / _ \
|
|
|
|
|
// | |\ | (_| | |\ V / __/
|
|
|
|
|
// |_| \_|\__,_|_| \_/ \___|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
type PollNaiveDeliberator struct {
|
|
|
|
|
type MajorityJudgmentDeliberator struct {
|
|
|
|
|
UseHighMean bool // should default to false ; strategy for even number of judgments
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err error) {
|
|
|
|
|
// Deliberate ranks Candidates and gathers statistics into a PollResult
|
|
|
|
|
func (deli *MajorityJudgmentDeliberator) Deliberate(poll *Poll) (_ *PollResult, err error) {
|
|
|
|
|
|
|
|
|
|
naiveTallier := &PollNaiveTallier{}
|
|
|
|
|
pollTally, err := naiveTallier.Tally(poll)
|
|
|
|
@ -56,7 +51,6 @@ func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err err
|
|
|
|
|
gradesProfile := make([]uint64, 0, amountOfGrades)
|
|
|
|
|
for i := 0; i < amountOfGrades; i++ {
|
|
|
|
|
gradesProfile = append(gradesProfile, candidateTally.Grades[i].Amount)
|
|
|
|
|
//gradesProfile = append(gradesProfile, uint64(i+1))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
meritProfile := &PollCandidateMeritProfile{
|
|
|
|
@ -65,8 +59,7 @@ func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err err
|
|
|
|
|
Position: 0, // see below
|
|
|
|
|
Grades: gradesProfile,
|
|
|
|
|
JudgmentsAmount: candidateTally.JudgmentsAmount,
|
|
|
|
|
//JudgmentsAmount: (6+1)*3,
|
|
|
|
|
CreatedUnix: creationTime,
|
|
|
|
|
CreatedUnix: creationTime,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
candidates = append(candidates, &PollCandidateResult{
|
|
|
|
@ -117,12 +110,14 @@ func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err err
|
|
|
|
|
// String scoring is not the fastest but it was within reach of a Go newbie.
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
GetScore computes the score of a Candidate
|
|
|
|
|
This method follows the following algorithm:
|
|
|
|
|
|
|
|
|
|
// Assume that each candidate has the same amount of judgments = MAX_JUDGES.
|
|
|
|
|
// (best fill with 0=REJECT to allow posterior candidate addition, cf. <paper>)
|
|
|
|
|
|
|
|
|
|
for each Candidate
|
|
|
|
|
|
|
|
|
|
tally = CandidateTally(Candidate) // sums of judgments, per grade, basically
|
|
|
|
|
score = "" // score is a string but could be raw bits
|
|
|
|
|
// When we append integers to score below,
|
|
|
|
@ -147,9 +142,8 @@ for each Candidate
|
|
|
|
|
|
|
|
|
|
// Use it later in a bubble sort or whatever
|
|
|
|
|
Candidate.score = score
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
func (deli *PollNaiveDeliberator) GetScore(pct *PollCandidateTally) (_ string) {
|
|
|
|
|
func (deli *MajorityJudgmentDeliberator) GetScore(pct *PollCandidateTally) (_ string) {
|
|
|
|
|
score := ""
|
|
|
|
|
|
|
|
|
|
ct := pct.Copy() // /!. Poll is not a copy (nor does it have to be)
|
|
|
|
|