コード例 #1
0
    def perform_tally(self):
        '''
        Actually calls to openstv to perform the tally
        '''
        from openstv.ballots import Ballots
        from openstv.plugins import getMethodPlugins

        # get voting and report methods
        methods = getMethodPlugins("byName", exclude0=False)

        # generate ballots
        dirtyBallots = Ballots()
        dirtyBallots.loadKnown(self.ballots_path, exclude0=False)
        dirtyBallots.numSeats = self.num_winners
        cleanBallots = dirtyBallots.getCleanBallots()

        # create and configure election
        e = methods[self.method_name](cleanBallots)

        # run election and generate the report
        # from celery.contrib import rdb; rdb.set_trace()
        e.runElection()

        # generate report
        from .json_report import JsonReport
        self.report = JsonReport(e)
        self.report.generateReport()
コード例 #2
0
ファイル: approval.py プロジェクト: Virako/agora-tally
    def perform_tally(self):
        '''
        Actually calls to openstv to perform the tally
        '''
        from openstv.ballots import Ballots
        from openstv.plugins import getMethodPlugins

        # get voting and report methods
        methods = getMethodPlugins("byName", exclude0=False)

        # generate ballots
        dirtyBallots = Ballots()
        dirtyBallots.loadKnown(self.ballots_path, exclude0=False)
        dirtyBallots.numSeats = self.num_seats
        cleanBallots = dirtyBallots.getCleanBallots()

        # create and configure election
        e = methods[self.method_name](cleanBallots)

        # run election and generate the report
        # from celery.contrib import rdb; rdb.set_trace()
        e.runElection()

        # generate report
        from .json_report import JsonReport
        self.report = JsonReport(e)
        self.report.generateReport()
コード例 #3
0
ファイル: borda.py プロジェクト: miguelramosfdz/agora-tally
    def perform_tally(self, questions):
        '''
        Actually calls to openstv to perform the tally
        '''
        from openstv.ballots import Ballots
        from openstv.plugins import getMethodPlugins

        # get voting and report methods
        methods = getMethodPlugins("byName", exclude0=False)

        # generate ballots
        dirtyBallots = Ballots()
        dirtyBallots.loadKnown(self.ballots_path, exclude0=False)
        dirtyBallots.numSeats = self.num_winners
        cleanBallots = dirtyBallots.getCleanBallots()

        # create and configure election
        e = methods[self.method_name](cleanBallots)
        question = questions[self.question_num]
        e.maxChosableOptions = question['max']

        # run election and generate the report
        e.runElection()

        # generate report
        from .json_report import JsonReport
        self.report = JsonReport(e)
        self.report.generateReport()
コード例 #4
0
    def perform_tally(self):
        '''
        Actually calls to openstv to perform the tally
        '''
        from openstv.ballots import Ballots
        from openstv.plugins import getMethodPlugins

        # get voting and report methods
        methods = getMethodPlugins("byName", exclude0=False)

        # generate ballots
        dirtyBallots = Ballots()
        dirtyBallots.loadKnown(self.ballots_path, exclude0=False)
        dirtyBallots.numSeats = self.num_seats
        cleanBallots = dirtyBallots.getCleanBallots()

        # create and configure election
        e = methods[self.method_name](cleanBallots)

        if self.strong_tie_break_method is not None:
            e.strongTieBreakMethod = self.strong_tie_break_method

        if self.weak_tie_break_method is not None:
            e.weakTieBreakMethod = self.weak_tie_break_method

        if self.digits_precision is not None:
            e.prec = self.digits_precision

        # run election and generate the report
        e.runElection()

        # generate report
        from .json_report import JsonReport
        self.report = JsonReport(e)
        self.report.generateReport()
コード例 #5
0
ファイル: borda.py プロジェクト: Findeton/agora-tally
    def perform_tally(self, questions):
        '''
        Actually calls to openstv to perform the tally
        '''
        from openstv.ballots import Ballots
        from openstv.plugins import getMethodPlugins

        # get voting and report methods
        methods = getMethodPlugins("byName", exclude0=False)

        # generate ballots
        dirtyBallots = Ballots()
        dirtyBallots.loadKnown(self.ballots_path, exclude0=False)
        dirtyBallots.numSeats = self.num_winners
        cleanBallots = dirtyBallots.getCleanBallots()

        # create and configure election
        e = methods[self.method_name](cleanBallots)
        question = questions[self.question_num]
        e.maxChosableOptions = question['max']

        # run election and generate the report
        e.runElection()

        # generate report
        from .json_report import JsonReport
        self.report = JsonReport(e)
        self.report.generateReport()
コード例 #6
0
    def perform_tally(self):
        '''
        Actually calls to openstv to perform the tally
        '''
        from openstv.ballots import Ballots
        from openstv.plugins import getMethodPlugins

        # get voting and report methods
        methods = getMethodPlugins("byName", exclude0=False)

        # generate ballots
        dirtyBallots = Ballots()
        dirtyBallots.loadKnown(self.ballots_path, exclude0=False)
        dirtyBallots.numSeats = self.num_seats
        cleanBallots = dirtyBallots.getCleanBallots()

        # create and configure election
        e = methods[self.method_name](cleanBallots)

        if self.strong_tie_break_method is not None:
            e.strongTieBreakMethod = self.strong_tie_break_method

        if self.weak_tie_break_method is not None:
            e.weakTieBreakMethod = self.weak_tie_break_method

        if self.digits_precision is not None:
            e.prec = self.digits_precision

        # run election and generate the report
        e.runElection()

        # generate report
        from .json_report import JsonReport
        self.report = JsonReport(e)
        self.report.generateReport()
コード例 #7
0
    print usage
    sys.exit(1)

name = args[0]
bltFn = args[1]

if name not in methodNames:
    print "Unrecognized method '%s'" % name
    print usage
    sys.exit(1)

try:
    dirtyBallots = Ballots()
    dirtyBallots.loadKnown(bltFn, exclude0=False)
    if numSeats:
        dirtyBallots.numSeats = numSeats
    cleanBallots = dirtyBallots.getCleanBallots()
except RuntimeError, msg:
    print msg
    sys.exit(1)


def doElection(reps=1):
    "run election with repeat count for profiling"
    for i in xrange(reps):
        e = methods[name](cleanBallots)
        if strongTieBreakMethod is not None:
            e.strongTieBreakMethod = strongTieBreakMethod
        if weakTieBreakMethod is not None:
            e.weakTieBreakMethod = weakTieBreakMethod
        if prec is not None:
コード例 #8
0
ファイル: runElection.py プロジェクト: Conservatory/openstv
  print usage
  sys.exit(1)

name = args[0]
bltFn = args[1]

if name not in methodNames:
  print "Unrecognized method '%s'" % name
  print usage
  sys.exit(1)

try:
  dirtyBallots = Ballots()
  dirtyBallots.loadKnown(bltFn, exclude0=False)
  if numSeats:
    dirtyBallots.numSeats = numSeats
  cleanBallots = dirtyBallots.getCleanBallots()
except RuntimeError, msg:
  print msg
  sys.exit(1)

def doElection(reps=1):
  "run election with repeat count for profiling"
  for i in xrange(reps):
    e = methods[name](cleanBallots)
    if strongTieBreakMethod is not None:
      e.strongTieBreakMethod = strongTieBreakMethod
    if weakTieBreakMethod is not None:
      e.weakTieBreakMethod = weakTieBreakMethod
    if prec is not None:
      e.prec = prec
コード例 #9
0
    def count(cls, vote, **kwargs):
        from Meeting.models import BallotEntry, Vote
        seats = kwargs.get("num_seats", 1)
        assert vote.method == Vote.STV
        ballots = Ballots()

        options = vote.option_set.all().order_by('pk')
        option_translation = {}
        names = []
        for index, option in enumerate(options):
            option_translation[option.id] = index
            names.append(option.name)
        ballots.setNames(names)
        ballots.numSeats = seats

        voter = -1
        ballot = []
        for be in BallotEntry.objects.filter(option__vote=vote).order_by('token_id', 'value').all():
            if voter != be.token_id and ballot != []:
                ballots.appendBallot(ballot)
                ballot = []
            voter = be.token_id
            ballot.append(option_translation[be.option_id])
        if ballots != []:
            ballots.appendBallot(ballot)

        electionCounter = ScottishSTV(ballots)
        electionCounter.strongTieBreakMethod = "manual"
        electionCounter.breakTieRequestQueue = Queue(1)
        electionCounter.breakTieResponseQueue = Queue(1)
        countThread = Thread(target=electionCounter.runElection)
        countThread.start()
        while countThread.isAlive():
            sleep(0.1)
            if not electionCounter.breakTieRequestQueue.empty():
                [tiedCandidates, names, what] = electionCounter.breakTieRequestQueue.get()
                c = cls.ask_user_to_break_tie(tiedCandidates, names, what, vote)
                electionCounter.breakTieResponseQueue.put(c)
            if "R" in vars(electionCounter):
                status = "Counting votes using {}\nRound: {}".format(electionCounter.longMethodName,
                                                                     electionCounter.R + 1)
            else:
                status = "Counting votes using %s\nInitializing..." % \
                         electionCounter.longMethodName
            logger.debug(status)
        logger.info(electionCounter.winners)
        vote.refresh_from_db()
        winners = []
        losers = []
        for w in electionCounter.winners:
            winners.append(ballots.names[w])
        for l in electionCounter.losers:
            losers.append(ballots.names[l])
        vote.results = "Winners: {} \nLosers:{}".format(winners, losers)
        r = YamlReport(electionCounter, outputToString=True)
        r.generateReport()
        report = "\n"
        for index, name in enumerate(ballots.names):
            report += "[{}] -> {}\n".format(index, name)
        report += r.outputFile
        vote.results += report
        vote.save()