-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatchTimelinePreProcessor.py
184 lines (154 loc) · 7.4 KB
/
MatchTimelinePreProcessor.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#Participants - 330 Total For all Champtions
# Chamption Stats - 25
# Total Damage Done
# Total damage to champtions
# Total damage taken
# Jungle Minions killed
# Minions killed
# Level
# Time enemy spent
# Total Gold
#Events
# Ward_placed
# Yellow_trinket
# blue_trinked
# Sight_ward
# Control_ward
# Ward_killed
# Yellow_trinket
# blue_trinked
# Sight_ward
# Control_ward
#Champion_kill
# killerId - 10 features
# victim_id - 10 features
# assistingParticipantIds (list) - 10 features
#champion_special_kill
# type: kill_ace (for team)
#building_kill
# type: tower_building - 1 feature for team
# type: INHIBITOR_BUILDING - 1 feature for team
#ELITE_MONSTER_KILL (All by team id)
# monster_type: baron_nashor
# monster_type: dragon
# monster_type: RIFTHERALD
#game_end
import json
import progressbar
validWardTypes = ['YELLOW_TRINKET', "BLUE_TRINKET", "SIGHT_WARD", "CONTROL_WARD"]
team100Ids = [1, 2, 3, 4, 5]
team200Ids = [6, 7, 8, 9, 10]
mactchdict = dict()
print("Pre Process Match Time Lines")
with open("Matches.json", "r") as infile:
matches = json.load(infile)
#List of all the matches:
widgets = ['[', progressbar.Counter(format='%(value)d/%(max_value)d'), ']', progressbar.Timer(format="Elapsed Time: %(elapsed)s"), ']', progressbar.Bar('*')]
for i in progressbar.progressbar(range(len(matches)), widgets=widgets):
match = matches[i]
#Match is a dict of [gameid, frames]
overalldict = dict()
matchinfo = dict()
teaminfo = dict()
teaminfo['Team100_Aces'] = 0
teaminfo['Team200_Aces'] = 0
teaminfo['Team100_TowerKills'] = 0
teaminfo['Team200_TowerKills'] = 0
teaminfo['Team100_InhibKills'] = 0
teaminfo['Team200_InhibKills'] = 0
teaminfo['Team100_Barons'] = 0
teaminfo['Team200_Barons'] = 0
teaminfo['Team100_RiftHeralds'] = 0
teaminfo['Team200_RiftHeralds'] = 0
teaminfo['Team100_Dragons'] = 0
teaminfo['Team200_Dragons'] = 0
#All participant info for a specific frame
participantinfo = dict()
for i in range(1, 11):
participantinfo[f'Champ{i}_wardsPlaced'] = 0
participantinfo[f'Champ{i}_wardsKilled'] = 0
participantinfo[f'Champ{i}_kills'] = 0
participantinfo[f'Champ{i}_deaths'] = 0
participantinfo[f'Champ{i}_assists'] = 0
frameid = 0
for frame in match["frames"]:
#Frame is a dictionary of [events, participantInfo]
#For each event
for event in frame["events"]:
eventType = event['type']
if (eventType == 'WARD_PLACED') and (event['wardType'] in validWardTypes):
id = event["creatorId"]
participantinfo[f'Champ{id}_wardsPlaced'] += 1
elif (eventType == 'WARD_KILL') and (event['wardType'] in validWardTypes):
id = event["killerId"]
if(id != 0):
participantinfo[f'Champ{id}_wardsKilled'] += 1
elif (eventType == 'CHAMPION_KILL'):
killerId = event['killerId']
victimId = event['victimId']
if (killerId != 0):
participantinfo[f'Champ{killerId}_kills'] += 1
participantinfo[f'Champ{victimId}_deaths'] += 1
if "assistingParticipantIds" in event.keys():
for assitId in event['assistingParticipantIds']:
participantinfo[f'Champ{assitId}_assists'] += 1
elif (eventType == 'CHAMPION_SPECIAL_KILL') and event['killType'] == "KILL_ACE":
if (event['killerId'] in team100Ids):
teaminfo['Team100_Aces'] += 1
elif (event['killerId'] in team200Ids):
teaminfo['Team200_Aces'] += 1
elif (eventType == 'BUILDING_KILL'):
if (event['buildingType'] == "TOWER_BUILDING"):
if (event['killerId'] in team100Ids):
teaminfo[f'Team100_TowerKills'] += 1
elif (event['killerId'] in team200Ids):
teaminfo[f'Team200_TowerKills'] += 1
elif (event['buildingType'] == "INHIBITOR_BUILDING"):
if (event['killerId'] in team100Ids):
teaminfo[f'Team100_InhibKills'] += 1
elif (event['killerId'] in team200Ids):
teaminfo[f'Team200_InhibKills'] += 1
pass
elif (eventType == 'ELITE_MONSTER_KILL'):
teamid = event['killerTeamId']
if(event['monsterType'] == 'RIFTHERALD'):
if (event['killerId'] in team100Ids):
teaminfo['Team100_RiftHeralds'] += 1
elif (event['killerId'] in team200Ids):
teaminfo['Team200_RiftHeralds'] += 1
if(event['monsterType'] == 'DRAGON'):
teaminfo[f'Team{teamid}_Dragons'] += 1
if(event['monsterType'] == 'BARON_NASHOR'):
teaminfo[f'Team{teamid}_Barons'] += 1
pass
elif (eventType == 'GAME_END'):
matchinfo['WinningTeam'] = event['winningTeam']
#For each participant
for participantid in frame["participantInfo"]:
#Participant is a dictionary
participant = frame["participantInfo"][participantid]
#Base damage
participantinfo[f'Champ{participantid}_jungleMinionsKilled'] = participant['jungleMinionsKilled']
participantinfo[f'Champ{participantid}_level'] = participant['level']
participantinfo[f'Champ{participantid}_minionsKilled'] = participant['minionsKilled']
participantinfo[f'Champ{participantid}_timeEnemySpentControlled'] = participant['timeEnemySpentControlled']
participantinfo[f'Champ{participantid}_totalGold'] = participant['totalGold']
#Damage stats
participantinfo[f'Champ{participantid}_totalDamageDone'] = participant['damageStats']['totalDamageDone']
participantinfo[f'Champ{participantid}_totalDamageDoneToChampions'] = participant['damageStats']['totalDamageDoneToChampions']
participantinfo[f'Champ{participantid}_totalDamageTaken'] = participant['damageStats']['totalDamageTaken']
#Add each stat to the dictionary of chamption stats
for statName in participant['championStats']:
participantinfo[f'Champ{participantid}_{statName}'] = participant['championStats'][statName]
newdict = dict()
newdict.update(teaminfo.copy())
newdict.update(participantinfo.copy())
overalldict[frameid] = newdict.copy()
frameid += 1
evenmoreoverall = dict()
evenmoreoverall['winningteam'] = matchinfo['WinningTeam']
evenmoreoverall['frames'] = overalldict.copy()
mactchdict[match['gameid']] = evenmoreoverall.copy()
print("\nWrite Processed File")
with open("MatchesProcessed.json", "w") as outfile:
json.dump(mactchdict, outfile, separators=(',', ':'))