Skip to content

Latest commit

 

History

History
 
 

elections

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Election tabulation script

The script in this directory converts a comma-separated value (CSV) file from a Jupyter Executive Council election into an .ini file and a .txt file for use with the Apache STeVe script stv_tool.py. After running this latter script, which is stored in the apache/steve project, you will determine which candidates have won.

This script requires Python 3; it is known to work with Python 3.10.8.

Input files

You should have a file votes.csv in the current directory. This is a comma-separated value file exported from Google Forms's vote output.

The first row of votes.csv should include column headers with candidate names in square brackets. (Any text before the opening bracket and after the closing bracket is ignored.)

The second row, and all remaining rows of votes.csv, should be lists of numbered priorities for each candidate. A candidate not ranked should have a rank of an empty string. Two candidates may not have the same rank. Ranks may be skipped; this does not affect the conversion. See example below.

Sample input file and output

The file votes.csv contains nine candidates, whose names are listed in square brackets in the first row, and three votes, in subsequent rows. Each of these votes specifies at least one candidate with a rank. Rank 1 is the customer's first (highest) preference. Larger numbers indicate later (lower) preferences.

The first vote ranks all nine candidates with different ranks. This row's output includes all nine candidates, in ascending order of rank, or descending order of preference.

The second vote ranks four candidates using ranks 1, 2, 3, and 4. These four candidates are output in ascending order of rank, or descending order of preference. The other five candidates are absent from the output.

The third vote ranks four candidates using ranks 2, 4, 6, and 8. These four candidates are output in ascending order of rank, with nothing output for the unused ranks. The output for candidate preferences is the same as for the second vote.

When you run python process-votes.py, two files are output.

board_nominations.ini assigns each candidate a single letter. (You can have up to 26 candidates.)

[nominees]
a: John Appleton
b: Nancy Bass
c: Carla Chang
d: Greg Donaldson
e: Paula Edwards
f: Kimiko Fukui
g: Kanu Gandhi
h: Eric Harris
i: Susan Irving

votedata.txt contains one row for each vote. The date and voter hash are generated by process-votes.py and do not represent the date at which the vote was cast or any identifying characteristic of the voter. They are included for the sole purpose of satisfying the Apache STeVe tabulation script's validator. The rightmost column displays the voter's preferences in descending order, as a string of candidate letters. For example, a voter who preferred first Appleton, Bass, and then Chang from the above slate would have their vote represented as abc.

[2022/11/30 14:28:14] d232776997574c0db2de32dbb0223d31 cadbfgeih
[2022/11/30 14:28:14] bbe953105dfe4db2881bdd9242ad7d9d acfi
[2022/11/30 14:28:14] d84679cb55784d378bcf48b1beae36c7 acfi

Running a tabulation

From the directory where you have votes.csv, run process-votes.py.

This script produces board_nominations.ini and votedata.txt for use with the Apache STeVe tabulation script (stv_tool.py). Run this script, passing the number of seats to elect with the -s parameter. In the example below, the tabulation script will select two winners. You can get more verbose output using the -v parameter.

/path/to/steve/monitoring/stv_tool.py -s 2 votedata.txt

When run with the votedata.txt file shown above, Appleton and Chang are elected.

John Appleton                            elected
Nancy Bass                               not elected
Carla Chang                              elected
Greg Donaldson                           not elected
Paula Edwards                            not elected
Kimiko Fukui                             not elected
Kanu Gandhi                              not elected
Eric Harris                              not elected
Susan Irving                             not elected

Script by Jason Weill (@jweill-aws)