This is an automated email from the ASF dual-hosted git repository.
gstein pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git
The following commit(s) were added to refs/heads/trunk by this push:
new a203000 Deprecate run_vote(), in favor of run_stv()
a203000 is described below
commit a2030009b84e590c7585d7415289b08414dd2074
Author: Greg Stein <[email protected]>
AuthorDate: Thu Jun 2 17:42:05 2022 -0500
Deprecate run_vote(), in favor of run_stv()
Adjust params slightly. Add some assertions. Add some debug code to
verify that the ordering of ballots do not matter (tho choices do!).
Remove a dumb block of code for num_seats<=0.
---
monitoring/stv_tool.py | 28 +++++++++++++++++++++++-----
1 file changed, 23 insertions(+), 5 deletions(-)
diff --git a/monitoring/stv_tool.py b/monitoring/stv_tool.py
index d569f14..0315cd3 100755
--- a/monitoring/stv_tool.py
+++ b/monitoring/stv_tool.py
@@ -121,22 +121,40 @@ def read_labelmap(fname):
sys.exit(2)
+#@deprecated
def run_vote(names, votes, num_seats):
+
+ # List of votestrings, each as a list of ordered name choices.
+ ordered_votes = votes.values()
+
+ return run_stv(names, ordered_votes, num_seats)
+
+
+def run_stv(names: list, ordered_votes: list, num_seats: int):
+
+ # NOTE: NAMES must be a list for repeatability purposes. It does not
+ # need to obey any particular ordering rules, but when re-running
+ # tallies, NAMES must be presented with the same ordering.
+
+ assert len(set(names)) == len(names), "duplicates present!"
+ assert num_seats > 0
+
candidates = CandidateList(names)
# name -> Candidate
remap = dict((c.name, c) for c in candidates.l)
- # Turn VOTES into a list of ordered-lists of Candidate objects
- votes = [[remap[n] for n in choices] for choices in votes.values()]
+ # We can test that ordering of voters has no bearing. Perform runs
+ # and alter the .seed() value.
+ #ordered_votes = list(ordered_votes); random.seed(1);
random.shuffle(ordered_votes); print('VOTE:', ordered_votes[0])
+
+ # VOTES is a list of ordered-lists of Candidate objects
+ votes = [[remap[n] for n in choices] for choices in ordered_votes]
if candidates.count(ELECTED + HOPEFUL) <= num_seats:
dbg('All candidates elected')
candidates.change_state(HOPEFUL, ELECTED)
return candidates
- if num_seats <= 0:
- candidates.change_state(HOPEFUL, ELIMINATED)
- return candidates
quota = None # not used on first pass
iteration = 1