From a67fa19f634b89543866edaf14c6884cc33f16de Mon Sep 17 00:00:00 2001 From: Mia Nordentoft Date: Thu, 13 Jun 2019 14:36:17 +0200 Subject: [PATCH] Backport from vocho-gui, bump minor to 1.4.0 --- package-lock.json | 4 ++-- package.json | 2 +- src/calc.js | 34 +++++++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5c48c32..50b65e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "vocho-term", - "version": "1.2.2", + "version": "1.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1938,7 +1938,7 @@ "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, "vocho-lib": { - "version": "git+https://github.com/tejoesperanto/vocho-lib.git#50b5beabda976a57bf5867330a2f393be2185417", + "version": "git+https://github.com/tejoesperanto/vocho-lib.git#4ad9a7574637573ea0389ac079ac9dd0304db579", "from": "git+https://github.com/tejoesperanto/vocho-lib.git" }, "which": { diff --git a/package.json b/package.json index f0fae60..a89c3c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vocho-term", - "version": "1.3.0", + "version": "1.4.0", "description": "", "main": "src/index.js", "scripts": { diff --git a/src/calc.js b/src/calc.js index 24e0dd2..07e9e5d 100644 --- a/src/calc.js +++ b/src/calc.js @@ -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(', '); }