Skip to content
This repository has been archived by the owner on Feb 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1 from Findeton/next
Browse files Browse the repository at this point in the history
add BordaCustom
  • Loading branch information
edulix committed Apr 6, 2015
2 parents 14ce3fa + e7137bf commit 5bea65b
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions openstv/MethodPlugins/BordaCustom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"Plugin module for Borda BordaCustom"

## Copyright (C) 2015 Felix Robles Elvira
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.

__revision__ = "$Id: BordaCustom.py 715 2015-02-27 17:00:55Z edulix $"

from openstv.STV import NonIterative
from openstv.plugins import MethodPlugin

##################################################################

class BordaCustom(NonIterative, MethodPlugin):
"Nauru Borda count"

methodName = "BordaCustom"
longMethodName = "Custom Borda Count"
status = 1
weightByPosition = None

htmlBody = """
<p>With the Borda count, candidates recieve points based on their
position on the ballots. The BordaCustom class allows to define the
points candidates receive for their position on the ballots.</p>
"""

htmlHelp = (MethodPlugin.htmlBegin % (longMethodName, longMethodName)) +\
htmlBody + MethodPlugin.htmlEnd

def __init__(self, b):
NonIterative.__init__(self, b)
MethodPlugin.__init__(self)

self.createGuiOptions([])

def preCount(self):
NonIterative.preCount(self)

self.optionsMsg = ""
self.prec = 0
self.p = 10**self.prec

def countBallots(self):
"Count the votes using the Borda Count."

# Add up the Borda counts
for i in range(self.b.numWeightedBallots):
weight, blt = self.b.getWeightedBallot(i)
# Ranked candidates get their usual Borda score
for j, c in enumerate(blt):
self.count[c] += self.p * weight * self.weightByPosition[j]

self.msg += "Borda count totals. "

# Choose the winners
desc = self.chooseWinners()
self.msg += desc

0 comments on commit 5bea65b

Please sign in to comment.