-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display total count instead of percent and order by count #123
Changes from all commits
6e40d7d
bb7d2ae
57d0a32
4a55280
801594b
18be67e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -42,31 +42,20 @@ const countRankResult = (rankResult: number[][], rank: RankQuestion) => { | |||||||||||||||||||||||||||||||||||||||||
// percentage of the total number of votes and which candidate(s) in the | ||||||||||||||||||||||||||||||||||||||||||
// select.Choices has the most votes | ||||||||||||||||||||||||||||||||||||||||||
const countSelectResult = (selectResult: number[][]) => { | ||||||||||||||||||||||||||||||||||||||||||
const resultsInPercent: string[] = []; | ||||||||||||||||||||||||||||||||||||||||||
const maxIndices: number[] = []; | ||||||||||||||||||||||||||||||||||||||||||
let max = 0; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const results = selectResult.reduce((a, b) => { | ||||||||||||||||||||||||||||||||||||||||||
return a.map((value, index) => { | ||||||||||||||||||||||||||||||||||||||||||
const current = value + b[index]; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
if (current >= max) { | ||||||||||||||||||||||||||||||||||||||||||
max = current; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
return current; | ||||||||||||||||||||||||||||||||||||||||||
const results: [string, number][] = []; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
selectResult | ||||||||||||||||||||||||||||||||||||||||||
.reduce( | ||||||||||||||||||||||||||||||||||||||||||
(tally, currBallot) => tally.map((currCount, index) => currCount + currBallot[index]), | ||||||||||||||||||||||||||||||||||||||||||
new Array(selectResult[0].length).fill(0) | ||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||
.forEach((totalCount) => { | ||||||||||||||||||||||||||||||||||||||||||
results.push([ | ||||||||||||||||||||||||||||||||||||||||||
(Math.round((totalCount / selectResult.length) * 100 * 100) / 100).toFixed(2).toString(), | ||||||||||||||||||||||||||||||||||||||||||
totalCount, | ||||||||||||||||||||||||||||||||||||||||||
]); | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+47
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or remove the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||
}, new Array(selectResult[0].length).fill(0)); | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
results.forEach((count, index) => { | ||||||||||||||||||||||||||||||||||||||||||
if (count === max) { | ||||||||||||||||||||||||||||||||||||||||||
maxIndices.push(index); | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
const percentage = (count / selectResult.length) * 100; | ||||||||||||||||||||||||||||||||||||||||||
const roundedPercentage = (Math.round(percentage * 100) / 100).toFixed(2); | ||||||||||||||||||||||||||||||||||||||||||
resultsInPercent.push(roundedPercentage); | ||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||
return { resultsInPercent, maxIndices }; | ||||||||||||||||||||||||||||||||||||||||||
return results; | ||||||||||||||||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
// Count the number of votes for each candidate and returns the counts and the | ||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ | |
"Configuration": { | ||
"Title": { | ||
"En": "Colours", | ||
"Fr": "", | ||
"De": "" | ||
"Fr": "Couleurs", | ||
"De": "Farben" | ||
}, | ||
"Scaffold": [ | ||
{ | ||
|
@@ -42,6 +42,43 @@ | |
], | ||
"Ranks": [], | ||
"Texts": [] | ||
}, | ||
{ | ||
"ID": "1NqhDffw", | ||
"Title": { | ||
"En": "Colours", | ||
"Fr": "Couleurs", | ||
"De": "Farben" | ||
}, | ||
"Order": [ | ||
"riJFjw0q" | ||
], | ||
"Subjects": [], | ||
"Selects": [ | ||
{ | ||
"ID": "riJFjw0q", | ||
"Title": { | ||
"En": "CMYK", | ||
"Fr": "CMJN", | ||
"De": "CMYK" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Joke: Wir haben keine Übersetzung dafür? Sowas... "CMGS"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://www.din.de/de/wdc-beuth:din21:5463877 jedenfalls nicht in Deutschland 🤷♀️ |
||
}, | ||
"MaxN": 3, | ||
"MinN": 1, | ||
"Choices": [ | ||
"{\"en\":\"Cyan\",\"fr\":\"Cyan\",\"de\":\"Cyan\"}", | ||
"{\"en\":\"Magenta\",\"fr\":\"Magenta\",\"de\":\"Magenta\"}", | ||
"{\"en\":\"Yellow\",\"fr\":\"Jaune\",\"de\":\"Gelb\"}", | ||
"{\"en\":\"Key\",\"fr\":\"Noir\",\"de\":\"Schwarz\"}" | ||
], | ||
"Hint": { | ||
"En": "", | ||
"Fr": "", | ||
"De": "" | ||
} | ||
} | ||
], | ||
"Ranks": [], | ||
"Texts": [] | ||
} | ||
] | ||
}, | ||
|
@@ -54,11 +91,13 @@ | |
"grpc://dela-worker-2:2000", | ||
"grpc://dela-worker-3:2000" | ||
], | ||
"ChunksPerBallot": 1, | ||
"BallotSize": 23, | ||
"ChunksPerBallot": 2, | ||
"BallotSize": 48, | ||
"Voters": [ | ||
"oUItDdhhEE", | ||
"WZyqP1gssL", | ||
"K7ZNvumBVc" | ||
"brcLwsgGcU", | ||
"JThb56JvGF", | ||
"zXcZU5QNwn", | ||
"bWxTfeq4t5" | ||
] | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The linter doesn't complain? I thought you'd have to write
.map(([_, totalCount]
here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, the linter is quite happy like that and actually made me change it to this 🤷♀️