The Hare-Clark electoral counting system, implemented in Python.
Project description
The Hare-Clark electoral system in Python
The Hare-Clark electoral system is a preferential voting system used for elections in Tasmania and the Australian Capital Territory. This small Python package provides an implementation of this system, with the ability to load votes from a range of sources and formats.
Table of Contents
The voting system
TODO
Installation
This package is available on PyPI, and can be installed with pip;
pip install hcvote
Alternatively, you can clone the repository and install it directly with pip;
git clone git@github.com:LiamBlake/hcvote.git
cd hcvote
pip install .
To install the development and testing tools, run
pip install -e .[dev,test]
Usage
The Position
class
The main functionality is contained by the Position
class, which represents a position with one or more vacancies:
from hcvote import Position
# The names of the candidates
names = ["Platypus", "Wombat", "Kangaroo", "Koala"]
# Create a position with 2 available places
p = Position(no_vac=2, candidates=names)
Votes can be added via the add_votes
method, which accepts a list of lists, where each sublist corresponds to a vote. Each vote is an ordered list of either the candidate names or corresponding (one-based) indices matching the order originally passed to candidates
when constructing the Position
;
votes = []
# This vote has Wombat as the first preference, Platypus as the second, etc.
votes[0] = ["Wombat", "Platypus", "Koala", "Wombat"]
# Alternatively, (one-based) indices can be used.
# This vote has Koala as the first preference, Wombat as the second, etc.
votes[1] = [4, 2, 1, 3]
# Add the votes to the Position
p.add_votes(votes)
To perform the count once all votes have been added, call the count_vote
method:
p.count_vote()
The elected candidates are then available from the elected
property:
p.elected
which returns as list of the elected candidates.
Vote Validation
TODO
Loading votes from other sources
TODO
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 hcvote-0.2.0.tar.gz
.
File metadata
- Download URL: hcvote-0.2.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab830431b2c8ccf6e4a0c73cc3f0647c0b50174234ef23c04392da2236e8535d |
|
MD5 | 737c16d2bdf7d18e8a7cf36870e669b6 |
|
BLAKE2b-256 | fc7e946710dcb1315c77b861cc2395d1bb3ccde46d46035efbde2683c6d5779d |
File details
Details for the file hcvote-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: hcvote-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98043c0336e417c52a02fdf408ebbeee135b583f6ce7e46b577bb64e128cc24d |
|
MD5 | 8a38d5cb854bd8de8618f9f1b4ce4e18 |
|
BLAKE2b-256 | aa9654fadc1ca9639696f4fb10353d20d79147ab97eb4478eeb74f6759e9fbe6 |