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 8459d64d4639b77c2a3b49293abf4214dbe7a76a Author: Greg Stein <[email protected]> AuthorDate: Thu Jun 2 21:58:16 2022 -0500 Run STV through the v3 path. The v3 code loads stv_tool, and this new script runs the voting through that loading mechanism. Future work will use the v3 tally() function, but this helps to sketch out testing/comparison with more of the v3 apparatus. --- v3/test/populate_v2_stv.sh | 8 +++++++ v3/test/run_stv.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/v3/test/populate_v2_stv.sh b/v3/test/populate_v2_stv.sh index a06e491..e46b0a7 100755 --- a/v3/test/populate_v2_stv.sh +++ b/v3/test/populate_v2_stv.sh @@ -30,11 +30,15 @@ MEETINGS_DIR="$1" REFERENCE_DIR="v2-stv-ref" mkdir "$REFERENCE_DIR" || /bin/true +V3_DIR="v3-stv" +mkdir "$V3_DIR" || /bin/true + THIS_FILE=`realpath $0` THIS_DIR=`dirname "$THIS_file"` #echo $THIS_FILE STV_TOOL=`realpath "$THIS_DIR/../../monitoring/stv_tool.py"` echo $STV_TOOL +V3_TOOL="${THIS_DIR}/run_stv.py" #echo "ls $MEETINGS_DIR/*/raw_board_votes.txt" @@ -43,4 +47,8 @@ for v in `ls $MEETINGS_DIR/*/raw_board_votes.txt`; do DATE=`echo $v | sed -n 's#.*/\([0-9]*\)/.*#\1#p'` echo $DATE "$STV_TOOL" -v "$v" > "$REFERENCE_DIR/$DATE" + + MTG_DIR=`dirname "$v"` + #echo $MTG_DIR + "$V3_TOOL" "${MTG_DIR}" > "${V3_DIR}/$DATE" done diff --git a/v3/test/run_stv.py b/v3/test/run_stv.py new file mode 100755 index 0000000..c33dcd6 --- /dev/null +++ b/v3/test/run_stv.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python3 +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# ---- +# +# ### TBD: DOCCO +# USAGE: run_stv.py .../Meetings/yyyymmdd +# + +import sys +import os.path + +# Ensure that we can import the "steve" package. +THIS_DIR = os.path.realpath(os.path.dirname(__file__)) +sys.path.insert(0, os.path.dirname(THIS_DIR)) +import steve.vtypes.stv + +stv_tool = steve.vtypes.stv.load_stv() +stv_tool.VERBOSE = True + +def main(mtgdir): + rawfile = os.path.join(mtgdir, 'raw_board_votes.txt') + labelfile = os.path.join(mtgdir, 'board_nominations.ini') + + assert os.path.exists(rawfile) + assert os.path.exists(labelfile) + + labelmap = stv_tool.read_labelmap(labelfile) + # Construct a label-sorted list of names from the labelmap. + names = [name for _, name in sorted(labelmap.items())] + + # Turn votes using labels into by-name. + votes_by_label = stv_tool.read_votefile(rawfile).values() + votes = [[labelmap[l] for l in vote] for vote in votes_by_label] + + candidates = stv_tool.run_stv(names, votes, 9) + candidates.print_results() + + ### ugh. for comparison, do it: + print('Done!') + + +if __name__ == '__main__': + main(sys.argv[1])
