Minor tweaks

Show progressive transfers during exclusive Gregory exclusion
Don't perform bulk election in the middle of an exclusion
Limit decimals displayed if using fixed numbers with < 2 dps
This commit is contained in:
RunasSudo 2020-12-27 21:50:30 +11:00
parent f6596bd8e8
commit 4e06dfe068
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 23 additions and 20 deletions

View File

@ -213,9 +213,12 @@ async function clickCount() {
if (countCard.state === py.pyRCV2.model.CandidateState.WITHDRAWN) {
elTd.classList.add('excluded');
elTd.innerText = 'WD';
} else if (countCard.state === py.pyRCV2.model.CandidateState.EXCLUDED || countCard.state === py.pyRCV2.model.CandidateState.EXCLUDING) {
} else if (countCard.state === py.pyRCV2.model.CandidateState.EXCLUDED) {
elTd.classList.add('excluded');
elTd.innerText = 'Ex';
} else if (countCard.state === py.pyRCV2.model.CandidateState.EXCLUDING) {
elTd.classList.add('excluded');
elTd.innerText = countCard.votes;
} else {
elTd.innerText = countCard.votes;
}

View File

@ -34,6 +34,8 @@ onmessage = function(evt) {
py.pyRCV2.numbers.set_dps(evt.data.fixedDPs);
}
let ppDP = evt.data.fixedDPs > 2 ? 2 : evt.data.fixedDPs;
let election = py.pyRCV2.blt.readBLT(evt.data.data);
postMessage({'type': 'init', 'election': {
'candidates': election.candidates.map(c => c.py_name)
@ -63,20 +65,20 @@ onmessage = function(evt) {
postMessage({'type': 'result', 'result': {
'comment': result.comment,
'candidates': result.candidates.py_items().map(([c, cc]) => [c.py_name, {
'transfers': cc.transfers.pp(2),
'votes': cc.votes.pp(2),
'transfers': cc.transfers.pp(ppDP),
'votes': cc.votes.pp(ppDP),
'state': cc.state
}]),
'exhausted': {
'transfers': result.exhausted.transfers.pp(2),
'votes': result.exhausted.votes.pp(2)
'transfers': result.exhausted.transfers.pp(ppDP),
'votes': result.exhausted.votes.pp(ppDP)
},
'loss_fraction': {
'transfers': result.loss_fraction.transfers.pp(2),
'votes': result.loss_fraction.votes.pp(2)
'transfers': result.loss_fraction.transfers.pp(ppDP),
'votes': result.loss_fraction.votes.pp(ppDP)
},
'total': result.total.pp(2),
'quota': result.quota.pp(2)
'total': result.total.pp(ppDP),
'quota': result.quota.pp(ppDP)
}});
// Step election
@ -89,20 +91,20 @@ onmessage = function(evt) {
postMessage({'type': 'result', 'result': {
'comment': result.comment,
'candidates': result.candidates.py_items().map(([c, cc]) => [c.py_name, {
'transfers': cc.transfers.pp(2),
'votes': cc.votes.pp(2),
'transfers': cc.transfers.pp(ppDP),
'votes': cc.votes.pp(ppDP),
'state': cc.state
}]),
'exhausted': {
'transfers': result.exhausted.transfers.pp(2),
'votes': result.exhausted.votes.pp(2)
'transfers': result.exhausted.transfers.pp(ppDP),
'votes': result.exhausted.votes.pp(ppDP)
},
'loss_fraction': {
'transfers': result.loss_fraction.transfers.pp(2),
'votes': result.loss_fraction.votes.pp(2)
'transfers': result.loss_fraction.transfers.pp(ppDP),
'votes': result.loss_fraction.votes.pp(ppDP)
},
'total': result.total.pp(2),
'quota': result.quota.pp(2)
'total': result.total.pp(ppDP),
'quota': result.quota.pp(ppDP)
}});
}
}

View File

@ -157,9 +157,7 @@ class BaseSTVCounter:
# Are there just enough candidates to fill all the seats?
if self.options['bulk_elect']:
if self.num_elected + sum(1 for c, cc in self.candidates.items() if cc.state == CandidateState.HOPEFUL) <= self.election.seats:
# TODO: Sort by size
if self.num_elected + sum(1 for c, cc in self.candidates.items() if cc.state == CandidateState.HOPEFUL or cc.state == CandidateState.EXCLUDING) <= self.election.seats:
# Declare elected all remaining candidates
for candidate, count_card in self.candidates.items():
if count_card.state == CandidateState.HOPEFUL: