Exemplo n.º 1
0
  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)
Exemplo n.º 2
0
  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"])
Exemplo n.º 3
0
    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"])
Exemplo n.º 4
0
 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"])
Exemplo n.º 5
0
    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"
        ])
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
  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
Exemplo n.º 8
0
  def preCount(self):
    OrderDependentSTV.preCount(self)

    self.optionsMsg = "Using a %s threshold." % \
                      string.join(self.threshName, "-")
Exemplo n.º 9
0
    def preCount(self):
        OrderDependentSTV.preCount(self)

        self.optionsMsg = "Using a %s threshold." % \
                          string.join(self.threshName, "-")