# pyRCV2: Preferential vote counting # Copyright © 2020 Lee Yingtong Li (RunasSudo) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . __pragma__ = lambda x: None is_py = False __pragma__('skip') is_py = True __pragma__('noskip') class TiesPrompt: """Prompt the user to break ties""" def choose_lowest(self, l): if is_py: print('Multiple tied candidates:') for i, x in enumerate(l): print('{}. {}'.format(i + 1, x[0].name)) while True: choice = input('Which candidate to select? ') try: choice = int(choice) if choice >= 1 and choice < len(l) + 1: break except ValueError: pass print() return l[i - 1] else: # UNUSED IN JS - Cannot call window.prompt from Web Worker # TODO: Work this out message = '' for i, x in enumerate(l): message += (i + 1) + '. ' + x[0].name message += 'Which candidate to select?' while True: choice = window.prompt(message) try: choice = int(choice) if choice >= 1 and choice < len(l) + 1: break except ValueError: pass return l[i - 1] def choose_highest(self, l): return self.choose_lowest(l) class TiesBackwards: def choose_lowest(self, l): raise Exception('Not yet implemented') def choose_highest(self, l): raise Exception('Not yet implemented') class TiesRandom: def choose_lowest(self, l): raise Exception('Not yet implemented') def choose_highest(self, l): raise Exception('Not yet implemented')