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