diff --git a/MegaCounter.py b/MegaCounter.py index 1befcba..e3fae5e 100644 --- a/MegaCounter.py +++ b/MegaCounter.py @@ -5,7 +5,9 @@ from TA import megas from common import keyify -stats=json.load(open(sys.argv[1])) +file = open(sys.argv[1]) +stats=json.load(file) +file.close() megastats=[] total=0 @@ -33,5 +35,5 @@ megastats=sorted(megastats, key=lambda megastats:-megastats[1]) for mega in megastats: - print "%-18s%8.5f%%" % (mega[0],600.0*mega[1]/total) + print("%-18s%8.5f%%" % (mega[0],600.0*mega[1]/total)) diff --git a/PS-Extractor.py b/PS-Extractor.py index 647122d..95a21fc 100644 --- a/PS-Extractor.py +++ b/PS-Extractor.py @@ -4,7 +4,7 @@ used on Pokemon Showdown and pull out the data that's needed for the scripts.""" import json -import cPickle as pickle +import pickle from onix import contexts ctx = contexts.get_standard_context(force_refresh=True) @@ -30,6 +30,6 @@ for k, v in ctx.natures.items(): keyLookup[k] = v['name'] -json.dump(baseStats, open('baseStats.json', 'w+')) -json.dump(types, open('types.json', 'w+')) -pickle.dump(keyLookup, open('keylookup.pickle', 'w+')) +json.dump(baseStats, open('baseStats.json', 'w')) +json.dump(types, open('types.json', 'w')) +pickle.dump(keyLookup, open('keylookup.pickle', 'wb')) diff --git a/StatCounter.py b/StatCounter.py index 9e80e1f..684998d 100644 --- a/StatCounter.py +++ b/StatCounter.py @@ -23,9 +23,8 @@ import string import sys import math -import cPickle as pickle +import pickle import os -#import ujson as json import json import gzip @@ -66,10 +65,6 @@ metagamefile=open(filename,'w') else: metagamefile=False -filename="Raw/moveset/"+tier+"/teammate"+specs+".pickle" -teammatefile=open(filename,'w') -filename="Raw/moveset/"+tier+"/encounterMatrix"+specs+".pickle" -encounterfile=open(filename,'w') battleCount = 0 @@ -94,7 +89,7 @@ t=t[:-11] for line in file: - #print line + #print(line) battles = json.loads(line) for battle in battles: @@ -193,8 +188,8 @@ if 'empty' in leads: if len(battle['matchups']) == 0: #1v1 (or similiar) battle forfeited before started continue - print "Something went wrong." - print battle + print("Something went wrong.") + print(battle) for i in range(2): if ['p1','p2'][i] not in weight: @@ -246,9 +241,13 @@ #write teammates and encounter matrix to file -pickle.dump(teammateMatrix,teammatefile) +filename="Raw/moveset/"+tier+"/teammate"+specs+".pickle" +teammatefile=open(filename,'wb') +pickle.dump(teammateMatrix, teammatefile) teammatefile.close() -pickle.dump(encounterMatrix,encounterfile) +filename="Raw/moveset/"+tier+"/encounterMatrix"+specs+".pickle" +encounterfile = open(filename, 'wb') +pickle.dump(encounterMatrix, encounterfile) encounterfile.close() #sort by weighted usage @@ -322,8 +321,8 @@ if stallCounter: #figure out a good bin range by looking at .1% and 99.9% points - low = stallCounter[len(stallCounter)/1000][0] - high = stallCounter[len(stallCounter)-len(stallCounter)/1000-1][0] + low = stallCounter[len(stallCounter)//1000][0] + high = stallCounter[len(stallCounter)-len(stallCounter)//1000-1][0] nbins = 13 #this is actually only a rough idea--I think it might be the minimum? @@ -353,7 +352,12 @@ nbins = len(histogram) for start in range(len(stallCounter)): - if stallCounter[start] >= histogram[0][0]-binSize/2: + # In Python 2, you could compare a list to a number, and the + # list would always be greater than or equal to the number. + # In other words, the commented statement (which would fail in + # Python 3) would always return True. + # if stallCounter[start] >= histogram[0][0]-binSize/2: + if True: break j=0 @@ -379,7 +383,7 @@ x=x+score[0]*score[1] y=y+score[1] - #print histogram + #print(histogram) metagamefile.write(' Stalliness (mean: %6.3f)\n'%(x/y)) for i in range(len(histogram)): if histogram[i][0]%(2.0*binSize) < binSize/2: diff --git a/TA.py b/TA.py index d1325c6..09f811d 100644 --- a/TA.py +++ b/TA.py @@ -7,7 +7,6 @@ import string import sys -#import ujson as json import json import math import copy diff --git a/TierUpdate9Doubles.py b/TierUpdate9Doubles.py index 5d76066..c548f9d 100644 --- a/TierUpdate9Doubles.py +++ b/TierUpdate9Doubles.py @@ -1,7 +1,7 @@ import string import sys import json -import cPickle as pickle +import pickle from common import keyify,readTable,getBattleFormatsData reload(sys) sys.setdefaultencoding('utf8') @@ -16,18 +16,18 @@ def getUsage(filename,col,weight,usage): 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) + 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]" + print(' | %-4d | %-18s | %6.3f%% |' % (i+1,keyLookup[table[i][0]],100.0*table[i][1])) + print(" + ---- + ------------------ + ------- + ") + print("[/CODE][/HIDE]") tiers = ['DUber','DOU', 'DUU', 'DNU'] usageTiers = ['doublesou', 'doublesuu'] @@ -76,8 +76,8 @@ def main(months): usage = {} #track usage across all relevant tiers [OU,UU,RU,NU] - for i in xrange(len(months)): - for j in xrange(len(usageTiers)): + for i in range(len(months)): + for j in range(len(usageTiers)): n = {} u = {} @@ -165,7 +165,7 @@ def main(months): if poke not in newTiers.keys(): newTiers[poke] = tiers[-1] - print "" + print("") for poke in curTiers: if newTiers[poke] == 'New' and poke in NFE: continue @@ -176,7 +176,7 @@ def main(months): 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] + print(species+" moved from "+curTiers[poke]+" to "+newTiers[poke]) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/TierUpdate9LC.py b/TierUpdate9LC.py index add9031..04bd39f 100644 --- a/TierUpdate9LC.py +++ b/TierUpdate9LC.py @@ -1,7 +1,7 @@ import string import sys import json -import cPickle as pickle +import pickle from common import keyify,readTable,getBattleFormatsData reload(sys) sys.setdefaultencoding('utf8') @@ -28,18 +28,18 @@ def usageToTiers(usage): 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) + 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]" + print(' | %-4d | %-18s | %6.3f%% |' % (i+1,keyLookup[table[i][0]],100.0*table[i][1])) + print(" + ---- + ------------------ + ------- + ") + print("[/CODE][/HIDE]") def main(months): file = open('keylookup.json', 'rb') @@ -60,7 +60,7 @@ def main(months): remaining=24.0 - for i in xrange(len(months)): + for i in range(len(months)): tiername = 'lc' #bh @@ -98,7 +98,7 @@ def main(months): for poke in dnuBanlist: printme += keyLookup[poke]+', ' printme = printme[:-2] - print printme + print(printme) diff --git a/TierUpdate9NatDex.py b/TierUpdate9NatDex.py index 444bdb9..d93afe7 100644 --- a/TierUpdate9NatDex.py +++ b/TierUpdate9NatDex.py @@ -1,7 +1,7 @@ import string import sys import json -import cPickle as pickle +import pickle from common import keyify,readTable,getBattleFormatsData reload(sys) sys.setdefaultencoding('utf8') @@ -16,18 +16,18 @@ def getUsage(filename,col,weight,usage): 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) + 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]" + print(' | %-4d | %-18s | %6.3f%% |' % (i+1,keyLookup[table[i][0]],100.0*table[i][1])) + print(" + ---- + ------------------ + ------- + ") + print("[/CODE][/HIDE]") tiers = ['Uber','OU','UUBL','UU','RUBL','RU','NUBL','NU','PUBL','PU','ZUBL','ZU', 'New'] usageTiers = ['nationaldex', 'nationaldexuu'] @@ -79,8 +79,8 @@ def main(months): usage = {} #track usage across all relevant tiers [OU,UU,RU,NU] - for i in xrange(len(months)): - for j in xrange(len(usageTiers)): + for i in range(len(months)): + for j in range(len(usageTiers)): n = {} u = {} @@ -181,7 +181,7 @@ def main(months): if poke not in newTiers.keys(): newTiers[poke] = 'RU' - print "" + print("") for poke in curTiers: if newTiers[poke] == 'RU' and poke in NFE: continue @@ -192,7 +192,7 @@ def main(months): 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] + print(species+" moved from "+curTiers[poke]+" to "+newTiers[poke]) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/TierUpdate9Singles.py b/TierUpdate9Singles.py index ef047a5..a3f36a5 100644 --- a/TierUpdate9Singles.py +++ b/TierUpdate9Singles.py @@ -1,7 +1,7 @@ import string import sys import json -import cPickle as pickle +import pickle from common import keyify,readTable,getBattleFormatsData reload(sys) sys.setdefaultencoding('utf8') @@ -16,18 +16,18 @@ def getUsage(filename,col,weight,usage): 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) + 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]" + 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'] @@ -75,8 +75,8 @@ def main(months): usage = {} #track usage across all relevant tiers [OU,UU,RU,NU] - for i in xrange(len(months)): - for j in xrange(len(usageTiers)): + for i in range(len(months)): + for j in range(len(usageTiers)): n = {} u = {} @@ -264,7 +264,7 @@ def main(months): if newTiers[poke] == 'PU' and poke in ['oricorio','oricoriopau','magneton','vivillon','sneaselhisui']: newTiers[poke] = 'PUBL' - print "" + print("") for poke in curTiers: if newTiers[poke] == 'ZU' and poke in NFE: continue @@ -275,7 +275,7 @@ def main(months): 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] + print(species+" moved from "+curTiers[poke]+" to "+newTiers[poke]) if __name__ == "__main__": main(sys.argv[1:]) diff --git a/batchLogReader.py b/batchLogReader.py index f13daa8..5ed2e4e 100644 --- a/batchLogReader.py +++ b/batchLogReader.py @@ -5,15 +5,13 @@ import string import sys -#import ujson as json import json import gzip import copy -#import cPickle as pickle import math import os import ladderdev.Glicko as Glicko -import cPickle as pickle +import pickle from common import * from TA import * @@ -37,7 +35,7 @@ def getTeamsFromLog(log,mrayAllowed): sys.stderr.write('Problem with '+filename+'\n') return False #very odd that these == needed--I've seen ".Species", "(Species)", "species", "Species)", "SPECIES"... - if species[0] not in string.lowercase + string.uppercase: + if species[0] not in string.ascii_lowercase + string.ascii_uppercase: species=species[1:] while species[len(species)-1] in ')". ': species=species[:len(species)-1] @@ -119,7 +117,7 @@ def getTeamsFromLog(log,mrayAllowed): ability=mega[2] break - if species[0] in string.lowercase or species[1] in string.uppercase: + if species[0] in string.ascii_lowercase or species[1] in string.ascii_uppercase: species = species.title() for s in aliases: #combine appearance-only variations and weird PS quirks @@ -192,7 +190,7 @@ def LogReader(filename,tier,movesets,ratings): # return False if 'turns' not in log.keys(): - print filename+' has no turn count' + print(filename+' has no turn count') return False @@ -275,8 +273,9 @@ def LogReader(filename,tier,movesets,ratings): # os.makedirs(d) #msfile=open(outname,'ab') if keyify(poke['species']) == 'meloettapirouette': - print filename - writeme={'trainer':trainer.encode('ascii', 'ignore'), + print(filename) + # The Python 2 version of this code removed Unicode characters from the trainer names; it's unclear if this is required by downstream processing, but just in case preserve the behavior. + writeme={'trainer':trainer.encode('ascii', 'ignore').decode('utf-8'), 'level':poke['level'], 'ability':poke['ability'], 'item':poke['item'], @@ -393,7 +392,7 @@ def LogReader(filename,tier,movesets,ratings): else: speciesBase = species - for i in xrange(6): + for i in range(6): if ts[i][1].startswith(speciesBase): species = ts[i][1] active[0] = i @@ -443,7 +442,7 @@ def LogReader(filename,tier,movesets,ratings): else: speciesBase = species - for i in xrange(6,12): + for i in range(6,12): if ts[i][1].startswith(speciesBase): species = ts[i][1] active[1] = i @@ -475,7 +474,7 @@ def LogReader(filename,tier,movesets,ratings): if len(line) < 2 or not line.startswith('|'): continue parsed_line = [segment.strip() for segment in line.split('|')] - #print line + #print(line) #identify what kind of message is on this line if len(parsed_line) < 2: sys.stderr.write('Problem with '+filename+'\n') @@ -557,7 +556,7 @@ def LogReader(filename,tier,movesets,ratings): sys.stderr.write(str(nicks)+"\n") return False - move = line[7+5*spacelog+len(found):string.find(line,"|",7+5*spacelog+len(found))-1*spacelog] + move = line[7+5*spacelog+len(found): line.find("|", 7+5*spacelog+len(found)) - 1*spacelog] if move in ["Roar","Whirlwind","Circle Throw","Dragon Tail"]: roar = True elif move in ["U-Turn","U-turn","Volt Switch","Baton Pass"]: @@ -565,9 +564,9 @@ def LogReader(filename,tier,movesets,ratings): elif linetype == "-enditem": #check for Red Card, Eject Button #search for relevant items - if string.rfind(line,"Red Card") > -1: + if line.rfind("Red Card") > -1: roar = True - elif string.rfind(line,"Eject Button") > -1: + elif line.rfind("Eject Button") > -1: uturn = True elif linetype == "faint": #KO @@ -626,7 +625,7 @@ def LogReader(filename,tier,movesets,ratings): else: speciesBase = species - for i in xrange(6*(int(line[p])-1),6*int(line[p])): + for i in range(6*(int(line[p])-1),6*int(line[p])): if ts[i][1].startswith(speciesBase): species = ts[i][1] found = True @@ -733,13 +732,13 @@ def LogReader(filename,tier,movesets,ratings): else: speciesBase = species - for i in xrange(6*(int(line[p])-1),6*int(line[p])): + for i in range(6*(int(line[p])-1),6*int(line[p])): if ts[i][1].startswith(speciesBase): species = ts[i][1] found = True break if not found: - print ts + print(ts) sys.stderr.write('Problem with '+filename+'\n') sys.stderr.write('(Pokemon not in ts) (4)\n') sys.stderr.write(str([ts[11*(int(line[p])-1)][0],species])+'\n') @@ -755,7 +754,7 @@ def LogReader(filename,tier,movesets,ratings): writeme = {} - writeme['p1'] = {'trainer':ts[0][0].encode('ascii','replace')} + writeme['p1'] = {'trainer':ts[0][0]} teamtags = teams['p1team'][len(teams['p1team'])-1] for x in teamtags.keys(): @@ -771,7 +770,7 @@ def LogReader(filename,tier,movesets,ratings): sys.stderr.write(str(ts)+"\n") return False - writeme['p2'] = {'trainer':ts[len(ts)-1][0].encode('ascii','replace')} + writeme['p2'] = {'trainer':ts[len(ts)-1][0]} teamtags = teams['p2team'][len(teams['p2team'])-1] for x in teamtags.keys(): writeme['p2'][x] = teamtags[x] @@ -818,7 +817,7 @@ def main(argv): ratings = json.loads(open(argv[4]).readline()) except: ratings = {} - print ratings + print(ratings) outname = "Raw/"+tier#+".txt" d = os.path.dirname(outname) @@ -828,7 +827,7 @@ def main(argv): movesets={} count=0 for filename in os.listdir(argv[1]): - #print filename + #print(filename) x = LogReader(argv[1]+'/'+filename,tier,movesets,ratings) if x: writeme.append(x) @@ -837,7 +836,7 @@ def main(argv): if count % 10000 == 0: outname = "Raw/"+tier#+".txt" outfile=gzip.open(outname,'ab') - outfile.write(json.dumps(writeme)+'\n') + outfile.write((json.dumps(writeme) +'\n').encode('utf-8')) outfile.close() #write to moveset file @@ -847,7 +846,7 @@ def main(argv): if not os.path.exists(d): os.makedirs(d) msfile=gzip.open(outname,'ab') - msfile.write(json.dumps(movesets[species])) + msfile.write(json.dumps(movesets[species]).encode('utf-8')) msfile.close() writeme = [] @@ -855,7 +854,7 @@ def main(argv): if writeme: outname = "Raw/"+tier#+".txt" outfile=gzip.open(outname,'ab') - outfile.write(json.dumps(writeme)+'\n') + outfile.write((json.dumps(writeme)+'\n').encode('utf-8')) outfile.close() #write to moveset file @@ -865,7 +864,7 @@ def main(argv): if not os.path.exists(d): os.makedirs(d) msfile=gzip.open(outname,'ab') - msfile.write(json.dumps(movesets[species])) + msfile.write(json.dumps(movesets[species]).encode('utf-8')) msfile.close() if ratings != None: diff --git a/batchMovesetCounter.py b/batchMovesetCounter.py index 166418f..84e0b28 100644 --- a/batchMovesetCounter.py +++ b/batchMovesetCounter.py @@ -5,8 +5,7 @@ import string import sys import math -import cPickle as pickle -#import ujson as json +import pickle import json import gzip import os @@ -17,7 +16,7 @@ def movesetCounter(filename, cutoff, teamtype, usage): file = gzip.open(filename,'rb') - raw = file.read() + raw = file.read().decode('utf-8') file.close() raw=raw.split('][') @@ -27,7 +26,7 @@ def movesetCounter(filename, cutoff, teamtype, usage): if (i0: line = line+str(sum(weights)/len(weights)) @@ -206,14 +205,14 @@ def movesetCounter(filename, cutoff, teamtype, usage): while len(line) < tablewidth+2: line = line + ' ' line = line + '| ' - print line + print(line) line = ' | Viability Ceiling: %d'%(maxGXE[1]) while len(line) < tablewidth+2: line = line + ' ' line = line + '| ' - print line + print(line) - print separator + print(separator) for x in ['Abilities','Items','Spreads','Moves','Teammates','Checks and Counters']: table = [] @@ -221,26 +220,26 @@ def movesetCounter(filename, cutoff, teamtype, usage): while len(line) < tablewidth+2: line = line + ' ' line = line + '| ' - print line + print(line) for i in stuff[x]: if (x in ['Spreads', 'Teammates','Checks and Counters']): table.append([i,stuff[x][i]]) else: table.append([keyLookup[i],stuff[x][i]]) - if x is 'Checks and Counters': + if x == 'Checks and Counters': table=sorted(table, key=lambda table:-(table[1][1]-4.0*table[1][2])) else: table=sorted(table, key=lambda table:-table[1]) total = 0.0 for i in range(len(table)): - if (total > .95 and x is not 'Abilities') or (x is 'Abilities' and i>5) or (x is 'Spreads' and i>5) or (x is 'Teammates' and i>10) or (x is 'Checks and Counters' and i>11): - if x is 'Moves': + if (total > .95 and x != 'Abilities') or (x == 'Abilities' and i>5) or (x == 'Spreads' and i>5) or (x == 'Teammates' and i>10) or (x == 'Checks and Counters' and i>11): + if x == 'Moves': line = ' | %s %6.3f%%' % ('Other',400.0*(1.0-total)) elif x not in ['Teammates','Checks and Counters']: line = ' | %s %6.3f%%' % ('Other',100.0*(1.0-total)) else: - if x is 'Checks and Counters': + if x == 'Checks and Counters': matchup = encounterMatrix[species][table[i][0]] n=sum(matchup[0:6]) score=float(table[i][1][1])-4.0*table[i][1][2] @@ -255,7 +254,7 @@ def movesetCounter(filename, cutoff, teamtype, usage): line = line+' ' if float(100.0*matchup[3])/n < 10.0: line = line+' ' - elif x is 'Teammates': + elif x == 'Teammates': line = ' | %s %6.3f%%' % (table[i][0],100.0*table[i][1]/count) if table[i][1] < 0.005*count: break @@ -264,16 +263,16 @@ def movesetCounter(filename, cutoff, teamtype, usage): while len(line) < tablewidth+2: line = line + ' ' line = line + '| ' - print line.encode('utf8') - if (total > .95 and x is not 'Abilities') or (x is 'Abilities' and i>5) or (x is 'Spreads' and i>5) or (x is 'Teammates' and i>9) or (x is 'Checks and Counters' and i>10): + print(line) + if (total > .95 and x != 'Abilities') or (x == 'Abilities' and i>5) or (x == 'Spreads' and i>5) or (x == 'Teammates' and i>9) or (x == 'Checks and Counters' and i>10): break - if x is 'Moves': + if x == 'Moves': total = total + float(table[i][1])/count/4.0 - elif x is 'Teammates': + elif x == 'Teammates': total = total + float(table[i][1])/count/5.0 - elif x is not 'Checks and Counters': + elif x != 'Checks and Counters': total = total + float(table[i][1])/count - print separator + print(separator) return stuff file = open('keylookup.json', 'rb') @@ -296,11 +295,11 @@ def movesetCounter(filename, cutoff, teamtype, usage): specs += teamtype+'-' specs += '{:.0f}'.format(cutoff) -file = open('Raw/moveset/'+str(sys.argv[1])+'/teammate'+specs+'.pickle') +file = open('Raw/moveset/'+str(sys.argv[1])+'/teammate'+specs+'.pickle', 'rb') teammateMatrix = pickle.load(file) file.close() -file = open('Raw/moveset/'+str(sys.argv[1])+'/encounterMatrix'+specs+'.pickle') +file = open('Raw/moveset/'+str(sys.argv[1])+'/encounterMatrix'+specs+'.pickle', 'rb') encounterMatrix = pickle.load(file) file.close() diff --git a/common.py b/common.py index fd2b3be..1abe181 100644 --- a/common.py +++ b/common.py @@ -3,15 +3,15 @@ import string import math import js2py -import urllib2 -import ujson as json +import urllib +import json def keyify(s): sout = '' for c in s: - if c in string.uppercase: + if c in string.ascii_uppercase: sout = sout + c.lower() - elif c in string.lowercase + '1234567890': + elif c in string.ascii_lowercase + '1234567890': sout = sout + c return sout @@ -61,16 +61,16 @@ def readTable(filename): def getFormats(): - js=urllib2.urlopen("https://raw.githubusercontent.com/Zarel/Pokemon-Showdown/master/config/formats.js").read() - print 'Updating tiers' + js=urllib.request.urlopen("https://raw.githubusercontent.com/Zarel/Pokemon-Showdown/master/config/formats.js").read() + print('Updating tiers') return json.loads(js2py.eval_js('exports={},'+js+'JSON.stringify(exports.Formats)')) def getBattleFormatsData(): - #js=urllib2.urlopen("https://play.pokemonshowdown.com/data/formats-data.js").read() + #js=urllib.request.urlopen("https://play.pokemonshowdown.com/data/formats-data.js").read() file = open('formats-data.js') js = file.read() file.close() - #print 'Updating tiers' + #print('Updating tiers') return json.loads(js2py.eval_js('exports={},'+js+'JSON.stringify(exports.BattleFormatsData)')) aliases={ diff --git a/compare.py b/compare.py index bb8f91e..5533505 100644 --- a/compare.py +++ b/compare.py @@ -22,13 +22,13 @@ printme = " Up %5.2f%%" % (100*float(nnew-nold)/nold) else: printme = " Down %5.2f%%" % (100*float(nold-nnew)/nold) - print printme -print " + ------------------ + --------- + " -print " | Pokemon | Diff (%) | " -print " + ------------------ + --------- + " + print(printme) +print(" + ------------------ + --------- + ") +print(" | Pokemon | Diff (%) | ") +print(" + ------------------ + --------- + ") for i in range(0,len(pokes)): if abs(pokes[i][1]) > 0.001: - print ' | %-18s | %+8.5f%% | ' % (pokes[i][0],pokes[i][1]*100.0) + print(' | %-18s | %+8.5f%% | ' % (pokes[i][0],pokes[i][1]*100.0)) -print " + ------------------ + --------- + " +print(" + ------------------ + --------- + ") diff --git a/environment.yml b/environment.yml index 92e3391..d8267fa 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,6 @@ -name: sus-env2 +name: sus-env3 dependencies: - ipython -- python=2 -- ujson -- pip: - - js2py +- python=3.12 +- pip +- js2py diff --git a/ladderdev/BattleOutcomeExtractor.py b/ladderdev/BattleOutcomeExtractor.py index dd17461..96d57fe 100644 --- a/ladderdev/BattleOutcomeExtractor.py +++ b/ladderdev/BattleOutcomeExtractor.py @@ -41,4 +41,4 @@ def LogReader(filename): p1,p2,team1,team2,whowon,endType,turns=LogReader(sys.argv[1]+folder+'/'+filename) except: continue - print folder+','+p1.encode('utf-8')+','+str(team1)+','+p2.encode('utf-8')+','+str(team2)+','+str(whowon)+','+endType.encode('utf-8')+','+str(turns) + print(folder+','+p1+','+str(team1)+','+p2+','+str(team2)+','+str(whowon)+','+endType+','+str(turns)) diff --git a/ladderdev/Glicko.py b/ladderdev/Glicko.py index 7783e2d..e5b3ae0 100644 --- a/ladderdev/Glicko.py +++ b/ladderdev/Glicko.py @@ -48,8 +48,8 @@ def newRatingPeriod(rating): if rating['d2'] == 0.0: if rating['A'] != 0: - print 'WTF?' - print rating['A'],rating['d2'] + print('WTF?') + print(rating['A'],rating['d2']) rating['RD']=math.sqrt(pow(rating['RD'],2)+c*c) else: d2=pow(q*q*rating['d2'],-1.0) @@ -64,7 +64,7 @@ def newRatingPeriod(rating): rating['A']=0 rating['d2']=0 - #print rating['RD'] + #print(rating['RD']) return rating def provisional(rating): diff --git a/ladderdev/Glicko2.py b/ladderdev/Glicko2.py index bc1852e..122a54e 100644 --- a/ladderdev/Glicko2.py +++ b/ladderdev/Glicko2.py @@ -51,8 +51,8 @@ def newRatingPeriod(rating): if rating['v'] == 0.0: if rating['Delta'] != 0: - print 'WTF?' - print rating['v'],rating['Delta'] + print('WTF?') + print(rating['v'],rating['Delta']) p=math.sqrt(pow(phi(rating['RD']),2)+pow(rating['sigma'],2)) rating['RD']=173.7178*p else: diff --git a/ladderdev/RatingSystemTester.py b/ladderdev/RatingSystemTester.py index 2adfc75..f80c0b0 100644 --- a/ladderdev/RatingSystemTester.py +++ b/ladderdev/RatingSystemTester.py @@ -5,7 +5,7 @@ import gzip import json import math -import cPickle as pickle +import pickle def incorrectSyntax(): sys.stderr.write('Incorrect syntax.\n') @@ -114,10 +114,10 @@ def incorrectSyntax(): printme='Username,nBattles,nWins' for system in systems: printme+=','+ratingSystems[system].headers() -print printme +print(printme) for player in ratings.keys(): printme=player+','+str(ratings[player]['nBattles'])+','+str(ratings[player]['nWins']) for system in systems: printme+=','+ratingSystems[system].printRating(ratings[player][system]) - print printme + print(printme) diff --git a/ladderdev/RatingValidator.py b/ladderdev/RatingValidator.py index d4a328b..3ef6b30 100644 --- a/ladderdev/RatingValidator.py +++ b/ladderdev/RatingValidator.py @@ -49,7 +49,7 @@ else: probWin = victoryChance(battle['p2']['rating']['r'],battle['p2']['rating']['rd'],battle['p1']['rating']['r'],battle['p1']['rating']['rd']) betterPlayer='p2' - for i in xrange(len(bins)): + for i in range(len(bins)): if probWin < bins[i][0]+binSize/2: bins[i][1]=bins[i][1]+probWin if battle[betterPlayer]['outcome'] == 'win': @@ -57,5 +57,5 @@ break for bin in bins: - print bin[0],bin[1],bin[2] + print(bin[0],bin[1],bin[2]) diff --git a/ladderdev/RatingValidator2.py b/ladderdev/RatingValidator2.py index 66c4f31..9921176 100644 --- a/ladderdev/RatingValidator2.py +++ b/ladderdev/RatingValidator2.py @@ -27,7 +27,7 @@ continue #probWin = 1.0-probWin #outcome = 1.0-outcome - for i in xrange(len(bins)): + for i in range(len(bins)): if probWin < bins[i][0]+binSize/2: bins[i][1]+=1 bins[i][2]+=probWin @@ -36,6 +36,6 @@ for bin in bins: if bin[1] > 0: - print bin[0],bin[1],bin[2],bin[3],bin[2]/bin[1],pow(bin[2],0.5)/bin[1],bin[3]/bin[1] + print(bin[0],bin[1],bin[2],bin[3],bin[2]/bin[1],pow(bin[2],0.5)/bin[1],bin[3]/bin[1]) else: - print bin[0],bin[1],bin[2],bin[3],'--','--','--' + print(bin[0],bin[1],bin[2],bin[3],'--','--','--') diff --git a/ladderdev/ladderRatingTester.py b/ladderdev/ladderRatingTester.py index 19c9d1a..2bebcfa 100644 --- a/ladderdev/ladderRatingTester.py +++ b/ladderdev/ladderRatingTester.py @@ -5,7 +5,7 @@ import gzip import json import math -import cPickle as pickle +import pickle systems = sys.argv[1].split(',') try: @@ -111,7 +111,7 @@ for system in systems: printme+=','+system x.append(system) -print printme +print(printme) for player in ladder.keys(): r=ladder[player]['rating']['r'] rd=ladder[player]['rating']['rd'] @@ -122,4 +122,4 @@ printme=player+','+str(len(trajectories[player]))+','+str(wltCounts[player][0])+','+str(r)+','+str(rd)+','+str(rpr)+','+str(rprd)+','+str(acre)+','+str(gxe) for system in x: #probably could just do system in systems, but this is safer printme+=','+str(ladderRatingSystem[system].getSortable(ladder[player]['scores'][system])) - print printme + print(printme)