forked from smogon/usage-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TierUpdate9Singles.py
282 lines (240 loc) · 8.59 KB
/
TierUpdate9Singles.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import string
import sys
import json
import cPickle as pickle
from common import keyify,readTable,getBattleFormatsData
reload(sys)
sys.setdefaultencoding('utf8')
def getUsage(filename,col,weight,usage):
tempUsage, nBattles = readTable(filename)
for i in tempUsage:
if keyify(i) not in usage:
usage[keyify(i)]=[0,0,0,0,0]
if i != 'empty':
usage[keyify(i)][col] = usage[keyify(i)][col]+weight*6.0*tempUsage[i]/sum(tempUsage.values())/24
def makeTable(table,name,keyLookup):
print "[HIDE="+name+"][CODE]"
print "Combined usage for "+name
print " + ---- + ------------------ + ------- + "
print " | Rank | Pokemon | Percent | "
print " + ---- + ------------------ + ------- + "
print ' | %-4d | %-18s | %6.3f%% |' % (1,keyLookup[table[0][0]],table[0][1]*100)
for i in range(1,len(table)):
if table[i][1] < 0.001:
break
print ' | %-4d | %-18s | %6.3f%% |' % (i+1,keyLookup[table[i][0]],100.0*table[i][1])
print " + ---- + ------------------ + ------- + "
print "[/CODE][/HIDE]"
tiers = ['Uber','New','OU','UUBL','UU','RUBL','RU','NUBL','NU','PUBL','PU','ZUBL','ZU']
usageTiers = ['ou', 'uu', 'ru', 'nu', 'pu']
def main(months):
file = open('keylookup.json', 'rb')
keyLookup = json.load(file)
file.close()
rise = [0.08827751140,0.06715839608,0.04515839608][len(months)-1]
drop = [0.01528524706,0.02284003156,0.04515839608][len(months)-1]
rise = [0.99515839608,0.99515839608,0.04515839608][len(months)-1]
rise = [0.04515839608,0.04515839608,0.04515839608][len(months)-1]
#rise = [0.99515839608,0.99515839608,0.99515839608][len(months)-1]
drop = [0.04515839608,0.04515839608,0.04515839608][len(months)-1]
#drop = [0.02,0.02284003156,0.04515839608][len(months)-1]
formatsData = getBattleFormatsData()
curTiers = {}
NFE=[]
for poke in formatsData:
if poke in ['pichuspikyeared', 'unownb', 'unownc', 'unownd', 'unowne', 'unownf', 'unowng', 'unownh', 'unowni', 'unownj', 'unownk', 'unownl', 'unownm', 'unownn', 'unowno', 'unownp', 'unownq', 'unownr', 'unowns', 'unownt', 'unownu', 'unownv', 'unownw', 'unownx', 'unowny', 'unownz', 'unownem', 'unownqm', 'burmysandy', 'burmytrash', 'cherrimsunshine', 'shelloseast', 'gastrodoneast', 'deerlingsummer', 'deerlingautumn', 'deerlingwinter', 'sawsbucksummer', 'sawsbuckautumn', 'sawsbuckwinter', 'keldeoresolution', 'genesectdouse', 'genesectburn', 'genesectshock', 'genesectchill', 'basculinbluestriped', 'darmanitanzen','keldeoresolute','pikachucosplay']:
continue
if 'isNonstandard' in formatsData[poke]:
if formatsData[poke]['isNonstandard']:
continue
#if 'requiredItem' in formatsData[poke]:
# continue
#if poke == 'rayquazamega':
# continue
if 'tier' not in formatsData[poke].keys():
continue
old = formatsData[poke]['tier']
if old[0] == '(' and old[1] == 'P':
old = 'ZU'
if old in ['NFE','LC','LC Uber']:
NFE.append(poke)
if old == 'Illegal' or old == 'Unreleased':
continue
elif old not in tiers and poke not in NFE and old[0] != '(':
old = tiers[-1]
curTiers[poke]=old
usage = {} #track usage across all relevant tiers [OU,UU,RU,NU]
for i in xrange(len(months)):
for j in xrange(len(usageTiers)):
n = {}
u = {}
baseline = "1630"
if usageTiers[j] in ['ou']:
baseline = "1695"
for k in ('', 'suspecttest', 'alpha', 'beta'):
try:
u[k], n[k] = readTable(months[i]+"/Stats/gen9"+usageTiers[j]+k+"-"+baseline+".txt")
except IOError:
pass
ntot = sum(n.values())
for k in u:
for poke in u[k]:
if keyify(poke) not in usage:
usage[keyify(poke)]=[0]*len(usageTiers)
if poke != 'empty':
usage[keyify(poke)][j] += n[k]/ntot*u[k][poke]/len(months)
#generate three-month tables and start working on that new tier list
OU = []
UU = []
RU = []
NU = []
PU = []
for i in usage:
if usage[i][0] > 0.0:
OU.append([i,usage[i][0]])
if usage[i][1] > 0.0:
UU.append([i,usage[i][1]])
if usage[i][2] > 0.0:
RU.append([i,usage[i][2]])
if usage[i][3] > 0.0:
NU.append([i,usage[i][3]])
if usage[i][4] > 0.0:
PU.append([i,usage[i][4]])
OU = sorted(OU, key=lambda OU:-OU[1])
UU = sorted(UU, key=lambda UU:-UU[1])
RU = sorted(RU, key=lambda RU:-RU[1])
NU = sorted(NU, key=lambda NU:-NU[1])
PU = sorted(PU, key=lambda PU:-PU[1])
makeTable(OU,"OU (1695 stats)",keyLookup)
makeTable(UU,"UU (1630 stats)",keyLookup)
makeTable(RU,"RU (1630 stats)",keyLookup)
makeTable(NU,"NU (1630 stats)",keyLookup)
makeTable(PU,"PU (1630 stats)",keyLookup)
newTiers={}
#start with Ubers
for poke in curTiers.keys():
if curTiers[poke] == 'Uber':
newTiers[poke] = 'Uber'
for poke in curTiers.keys():
if poke not in usage:
newTiers[poke] = curTiers[poke]
#next do the OU rises
for poke in curTiers.keys():
if poke not in usage:
continue
if usage[poke][0] > rise and poke not in newTiers.keys():
newTiers[poke] = 'OU'
#next do the UU drops
for poke in curTiers.keys():
if poke not in usage:
continue
if curTiers[poke] == 'OU' and poke not in newTiers.keys():
if usage[poke][0] < drop:
newTiers[poke] = 'UU'
else:
newTiers[poke] = 'OU'
#next do BL
for poke in curTiers.keys():
if poke not in usage:
continue
if curTiers[poke] == 'UUBL' and poke not in newTiers.keys():
newTiers[poke] = 'UUBL'
#next do the UU rises
for poke in curTiers.keys():
if poke not in usage:
continue
if usage[poke][1] > rise and poke not in newTiers.keys():
newTiers[poke] = 'UU'
#next do the RU drops
for poke in curTiers.keys():
if poke not in usage:
continue
if curTiers[poke] == 'UU' and poke not in newTiers.keys():
if usage[poke][1] < drop:
newTiers[poke] = 'RU'
else:
newTiers[poke] = 'UU'
#next do BL2
for poke in curTiers.keys():
if poke not in usage:
continue
if curTiers[poke] == 'RUBL' and poke not in newTiers.keys():
newTiers[poke] = 'RUBL'
#next do the RU rises
for poke in curTiers.keys():
if poke not in usage:
continue
if usage[poke][2] > rise and poke not in newTiers.keys():
newTiers[poke] = 'RU'
#next do the NU drops
for poke in curTiers.keys():
if curTiers[poke] == 'RU' and poke not in newTiers.keys():
if usage[poke][2] < drop:
newTiers[poke] = 'NU'
else:
newTiers[poke] = 'RU'
#next do BL3
for poke in curTiers.keys():
if curTiers[poke] == 'NUBL' and poke not in newTiers.keys():
newTiers[poke] = 'NUBL'
#next do the NU rises
for poke in curTiers.keys():
if poke not in usage:
continue
if usage[poke][3] > rise and poke not in newTiers.keys():
newTiers[poke] = 'NU'
#next do the PU drops
for poke in curTiers.keys():
if curTiers[poke] == 'NU' and poke not in newTiers.keys():
if usage[poke][3] < drop:
newTiers[poke] = 'PU'
else:
newTiers[poke] = 'NU'
#next do BL4
for poke in curTiers.keys():
if curTiers[poke] == 'PUBL' and poke not in newTiers.keys():
newTiers[poke] = 'PUBL'
#next do the PU rises
for poke in curTiers.keys():
if poke not in usage:
continue
if usage[poke][4] > rise and poke not in newTiers.keys():
newTiers[poke] = 'PU'
#next do the ZU drops
for poke in curTiers.keys():
if curTiers[poke] == 'PU' and poke not in newTiers.keys():
if usage[poke][4] < drop:
newTiers[poke] = 'ZU'
else:
newTiers[poke] = 'PU'
#next do ZUBL
for poke in newTiers.keys():
if newTiers[poke] == 'ZU' and poke in ['']:
newTiers[poke] = 'ZUBL'
#the rest go in the lowest tier
for poke in curTiers.keys():
if poke not in newTiers.keys():
newTiers[poke] = tiers[-1]
for poke in newTiers.keys():
if newTiers[poke] == 'UU' and poke in ['espathra', 'baxcalibur', 'hydreigon']:
newTiers[poke] = 'UUBL'
if newTiers[poke] == 'RU' and poke in ['haxorus','lycanrocdusk','drednaw','toxtricity','flamigo','hawlucha','polteageist','oricoriopompom']:
newTiers[poke] = 'RUBL'
if newTiers[poke] == 'NU' and poke in ['florges','indeedee','oricoriopompom','venomoth','goodra','cetitan','oricoriosensu','barraskewda']:
newTiers[poke] = 'NUBL'
if newTiers[poke] == 'PU' and poke in ['oricorio','oricoriopau','magneton','vivillon','sneaselhisui']:
newTiers[poke] = 'PUBL'
print ""
for poke in curTiers:
if newTiers[poke] == 'ZU' and poke in NFE:
continue
if curTiers[poke] != newTiers[poke]:
species = keyLookup[poke]
if species.endswith('-Mega') or species.endswith('-Mega-X') or species.endswith('-Mega-Y') or species.endswith('-Primal'):
base = keyify(species[:species.index('-')]) #none of the megas have hyphenated names
if tiers.index(newTiers[base]) < tiers.index(newTiers[poke]): #if the base is in a higher tier
newTiers[poke] = newTiers[base]
continue
print species+" moved from "+curTiers[poke]+" to "+newTiers[poke]
if __name__ == "__main__":
main(sys.argv[1:])