A simple STAR vote tabulator
Project description
starvote
A simple STAR vote tabulator
Copyright 2023 by Larry Hastings
STAR voting is a relatively-new electoral system. It's simple to vote and simple to tabulate. While a completely fair and perfect electoral system is impossible, STAR voting's approach makes reasonable tradeoffs and avoids the worst electoral system pitfalls. It's really great!
This module, starvote, implements a simple STAR vote tabulator.
To use, import starvote
, then instantiate a starvote.Poll
object.
Feed in the ballots using poll.add_ballot(ballot)
; ballots are dict
objects,
mapping the candidate to the ballot's vote for the candidate
(an int
in the range 0 to 5 inclusive).
Once you've added all the ballots, call poll.result
to compute the winner.
If there's an unbreakable tie, poll.result
will raise an
UnbreakableTieError
.
If you want to see how the vote was tabulated, pass in an argument
to the print
keyword-only argument to poll.result
. This should
be a function that behaves like the builtin print
function; it
will only ever be called with positional parameters.
Here's an example of computing a poll between Amy, Brian, and Chuck:
import starvote
poll = starvote.Poll()
poll.add_ballot({'Amy': 1, 'Brian': 3, 'Chuck': 5})
poll.add_ballot({'Amy': 5, 'Brian': 2, 'Chuck': 3})
poll.add_ballot({'Amy': 4, 'Brian': 4, 'Chuck': 5})
winner = poll.result(print=print)
print()
print(f"[Winner]\n{winner}")
Here's what the output of this program looks like:
[Score round]
Chuck -- 13 (average 4.33)
Amy -- 10 (average 3.33)
Brian -- 9 (average 3.00)
[Automatic runoff round]
Chuck -- 2
Amy -- 1
No preference -- 0
[Winner]
Chuck
If the module is executed as a script, it will read a single CSV file in star.vote format, tabulate, and print the result. For example, you can run this from the root of the source-code repository:
% python3 -m starvote sample_votes/sample_vote_automatic_runoff_breakable_tie.csv
to see how starvote handles a tie during the automatic runoff round.
Limitations
Currently this module only supports single-winner STAR voting; variants such as Bloc STAR and Proportional STAR (aka Allocated Score) are not yet supported.
License
starvote is licensed using the
MIT license.
See the LICENSE
file.
The source code repository includes sample ballots downloaded from https://star.vote/. The licensing of these sample ballots is unclear, but they're assumed to be public-domain or otherwise freely redistributable.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file starvote-1.0.tar.gz
.
File metadata
- Download URL: starvote-1.0.tar.gz
- Upload date:
- Size: 164.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.30.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e18640f4704ac3e0692fcf78546624b663163c6d6a6c2cea22175dbcd7de203b |
|
MD5 | b3642aac30ff76365a4cf36224f930ee |
|
BLAKE2b-256 | c6a538bc3e9559a31b33d77f880f290e1bb41477655299b787612867c0ac1713 |
File details
Details for the file starvote-1.0-py3-none-any.whl
.
File metadata
- Download URL: starvote-1.0-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.30.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c94abab8bebaae264ed8571bba7521e741e0835de6e24b5b832b9b1ef3255a7 |
|
MD5 | ce21f2fe27e8ec2228470efcbc774522 |
|
BLAKE2b-256 | a0ff76380c2b2131e1b79e84ec57c0ba6d517d8ed8a4de53be5a3edd39d0ebf7 |