Skip to main content

The Hare-Clark electoral counting system, implemented in Python.

Project description

PyPI codecov Unit tests Code style checks

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

  1. The voting system
  2. Installation
  3. Usage
    1. The Position class
    2. Vote validation
    3. Loading from other sources

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


Download files

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

Source Distribution

hcvote-0.2.0.tar.gz (8.1 kB view hashes)

Uploaded Source

Built Distribution

hcvote-0.2.0-py3-none-any.whl (8.8 kB view hashes)

Uploaded Python 3

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