-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetValuesfromJSON.py
More file actions
122 lines (115 loc) · 5.85 KB
/
GetValuesfromJSON.py
File metadata and controls
122 lines (115 loc) · 5.85 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
import json
import pandas as pd
studentsList = []
blueteamId = 0
# print("Started Reading JSON file which contains multiple JSON document")
with open('match_data.json') as f:
for jsonObj in f:
studentDict = json.loads(jsonObj)
studentsList.append(studentDict)
data = []
[studentsList] = studentsList # remove-the-outer-list-of-a-double-list [[]] -> []
# print("Printing each JSON Decoded Object")
for student in studentsList:
mydict = {}
BlueTeam_assists = 0
RedTeam_assists = 0
BlueTeam_goldEarned = 0
RedTeam_goldEarned = 0
BlueTeam_championLevel = 0
RedTeam_championLevel = 0
# print(student['info']['gameId'])
gameId = student['info']['gameId']
# mydict['gameId'] = gameId
for participant in student['info']['participants']:
if participant['summonerName']=='Timoschka17':
# print(participant['summonerName'],participant['teamId']) # get teamId since we need to know to team Timoschka belongs and based on that Timoschka's team is gonna be the Blue Team
blueteamId = participant['teamId']
for participant in student['info']['participants']: # get blue/red team total assists
if participant["teamId"] == blueteamId & participant["teamId"] != 0:
# Add the participant's assists to the BlueTeam assists
BlueTeam_assists += participant['assists']
if participant["teamId"] != blueteamId & participant["teamId"] != 0:
# Add the participant's assists to the RedTeam assists
RedTeam_assists += participant['assists']
# mydict['blueAssists'] = BlueTeam_assists
# mydict['redAssists'] = RedTeam_assists
for participant in student['info']['participants']: # get blue/red team total gold earned
if participant["teamId"] == blueteamId & participant["teamId"] != 0:
# Add the participant's total gold to the BlueTeam total gold
BlueTeam_goldEarned += participant['goldEarned']
if participant["teamId"] != blueteamId & participant["teamId"] != 0:
# Add the participant's total gold to the RedTeam total gold
RedTeam_goldEarned += participant['goldEarned']
# mydict['blueTotalGold'] = BlueTeam_goldEarned
# mydict['redTotalGold'] = RedTeam_goldEarned
redGoldDiff = RedTeam_goldEarned - BlueTeam_goldEarned
# mydict['redGoldDiff'] = redGoldDiff
blueGoldDiff = BlueTeam_goldEarned - RedTeam_goldEarned
# mydict['blueGoldDiff'] = blueGoldDiff
for participant in student['info']['participants']: # get blue/red team Average level
if participant["teamId"] == blueteamId & participant["teamId"] != 0:
# Add the participant's Average level to the BlueTeam Average level
BlueTeam_championLevel += participant['champLevel']
if participant["teamId"] != blueteamId & participant["teamId"] != 0:
# Add the participant's Average level to the RedTeam Average level
RedTeam_championLevel += participant['champLevel']
BlueTeam_AvgLevel = BlueTeam_championLevel/5
# mydict['blueAvgLevel'] = BlueTeam_AvgLevel
RedTeam_AvgLevel = RedTeam_championLevel/5
# mydict['redAvgLevel'] = RedTeam_AvgLevel
for team in student['info']['teams']:
if team['teamId']==blueteamId:
# print('This is BlueTeam kills: ')
# print(team['objectives']['champion']['kills'],team['teamId']) # get champkills of the team with the corresponding teamId. if teamId == teamId of Timoschka, then champkills are Blue team champion kills
BlueteamKills = team['objectives']['champion']['kills']
# mydict['blueKills'] = BlueteamKills
# print('This is BlueTeam Firstblood: ')
# print(team['objectives']['champion']['first'],team['teamId'])
BlueTeamfirstblood = team['objectives']['champion']['first']
if BlueTeamfirstblood == False:
BlueTeamfirstblood = 0
if BlueTeamfirstblood == True:
BlueTeamfirstblood = 1
# mydict['blueFirstBlood'] = BlueTeamfirstblood
# print('BlueTeam Win: ',team['win'])
BlueTeamWin = team['win'] # ersetzen mit '0' anstatt 'false/true' blueWins
if BlueTeamWin == False:
BlueTeamWin = 0
if BlueTeamWin == True:
BlueTeamWin = 1
# mydict['blueWins'] = BlueTeamWin
else:
# print('This is RedTeam kills: ')
# print(team['objectives']['champion']['kills'],team['teamId'])
RedteamKills = team['objectives']['champion']['kills']
# mydict['redKills'] = RedteamKills
# print('This is RedTeam Firstblood: ')
# print(team['objectives']['champion']['first'],team['teamId'])
RedTeamfirstblood = team['objectives']['champion']['first']
if RedTeamfirstblood == False:
RedTeamfirstblood = 0
if RedTeamfirstblood == True:
RedTeamfirstblood = 1
# mydict['redFirstBlood'] = RedTeamfirstblood
# print('RedTeam Win: ',team['win'])
RedTeamWin = team['win']
mydict['gameId'] = gameId
mydict['blueWins'] = BlueTeamWin
mydict['blueFirstBlood'] = BlueTeamfirstblood
mydict['blueKills'] = BlueteamKills
mydict['blueAssists'] = BlueTeam_assists
mydict['blueTotalGold'] = BlueTeam_goldEarned
mydict['blueAvgLevel'] = BlueTeam_AvgLevel
mydict['blueGoldDiff'] = blueGoldDiff
mydict['redFirstBlood'] = RedTeamfirstblood
mydict['redKills'] = RedteamKills
mydict['redAssists'] = RedTeam_assists
mydict['redTotalGold'] = RedTeam_goldEarned
mydict['redAvgLevel'] = RedTeam_AvgLevel
mydict['redGoldDiff'] = redGoldDiff
data.append(mydict)
# Create a dataframe from the list of dictionaries
df = pd.DataFrame(data)
# Print the dataframe
print(df)