fix: dynamically count the digits we're going to need for the score

Solves two leftover `fixme`s to clean up things.
main
Dominique Merle 3 years ago
parent e303d53565
commit 99271d0883

@ -93,8 +93,9 @@ func (mj *MajorityJudgment) ComputeScore(tally *ProposalTally, favorContestation
analysis := &ProposalAnalysis{}
amountOfJudgments := tally.CountJudgments()
amountOfDigitsForGrade := 3 // fixme: compute
amountOfDigitsForAdhesionScore := 12 // fixme: compute
amountOfGrades := tally.CountAvailableGrades()
amountOfDigitsForGrade := countDigitsUint8(amountOfGrades)
amountOfDigitsForAdhesionScore := countDigitsUint64(amountOfJudgments * 2)
mutatedTally := tally.Copy()
for range tally.Tally { // loop once per grade
@ -110,3 +111,21 @@ func (mj *MajorityJudgment) ComputeScore(tally *ProposalTally, favorContestation
return score, nil
}
func countDigitsUint8(i uint8) (count uint64) {
for i > 0 {
i = i / 10 // euclidean division
count++
}
return
}
func countDigitsUint64(i uint64) (count uint64) {
for i > 0 {
i = i / 10 // Euclid wuz hear
count++
}
return
}

Loading…
Cancel
Save