-
Notifications
You must be signed in to change notification settings - Fork 13
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
Cumulative voting #106
Cumulative voting #106
Conversation
Looks like creating this new |
Hi @cdonnay, I view the A couple thoughts here: When we first designed the class, I think we didn't think users would really need to touch it much, but I don't think that's really the case anymore. So I think if we give a little more flexibility in how we initialize a Ballot, we won't need a second class. I think an optional |
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.
Left some inline comments, overall I'd agree with @jgibson517 that it'd make sense to combine these into one type to avoid the duplication. The places where they differ could be smoothed out by adding additional helper methods onto Ballot
itself, or within Cumulative
tiebreak=self.tiebreak) | ||
|
||
if ranking != untied_ranking: | ||
print("A tie was broken.") |
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.
probably want to avoid print
here, maybe logging
or adding some other way of checking this after the fact if desired
@@ -13,7 +14,7 @@ class Election(ABC): | |||
""" | |||
|
|||
def __init__(self, profile: PreferenceProfile, ballot_ties: bool = True): | |||
if ballot_ties: | |||
if ballot_ties and isinstance(profile.ballots[0], Ballot): |
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 think a comment here to clarify this logic would be helpful
weight = ballot.weight / num_ballots | ||
else: | ||
|
||
if isinstance(self.ballots[0], Ballot): |
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.
a lot of shared code between these two, moot if they merge, but I'd refactor this to avoid duplication if not
writer.writeheader() | ||
for ballot in self.ballots: | ||
writer.writerow({"weight": ballot.weight, "ranking": ballot.ranking}) | ||
if isinstance(self.ballots[0], Ballot): |
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.
same as above comment, lots of duplication here when the two types can probably share most of the logic
re: mypy errors |
Alright, let me take another go at this using just a |
This PR adds functionality for points based ballots. I felt like this deserved a new class, as it really is distinct from full rankings.
PointBallot
classPreferenceProfile
to handle new ballot classCumulative
ballot generator class to create ballots for cumulative style elections.HighestScore
election that takes aPreferenceProfile
ofPointBallot
s and chooses the@jamesturk @drdeford @jgibson517 @jennjwang @ziglaser