forked from rhartsfield/DataMiningLoL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparseMatch.py
More file actions
262 lines (247 loc) · 7.49 KB
/
parseMatch.py
File metadata and controls
262 lines (247 loc) · 7.49 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
from cassiopeia import riotapi
riotapi.set_region("NA")
riotapi.set_api_key("bf735671-a14a-4c52-8e02-ed476b7f8434")
riotapi.set_rate_limits((10, 10), (500, 600))
def getDeaths(match):
deathList = []
frameSet = match.frames
eventSet = [event for eventList in [frame.events for frame in frameSet] for event in eventList]
for event in eventSet:
if event.type.name == 'kill':
deathList.append(event)
return deathList
def getWinner(match):
#Return winner of the match
if match.blue_team.data.winner:
return 0
else:
return 1
def getRoles(match):
'''Return a dict with the following setup:
{'teamPosition': idNum}
'''
roleMap = {}
#Take care of the duo lanes where sup can't be auto determined
#Base this on CS value
blueDuo = []
for p in match.blue_team.participants:
if p.timeline.role.name == 'duo':
blueDuo.append(p)
redDuo = []
for p in match.red_team.participants:
if p.timeline.role.name == 'duo':
redDuo.append(p)
if blueDuo:
if blueDuo[0].stats.data.minionsKilled > blueDuo[1].stats.data.minionsKilled:
roleMap['blueADC'] = blueDuo[0].id
roleMap['blueSup'] = blueDuo[1].id
else:
roleMap['blueADC'] = blueDuo[1].id
roleMap['blueSup'] = blueDuo[0].id
if redDuo:
if redDuo[0].stats.data.minionsKilled > redDuo[1].stats.data.minionsKilled:
roleMap['redADC'] = redDuo[0].id
roleMap['redSup'] = redDuo[1].id
else:
roleMap['redADC'] = redDuo[1].id
roleMap['redSup'] = redDuo[0].id
#Full dictionary creation step
for p in match.blue_team.participants:
if p.timeline.role.name == 'none':
curRole = p.timeline.lane.name
else:
curRole = p.timeline.role.name
curLane = p.timeline.lane.name
if curRole == 'jungle':
roleMap['blueJung'] = p.id
elif curRole == 'support':
roleMap['blueSup'] = p.id
elif curRole == 'duo':
continue
elif curRole == 'carry':
roleMap['blueADC'] = p.id
else:
if curLane == 'top_lane':
roleMap['blueTop'] = p.id
else:
roleMap['blueMid'] = p.id
for p in match.red_team.participants:
if p.timeline.role.name == 'none':
curRole = p.timeline.lane.name
else:
curRole = p.timeline.role.name
curLane = p.timeline.lane.name
if curRole == 'jungle':
roleMap['redJung'] = p.id
elif curRole == 'support':
roleMap['redSup'] = p.id
elif curRole == 'duo':
continue
elif curRole == 'carry':
roleMap['redADC'] = p.id
else:
if curLane == 'top_lane':
roleMap['redTop'] = p.id
else:
roleMap['redMid'] = p.id
return roleMap
def getTeamStats(team):
'''
Returns a list of the below stats with bool values at
indexes 2-7 (Should not normalize these same way)
'''
return [team.data.baronKills,
team.data.dragonKills,
1 if team.data.firstBaron else 0,
1 if team.data.firstBlood else 0,
1 if team.data.firstDragon else 0,
1 if team.data.firstInhibitor else 0,
1 if team.data.firstRiftHerald else 0,
1 if team.data.firstTower else 0,
team.data.inhibitorKills,
team.data.riftHeraldKills,
team.data.towerKills,
]
def checkforZeroes(delta):
'''
Pad values for the delta statistics if game ends early
'''
tenToTwenty = delta.tenToTwenty
twentyToThirty = delta.twentyToThirty
thirtyToEnd = delta.thirtyToEnd
if twentyToThirty == 0:
twentyToThirty = tenToTwenty
thirtyToEnd = tenToTwenty
elif thirtyToEnd == 0:
thirtyToEnd = twentyToThirty
return twentyToThirty, thirtyToEnd
def getTierVal(p):
try:
tier = p.previous_season_tier.name
except ValueError:
return 0.0
if tier == 'bronze':
return 0.2
if tier == 'silver':
return 0.4
if tier == 'gold':
return 0.6
if tier == 'platinum':
return 0.8
if tier == 'diamond':
return 1.0
return 1.2
def getClusterVal(p):
'''
TODO: Import the clusters for proper tier
Get the percent of deaths outside clusters
'''
try:
tier = p.previous_season_tier.name
except ValueError:
tier = 'bronze'
return 0
def getPStats(p, matchLen):
'''
Anything multiplied by coeff is changed to be 'cs per min'
Possible None types with the deltas, currently throw these matches out
If games end early, deltas are padded based on prev delta value
Indexes 3-8 are bools for future normalization
'''
tier = getTierVal(p)
clusters = getClusterVal(p)
zZ = p.timeline.data
coeff = 1/matchLen
csPer20, csPer30 = checkforZeroes(zZ.creepsPerMinDeltas)
csDiff20, csDiff30 = checkforZeroes(zZ.csDiffPerMinDeltas)
dmgTakeDiff20, dmgTakeDiff30 = checkforZeroes(zZ.damageTakenDiffPerMinDeltas)
dmgTakePer20, dmgTakePer30 = checkforZeroes(zZ.damageTakenPerMinDeltas)
gold20, gold30 = checkforZeroes(zZ.goldPerMinDeltas)
xpDiff20, xpDiff30 = checkforZeroes(zZ.xpDiffPerMinDeltas)
xpPer20, xpPer30 = checkforZeroes(zZ.xpPerMinDeltas)
return [tier,
p.stats.data.assists*coeff,
p.stats.data.deaths*coeff,
p.stats.data.doubleKills,
1 if p.stats.data.firstBloodAssist else 0,
1 if p.stats.data.firstBloodKill else 0,
1 if p.stats.data.firstInhibitorAssist else 0,
1 if p.stats.data.firstInhibitorKill else 0,
1 if p.stats.data.firstTowerAssist else 0,
1 if p.stats.data.firstTowerKill else 0,
p.stats.data.goldEarned*coeff,
p.stats.data.goldSpent*coeff,
p.stats.data.killingSprees,
p.stats.data.kills*coeff,
p.stats.data.largestKillingSpree,
p.stats.data.largestMultiKill,
p.stats.data.magicDamageTaken*coeff,
p.stats.data.minionsKilled*coeff,
p.stats.data.neutralMinionsKilled*coeff,
p.stats.data.neutralMinionsKilledEnemyJungle*coeff,
p.stats.data.neutralMinionsKilledTeamJungle*coeff,
p.stats.data.pentaKills,
p.stats.data.physicalDamageTaken*coeff,
p.stats.data.quadraKills,
p.stats.data.sightWardsBoughtInGame*coeff,
p.stats.data.totalDamageDealt*coeff,
p.stats.data.totalDamageDealtToChampions*coeff,
p.stats.data.totalDamageTaken*coeff,
p.stats.data.totalHeal*coeff,
p.stats.data.totalTimeCrowdControlDealt*coeff,
p.stats.data.totalUnitsHealed*coeff,
p.stats.data.towerKills*coeff,
p.stats.data.visionWardsBoughtInGame*coeff,
p.stats.data.wardsKilled*coeff,
p.stats.data.wardsPlaced*coeff,
zZ.creepsPerMinDeltas.zeroToTen,
zZ.creepsPerMinDeltas.tenToTwenty,
csPer20,
csPer30,
zZ.csDiffPerMinDeltas.zeroToTen,
zZ.csDiffPerMinDeltas.tenToTwenty,
csDiff20,
csDiff30,
zZ.damageTakenDiffPerMinDeltas.zeroToTen,
zZ.damageTakenDiffPerMinDeltas.tenToTwenty,
dmgTakeDiff20,
dmgTakeDiff30,
zZ.damageTakenPerMinDeltas.zeroToTen,
zZ.damageTakenPerMinDeltas.tenToTwenty,
dmgTakePer20,
dmgTakePer30,
zZ.goldPerMinDeltas.zeroToTen,
zZ.goldPerMinDeltas.tenToTwenty,
gold20,
gold30,
zZ.xpDiffPerMinDeltas.zeroToTen,
zZ.xpDiffPerMinDeltas.tenToTwenty,
xpDiff20,
xpDiff30,
zZ.xpPerMinDeltas.zeroToTen,
zZ.xpPerMinDeltas.tenToTwenty,
xpPer20,
xpPer30
]
def processMatch(match):
'''
Returns a list with attributes arranged as following:
[class, blue_team, red_team, blue_players(Top, Mid, Jungle, ADC, Sup), red_players(Top, Mid, Jungle, ADC, Sup)]
'''
winClass = getWinner(match)
roleMap = getRoles(match)
blueStats = getTeamStats(match.blue_team)
redStats = getTeamStats(match.red_team)
statMap = {}
matchLen = match.duration.total_seconds()/60
for p in match.participants:
curId = p.id
curList = getPStats(p, matchLen)
statMap[curId] = curList
final = ([winClass]+blueStats+redStats+statMap[roleMap['blueTop']]+
statMap[roleMap['blueMid']]+statMap[roleMap['blueJung']]+
statMap[roleMap['blueSup']]+statMap[roleMap['blueADC']]+
statMap[roleMap['redTop']]+statMap[roleMap['redMid']]+
statMap[roleMap['redJung']]+statMap[roleMap['redSup']]+
statMap[roleMap['redADC']])
return final