From 71de14ecfca6cc47444d2198b18a0d71eabc99de Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 28 Feb 2021 23:15:43 +1100 Subject: [PATCH] Display --no-bulk-elect as one stage on web version --- docs/options.md | 2 +- pyRCV2/method/base_stv.py | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/docs/options.md b/docs/options.md index 8ef196d..0bccf76 100644 --- a/docs/options.md +++ b/docs/options.md @@ -57,7 +57,7 @@ This option allows you to specify whether the votes required for election can ch When bulk election is enabled (default), all remaining candidates are declared elected in a single stage once the number of not-excluded candidates exactly equals the number of vacancies to fill. Further surplus distributions are not performed. This is typical of most STV rules. -When bulk election is disabled, surpluses continue to be distributed even once the number of not-excluded candidates exactly equals the number of vacancies to fill. Once there are no more surpluses to distribute, the candidates are declared elected, one by one, in descending order of votes. This ensures that only one candidate is ever elected in each round and the order of election is well-defined, which is required e.g. for some affirmative action rules. +When bulk election is disabled, surpluses continue to be distributed even once the number of not-excluded candidates exactly equals the number of vacancies to fill. Once there are no more surpluses to distribute, the candidates are declared elected, one by one, in descending order of votes. This ensures that only one candidate is ever elected at a time and the order of election is well-defined, which is required e.g. for some affirmative action rules. ## Bulk exclusion (--bulk-exclude) diff --git a/pyRCV2/method/base_stv.py b/pyRCV2/method/base_stv.py index 1fa3a4f..f394771 100644 --- a/pyRCV2/method/base_stv.py +++ b/pyRCV2/method/base_stv.py @@ -304,11 +304,23 @@ class BaseSTVCounter: # Declare elected one remaining candidate at a time hopefuls = [(c, cc) for c, cc in self.candidates.items() if cc.state == CandidateState.HOPEFUL] hopefuls.sort(key=lambda x: x[1].votes, reverse=True) - candidate_elected, count_card = self.choose_highest(hopefuls) - count_card.state = CandidateState.PROVISIONALLY_ELECTED - self.num_elected += 1 - count_card.order_elected = self.num_elected + order_elected = [] + + while len(hopefuls) > 0: + x = self.choose_highest(hopefuls) + + x[1].state = CandidateState.PROVISIONALLY_ELECTED + self.num_elected += 1 + x[1].order_elected = self.num_elected + + order_elected.append(x[0].name) + hopefuls.remove(x) + + if len(order_elected) == 1: + self.logs.append(order_elected[0].name + ' is elected to fill the remaining vacancy.') + else: + self.logs.append(self.pretty_join(order_elected) + ' are elected to fill the remaining vacancies.') return self.make_result('Bulk election')