Tweak CLI interface
Default to "prompt" for ties Allow hiding excluded candidates and sorting by votes in count report
This commit is contained in:
parent
61601f05cc
commit
1f4c7f8efe
@ -41,11 +41,17 @@ def add_parser(subparsers):
|
||||
parser.add_argument('--exclusion', choices=['one_round', 'parcels_by_order', 'by_value', 'wright'], default='one_round', help='how to perform exclusions (default: one_round)')
|
||||
parser.add_argument('--ties', '-t', action='append', choices=['backwards', 'prompt', 'random'], default=None, help='how to resolve ties (default: backwards then random)')
|
||||
parser.add_argument('--random-seed', default=None, help='arbitrary string used to seed the RNG for random tie breaking')
|
||||
parser.add_argument('--hide-excluded', action='store_true', help='hide excluded candidates from results report')
|
||||
parser.add_argument('--sort-votes', action='store_true', help='sort candidates by votes in results report')
|
||||
|
||||
def print_step(stage, result):
|
||||
def print_step(args, stage, result):
|
||||
print('{}. {}'.format(stage, result.comment))
|
||||
|
||||
for candidate, count_card in result.candidates.items():
|
||||
results = list(result.candidates.items())
|
||||
if args.sort_votes:
|
||||
results.sort(key=lambda x: x[1].votes, reverse=True)
|
||||
|
||||
for candidate, count_card in results:
|
||||
state = None
|
||||
if count_card.state == pyRCV2.model.CandidateState.ELECTED or count_card.state == pyRCV2.model.CandidateState.PROVISIONALLY_ELECTED or count_card.state == pyRCV2.model.CandidateState.DISTRIBUTING_SURPLUS:
|
||||
state = 'ELECTED'
|
||||
@ -54,10 +60,14 @@ def print_step(stage, result):
|
||||
elif count_card.state == pyRCV2.model.CandidateState.WITHDRAWN:
|
||||
state = 'Withdrawn'
|
||||
|
||||
ppVotes = count_card.votes.pp(2)
|
||||
ppTransfers = count_card.transfers.pp(2)
|
||||
|
||||
if state is None:
|
||||
print('- {}: {} ({})'.format(candidate.name, count_card.votes.pp(2), count_card.transfers.pp(2)))
|
||||
print('- {}: {} ({})'.format(candidate.name, ppVotes, ppTransfers))
|
||||
else:
|
||||
print('- {}: {} ({}) - {}'.format(candidate.name, count_card.votes.pp(2), count_card.transfers.pp(2), state))
|
||||
if not (args.hide_excluded and state == 'Excluded' and (ppVotes == '0.00' or ppVotes == '-0.00') and (ppTransfers == '0.00' or ppTransfers == '-0.00')):
|
||||
print('- {}: {} ({}) - {}'.format(candidate.name, ppVotes, ppTransfers, state))
|
||||
|
||||
print('Exhausted: {} ({})'.format(result.exhausted.votes.pp(2), result.exhausted.transfers.pp(2)))
|
||||
print('Loss to fraction: {} ({})'.format(result.loss_fraction.votes.pp(2), result.loss_fraction.transfers.pp(2)))
|
||||
@ -88,7 +98,7 @@ def main(args):
|
||||
counter = WIGSTVCounter(election, vars(args))
|
||||
|
||||
if args.ties is None:
|
||||
args.ties = ['backwards', 'random']
|
||||
args.ties = ['prompt']
|
||||
|
||||
counter.options['ties'] = []
|
||||
for t in args.ties:
|
||||
@ -109,7 +119,7 @@ def main(args):
|
||||
stage = 1
|
||||
result = counter.reset()
|
||||
|
||||
print_step(stage, result)
|
||||
print_step(args, stage, result)
|
||||
|
||||
# Step election
|
||||
while True:
|
||||
@ -119,4 +129,4 @@ def main(args):
|
||||
if isinstance(result, pyRCV2.model.CountCompleted):
|
||||
break
|
||||
|
||||
print_step(stage, result)
|
||||
print_step(args, stage, result)
|
||||
|
Reference in New Issue
Block a user