-
Notifications
You must be signed in to change notification settings - Fork 23
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
Adding tiebreaker order #379
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { permissions } from '../../../domain_model/permissions'; | |
import { VotingMethods } from '../Tabulators/VotingMethodSelecter'; | ||
import { IElectionRequest } from "../IRequest"; | ||
import { Response, NextFunction } from 'express'; | ||
var seedrandom = require('seedrandom'); | ||
|
||
const BallotModel = ServiceLocator.ballotsDb(); | ||
|
||
|
@@ -48,8 +49,11 @@ const getElectionResults = async (req: IElectionRequest, res: Response, next: Ne | |
} | ||
const msg = `Tabulating results for ${voting_method} election` | ||
Logger.info(req, msg); | ||
results[race_index] = VotingMethods[voting_method](candidateNames, cvr, num_winners) | ||
let rng = seedrandom(election.election_id + ballots.length.toString()) | ||
const tieBreakOrders = election.races[race_index].candidates.map((Candidate) => (rng() as number)) | ||
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. I was initially confused here since rng() outputs floats, but the test cases work with lists of unique integers. But it looks like it'll work fine. I guess it's technically possible for rng() to output the same number twice? but I'm not worried about that 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. I'm not worried about duplicate floats. And I think in JS integers are just treated as floats. |
||
results[race_index] = VotingMethods[voting_method](candidateNames, cvr, num_winners, tieBreakOrders) | ||
} | ||
|
||
res.json( | ||
{ | ||
Election: election, | ||
|
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.
I'm surprised the base math class didn't support seeding, weird
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.
Yea its frustrating. That's why I didn't go with seeds before, but I found a library that does it.