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