def checkMinRequirements(self): "Only attempt to count votes if there are enough candidates and voters." OrderDependentSTV.checkMinRequirements(self) if self.b.numBallots < self.batchCutoff * self.numSeats: raise RuntimeError, """\ Not enough ballots to run an election. Need at least %d ballots but have only %d.""" % ( self.batchCutoff*self.numSeats, self.b.numBallots)
def __init__(self, b): OrderDependentSTV.__init__(self, b) MethodPlugin.__init__(self) self.threshName = ["Droop", "Static", "Whole"] self.delayedTransfer = "Off" self.batchElimination = "Zero" self.batchCutoff = 50 self.createGuiOptions(["thresh0", "thresh1", "delayedTransfer", "batchElimination", "batchCutoff"])
def __init__(self, b): OrderDependentSTV.__init__(self, b) MethodPlugin.__init__(self) self.batchElimination = "Cutoff" self.batchCutoff = 50 self.threshName = ["Droop", "Static", "Whole"] self.delayedTransfer = "Off" self.saveWinnersBallots = False self.outputDir = None self.createGuiOptions(["saveWinnersBallots"])
def __init__(self, b): OrderDependentSTV.__init__(self, b) MethodPlugin.__init__(self) self.batchElimination = "Cutoff" self.batchCutoff = 50 self.threshName = ["Droop", "Static", "Whole"] self.delayedTransfer = "Off" self.saveWinnersBallots = False self.outputDir = None self.createGuiOptions(["saveWinnersBallots"])
def __init__(self, b): OrderDependentSTV.__init__(self, b) MethodPlugin.__init__(self) self.threshName = ["Droop", "Static", "Whole"] self.delayedTransfer = "Off" self.batchElimination = "Zero" self.batchCutoff = 50 self.createGuiOptions([ "thresh0", "thresh1", "delayedTransfer", "batchElimination", "batchCutoff" ])
def postCount(self): "Save ballots of winners to a file so that vacancies may be filled." OrderDependentSTV.postCount(self) if not self.saveWinnersBallots: return self.msg.append("") self.msg[self.R+1] = "The winning candidates' votes are stored in the "\ "following files:\n" # Stuff used for creating a unique valid filename for each candidate assert (os.path.exists(self.outputDir)) validChars = string.ascii_letters + string.digits # For each candidate save the candidate's ballots to a unique # filename that starts with the ballot file name. for c in self.winners: # Create a unique filename cName = self.b.names[c] cNameNorm = string.join((x for x in cName if x in validChars), "") fName = os.path.join(self.outputDir, cNameNorm + ".blt") i = 1 while os.path.exists(fName): i += 1 fName = os.path.join(self.outputDir, cNameNorm + str(i) + ".blt") self.msg[self.R + 1] += " %s -> %s\n" % (cName, fName) # Create a new ballots object for each winner candidateBallots = self.b.copy(False) candidateBallots.withdrawn = self.winners.copy() candidateBallots.numSeats = 1 candidateBallots.title = "%s's ballots from %s" % (cName, self.b.title) # Copy the relevant ballots and save for i in self.votes[c]: ballot, ID = self.b.getBallotAndID(i) candidateBallots.appendBallot(ballot, ID) candidateBallots.saveAs(fName) del candidateBallots
def postCount(self): "Save ballots of winners to a file so that vacancies may be filled." OrderDependentSTV.postCount(self) if not self.saveWinnersBallots: return self.msg.append("") self.msg[self.R+1] = "The winning candidates' votes are stored in the "\ "following files:\n" # Stuff used for creating a unique valid filename for each candidate assert(os.path.exists(self.outputDir)) validChars = string.ascii_letters + string.digits # For each candidate save the candidate's ballots to a unique # filename that starts with the ballot file name. for c in self.winners: # Create a unique filename cName = self.b.names[c] cNameNorm = string.join((x for x in cName if x in validChars), "") fName = os.path.join(self.outputDir, cNameNorm + ".blt") i = 1 while os.path.exists(fName): i += 1 fName = os.path.join(self.outputDir, cNameNorm + str(i) + ".blt") self.msg[self.R+1] += " %s -> %s\n" % (cName, fName) # Create a new ballots object for each winner candidateBallots = self.b.copy(False) candidateBallots.withdrawn = self.winners.copy() candidateBallots.numSeats = 1 candidateBallots.title = "%s's ballots from %s" % (cName, self.b.title) # Copy the relevant ballots and save for i in self.votes[c]: ballot, ID = self.b.getBallotAndID(i) candidateBallots.appendBallot(ballot, ID) candidateBallots.saveAs(fName) del candidateBallots
def preCount(self): OrderDependentSTV.preCount(self) self.optionsMsg = "Using a %s threshold." % \ string.join(self.threshName, "-")
def preCount(self): OrderDependentSTV.preCount(self) self.optionsMsg = "Using a %s threshold." % \ string.join(self.threshName, "-")