-
Notifications
You must be signed in to change notification settings - Fork 1
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
Concise STV #6
base: master
Are you sure you want to change the base?
Concise STV #6
Conversation
@@ -21,50 +21,20 @@ class Candidate: | |||
""" | |||
|
|||
def __init__(self, uid, name=None): | |||
"""Initializes Candidate with name and uid. |
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.
standard methods don't really need docstrings
@@ -11,7 +11,7 @@ | |||
__status__ = "Production" | |||
|
|||
|
|||
class Candidate: | |||
class Candidate(object): |
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.
old style classes might cause issues on some platforms
return 'VoteTracker(votes_for_candidate={!r}, votes_cast={!r})'.format( | ||
self._votes_for_candidate, self.votes_cast) | ||
|
||
def decription(self): | ||
"""Returns a printable long-form user representation of the VoteTracker. | ||
|
||
Returns: | ||
String containing the printable representation of the VoteTracker. | ||
:return String containing the printable representation of the |
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.
There is a standard for autodocumentation:
https://thomas-cokelaer.info/tutorials/sphinx/docstring_python.html
@@ -863,7 +851,7 @@ def test_cgp_grey_animal_kingdom(self): | |||
tiger = Candidate('tiger', name='Tiger') | |||
lynx = Candidate('lynx', name='Lynx') | |||
|
|||
expected_winners = set([gorilla, monkey, tiger]) | |||
expected_winners = {gorilla, monkey, tiger} |
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.
set comprehensions:
https://www.smallsurething.com/list-dict-and-set-comprehensions-by-example/
tests.py
Outdated
candidates.append(candidate_for_id[candidate_id]) | ||
return candidates | ||
|
||
return [Candidate(CANDIDATE_IDS[candidate_id]) |
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.
list comprehensions:
https://www.smallsurething.com/list-dict-and-set-comprehensions-by-example/
I would like you guys to review this implementation of STV. I will be happy to give you a code walkthrough in a personal or an online meeting.
Why Python
The proposed solution is to gradually port elections platform to Python, namely Django. There are much more people familiar with Python on campus, and it offers decent administration console out of the box.
As a first step, I am going to port create a baseline project, which will not be exposed outside but will allow us to perform some administrative tasks, such as creating/editing elections and calculating election results. Since fair implementation of STV was a big concern in Senate last year (which I totally understand), I would like you to review my implementation.
Why not existing implementation
code in
electionspy
is overly verbose and is not very Pythonic. It doesn't follow many conventions, excessively uses classes, misses logging, and can be best described by a God-method pattern (Elections.compute_results
is 240LOC + service classes and methods). After giving a try to make it up to standard, I found it will take less time to restart.Testing and debugging
All existing tests are included as doctests. Run:
python -m doctest stv.py
Concise debugging output is generated if logging is configured at
INFO
level.DEBUG
produces even more verbose output. Simply config logging before calling stv:logging.basicConfig(level=logging.INFO)