Skip to content

Commit

Permalink
Move undervotes & Add Test
Browse files Browse the repository at this point in the history
  • Loading branch information
ArendPeter committed Dec 16, 2024
1 parent 56ebc81 commit 83ba050
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const getElectionResults = async (req: IElectionRequest, res: Response, next: Ne
const cvr: number[][] = []
ballots.forEach((ballot: Ballot) => {
const vote = ballot.votes.find((vote) => vote.race_id === race_id)
let maxScoreGiven = vote?.scores.reduce((prev, s) => Math.max(prev, s.score ?? 0), 0) ?? 0;
if (vote && maxScoreGiven > 0) {
if (vote) {
cvr.push(vote.scores.map((score: Score) => (
score.score
)))
Expand Down
15 changes: 15 additions & 0 deletions packages/backend/src/Tabulators/AllocatedScore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ describe("Allocated Score Tests", () => {
expect(results.summaryData.weightedScoresByRound[1]).toStrictEqual([0, 0, 14, 18]);
expect(results.summaryData.splitPoints[0]).toStrictEqual(0.8);
})
test("Voters < Winners", () => {
const candidates = ['Allison', 'Bill', 'Carmen', 'Doug']
const votes = [
[5, 5, 0, 0],
[5, 4, 3, 0],
]
const results = AllocatedScore(candidates, votes, 3, [], false, false)
expect(results.elected.length).toBe(3);
expect(results.elected[0].name).toBe('Allison');
expect(results.elected[1].name).toBe('Bill');
expect(results.elected[2].name).toBe('Carmen');
expect(results.summaryData.weightedScoresByRound[0]).toStrictEqual([10, 9, 3, 0]);
expect(results.summaryData.weightedScoresByRound[1]).toStrictEqual([0, 6, 2, 0]);
expect(results.summaryData.weightedScoresByRound[2]).toStrictEqual([0, 0, 2, 0]);
})
test("Fractional surplus", () => {
// Two winners, two main parties, Allison wins first round with highest score, Allison has 8 highest level supporters, more than the quota of 6 voters
// Voters who gave Allison their highest score have their ballot weight reduced to (1-6/8) = 0.25
Expand Down
3 changes: 0 additions & 3 deletions packages/backend/src/Tabulators/ParseData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ module.exports = function ParseData(data: ballot[], validityCheck = getStarBallo
}
else if (ballotValidity.isUnderVote) {
underVotes += 1
scores.push(row)
// under votes should not count as a valid vote
//validVotes.push(voter);
}
else {
scores.push(row)
Expand Down
8 changes: 3 additions & 5 deletions packages/frontend/src/components/Election/Results/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,11 @@ function PRResultsViewer() {
</WidgetContainer>
<DetailExpander>
<WidgetContainer>
<Widget title={t('results.star_pr.table_title')} wide>
<ResultsTable className='starPRTable' data={tabulationRows}/>
</Widget>
<Widget title={t('results.star_pr.table_title')} wide>
<ResultsTable className='starPRTable' data={tabulationRows}/>
</Widget>
</WidgetContainer>
<WidgetContainer>
{flags.isSet('ALL_STATS') &&
<Widget title={t('results.star.detailed_steps_title')} wide>
<div className='detailedSteps'>
<ol style={{textAlign: 'left'}}>
Expand All @@ -413,7 +412,6 @@ function PRResultsViewer() {
</ol>
</div>
</Widget>
}
</WidgetContainer>
<DetailExpander level={1}>
<WidgetContainer>
Expand Down

0 comments on commit 83ba050

Please sign in to comment.