-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfindId.py
More file actions
184 lines (148 loc) · 4.34 KB
/
Copy pathfindId.py
File metadata and controls
184 lines (148 loc) · 4.34 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
import requests, time, json
import urllib2
API_KEY = "497286e9-f643-4e1c-8028-3149a3887044";
"""
Given a match ID, writes to the appropriate files.
"""
def idstats(ids):
r = requests.get("https://na.api.pvp.net/api/lol/na/v2.2/match/" +str(ids)+ "?api_key=497286e9-f643-4e1c-8028-3149a3887044")
if r.status_code != 200:
print(r.status_code)
if(r.status_code == 404):
print(ids)
print("Time out, sleeping 10s, IDSTATS")
time.sleep(10);
return idstats(ids)
data = json.loads(r.text)
winning_id = 0;
winning_team = data["teams"][0]["winner"];
if(winning_team):
winning_team = data["teams"][0]["teamId"];
else:
winning_id = 1;
winning_team = data["teams"][1]["teamId"];
players = data["participants"];
losers = [];
grades = {}
for p in players:
p_id = p["participantId"];
summonerId = data["participantIdentities"][p_id-1]["player"]["summonerId"];
if(p["teamId"] != winning_team):
losers.append(summonerId)
continue;
kills = int(p["stats"]["kills"])
assists = int(p["stats"]["assists"])
death = int(p["stats"]["deaths"])
match_duration = int(data["matchDuration"])
fb = data["teams"][winning_id]["firstBlood"];
grades[summonerId] = grade(kills, death, assists, match_duration, fb);
for i in grades.keys():
f = open('./players/'+str(i), 'a')
loser_str = "";
for j in losers:
loser_str = loser_str+" "+str(j)
f.write(str(grades[i])+" "+loser_str+"\n");
f.close();
def downloadMatches(summoner_id):
global API_KEY
r = requests.get("https://na.api.pvp.net/api/lol/na/v2.2/matchlist/by-summoner/"+str(summoner_id)+"?beginTime=1444794610796&endTime=1445399410796&rankedQueues=RANKED_SOLO_5x5&seasons=SEASON2015&api_key="+API_KEY)
if r.status_code != 200:
print(r.status_code);
if(r.status_code == 404):
print(summoner_id)
print("Time out, sleeping 10s");
time.sleep(10);
return downloadMatches(summoner_id)
return r.text;
"""
Returns -1 if the data is not a ranked solo RANKED_SOLO_5x5
or the match has already been recorded.
"""
def getValidMatchId(match, seen_id):
if(match["queue"] != "RANKED_SOLO_5x5"):
return -1;
match_id = int(match["matchId"]);
if(match_id in seen_id):
return -1;
return match_id;
def main():
matches, summoners = init();
try:
for i in summoners:
m = downloadMatches(i);
j = json.loads(m);
try:
ml = j["matches"];
except Exception as e:
continue;
count = 0;
for j in ml:
if(count>10):
count = 0;
break;
match_id = getValidMatchId(j, matches)
if(match_id == -1):
continue;
count = count+1;
matches.append(match_id)
idstats(match_id);
except Exception as e:
print(e)
raise(e)
quit(matches);
quit(matches)
def init():
matches = [];
players = [];
try:
f = open('matches.txt', 'r')
except:
return matches;
g = open('players.txt', 'r')
for line in f:
matches.append(int(line.strip()));
f.close();
for line in g:
x = line.strip().split(" ");
players.append(int(x[1]));
g.close();
return matches, players
def quit(matches):
f = open('matches.txt', 'w');
for match in matches:
f.write(str(match));
f.close()
def grade(k, d, a, duration, fb):
if(d<1):
d = 1;
kda_ratio = (k+a)/d;
kda_score = 0;
if(kda_ratio<.5):
kda_score = 1
elif(kda_ratio<1):
kda_score = 2;
elif(kda_ratio<2):
kda_score = 3;
elif(kda_ratio<4):
kda_score = 4;
else:
kda_score = 5;
d_mult = 0;
if(duration<1000):
d_mult = 4;
elif(duration<1500):
d_mult = 2
elif(duration<2000):
d_mult = 1
else:
d_mult = 0;
fbonus = 0;
if(fb):
fbonus = 1;
totalscore = kda_score+d_mult+fbonus
if(totalscore<0):
return 0;
elif(totalscore>10):
return 10;
return totalscore;
main();