Skip to main content

STV polling methods

Reason this release was yanked:

Bug in Scottish STV, where not all votes are transfered when electing multiple candidates

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.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.1.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

STVPoll-0.4.1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: STVPoll-0.4.1.tar.gz
  • Upload date:
  • Size: 10.6 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.1.tar.gz
Algorithm Hash digest
SHA256 dcf83230e18c535363e9203e2340f3d80324c96e2be2e6b119f01ea0e7a0e355
MD5 dceccdbd00fa0cfaca2b132b18ae46e6
BLAKE2b-256 75d05a94d7ffb436299293185ed4494a06052784dd05f597d8afd7dcd2ac42c7

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: STVPoll-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 17.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 696146312d612bc8719ff210178bd25bacfb09f94ac2dfa1830d3feeb5b80502
MD5 a11215b783e047ee80e1cf1c2d5c3a53
BLAKE2b-256 7c5d34f1f89622663f34f454b6324444768b43c818a2ecc922dc269c5c6a50e4

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