|
|
|
extends Resource
|
|
|
|
class_name MajorityJudgmentPollTally
|
|
|
|
|
|
|
|
"""
|
|
|
|
Generated by one of the implementations of
|
|
|
|
MajorityJudgmentAbstractTallier.
|
|
|
|
|
|
|
|
It should hold all the data we need to display the results.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
export(Resource) var poll #:MajorityJudgmentPoll
|
|
|
|
|
|
|
|
|
|
|
|
# Array of MajorityJudgmentCandidateTally
|
|
|
|
# Sorted from best to worst, sometimes arbitrary
|
|
|
|
# as some candidates may have the exact same position,
|
|
|
|
# because they have the exact same merit profile,
|
|
|
|
# so check each MajorityJudgmentCandidateTally.position.
|
|
|
|
export(Array, Resource) var candidates_tallies:Array
|
|
|
|
|
|
|
|
|
|
|
|
func get_tally_of_candidate(candidate:MajorityJudgmentCandidate) -> MajorityJudgmentCandidateTally:
|
|
|
|
for candidate_tally in self.candidates_tallies:
|
|
|
|
if candidate_tally.candidate == candidate:
|
|
|
|
return candidate_tally
|
|
|
|
assert(false, "Candidate tally not found.")
|
|
|
|
return MajorityJudgmentCandidateTally.new() # urgh
|
|
|
|
|
|
|
|
|
|
|
|
func get_position_of_candidate(candidate:MajorityJudgmentCandidate, unique=false) -> int:
|
|
|
|
if unique:
|
|
|
|
var position := 0
|
|
|
|
for candidate_tally in self.candidates_tallies:
|
|
|
|
if candidate_tally.candidate == candidate:
|
|
|
|
return position
|
|
|
|
position += 1
|
|
|
|
else:
|
|
|
|
for candidate_tally in self.candidates_tallies:
|
|
|
|
if candidate_tally.candidate == candidate:
|
|
|
|
return candidate_tally.position
|
|
|
|
|
|
|
|
assert(false, "Candidate cannot be found.")
|
|
|
|
return -1
|
|
|
|
|