Advertisement
Guest User

STV1

a guest
Feb 24th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.87 KB | None | 0 0
  1. import openpyxl
  2. from openpyxl import Workbook
  3. from openpyxl import load_workbook
  4.  
  5. wb = load_workbook('STV.xlsx') #Replace with file name.
  6. ws = wb.active #Sets active sheet.
  7. votes = {} #Votes for each person.
  8. voters = {} #Voters for each person.
  9. voterNomLen = {} #Number of candidates each person has nominated.
  10. votersList = [] #List of voters.
  11. voterNum = 0 #Number of voters.
  12. minVotes = 0 #Minimum number of votes required to win.
  13. cansList = [] #List of candidates.
  14. invalCans = [] #Removed candidates.
  15. invalVoters = [] #Removed voters.
  16. winners = [] #List of winners.
  17. letterList = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
  18.               'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
  19.               'U', 'V', 'W', 'X', 'Y', 'Z',
  20.               'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ',
  21.               'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT',
  22.               'AU', 'AV', 'AW', 'AX', 'AY', 'AZ']
  23.  
  24. class STVfunctions:
  25.     def __init__(self, ws, voterNum, votersList, voterNomLen):
  26.         self.ws = ws
  27.         self.voterNum = voterNum
  28.         self.votersList = votersList
  29.         self.voterNomLen = voterNomLen
  30.  
  31.     def voterNomLenFunction():
  32.         for a in range(votersList):
  33.             for b in range(50):
  34.                 if ws[letterList[a]+str(b)] == '':
  35.                     voterNomLen
  36.  
  37.     def votersListFunction(self):
  38.         for i in range(50):
  39.             if ws[str(letterList[i])+'1'] != 'BREAK':
  40.                 votersList.append(str(letterList[i]))
  41.             else:
  42.                 return votersList
  43.  
  44.     def checkWin(votes):
  45.         if votes[candidates[i]] >= minVotes:
  46.             return True
  47.         return False
  48.  
  49. x = STVfunctions(ws, voterNum, votersList, letterList) #Sets up the class STVfunctions.
  50. votersList = x.votersListFunction()
  51. voterNum = len(votersList)
  52. minVotes = voterNum/3
  53.  
  54. print(votersList)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement