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

commit f225a7b8da2a95be7bdbbea65257fb7c09e14a5d
Author: Greg Stein <[email protected]>
AuthorDate: Tue Jun 7 01:04:39 2022 -0500

    implement the STV vote type
---
 v3/steve/vtypes/stv.py | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/v3/steve/vtypes/stv.py b/v3/steve/vtypes/stv.py
index 0f8889b..9441ddb 100644
--- a/v3/steve/vtypes/stv.py
+++ b/v3/steve/vtypes/stv.py
@@ -36,4 +36,26 @@ def load_stv():
 
 
 def tally(votestrings, kv):
-    pass
+
+    # kv['labelmap'] should be: LABEL: NAME
+    # for example: { 'a': 'John Doe', }
+    labelmap = kv['labelmap']
+
+    seats = kv['seats']
+
+    # Remap all votestrings from a string sequence of label characters,
+    # into a sequence of NAMEs.
+    votes = [[labelmap[c] for c in v] for v in votestrings]
+
+    stv = load_stv()
+
+    # NOTE: it is important that the names are sorted, to create a
+    # reproducible list of names.
+    results = stv.run_stv(sorted(labelmap.values()), votes, seats)
+
+    human = '\n'.join(
+        f'{c.name:40}{" " if c.status == stv.ELECTED else " not "}selected'
+        for c in results.l
+        )
+    data = { 'raw': results, }
+    return human, data

Reply via email to