Condorcet is a utility for evaluating votes using the condorcet method
Project description
Condorcet
Condorcet is a Python library for evaluating votes using the condorcet method.
Installation
pip install condorcet
Synopsis
The library exposes a class CondorcetEvaluator
which is called with a list of candidates and a list of votes in order to instantiate an evaluator.
# Attention! This is pseudo-code!!
CondorcetEvaluator : List[Candidates], List[Votes] -> CondorcetEvaluator
This instantiated evaluator has a method get_n_winners
which takes a (non-negative) integer, n, and returns a list containing at most the first n winners in order, along with a table of pairwise wins and losses for the remainder of the candidates (the ones who are not in the list of winners).
At most, because some times there may not be that many winners — a cycle might exist among a set of candidates. This is one of the motivations for returning a table of pairwise wins and losses along with the list of winners.
# Attention! This is pseudo-code!!
CondorcetEvaluator.get_n_winners : int -> List[Candidates], WinsAndLossesTable
And that is that for that!
Quick Start: Rochambeau Games
This years' edition of the Rochambeau Games had seven people ranking four candidates &mdash Rock, Paper, Scissors, and the relatively unknown Dynamite &mdash from 1 to 4, where candidate 1 on someone's ballot would be their most prefered candidate, and 4, the less preferred.
As the election officer you are to evaluate their votes according to the Condorcet method and announce the result.
You have the following data:
candidates = ["Rock", "Paper", "Scissors", "Dynamite"]
votes = [
{"Rock": 1, "Scissors": 2, "Dynamite": 3, "Paper": 4},
{"Rock": 1, "Dynamite": 2, "Scissors": 3, "Paper": 4},
{"Dynamite": 1, "Paper": 2, "Rock": 3, "Scissors": 4},
{"Paper": 1, "Dynamite": 2, "Rock": 3, "Scissors": 4},
{"Scissors": 1, "Paper": 2, "Dynamite": 3, "Rock": 4},
{"Scissors": 1, "Dynamite": 2, "Paper": 3, "Rock": 4},
{"Rock": 1, "Paper": 2, "Dynamite": 3, "Scissors": 4},
]
You want to announce how the four candidates fared with respect to each other. So, you instantiate a condorcet evaluator using the list of candidates and list of votes, and ask it to produce four winners as shown below:
import condorcet
evaluator = condorcet.CondorcetEvaluator(candidates=candidates, votes=votes)
winners, rest_of_table = evaluator.get_n_winners(4)
Print out the list of winners.
print(winners)
# ['Dynamite']
Four winners were asked for, but only one was returned. Studying the table of wins and losses for the rest of the candidates will throw light on the underlying issue.
print(rest_of_table)
# {
# 'Paper': {
# 'losses': ['Scissors'],
# 'wins': ['Rock']
# },
# 'Rock': {
# 'losses': ['Paper'],
# 'wins': ['Scissors']
# },
# 'Scissors': {
# 'losses': ['Rock'],
# 'wins': ['Paper']
# }
# }
The wins and losses table for the rest of the candidates shows that no winner could be picked among them, as each one has lost to at least one of the other.
Contributing
Condorcet is happy to receive contributions. Please submit a PR/MR containing your contribution (including tests if it's a code contribution) and bug the maintainer to review and merge.
Don't forget to add yourself to CONTRIBUTORS.txt
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 condorcet-0.1.1.tar.gz
.
File metadata
- Download URL: condorcet-0.1.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.8.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba53f89ea2be76ba6fcb24bc381293b68a49bc25d2b8ca0d4b922f1b71b9c436 |
|
MD5 | 58090a2ca78e7a370ae41b534a9cce96 |
|
BLAKE2b-256 | 834987fb842d59004ae3cff551caca60a29b1f005a267e92aa6bcc7e374fb47c |
File details
Details for the file condorcet-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: condorcet-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.5 CPython/3.8.1 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c69ebb2292f9fae51f8b3f740a1695f97560fbcc8a5f1d6d8bce91157d7fffc |
|
MD5 | 98f88455b42399e2e6d831d492aa3311 |
|
BLAKE2b-256 | 023d09eb3bbe31ca8a9d1324f3450f939cea5bd2c348033a5bb7181a57dcf437 |