Allow displaying results to >2 dps in JS client
This commit is contained in:
parent
1316c82c35
commit
14b1dfb787
@ -142,7 +142,14 @@
|
|||||||
</label>
|
</label>
|
||||||
<label>
|
<label>
|
||||||
Decimal places (if Numbers = Fixed):
|
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>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-12 subheading">
|
<div class="col-12 subheading">
|
||||||
|
@ -36,6 +36,7 @@ function changePreset() {
|
|||||||
document.getElementById('chkDeferSurpluses').checked = false;
|
document.getElementById('chkDeferSurpluses').checked = false;
|
||||||
document.getElementById('selNumbers').value = 'fixed';
|
document.getElementById('selNumbers').value = 'fixed';
|
||||||
document.getElementById('txtDP').value = '5';
|
document.getElementById('txtDP').value = '5';
|
||||||
|
document.getElementById('txtPPDP').value = '2';
|
||||||
document.getElementById('chkRoundQuota').checked = true;
|
document.getElementById('chkRoundQuota').checked = true;
|
||||||
document.getElementById('txtRoundQuota').value = '0';
|
document.getElementById('txtRoundQuota').value = '0';
|
||||||
document.getElementById('chkRoundVotes').checked = false;
|
document.getElementById('chkRoundVotes').checked = false;
|
||||||
@ -54,6 +55,7 @@ function changePreset() {
|
|||||||
document.getElementById('chkBulkExclusion').checked = true;
|
document.getElementById('chkBulkExclusion').checked = true;
|
||||||
document.getElementById('chkDeferSurpluses').checked = false;
|
document.getElementById('chkDeferSurpluses').checked = false;
|
||||||
document.getElementById('selNumbers').value = 'rational';
|
document.getElementById('selNumbers').value = 'rational';
|
||||||
|
document.getElementById('txtPPDP').value = '2';
|
||||||
document.getElementById('chkRoundQuota').checked = false;
|
document.getElementById('chkRoundQuota').checked = false;
|
||||||
document.getElementById('chkRoundVotes').checked = false;
|
document.getElementById('chkRoundVotes').checked = false;
|
||||||
document.getElementById('chkRoundTVs').checked = false;
|
document.getElementById('chkRoundTVs').checked = false;
|
||||||
@ -72,6 +74,7 @@ function changePreset() {
|
|||||||
document.getElementById('chkDeferSurpluses').checked = false;
|
document.getElementById('chkDeferSurpluses').checked = false;
|
||||||
document.getElementById('selNumbers').value = 'fixed';
|
document.getElementById('selNumbers').value = 'fixed';
|
||||||
document.getElementById('txtDP').value = '5';
|
document.getElementById('txtDP').value = '5';
|
||||||
|
document.getElementById('txtPPDP').value = '0';
|
||||||
document.getElementById('chkRoundQuota').checked = true;
|
document.getElementById('chkRoundQuota').checked = true;
|
||||||
document.getElementById('txtRoundQuota').value = '0';
|
document.getElementById('txtRoundQuota').value = '0';
|
||||||
document.getElementById('chkRoundVotes').checked = true;
|
document.getElementById('chkRoundVotes').checked = true;
|
||||||
@ -92,6 +95,7 @@ function changePreset() {
|
|||||||
document.getElementById('chkDeferSurpluses').checked = false;
|
document.getElementById('chkDeferSurpluses').checked = false;
|
||||||
document.getElementById('selNumbers').value = 'fixed';
|
document.getElementById('selNumbers').value = 'fixed';
|
||||||
document.getElementById('txtDP').value = '5';
|
document.getElementById('txtDP').value = '5';
|
||||||
|
document.getElementById('txtPPDP').value = '2';
|
||||||
document.getElementById('chkRoundQuota').checked = true;
|
document.getElementById('chkRoundQuota').checked = true;
|
||||||
document.getElementById('txtRoundQuota').value = '0';
|
document.getElementById('txtRoundQuota').value = '0';
|
||||||
document.getElementById('chkRoundVotes').checked = false;
|
document.getElementById('chkRoundVotes').checked = false;
|
||||||
@ -111,6 +115,7 @@ function changePreset() {
|
|||||||
document.getElementById('chkDeferSurpluses').checked = true;
|
document.getElementById('chkDeferSurpluses').checked = true;
|
||||||
document.getElementById('selNumbers').value = 'fixed';
|
document.getElementById('selNumbers').value = 'fixed';
|
||||||
document.getElementById('txtDP').value = '5';
|
document.getElementById('txtDP').value = '5';
|
||||||
|
document.getElementById('txtPPDP').value = '3';
|
||||||
document.getElementById('chkRoundQuota').checked = true;
|
document.getElementById('chkRoundQuota').checked = true;
|
||||||
document.getElementById('txtRoundQuota').value = '3';
|
document.getElementById('txtRoundQuota').value = '3';
|
||||||
document.getElementById('chkRoundVotes').checked = true;
|
document.getElementById('chkRoundVotes').checked = true;
|
||||||
@ -133,6 +138,7 @@ function changePreset() {
|
|||||||
document.getElementById('chkDeferSurpluses').checked = true;
|
document.getElementById('chkDeferSurpluses').checked = true;
|
||||||
document.getElementById('selNumbers').value = 'fixed';
|
document.getElementById('selNumbers').value = 'fixed';
|
||||||
document.getElementById('txtDP').value = '5';
|
document.getElementById('txtDP').value = '5';
|
||||||
|
document.getElementById('txtPPDP').value = '2';
|
||||||
document.getElementById('chkRoundQuota').checked = true;
|
document.getElementById('chkRoundQuota').checked = true;
|
||||||
document.getElementById('txtRoundQuota').value = '2';
|
document.getElementById('txtRoundQuota').value = '2';
|
||||||
document.getElementById('chkRoundVotes').checked = true;
|
document.getElementById('chkRoundVotes').checked = true;
|
||||||
@ -399,6 +405,7 @@ async function clickCount() {
|
|||||||
'data': {
|
'data': {
|
||||||
'numbers': document.getElementById('selNumbers').value,
|
'numbers': document.getElementById('selNumbers').value,
|
||||||
'fixedDPs': parseInt(document.getElementById('txtDP').value),
|
'fixedDPs': parseInt(document.getElementById('txtDP').value),
|
||||||
|
'ppDPs': parseInt(document.getElementById('txtPPDP').value),
|
||||||
'transfers': document.getElementById('selTransfers').value,
|
'transfers': document.getElementById('selTransfers').value,
|
||||||
'options': {
|
'options': {
|
||||||
'quota_criterion': document.getElementById('selQuotaCriterion').value,
|
'quota_criterion': document.getElementById('selQuotaCriterion').value,
|
||||||
@ -422,7 +429,7 @@ async function clickCount() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Pretty printing helper functions
|
// Pretty printing helper functions
|
||||||
let ppDPs = 2;
|
let ppDPs = parseInt(document.getElementById('txtPPDP').value);
|
||||||
if (document.getElementById('chkRoundVotes').checked) {
|
if (document.getElementById('chkRoundVotes').checked) {
|
||||||
let ppDPs2 = parseInt(document.getElementById('txtRoundVotes').value);
|
let ppDPs2 = parseInt(document.getElementById('txtRoundVotes').value);
|
||||||
if (ppDPs2 < ppDPs) {
|
if (ppDPs2 < ppDPs) {
|
||||||
|
@ -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');
|
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) {
|
onmessage = function(evt) {
|
||||||
if (evt.data.type === 'init') {
|
if (evt.data.type === 'init') {
|
||||||
@ -34,7 +34,7 @@ onmessage = function(evt) {
|
|||||||
py.pyRCV2.numbers.set_dps(evt.data.data.fixedDPs);
|
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);
|
let election = py.pyRCV2.blt.readBLT(evt.data.data.data);
|
||||||
postMessage({'type': 'init', 'election': {
|
postMessage({'type': 'init', 'election': {
|
||||||
@ -109,21 +109,21 @@ function resultToJS(result) {
|
|||||||
'stage': stage,
|
'stage': stage,
|
||||||
'comment': result.comment,
|
'comment': result.comment,
|
||||||
'candidates': result.candidates.py_items().map(([c, cc]) => [c.py_name, {
|
'candidates': result.candidates.py_items().map(([c, cc]) => [c.py_name, {
|
||||||
'transfers': cc.transfers.pp(ppDP),
|
'transfers': cc.transfers.pp(ppDPs),
|
||||||
'votes': cc.votes.pp(ppDP),
|
'votes': cc.votes.pp(ppDPs),
|
||||||
'state': cc.state,
|
'state': cc.state,
|
||||||
'order_elected': cc.order_elected,
|
'order_elected': cc.order_elected,
|
||||||
}]),
|
}]),
|
||||||
'exhausted': {
|
'exhausted': {
|
||||||
'transfers': result.exhausted.transfers.pp(ppDP),
|
'transfers': result.exhausted.transfers.pp(ppDPs),
|
||||||
'votes': result.exhausted.votes.pp(ppDP)
|
'votes': result.exhausted.votes.pp(ppDPs)
|
||||||
},
|
},
|
||||||
'loss_fraction': {
|
'loss_fraction': {
|
||||||
'transfers': result.loss_fraction.transfers.pp(ppDP),
|
'transfers': result.loss_fraction.transfers.pp(ppDPs),
|
||||||
'votes': result.loss_fraction.votes.pp(ppDP)
|
'votes': result.loss_fraction.votes.pp(ppDPs)
|
||||||
},
|
},
|
||||||
'total': result.total.pp(ppDP),
|
'total': result.total.pp(ppDPs),
|
||||||
'quota': result.quota.pp(ppDP),
|
'quota': result.quota.pp(ppDPs),
|
||||||
'vote_required_election': result.vote_required_election === null ? null : result.vote_required_election.pp(ppDP),
|
'vote_required_election': result.vote_required_election === null ? null : result.vote_required_election.pp(ppDPs),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user