STV polling methods
Project description
Library to perform STV Poll calculations. The package was created as part of the VoteIT project, specifically to handle larger elections that was hard to count with Markus Schulzes STV method.
Typical usage would be primary elections or elections with many winners from a pool of many candidates. The result will be proportional.
Fully supported:
Scottish STV
Instant-Runoff Voting (IRV)
Mostly working:
CPO STV (Does not fail gracefully if too many outcomes)
Example
Case from: https://en.wikipedia.org/wiki/Single_transferable_vote
from stvpoll.scottish_stv import ScottishSTV
example_ballots = (
(['orange'], 4),
(['pear', 'orange'], 2),
(['chocolate', 'strawberry'], 8),
(['chocolate', 'bonbon'], 4),
(['strawberry'], 1),
(['bonbon'], 1),
)
poll = ScottishSTV(seats=3, candidates=['orange', 'chocolate', 'pear', 'strawberry', 'bonbon'])
for (candidates, count) in example_ballots:
poll.add_ballot(candidates, count)
result = poll.calculate()
This will return a ElectionResult object that contains the result and some useful metadata. The elected attribute contains the elected candidates.
Candidates to the left have higher preference, so: [‘pear’, ‘orange’] means ‘pear’ before ‘orange’ etc. The number is how many of that kind of ballot there is.
result.elected_as_tuple()
('chocolate', 'orange', 'strawberry')
Code & Contributions
You may fork the code at: https://github.com/VoteIT/STVPoll
Please report any bugs there, or email info@voteit.se
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 STVPoll-0.4.5.tar.gz
.
File metadata
- Download URL: STVPoll-0.4.5.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6464d05759e423315b040d3cc020a9ccf8e9b33df371a606bc0eb4e746b8d00e |
|
MD5 | dbcdc5135b882ebdf967ae68c4ab1532 |
|
BLAKE2b-256 | 08a458a3c48572ee38f236170488ed41bf1810b9093bba9190c7e8159a8d9e65 |
File details
Details for the file STVPoll-0.4.5-py3-none-any.whl
.
File metadata
- Download URL: STVPoll-0.4.5-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa276574b422173abf331f1c70ea4db998f392dfe8fdb62205bddf2d0cbf22a3 |
|
MD5 | ffdcd70b32e6331f9be23e8e81ead306 |
|
BLAKE2b-256 | 6d2bcaba268e498c4aea608bff21ccf674a0983bff92d38dd9413837fc40a9aa |