-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsers.py
117 lines (92 loc) · 4.66 KB
/
parsers.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#sorts and filters gsi server dictionary and returns two lists, they contain each´s Team player name list in alphabetical order
def gsi_parse_player_list(payload):
payload = sorted(payload.items()) #sort dictionary (names, alphabetical)
players_t = []
players_ct = []
players = ""
for player in payload:
if player[1]["team"] == "T": #checks player team
players_t.append(player[1]["steamid"]) #appends player name to team list
elif player[1]["team"] == "CT":
players_ct.append(player[1]["steamid"])
else:
print("Player could not be asigned a Team or the payload is corrupted")
for i in range(len(players_t)): #adds players
players += players_t[i]
players += "/"
for j in range(len(players_ct)):
players += players_ct[j]
players += "/"
players = players[:-1] #selects all chars from beginign to the one before the last one
return players
#sorts and filters gsi server dictionary and returns two lists, they contain K/A/D in the alphabetical order of the player´s name
def gsi_parse_stats(payload):
payload = sorted(payload.items()) #sort dictionary (names, alphabetical)
team_t_stats = []
team_ct_stats = []
for player in payload:
p = [] #empty player list
if player[1]["team"] == "T": #checks player team
p.append(int(player[1]["kills"])) #appends stats to player list
p.append(int(player[1]["assists"]))
p.append(int(player[1]["deaths"]))
team_t_stats.append(p) #appends player to team list
elif player[1]["team"] == "CT":
p.append(int(player[1]["kills"]))
p.append(int(player[1]["assists"]))
p.append(int(player[1]["deaths"]))
team_ct_stats.append(p)
else:
print("Player could not be asigned a Team or the payload is corrupted")
return team_t_stats, team_ct_stats
#outputs two lists with team names/steamids in an sorted order | currently used for xlsx
def gsi_parse_names(payload):
payload = sorted(payload.items()) #sort dictionary (names, alphabetical)
team_t= []
team_ct= []
for player in payload:
if player[1]["team"] == "T": #checks player team
team_t.append(int(player[1]["steamid"])) #appends stats to player name
elif player[1]["team"] == "CT":
team_ct.append(int(player[1]["steamid"]))
else:
print("Player could not be asigned a Team or the payload is corrupted")
return team_t, team_ct
#takes a touple of the form ([[t_elo_1,t_elo_2,...],[ct_elo_1,ct_elo_2,...]]) and a string of the form "t_name_1/t_name_2.../ct_name_n"
#returns single string with player name and corosponding new elo "t_name_1:t_new_elo_1|...|ct_name_n:ct_new_elo_n"
def parse_payload_to_send(elo_list, player_dictionary): #elo_list[team(0 = t, 1 = ct)][player][0]
output_string = ""
player_dictionary = sorted(player_dictionary.items())
i = 0
for player in player_dictionary:
if player[1]["team"] == "T":
output_string += str(player[1]["steamid"]) + "$" + str(elo_list[0][i]) + ":" + str(player[1]["kills"]) + ":" + str(player[1]["assists"]) + ":" + str(player[1]["deaths"]) + "/"
i += 1
i = 0
for player in player_dictionary:
if player[1]["team"] == "CT":
output_string += str(player[1]["steamid"]) + "$" + str(elo_list[1][i]) + ":" + str(player[1]["kills"]) + ":" + str(player[1]["assists"]) + ":" + str(player[1]["deaths"]) + "/"
i += 1
return output_string[:-1]
def elo_str_to_elo_list(all_player_elo_str, player_dictionary):
player_dictionary = sorted(player_dictionary.items())
if isinstance(all_player_elo_str, list):
all_player_elo_list = all_player_elo_str
else:
all_player_elo_list = all_player_elo_str.split("/")
out_player_elo_list = [[],[]]
count_ts = 0
count_cts = 0
i = 0
for player in player_dictionary:
if player[1]["team"] == "T": #checks player team
count_ts += 1 #appends player name to team list
elif player[1]["team"] == "CT":
count_cts += 1
for _ in range(count_ts):
out_player_elo_list[0].append(int(all_player_elo_list[i]))
i += 1
for _ in range(count_cts):
out_player_elo_list[1].append(int(all_player_elo_list[i]))
i += 1
return out_player_elo_list