bradbeattie / python-vote-core

Python libraries for various electoral methods
http://modernballots.com
Other
140 stars 36 forks source link

Readme example fails #25

Open rdixit opened 8 years ago

rdixit commented 8 years ago

In [19]: ballots Out[19]: [{'ballot': [['A'], ['C'], ['D'], ['B']], 'count': 3}, {'ballot': [['B'], ['A'], ['C'], ['D']], 'count': 9}, {'ballot': [['C'], ['D'], ['A'], ['B']], 'count': 8}, {'ballot': [['D'], ['A'], ['B'], ['C']], 'count': 5}, {'ballot': [['D'], ['B'], ['C'], ['A']], 'count': 5}]

In [20]: SchulzeMethod(ballots, ballot_notation = "grouping").as_dict()

Exception Traceback (most recent call last)

in () ----> 1 SchulzeMethod(ballots, ballot_notation = "grouping").as_dict() /Users/rohan/Dropbox/PROJECTS/crowdocracy/pyvotecore/schulze_method.py in **init**(self, ballots, tie_breaker, ballot_notation) 25 ballots, 26 tie_breaker=tie_breaker, ---> 27 ballot_notation=ballot_notation, 28 ) 29 /Users/rohan/Dropbox/PROJECTS/crowdocracy/pyvotecore/condorcet.py in **init**(self, ballots, tie_breaker, ballot_notation) 108 @abstractmethod 109 def **init**(self, ballots, tie_breaker=None, ballot_notation=None): --> 110 self.standardize_ballots(ballots, ballot_notation) 111 super(CondorcetSystem, self).**init**(self.ballots, tie_breaker=tie_breaker) 112 /Users/rohan/Dropbox/PROJECTS/crowdocracy/pyvotecore/condorcet.py in standardize_ballots(self, ballots, ballot_notation) 48 ballot["ballot"][candidate] = float(rating) 49 else: ---> 50 raise Exception("Unknown notation specified", ballot_notation) 51 52 self.candidates = set() Exception: ('Unknown notation specified', 'grouping') ## In [21]: SchulzeMethod(ballots).as_dict() AttributeError Traceback (most recent call last) in () ----> 1 SchulzeMethod(ballots).as_dict() /Users/rohan/Dropbox/PROJECTS/crowdocracy/pyvotecore/schulze_method.py in **init**(self, ballots, tie_breaker, ballot_notation) 25 ballots, 26 tie_breaker=tie_breaker, ---> 27 ballot_notation=ballot_notation, 28 ) 29 /Users/rohan/Dropbox/PROJECTS/crowdocracy/pyvotecore/condorcet.py in **init**(self, ballots, tie_breaker, ballot_notation) 108 @abstractmethod 109 def **init**(self, ballots, tie_breaker=None, ballot_notation=None): --> 110 self.standardize_ballots(ballots, ballot_notation) 111 super(CondorcetSystem, self).**init**(self.ballots, tie_breaker=tie_breaker) 112 /Users/rohan/Dropbox/PROJECTS/crowdocracy/pyvotecore/condorcet.py in standardize_ballots(self, ballots, ballot_notation) 45 elif ballot_notation == CondorcetHelper.BALLOT_NOTATION_RATING or ballot_notation is None: 46 for ballot in self.ballots: ---> 47 for candidate, rating in ballot["ballot"].iteritems(): 48 ballot["ballot"][candidate] = float(rating) 49 else: AttributeError: 'list' object has no attribute 'iteritems' ## In [22]: SchulzeMethod(ballots) AttributeError Traceback (most recent call last) in () ----> 1 SchulzeMethod(ballots) /Users/rohan/Dropbox/PROJECTS/crowdocracy/pyvotecore/schulze_method.py in **init**(self, ballots, tie_breaker, ballot_notation) 25 ballots, 26 tie_breaker=tie_breaker, ---> 27 ballot_notation=ballot_notation, 28 ) 29 /Users/rohan/Dropbox/PROJECTS/crowdocracy/pyvotecore/condorcet.py in **init**(self, ballots, tie_breaker, ballot_notation) 108 @abstractmethod 109 def **init**(self, ballots, tie_breaker=None, ballot_notation=None): --> 110 self.standardize_ballots(ballots, ballot_notation) 111 super(CondorcetSystem, self).**init**(self.ballots, tie_breaker=tie_breaker) 112 /Users/rohan/Dropbox/PROJECTS/crowdocracy/pyvotecore/condorcet.py in standardize_ballots(self, ballots, ballot_notation) 45 elif ballot_notation == CondorcetHelper.BALLOT_NOTATION_RATING or ballot_notation is None: 46 for ballot in self.ballots: ---> 47 for candidate, rating in ballot["ballot"].iteritems(): 48 ballot["ballot"][candidate] = float(rating) 49 else: AttributeError: 'list' object has no attribute 'iteritems'
bradbeattie commented 8 years ago

Try the examples in test_functionality/test_schulze_method.py instead. I think the format was changed and the README was never updated.

rdixit commented 8 years ago

That worked! Thank you!

Up to you to close the issue or not. Appreciate your eyes on this Brad.