Skip to content

🗳 Python implementation of the Hare-Clark electoral system

License

Notifications You must be signed in to change notification settings

liamblake/hcvote

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 [email protected]: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

About

🗳 Python implementation of the Hare-Clark electoral system

Resources

License

Stars

Watchers

Forks

Languages