-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_pools.py
88 lines (61 loc) · 2.2 KB
/
generate_pools.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import json
class Player:
def __init__(self, name, GWR, OWGR):
self.name = name
self.GWR = GWR
self.OWGR = OWGR
class Group:
def __init__(self, playerA, playerB, playerC, playerD, groupOWGR, groupGWR):
self.playerA = playerA
self.playerB = playerB
self.playerC = playerC
self.playerD = playerD
self.groupOWGR = groupOWGR
self.groupGWR = groupGWR
def writeGroupsToFile(file_name, groups):
with open(file_name, 'w') as f:
for group in groups:
group_str = 'A: ' + group.playerA.name + ' B: ' + group.playerB.name + ' C: ' + group.playerC.name + \
' D: ' + group.playerD.name + ' OWGR: ' + \
str(group.groupOWGR) + ' GWR: ' + str(group.groupGWR)
f.write("%s\n" % group_str)
def playerDecoder(raw_players):
players = []
for player in raw_players:
players.append(Player(player['name'], player['GWR'], player['OWGR']))
return players
def get_group_gwr(group):
return group.groupGWR
def get_group_owgr(group):
return group.groupOWGR
def get_group_total_rank(group):
return group.groupOWGR + group.groupGWR
# Opening JSON file
f = open('data.json')
# returns JSON object as
# a dictionary
data = json.load(f)
groupA = playerDecoder(data['groupA'])
groupB = playerDecoder(data['groupB'])
groupC = playerDecoder(data['groupC'])
groupD = playerDecoder(data['groupD'])
# Closing file
f.close()
results = []
# Iterating through the json
# list
for playerA in groupA:
for playerB in groupB:
for playerC in groupC:
for playerD in groupD:
groupOWGR = playerA.OWGR + playerB.OWGR + playerC.OWGR + playerD.OWGR
groupGWR = playerA.GWR + playerB.GWR + playerC.GWR + playerD.GWR
results.append(Group(playerA, playerB, playerC,
playerD, groupOWGR, groupGWR))
writeGroupsToFile('unranked_results.txt', results)
results.sort(key=get_group_owgr)
writeGroupsToFile('owgr_results.txt', results)
results.sort(key=get_group_owgr)
writeGroupsToFile('gwr_results.txt', results)
results.sort(key=get_group_total_rank)
writeGroupsToFile('total_rank_results.txt', results)