-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathranked_vote.py
38 lines (30 loc) · 1.41 KB
/
ranked_vote.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import argparse
from pathlib import Path
from textwrap import dedent
from utils import run_stv, parse_tokens, parse_google_form, filter_valid
parser = argparse.ArgumentParser(
description=dedent("""
Run an STV
This script assumes that a Google form was created with a question on
it set up in the following way:
- Multiple-choice grid
- Limit to one response per colum
- Require a response in each row
- Columns must be integers with 1 being the first choice and
higher numbers being less-preferred.
The name of that question should be passed to this script as `question`.
""").strip(),
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument("ballots", type=Path, help="The CSV from Google Forms")
parser.add_argument("tokens", type=Path, help="The token file")
parser.add_argument("question", type=str, help="The question name on the form")
parser.add_argument("seats", type=int, help="Number of seats to elect")
parser.add_argument("--token_col", type=str, help="The column in the CSV containing the voting token", default="Voting Token")
args = parser.parse_args()
votes = parse_google_form(args.ballots, token_col=args.token_col)
valid_tokens = parse_tokens(args.tokens)
valid_votes, invalid_votes = filter_valid(votes, valid_tokens)
print(f"Running election for {args.seats} seats")
result = run_stv(valid_votes, args.question, args.seats)
print(result)