Skip to content

Commit

Permalink
Backport from vocho-gui, bump minor to 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
miestasmia committed Jun 13, 2019
1 parent dab1a39 commit a67fa19
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vocho-term",
"version": "1.3.0",
"version": "1.4.0",
"description": "",
"main": "src/index.js",
"scripts": {
Expand Down
34 changes: 27 additions & 7 deletions src/calc.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,38 @@ module.exports = function performElection (electionType, candidatesStr, ballotsS
} else if (electionType === 'STV') {
resultsText += `\nElektiĝkvoto: ${results.quota.toFixed(3)}`;

const votesTableData = [['Voĉdoneblo']];
for (let i = 0; i < results.rounds.length; i++) {
const round = results.rounds[i];

resultsText += `\n\n${style.bold.open}Vico ${i + 1}${style.bold.close}`;
votesTableData[0].push(`${i + 1}-a vico`);
}

if (round.elected.length) {
resultsText += `\nElektitaj: ${round.elected.join(', ')}`;
} else if (round.eliminated) {
resultsText += '\nMalelektita: ' + round.eliminated;
for (let cand of candidates) {
const row = [ cand ];
votesTableData.push(row);

for (let round of results.rounds) {
if (!(cand in round.votes)) {
row.push('');
continue;
}
const votes = round.votes[cand];
const votesRounded = votes.toFixed(3);

let col;
if (round.elected.includes(cand)) {
col = `${style.bold.open}${style.green.open}${votesRounded}${style.green.close}${style.bold.close}`;
} else if (cand === round.eliminated) {
col = `${style.bold.open}${style.red.open}${votesRounded}${style.red.close}${style.bold.close}`;
} else {
col = votesRounded;
}

row.push(col);
}
}

resultsText += '\n\n' + table(votesTableData);

resultsText += '\n\nVenkintoj (laŭ ordo de elektiĝo):\n' + results.winners.join(', ');
}

Expand Down

0 comments on commit a67fa19

Please sign in to comment.