feat: add the Index and Analysis to the ProposalResult

main
Dominique Merle 3 years ago
parent 34de1982b5
commit 013ff7456a

@ -52,15 +52,16 @@ func (mj *MajorityJudgment) Deliberate(tally *PollTally) (_ *PollResult, err err
proposalsResults := make(ProposalsResults, 0, 16)
proposalsResultsSorted := make(ProposalsResults, 0, 16)
for _, proposalTally := range tally.Proposals {
for proposalIndex, proposalTally := range tally.Proposals {
score, scoreErr := mj.ComputeScore(proposalTally, true)
if nil != scoreErr {
return nil, scoreErr
}
proposalResult := &ProposalResult{
Rank: 0, // we set it below after the sort
Score: score,
//Analysis: proposalTally.Analyze(),
Index: proposalIndex,
Score: score,
Analysis: proposalTally.Analyze(),
Rank: 0, // we set it below after the sort
}
proposalsResults = append(proposalsResults, proposalResult)
proposalsResultsSorted = append(proposalsResultsSorted, proposalResult)

@ -5,9 +5,10 @@ type PollResult struct {
}
type ProposalResult struct {
Index int // index of the proposal in the input proposals' tallies
Rank int // Rank starts at 1 (best) and goes upwards. Equal Proposals share the same rank.
Score string // higher lexicographically → better rank
Index int // index of the proposal in the input proposals' tallies
Rank int // Rank starts at 1 (best) and goes upwards. Equal Proposals share the same rank.
Score string // higher lexicographically → better rank
Analysis *ProposalAnalysis
}
// ProposalsResults implements sort.Interface based on the Score field.

@ -52,3 +52,9 @@ func (proposalTally *ProposalTally) RegradeJudgments(fromGrade uint8, intoGrade
return nil
}
func (proposalTally *ProposalTally) Analyze() (_ *ProposalAnalysis) {
analysis := &ProposalAnalysis{}
analysis.Run(proposalTally, true)
return analysis
}

Loading…
Cancel
Save