Show totals
This commit is contained in:
parent
e4bd80c26d
commit
93f0100856
@ -52,12 +52,15 @@ class STVCCounter:
|
||||
self.compute_quota()
|
||||
self.elect_meeting_quota()
|
||||
|
||||
__pragma__('opov')
|
||||
return CountStepResult(
|
||||
'First preferences',
|
||||
self.candidates,
|
||||
self.exhausted,
|
||||
self.total + self.exhausted.votes,
|
||||
self.quota
|
||||
)
|
||||
__pragma__('noopov')
|
||||
|
||||
def step(self):
|
||||
# Step count cards
|
||||
@ -76,12 +79,15 @@ class STVCCounter:
|
||||
if count_card.state == CandidateState.HOPEFUL:
|
||||
count_card.state = CandidateState.PROVISIONALLY_ELECTED
|
||||
|
||||
__pragma__('opov')
|
||||
return CountStepResult(
|
||||
'Bulk election',
|
||||
self.candidates,
|
||||
self.exhausted,
|
||||
self.total + self.exhausted.votes,
|
||||
self.quota
|
||||
)
|
||||
__pragma__('noopov')
|
||||
|
||||
# Do surpluses need to be distributed?
|
||||
__pragma__('opov')
|
||||
@ -118,12 +124,15 @@ class STVCCounter:
|
||||
self.compute_quota()
|
||||
self.elect_meeting_quota()
|
||||
|
||||
__pragma__('opov')
|
||||
return CountStepResult(
|
||||
'Surplus of ' + candidate_surplus.name,
|
||||
self.candidates,
|
||||
self.exhausted,
|
||||
self.total + self.exhausted.votes,
|
||||
self.quota
|
||||
)
|
||||
__pragma__('noopov')
|
||||
|
||||
# Insufficient winners and no surpluses to distribute
|
||||
# Exclude the lowest ranked hopeful
|
||||
@ -154,18 +163,21 @@ class STVCCounter:
|
||||
self.compute_quota()
|
||||
self.elect_meeting_quota()
|
||||
|
||||
__pragma__('opov')
|
||||
return CountStepResult(
|
||||
'Exclusion of ' + candidate_excluded.name,
|
||||
self.candidates,
|
||||
self.exhausted,
|
||||
self.total + self.exhausted.votes,
|
||||
self.quota
|
||||
)
|
||||
__pragma__('noopov')
|
||||
|
||||
def compute_quota(self):
|
||||
# Compute quota
|
||||
__pragma__('opov')
|
||||
total = sum((cc.votes for c, cc in self.candidates.items()), Num('0'))
|
||||
self.quota = total / Num(self.election.seats + 1)
|
||||
self.total = sum((cc.votes for c, cc in self.candidates.items()), Num('0'))
|
||||
self.quota = self.total / Num(self.election.seats + 1)
|
||||
__pragma__('noopov')
|
||||
|
||||
def elect_meeting_quota(self):
|
||||
|
@ -77,10 +77,11 @@ class CountCompleted:
|
||||
pass
|
||||
|
||||
class CountStepResult:
|
||||
def __init__(self, comment, candidates, exhausted, quota):
|
||||
def __init__(self, comment, candidates, exhausted, total, quota):
|
||||
self.comment = comment
|
||||
|
||||
self.candidates = candidates # SafeDict: Candidate -> CountCard
|
||||
self.exhausted = exhausted # CountCard
|
||||
|
||||
self.total = total
|
||||
self.quota = quota
|
||||
|
18
test.html
18
test.html
@ -105,6 +105,16 @@
|
||||
tblResults.appendChild(elExhausted1);
|
||||
tblResults.appendChild(elExhausted2);
|
||||
|
||||
// Total row
|
||||
elTotal = document.createElement('tr');
|
||||
elTotal.classList.add('info');
|
||||
elTd = document.createElement('td');
|
||||
elTd.style.borderTop = '1px solid black';
|
||||
elTd.style.borderBottom = '1px solid black';
|
||||
elTd.innerText = 'Total';
|
||||
elTotal.appendChild(elTd);
|
||||
tblResults.appendChild(elTotal);
|
||||
|
||||
// Quota row
|
||||
elQuota = document.createElement('tr');
|
||||
elQuota.classList.add('info');
|
||||
@ -174,6 +184,14 @@
|
||||
elTd.innerText = result.exhausted.votes;
|
||||
elExhausted2.appendChild(elTd);
|
||||
|
||||
// Display total
|
||||
elTd = document.createElement('td');
|
||||
elTd.classList.add('count');
|
||||
elTd.style.borderTop = '1px solid black';
|
||||
elTd.style.borderBottom = '1px solid black';
|
||||
elTd.innerText = result.total;
|
||||
elTotal.appendChild(elTd);
|
||||
|
||||
// Display quota
|
||||
elTd = document.createElement('td');
|
||||
elTd.classList.add('count');
|
||||
|
@ -23,6 +23,7 @@ onmessage = function(evt) {
|
||||
'transfers': result.exhausted.transfers.pp(2),
|
||||
'votes': result.exhausted.votes.pp(2)
|
||||
},
|
||||
'total': result.total.pp(2),
|
||||
'quota': result.quota.pp(2)
|
||||
}});
|
||||
|
||||
@ -44,6 +45,7 @@ onmessage = function(evt) {
|
||||
'transfers': result.exhausted.transfers.pp(2),
|
||||
'votes': result.exhausted.votes.pp(2)
|
||||
},
|
||||
'total': result.total.pp(2),
|
||||
'quota': result.quota.pp(2)
|
||||
}});
|
||||
}
|
||||
|
Reference in New Issue
Block a user