You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by gs...@apache.org on 2026/03/06 12:46:44 UTC

(steve) branch trunk updated (e81e78f -> 1e584ac)

This is an automated email from the ASF dual-hosted git repository.

gstein pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git


    from e81e78f  final tweak for new vote-results.json format
     new b9ec126  There is no workable "new format" inputs. Strip that broken "feature" out.
     new 9c7d674  Some simplifications and tweaks for more modern code.
     new f65ec11  whitespace only. no functional change.
     new 1e584ac  tweak to use pathlib rather than argv[0]

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 monitoring/stv_tool.py | 28 +++++++++---------
 whatif.py              | 80 ++++++++++++++++++++++++++++----------------------
 2 files changed, 59 insertions(+), 49 deletions(-)


(steve) 03/04: whitespace only. no functional change.

Posted by gs...@apache.org.
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 f65ec112da20e2f3f0ec483390e122753b1c0410
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Fri Mar 6 06:30:30 2026 -0600

    whitespace only. no functional change.
---
 whatif.py | 65 +++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 32 insertions(+), 33 deletions(-)

diff --git a/whatif.py b/whatif.py
index d1ffb3d..0e180b9 100755
--- a/whatif.py
+++ b/whatif.py
@@ -43,63 +43,62 @@ import stv_tool
 
 
 def usage():
-  print(f'Usage: {SCRIPTNAME} [-v] RAW_VOTES_FILE [seats] [-]name...')
-  sys.exit(1)
+    print(f'Usage: {SCRIPTNAME} [-v] RAW_VOTES_FILE [seats] [-]name...')
+    sys.exit(1)
 
 
-if True:  ### temporary. avoid indentation changes for now.
-  SCRIPTNAME = sys.argv.pop(0)
+SCRIPTNAME = sys.argv.pop(0)
 
-  if sys.argv and sys.argv[0] == '-v':
+if sys.argv and sys.argv[0] == '-v':
     stv_tool.VERBOSE = True
     sys.argv.pop(0)
 
-  # extract required vote file argument, and load votes from it
-  if not sys.argv or not os.path.exists(sys.argv[0]): usage()
-  votefile = sys.argv.pop(0)
-  names, votes = stv_tool.load_votes(votefile)
+# extract required vote file argument, and load votes from it
+if not sys.argv or not os.path.exists(sys.argv[0]): usage()
+votefile = sys.argv.pop(0)
+names, votes = stv_tool.load_votes(votefile)
 
-  # extract optional number of seats argument
-  if sys.argv and sys.argv[0].isdigit():
+# extract optional number of seats argument
+if sys.argv and sys.argv[0].isdigit():
     seats = int(sys.argv.pop(0))
-  else:
+else:
     seats = 9
 
-  # extract an alias list of first, last, and joined names
-  alias = {}
-  for name in names:
+# extract an alias list of first, last, and joined names
+alias = {}
+for name in names:
     lname = re.sub(r'[^\w ]', '', name.lower())
     alias[lname.replace(' ', '')] = name
     for part in lname.split(' '):
-      alias[part] = name
+        alias[part] = name
 
-  # validate input
-  for arg in sys.argv:
+# validate input
+for arg in sys.argv:
     if arg.lstrip('-').lower() not in alias:
-      sys.stderr.write('invalid selection: %s\n' % arg)
-      usage()
+        sys.stderr.write('invalid selection: %s\n' % arg)
+        usage()
 
-  if not sys.argv:
+if not sys.argv:
     # no changes to the candidates running
     pass
-  elif sys.argv[0][0] == '-':
+elif sys.argv[0][0] == '-':
     # remove candidates from vote
     for name in sys.argv: names.remove(alias[name.lstrip('-').lower()])
-  else:
+else:
     # only include specified candidates
     # NOTE: order is important, so sort the names for repeatability
     names = [ alias[n.lower()] for n in sorted(sys.argv) ]
 
-  # Trim the raw votes based on cmdline params. Eliminate votes that
-  # are not for one of the allowed names. Do not include voters who
-  # did not vote for anybody [post-trimming].
-  trimmed = [ ]
-  for voteseq in votes:
+# Trim the raw votes based on cmdline params. Eliminate votes that
+# are not for one of the allowed names. Do not include voters who
+# did not vote for anybody [post-trimming].
+trimmed = [ ]
+for voteseq in votes:
     newseq = [ v for v in voteseq if v in names ]
     if newseq:
-      trimmed.append(newseq)
+        trimmed.append(newseq)
 
-  # run the vote
-  candidates = stv_tool.run_stv(names, trimmed, seats)
-  candidates.print_results()
-  print('Done!')
+# run the vote
+candidates = stv_tool.run_stv(names, trimmed, seats)
+candidates.print_results()
+print('Done!')


(steve) 04/04: tweak to use pathlib rather than argv[0]

Posted by gs...@apache.org.
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 1e584ac373513dda1518eab50c76b41f78ba60b6
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Fri Mar 6 06:46:35 2026 -0600

    tweak to use pathlib rather than argv[0]
---
 whatif.py | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/whatif.py b/whatif.py
index 0e180b9..25a9eb8 100755
--- a/whatif.py
+++ b/whatif.py
@@ -35,7 +35,8 @@ import os.path
 import re
 import pathlib
 
-THIS_DIR = pathlib.Path(__file__).resolve().parent
+THIS_SCRIPT = pathlib.Path(__file__).resolve()
+THIS_DIR = THIS_SCRIPT.parent
 
 # We're a top-level script. Adjust the import path.
 sys.path.append(str(THIS_DIR / 'monitoring'))
@@ -43,11 +44,12 @@ import stv_tool
 
 
 def usage():
-    print(f'Usage: {SCRIPTNAME} [-v] RAW_VOTES_FILE [seats] [-]name...')
+    print(f'Usage: {THIS_SCRIPT.name} [-v] RAW_VOTES_FILE [seats] [-]name...')
     sys.exit(1)
 
 
-SCRIPTNAME = sys.argv.pop(0)
+# Get rid of the script name.
+_ = sys.argv.pop(0)
 
 if sys.argv and sys.argv[0] == '-v':
     stv_tool.VERBOSE = True


(steve) 01/04: There is no workable "new format" inputs. Strip that broken "feature" out.

Posted by gs...@apache.org.
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 b9ec1266085407efbddd910974beb96f535b1804
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Fri Mar 6 06:12:09 2026 -0600

    There is no workable "new format" inputs. Strip that broken "feature" out.
---
 monitoring/stv_tool.py | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/monitoring/stv_tool.py b/monitoring/stv_tool.py
index 4ef11ce..6b23243 100755
--- a/monitoring/stv_tool.py
+++ b/monitoring/stv_tool.py
@@ -96,7 +96,7 @@ def load_votes(fname):
   return names, votes
 
 
-def read_votefile(fname, newformat):
+def read_votefile(fname):
   """Return a list of votestrings, throwing out who produced each.
 
   Note: the file is time-ordered, and later votes override any prior
@@ -112,12 +112,9 @@ def read_votefile(fname, newformat):
       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 ]
+
+      # Format; example: abc
+      votes[vhash] = [ v for v in vstring ]
 
   # Discard voterhash, and just return the list of votes.
   return list(votes.values())
@@ -523,13 +520,16 @@ def main(argv):
       ### labels such as "AK" and "AB", yet the labels extracted from
       ### board_nominations.ini uses labels like "k" and "b".
       ### QUESTION: do new .json files have a mapping in them? eg. who is "AK"?
-      votes_by_label = process_jsonvotes(jvalue['votes'].values())
-      votes = [[labelmap[l] for l in votelist] for votelist in votes_by_label]
-    else:
-      newformat = (len(next(iter(labelmap))) > 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]
+
+      ### ANSWER: punt. the raw_board_votes.json looks unusable.
+      raise Exception('cannot use that .json file')
+
+    ### we have no files with content like this. Force to False.
+    #newformat = (len(next(iter(labelmap))) > 1)  # keys like "a" or "aa"?
+
+    # votes_by_label: [ [L1, L2, ...], [ L1, L2, ... ], ... ]
+    votes_by_label = read_votefile(args.raw_file)
+    votes = [[labelmap[label] for label in votelist] for votelist in votes_by_label]
 
   # Construct a label-sorted list of names from the labelmap.
   names = [name for _, name in sorted(labelmap.items())]


(steve) 02/04: Some simplifications and tweaks for more modern code.

Posted by gs...@apache.org.
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 9c7d674c61eb4983280df89689d1230723917c28
Author: Greg Stein <gs...@gmail.com>
AuthorDate: Fri Mar 6 06:16:19 2026 -0600

    Some simplifications and tweaks for more modern code.
---
 whatif.py | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/whatif.py b/whatif.py
index 4c11676..d1ffb3d 100755
--- a/whatif.py
+++ b/whatif.py
@@ -27,19 +27,28 @@
 #   whatif.py ../Meetings/20110712/raw_board_votes.txt -LawrenceRosen
 #   whatif.py ../Meetings/20110712/raw_board_votes.txt 1 kulp noirin geir chris
 
-import os.path
 import sys
+if __name__ != '__main__':
+    raise Exception('ERROR: not intended to be used as a library.')
+
+import os.path
 import re
+import pathlib
 
-sys.path.append(os.path.join(os.path.dirname(__file__), 'monitoring'))
+THIS_DIR = pathlib.Path(__file__).resolve().parent
+
+# We're a top-level script. Adjust the import path.
+sys.path.append(str(THIS_DIR / 'monitoring'))
 import stv_tool
 
+
 def usage():
-  print('Usage: %s [-v] RAW_VOTES_FILE [seats] [-]name...' % scriptname)
+  print(f'Usage: {SCRIPTNAME} [-v] RAW_VOTES_FILE [seats] [-]name...')
   sys.exit(1)
 
-if __name__ == '__main__':
-  scriptname = sys.argv.pop(0)
+
+if True:  ### temporary. avoid indentation changes for now.
+  SCRIPTNAME = sys.argv.pop(0)
 
   if sys.argv and sys.argv[0] == '-v':
     stv_tool.VERBOSE = True