-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalcs.py
67 lines (45 loc) · 1.67 KB
/
calcs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sic
class Calcs_member:
"""This class contains the name and votes for each class member"""
def __init__(self, theName, theVotes):
self.name = theName
self.votes = theVotes
@property
def name(self):
return self._name
@name.setter
def name(self, theName):
self._name = theName
@property
def votes(self):
return self._votes
@votes.setter
def votes(self, theVotes):
self._votes = theVotes
def __str__(self):
return "{} {}".format(self.name, self.votes)
def vote_extractor(member_list, member_name):
"""Extracts votes for a candidate from the other candidates
in a list"""
votes = []
for item in member_list:
if item != member_name:
for key in item.votes:
if key == member_name:
votes.append((item.name, item.votes[key]))
return votes
def member_creator(theLookup, search_dict, index=0, ):
"""Creates a new calcs_member for each object in the member
list which can be processed in calculations more easily"""
member_list = search_dict[theLookup].members
member_name = member_list[index].name
votes = vote_extractor(member_list=member_list, member_name=member_name)
calcs_member = Calcs_member(theName=member_name, theVotes=votes)
return calcs_member
def score_calc(calc_member):
"""Calculates the point allocation for a member
based on the votes stored in the object"""
vote1 = (100 - calc_member.votes[0][1]) / calc_member.votes[0][1]
vote2 = (100 - calc_member.votes[0][1]) / calc_member.votes[1][1]
score = 1/(1 + vote1 + vote2)
return round(score*100)