2022-06-25 08:43:38 +00:00
# Vote Counter
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
An opinionated single transferrable vote counter for the command line.
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
## Installation
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
Installation can be done via cargo by running:
2022-05-24 12:25:23 +00:00
```
2022-06-25 08:43:38 +00:00
cargo install vote-counter
2022-05-24 12:25:23 +00:00
```
2022-06-25 08:43:38 +00:00
## Demo
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
A sample `csv` file in the appropriate format is provided at the top level of this repository. Run:
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
```
vote-counter sample.csv --report
```
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
to count the votes from that file.
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
## Arguments
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
Running `vote-counter --help` will output the following:
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
```
USAGE:
vote-counter [OPTIONS] < PATH >
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
ARGS:
< PATH > Path to the CSV containing the ballots
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
OPTIONS:
-h, --help Print help information
--report Generate report of counting
-t, --threshold < THRESHOLD > Threshold to win [default: 0.5]
-V, --version Print version information
```
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
explaining each argument and how to use it.
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
## Ballot File
The ballot file should be a `csv` formatted as below:
| Peter | Mia | Hannah | Lee | Fred | Julia |
| ----- | --- | ------ | --- | ---- | ----- |
| | 2 | 1 | | | 3 |
| 1 | | 2 | 3 | 4 | |
| 5 | 4 | 3 | 1 | 2 | 6 |
Each row represents a ballot paper, where preferenced are expressed starting at 1, and continuing until the voter no longer has a preference.
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
## Validity of Votes
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
This program is generally permissive in the votes that are considered valid. If a ballot includes any number of non-negative preference numbers, none of which are repeating, the ballot is valid.
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
An invalid ballot occurs when the same preference is expressed twice.
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
For example, the following are not valid:
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
| Peter | Mia | Hannah | Lee | Fred | Julia |
| ----- | --- | ------ | --- | ---- | ----- |
| 1 | 1 | | 3 | | |
| 0 | 1 | | 4 | | 4 |
| 2 | | 2 | | 1 | |
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
However the following are valid:
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
| Peter | Mia | Hannah | Lee | Fred | Julia |
| ----- | --- | ------ | --- | ---- | ----- |
| 0 | 1 | 2 | | | 3 |
| | | 1 | 4 | | |
| 2 | | 5 | | | 1 |
2022-05-24 12:25:23 +00:00
2022-06-25 08:43:38 +00:00
Negative numbers are simply ignored.