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()
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()
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()
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()
def __init__(self, vote, membervotes, system="ScottishSTV"): self.vote = vote self.membervotes = membervotes self.tie = False methods = getMethodPlugins("byName", exclude0=False) if system not in methods: raise Exception("Unknown OpenSTV method " + system) self.system = methods[system] self.election = None
def __init__(self, parent): wx.Frame.__init__(self, parent, -1, "OpenSTV", size=(900, 600)) warnings.showwarning = self.catchWarnings # Get method plugins and create dict for easy access plugins = getMethodPlugins("classes") self.methodClasses1 = {} # Methods enabled by default self.methodClasses2 = {} # All methods self.lastMethod = "Scottish STV" for p in plugins: if p.status == 1: self.methodClasses1[p.longMethodName] = p self.methodClasses2[p.longMethodName] = p self.methodClasses = self.methodClasses1 # Methods currently viewable to user self.breakTiesRandomly = False fn = os.path.join(getHome(), "Icons", "pie.ico") self.icon = wx.Icon(fn, wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) self.lastBallotFile = "" self.electionList = [] self.menuBar = wx.MenuBar() self.MakeMenu() self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) # create a notebook self.notebook = wx.Notebook(self, -1) # create a console window self.console = wx.TextCtrl(self.notebook, -1, style=wx.TE_MULTILINE|wx.TE_READONLY|\ wx.TE_WORDWRAP|wx.FIXED|wx.TE_RICH2) self.console.SetMaxLength(0) ps = self.console.GetFont().GetPointSize() font = wx.Font(ps, wx.MODERN, wx.NORMAL, wx.NORMAL) self.console.SetFont(font) # add the console as the first page self.notebook.AddPage(self.console, "Console") self.output = Output(self.notebook) sys.stdout = self.output sys.stderr = self.output self.introText = """\ OpenSTV Copyright 2003-2010 Jeffrey O'Neill GNU General Public License See Help->License for more details. To run an election with an existing ballot file, select "New Election" from the File menu. To create a new ballot file, select "Create New Ballot File" from the File menu. To edit an existing ballot file, select "Edit Ballot File" from the File menu. For more information about the operation of OpenSTV, see the Help menu, go to www.OpenSTV.org, or send an email to [email protected]. """ self.console.AppendText(self.introText)
def get_election_classes(self): return getMethodPlugins("byName")
def get_election_types(self): return getMethodPlugins("byName").keys()
#!/usr/bin/env python "run an election from the command line with optional profiling" __revision__ = "$Id: runElection.py 715 2010-02-27 17:00:55Z jeff.oneill $" import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import getopt from openstv.ballots import Ballots from openstv.plugins import getMethodPlugins, getReportPlugins methods = getMethodPlugins("byName", exclude0=False) methodNames = methods.keys() methodNames.sort() reports = getReportPlugins("byName", exclude0=False) reportNames = reports.keys() reportNames.sort() usage = """ Usage: runElection.py [-p prec] [-r report] [-t tiebreak] [-w weaktie] [-s seats] [-P] [-x reps] method ballotfile -p: override default precision (in digits) -r: report format: %s -t: strong tie-break method: random*, alpha, index -w: weak tie-break method: (method-default)*, strong, forward, backward