Skip to main content

STV polling methods

Project description

STVPoll README

https://travis-ci.org/VoteIT/STVPoll.svg?branch=master

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

Changes

0.4.4 (2023-03-09)

  • Fix important bug related to vote transferring.

0.4.3 (2023-03-09)

  • Fix subtle bug in vote transfers, where current votes was not updated for every vote transfer.

0.4.2 (2023-03-09)

  • Fix bug in 0.4.1, where not all elected candidates votes were transferred to next preference.

0.4.1 (2023-03-09)

Important breaking changes: Result data structure is updated. Import paths changed.

  • Rewritten type annotations.

  • Rewritten internal data structures, minimizing mutation of data.

  • Introducing tiebreak strategies.

  • Random tiebreaks not uses a shuffled candidate list, which is reported as part of result.

  • Utility to recalculate result from previous polls, using ordered candidate list in randomized tiebreaks.

  • STVPollBase class moved from __init__.py to abcs.py.

  • Updated result data structure.

0.3.0 (dev)

  • Introduce pedantic_order=False, to avoid incomplete results when randomization can not affect who is elected.

0.2.3 (dev)

  • Fixed bug where votes were discarded in select_multiple.

  • Scottish STV: Select proposals in order of most votes, when there is no more competition.

0.2.2 (dev)

  • Fixed bug with tie in first round on Scottish STV.

  • Fixed bug in quota selection of all seats in CPO.

0.2.1 (dev)

  • Unreleased

0.2.0 (2018-05-23)

  • Fixed bug in deciding which vote to transfer first when multiple elected in Scottish STV. [schyffel] [robinharms]

  • Scottish STV: Resolve ties so that winners are always in correct ranking order (extreme case). [schyffel]

  • Now works on Python 3. [schyffel]

  • Test coverage 100 %. [schyffel]

0.1.4 (2018-05-12)

  • Fixed a situation where primary_candidate in rounds didn’t exist. [schyffel] [robinharms]

0.1.3 (2018-03-22)

  • Excluded empty ballots, so that they do not affect the quota. [schyffel]

0.1.2 (2017-11-24)

  • Fixed exception on empty ballots. [schyffel]

0.1.1 (2017-11-24)

  • Fixed case where randomization caused an exception. [schyffel]

0.1.0 (2017-11-03)

  • Initial version

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

STVPoll-0.4.4.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

STVPoll-0.4.4-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file STVPoll-0.4.4.tar.gz.

File metadata

  • Download URL: STVPoll-0.4.4.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for STVPoll-0.4.4.tar.gz
Algorithm Hash digest
SHA256 85b1e52f5fd5d47d8aaee6dfdd78f7aa2d6f3cdc468e2b37b61daa6aea7a163f
MD5 ffd4f1e08641471ad82481988ff2525d
BLAKE2b-256 2956c07649b6878f42eb756264f35febbc8b55827913fd37c1f3c82a558cbde0

See more details on using hashes here.

Provenance

File details

Details for the file STVPoll-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: STVPoll-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.7

File hashes

Hashes for STVPoll-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 88f00c6cda8c4e9b03d61cf279439e4a7cb31c9d2fd65dde462f6261e16ed1b1
MD5 fe365a6a7181e0cd7851da3d5432ad88
BLAKE2b-256 2dac5c9418864328021a2205802780717cb47bc7d7ef09553478112bf6158455

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page