Fix error/bug when excluding candidates in exclusive Gregory
This commit is contained in:
parent
7ad142f19d
commit
c9ff0a16fb
@ -104,6 +104,7 @@ function stepElection() {
|
|||||||
postMessage({'type': 'require_input', 'message': ex.message});
|
postMessage({'type': 'require_input', 'message': ex.message});
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
console.error(ex);
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,50 +127,51 @@ class ParcelledEGSTVCounter(UIGSTVCounter):
|
|||||||
next_preferences = SafeDict([(c, []) for c, cc in self.candidates.items()])
|
next_preferences = SafeDict([(c, []) for c, cc in self.candidates.items()])
|
||||||
next_exhausted = []
|
next_exhausted = []
|
||||||
|
|
||||||
parcel = count_card.parcels[0]
|
if len(count_card.parcels) > 0:
|
||||||
count_card.parcels.remove(parcel)
|
parcel = count_card.parcels[0]
|
||||||
|
count_card.parcels.remove(parcel)
|
||||||
# Count next preferences
|
|
||||||
for ballot, ballot_value in parcel:
|
|
||||||
__pragma__('opov')
|
|
||||||
candidate = next((c for c in ballot.preferences if self.candidates[c].state == CandidateState.HOPEFUL), None)
|
|
||||||
__pragma__('noopov')
|
|
||||||
|
|
||||||
if candidate is not None:
|
# Count next preferences
|
||||||
|
for ballot, ballot_value in parcel:
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
next_preferences[candidate].append((ballot, ballot_value))
|
candidate = next((c for c in ballot.preferences if self.candidates[c].state == CandidateState.HOPEFUL), None)
|
||||||
__pragma__('noopov')
|
__pragma__('noopov')
|
||||||
else:
|
|
||||||
next_exhausted.append((ballot, ballot_value))
|
if candidate is not None:
|
||||||
|
__pragma__('opov')
|
||||||
# Make transfers
|
next_preferences[candidate].append((ballot, ballot_value))
|
||||||
for candidate, cand_ballots in next_preferences.items():
|
__pragma__('noopov')
|
||||||
if len(cand_ballots) == 0:
|
else:
|
||||||
continue
|
next_exhausted.append((ballot, ballot_value))
|
||||||
|
|
||||||
new_parcel = []
|
# Make transfers
|
||||||
__pragma__('opov')
|
for candidate, cand_ballots in next_preferences.items():
|
||||||
self.candidates[candidate].parcels.append(new_parcel)
|
if len(cand_ballots) == 0:
|
||||||
__pragma__('noopov')
|
continue
|
||||||
|
|
||||||
|
new_parcel = []
|
||||||
|
__pragma__('opov')
|
||||||
|
self.candidates[candidate].parcels.append(new_parcel)
|
||||||
|
__pragma__('noopov')
|
||||||
|
|
||||||
|
num_votes = sum((bv for b, bv in cand_ballots), Rational('0'))
|
||||||
|
__pragma__('opov')
|
||||||
|
self.candidates[candidate].transfers += num_votes.to_num()
|
||||||
|
count_card.transfers -= num_votes.to_num()
|
||||||
|
__pragma__('noopov')
|
||||||
|
|
||||||
|
for ballot, ballot_value in cand_ballots:
|
||||||
|
new_parcel.append((ballot, ballot_value))
|
||||||
|
|
||||||
num_votes = sum((bv for b, bv in cand_ballots), Rational('0'))
|
# Credit exhausted votes
|
||||||
|
num_votes = sum((bv for b, bv in next_exhausted), Rational('0'))
|
||||||
__pragma__('opov')
|
__pragma__('opov')
|
||||||
self.candidates[candidate].transfers += num_votes.to_num()
|
self.exhausted.transfers += num_votes.to_num()
|
||||||
count_card.transfers -= num_votes.to_num()
|
count_card.transfers -= num_votes.to_num()
|
||||||
__pragma__('noopov')
|
__pragma__('noopov')
|
||||||
|
|
||||||
for ballot, ballot_value in cand_ballots:
|
for ballot, ballot_value in next_exhausted:
|
||||||
new_parcel.append((ballot, ballot_value))
|
self.exhausted.ballots.append((ballot, ballot_value))
|
||||||
|
|
||||||
# Credit exhausted votes
|
|
||||||
num_votes = sum((bv for b, bv in next_exhausted), Rational('0'))
|
|
||||||
__pragma__('opov')
|
|
||||||
self.exhausted.transfers += num_votes.to_num()
|
|
||||||
count_card.transfers -= num_votes.to_num()
|
|
||||||
__pragma__('noopov')
|
|
||||||
|
|
||||||
for ballot, ballot_value in next_exhausted:
|
|
||||||
self.exhausted.ballots.append((ballot, ballot_value))
|
|
||||||
|
|
||||||
if len(count_card.parcels) == 0:
|
if len(count_card.parcels) == 0:
|
||||||
count_card.state = CandidateState.EXCLUDED
|
count_card.state = CandidateState.EXCLUDED
|
||||||
|
Reference in New Issue
Block a user