Allow displaying results to >2 dps in JS client

This commit is contained in:
RunasSudo 2021-01-07 03:45:12 +11:00
parent 1316c82c35
commit 14b1dfb787
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
3 changed files with 27 additions and 13 deletions

View File

@ -142,7 +142,14 @@
</label>
<label>
Decimal places (if Numbers = Fixed):
<input type="number" id="txtDP" value="5" style="width: 3em;">
<input type="number" id="txtDP" value="5" min="0" style="width: 3em;">
</label>
</div>
<div class="col-12">
<label>
Display up to
<input type="number" id="txtPPDP" value="2" min="0" style="width: 3em;">
d.p.
</label>
</div>
<div class="col-12 subheading">

View File

@ -36,6 +36,7 @@ function changePreset() {
document.getElementById('chkDeferSurpluses').checked = false;
document.getElementById('selNumbers').value = 'fixed';
document.getElementById('txtDP').value = '5';
document.getElementById('txtPPDP').value = '2';
document.getElementById('chkRoundQuota').checked = true;
document.getElementById('txtRoundQuota').value = '0';
document.getElementById('chkRoundVotes').checked = false;
@ -54,6 +55,7 @@ function changePreset() {
document.getElementById('chkBulkExclusion').checked = true;
document.getElementById('chkDeferSurpluses').checked = false;
document.getElementById('selNumbers').value = 'rational';
document.getElementById('txtPPDP').value = '2';
document.getElementById('chkRoundQuota').checked = false;
document.getElementById('chkRoundVotes').checked = false;
document.getElementById('chkRoundTVs').checked = false;
@ -72,6 +74,7 @@ function changePreset() {
document.getElementById('chkDeferSurpluses').checked = false;
document.getElementById('selNumbers').value = 'fixed';
document.getElementById('txtDP').value = '5';
document.getElementById('txtPPDP').value = '0';
document.getElementById('chkRoundQuota').checked = true;
document.getElementById('txtRoundQuota').value = '0';
document.getElementById('chkRoundVotes').checked = true;
@ -92,6 +95,7 @@ function changePreset() {
document.getElementById('chkDeferSurpluses').checked = false;
document.getElementById('selNumbers').value = 'fixed';
document.getElementById('txtDP').value = '5';
document.getElementById('txtPPDP').value = '2';
document.getElementById('chkRoundQuota').checked = true;
document.getElementById('txtRoundQuota').value = '0';
document.getElementById('chkRoundVotes').checked = false;
@ -111,6 +115,7 @@ function changePreset() {
document.getElementById('chkDeferSurpluses').checked = true;
document.getElementById('selNumbers').value = 'fixed';
document.getElementById('txtDP').value = '5';
document.getElementById('txtPPDP').value = '3';
document.getElementById('chkRoundQuota').checked = true;
document.getElementById('txtRoundQuota').value = '3';
document.getElementById('chkRoundVotes').checked = true;
@ -133,6 +138,7 @@ function changePreset() {
document.getElementById('chkDeferSurpluses').checked = true;
document.getElementById('selNumbers').value = 'fixed';
document.getElementById('txtDP').value = '5';
document.getElementById('txtPPDP').value = '2';
document.getElementById('chkRoundQuota').checked = true;
document.getElementById('txtRoundQuota').value = '2';
document.getElementById('chkRoundVotes').checked = true;
@ -399,6 +405,7 @@ async function clickCount() {
'data': {
'numbers': document.getElementById('selNumbers').value,
'fixedDPs': parseInt(document.getElementById('txtDP').value),
'ppDPs': parseInt(document.getElementById('txtPPDP').value),
'transfers': document.getElementById('selTransfers').value,
'options': {
'quota_criterion': document.getElementById('selQuotaCriterion').value,
@ -422,7 +429,7 @@ async function clickCount() {
});
// Pretty printing helper functions
let ppDPs = 2;
let ppDPs = parseInt(document.getElementById('txtPPDP').value);
if (document.getElementById('chkRoundVotes').checked) {
let ppDPs2 = parseInt(document.getElementById('txtRoundVotes').value);
if (ppDPs2 < ppDPs) {

View File

@ -18,7 +18,7 @@
importScripts('vendor/BigInt_BigRat-a5f89e2.min.js', 'vendor/big-6.0.0.min.js', 'vendor/sjcl-1.0.8.min.js', 'bundle.js');
let stage, result, counter, ppDP, tiesPrompt;
let stage, result, counter, ppDPs, tiesPrompt;
onmessage = function(evt) {
if (evt.data.type === 'init') {
@ -34,7 +34,7 @@ onmessage = function(evt) {
py.pyRCV2.numbers.set_dps(evt.data.data.fixedDPs);
}
ppDP = evt.data.data.fixedDPs > 2 ? 2 : evt.data.data.fixedDPs;
ppDPs = evt.data.data.ppDPs;
let election = py.pyRCV2.blt.readBLT(evt.data.data.data);
postMessage({'type': 'init', 'election': {
@ -109,21 +109,21 @@ function resultToJS(result) {
'stage': stage,
'comment': result.comment,
'candidates': result.candidates.py_items().map(([c, cc]) => [c.py_name, {
'transfers': cc.transfers.pp(ppDP),
'votes': cc.votes.pp(ppDP),
'transfers': cc.transfers.pp(ppDPs),
'votes': cc.votes.pp(ppDPs),
'state': cc.state,
'order_elected': cc.order_elected,
}]),
'exhausted': {
'transfers': result.exhausted.transfers.pp(ppDP),
'votes': result.exhausted.votes.pp(ppDP)
'transfers': result.exhausted.transfers.pp(ppDPs),
'votes': result.exhausted.votes.pp(ppDPs)
},
'loss_fraction': {
'transfers': result.loss_fraction.transfers.pp(ppDP),
'votes': result.loss_fraction.votes.pp(ppDP)
'transfers': result.loss_fraction.transfers.pp(ppDPs),
'votes': result.loss_fraction.votes.pp(ppDPs)
},
'total': result.total.pp(ppDP),
'quota': result.quota.pp(ppDP),
'vote_required_election': result.vote_required_election === null ? null : result.vote_required_election.pp(ppDP),
'total': result.total.pp(ppDPs),
'quota': result.quota.pp(ppDPs),
'vote_required_election': result.vote_required_election === null ? null : result.vote_required_election.pp(ppDPs),
};
}