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 2caced1 support "new format" raw vote files
2caced1 is described below
commit 2caced1d74f358194f615c2f29db21645f0136e5
Author: Greg Stein <[email protected]>
AuthorDate: Mon Jul 28 18:16:09 2025 -0500
support "new format" raw vote files
---
monitoring/stv_tool.py | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/monitoring/stv_tool.py b/monitoring/stv_tool.py
index eb60b94..901c2fe 100755
--- a/monitoring/stv_tool.py
+++ b/monitoring/stv_tool.py
@@ -47,7 +47,7 @@ BILLIONTH = 0.000000001
# "[" date "]" voterhash votes
RE_VOTE = re.compile(r'\[.{19}\]\s+'
r'(?P<voterhash>[\w\d]{32})\s+'
- r'(?P<votes>[a-z]{1,26})',
+ r'(?P<votes>.*)$',
re.I)
VERBOSE = False
@@ -96,7 +96,7 @@ def load_votes(fname):
return names, votes
-def read_votefile(fname):
+def read_votefile(fname, newformat):
"""Return a list of votestrings, throwing out who produced each.
Note: the file is time-ordered, and later votes override any prior
@@ -108,10 +108,19 @@ def read_votefile(fname):
match = RE_VOTE.match(line)
if match:
# For a given voter hashcode, record their latest set of votes.
- votes[match.group('voterhash')] = match.group('votes')
+ vhash = match.group('voterhash')
+ vstring = match.group('votes').lower()
+ if vstring == '-': # abstain
+ continue
+ if newformat:
+ # New format; example: AA AB AC
+ votes[vhash] = [ v for v in vstring.split() ]
+ else:
+ # Old format; example: abc
+ votes[vhash] = [ v for v in vstring ]
# Discard voterhash, and just return the list of votes.
- return votes.values()
+ return list(votes.values())
def read_jsonvotes(fname):
@@ -493,8 +502,10 @@ def main(argv):
votes_by_label = read_jsonvotes(args.raw_file)
votes = [[labelmap[l.lower()] for l in vote.split()] for vote in
votes_by_label]
else:
- votes_by_label = read_votefile(args.raw_file)
- votes = [[labelmap[l] for l in vote] for vote in votes_by_label]
+ newformat = (len(list(labelmap.keys())[0]) > 1) # keys like "a" or "aa"?
+ # votes_by_label: [ [L1, L2, ...], [ L1, L2, ... ], ... ]
+ votes_by_label = read_votefile(args.raw_file, newformat)
+ votes = [[labelmap[label] for label in votelist] for votelist in
votes_by_label]
candidates = run_stv(names, votes, args.seats)
candidates.print_results()