-
Notifications
You must be signed in to change notification settings - Fork 0
/
RiotParser.py
81 lines (70 loc) · 3.26 KB
/
RiotParser.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
# This class does the following:
# Given the match data from get_match_by_matchid from RiotAPI
# Returns a panda Dataframe with the following column information (in this order):
# - Summoner name
# - Game Duration
# - Match Result
# - Champion
# - Creep Score
# - Gold Total
# - Champion Level
# - Vision Score
# TODO3 (stretch goals):
# color/scale the heatmap properly (40-60 instead of 0-100)
# adjust how big the map is (not ugly)
import pandas as pd
class RiotParser(object):
# SUMMONER_NAME = 'Summoner Name'
# GAME_DURATION = 'Game Duration'
# MATCH_RESULT = 'Match Result'
# CHAMPION_ID = 'Champion ID'
# CREEP_SCORE = 'Creep Score'
# GOLD_EARNED = 'Gold Earned'
# CHAMPION_LEVEL = 'Champion Level'
# VISION_SCORE = 'Vision Score'
def __init__(self, name):
self.summonerName = name
# Parses desired data (refer to above) from a list of matchData into a dictionary
def parseData(self, matchDataList):
# add all match data into a list
dataList = matchDataList
parsedData = {self.SUMMONER_NAME: [],
self.GAME_DURATION: [],
self.MATCH_RESULT: [],
self.CHAMPION_ID: [],
self.CREEP_SCORE: [],
self.GOLD_EARNED: [],
self.CHAMPION_LEVEL: [],
self.VISION_SCORE: []
}
for i in range(len(dataList)):
if 'mapId' in dataList[i].keys() and dataList[i]['mapId'] == 11 and dataList[i]['gameMode'] == 'CLASSIC':
participantID = 0
for participantIdentities in dataList[i]['participantIdentities']:
if self.summonerName == participantIdentities['player']['summonerName']:
participantID = participantIdentities['participantId']
mr = ''
if dataList[i]['participants'][participantID - 1]['stats']['win'] == True:
mr = 'Victory'
else:
mr = 'Defeat'
# Creating the dictionary
parsedData[self.SUMMONER_NAME].append(self.summonerName)
parsedData[self.GAME_DURATION].append(
dataList[i]['gameDuration'])
parsedData[self.MATCH_RESULT].append(mr)
parsedData[self.CHAMPION_ID].append(
dataList[i]['participants'][participantID - 1]['championId'])
parsedData[self.CREEP_SCORE].append(
dataList[i]['participants'][participantID - 1]['stats']['totalMinionsKilled'])
parsedData[self.GOLD_EARNED].append(
dataList[i]['participants'][participantID - 1]['stats']['goldEarned'])
parsedData[self.CHAMPION_LEVEL].append(
dataList[i]['participants'][participantID - 1]['stats']['champLevel'])
parsedData[self.VISION_SCORE].append(
dataList[i]['participants'][participantID - 1]['stats']['visionScore'])
df = pd.DataFrame.from_dict(parsedData)
for i in range(len(parsedData["Summoner Name"])):
rowLabelIndex = df.index[i]
df = df.rename(index={rowLabelIndex: "Match " + str(i + 1)})
return df