fix: elbow grease the copy mechanism to fix The Bug®

mj-v1.12
domi41 4 years ago
parent 29e4df2438
commit 1f168c3fa0

@ -40,7 +40,7 @@ func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err err
if 0 < missing {
candidateTally.JudgmentsAmount = pollTally.MaxJudgmentsAmount
candidateTally.Grades[0].Amount += missing
//println("Added the lost judgments", missing)
//println("Added the missing TO REJECT judgments", missing)
}
}
@ -66,7 +66,6 @@ func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err err
Grades: gradesProfile,
JudgmentsAmount: candidateTally.JudgmentsAmount,
//JudgmentsAmount: (6+1)*3,
//HalfJudgmentsAmount: candidateTally.JudgmentsAmount / 2,
CreatedUnix: creationTime,
}
@ -116,11 +115,9 @@ func (deli *PollNaiveDeliberator) Deliberate(poll *Poll) (_ *PollResult, err err
func (deli *PollNaiveDeliberator) GetScore(pct *PollCandidateTally) (_ string) {
score := ""
ct := *pct // looks like it's a copy of the primitives at least
ct := pct.Copy()
for _, _ = range pct.Poll.GetGradationList() {
//for _, _ = range pct.Poll.GetGrades() {
medianGrade := ct.GetMedian()
score += fmt.Sprintf("%03d", medianGrade)

@ -36,6 +36,26 @@ type PollCandidateTally struct {
CreatedUnix timeutil.TimeStamp
}
func (pct *PollCandidateTally) Copy() (_ *PollCandidateTally) {
grades := make([]*PollCandidateGradeTally, 0, 8)
for _, grade := range pct.Grades {
grades = append(grades, &PollCandidateGradeTally{
Grade: grade.Grade,
Amount: grade.Amount,
CreatedUnix: grade.CreatedUnix,
})
}
return &PollCandidateTally{
Poll: pct.Poll,
CandidateID: pct.CandidateID,
Grades: grades,
JudgmentsAmount: pct.JudgmentsAmount,
CreatedUnix: pct.CreatedUnix,
}
}
func (pct *PollCandidateTally) GetMedian() (_ uint8) {
if 0 == pct.JudgmentsAmount {
@ -93,7 +113,6 @@ func (pct *PollCandidateTally) GetBiggestGroup(aroundGrade uint8) (groupSize int
return aboveGroupSize, aboveGroupSign, aboveGroupGrade
}
return belowGroupSize, belowGroupSign, belowGroupGrade
}
func (pct *PollCandidateTally) RegradeJudgments(fromGrade uint8, toGrade uint8) {
@ -118,13 +137,6 @@ type PollTally struct {
CreatedUnix timeutil.TimeStamp
}
//// PollCandidateGrades implements sort.Interface based on the Score field.
//type PollCandidateGrades []*PollCandidateGradeTally
//
//func (a PollCandidateGrades) Len() int { return len(a) }
//func (a PollCandidateGrades) Less(i, j int) bool { return a[i].Score < a[j].Score }
//func (a PollCandidateGrades) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// _____ _ _ _
// |_ _|_ _| | (_) ___ _ __
// | |/ _` | | | |/ _ \ '__|

Loading…
Cancel
Save