Skip to main content

STV polling methods

Project description

STVPoll README

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

Work in progress:

  • CPO STV

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, bcount) in example_ballots:
    poll.add_ballot(candidates, bcount)

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
[<Candidate: chocolate>, <Candidate: orange>, <Candidate: 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.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.1.3.tar.gz (8.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: STVPoll-0.1.3.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for STVPoll-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a53200e07011f795b83236e4458f812457c36e03c042182e82722508e4de6b6b
MD5 e2f1389280bce2689d077849801dabc5
BLAKE2b-256 23db680838b65f920ca2c12d08f2626af2a01f99b94c6bfcd8957db6fd731b44

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