Fix bugs in ERS97 implementation

Re-calculate votes required for election after electing a candidate
Round votes required for election up in accordance with vote rounding
This commit is contained in:
RunasSudo 2021-01-04 20:46:18 +11:00
parent a9050e4124
commit 64d23751a5
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -530,11 +530,15 @@ class BaseSTVCounter:
self.quota = self.quota.round(self.options['round_quota'], self.quota.ROUND_UP) self.quota = self.quota.round(self.options['round_quota'], self.quota.ROUND_UP)
__pragma__('noopov') __pragma__('noopov')
if self.options['quota_mode'] == 'ers97': if self.options['quota_mode'] == 'ers97' and self.num_elected < self.election.seats:
# Calculate the total active vote # Calculate the total active vote
__pragma__('opov') __pragma__('opov')
total_active_vote = sum((cc.votes for c, cc in self.candidates.items() if cc.state == CandidateState.HOPEFUL), Num('0')) + sum((cc.votes - self.quota for c, cc in self.candidates.items() if cc.votes > self.quota), Num('0')) total_active_vote = \
sum((cc.votes for c, cc in self.candidates.items() if cc.state == CandidateState.HOPEFUL or cc.state == CandidateState.EXCLUDING), Num('0')) + \
sum((cc.votes - self.quota for c, cc in self.candidates.items() if cc.votes > self.quota), Num('0'))
self.vote_required_election = total_active_vote / Num(self.election.seats - self.num_elected + 1) self.vote_required_election = total_active_vote / Num(self.election.seats - self.num_elected + 1)
if self.options['round_votes'] is not None:
self.vote_required_election = self.vote_required_election.round(self.options['round_votes'], self.vote_required_election.ROUND_UP)
__pragma__('noopov') __pragma__('noopov')
def meets_quota(self, count_card): def meets_quota(self, count_card):
@ -576,6 +580,7 @@ class BaseSTVCounter:
meets_quota.remove(x) meets_quota.remove(x)
if self.options['quota_mode'] == 'ers97': if self.options['quota_mode'] == 'ers97':
self.compute_quota()
self.elect_meeting_quota() # Repeat as the vote required for election may have changed self.elect_meeting_quota() # Repeat as the vote required for election may have changed
# ----------------- # -----------------