Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port codebase to Python3 #2

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
6 changes: 4 additions & 2 deletions MegaCounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.loads(file.read())
file.close()

megastats=[]
total=0
Expand Down Expand Up @@ -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))

2 changes: 1 addition & 1 deletion PS-Extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 15 additions & 17 deletions StatCounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -94,7 +89,7 @@
t=t[:-11]

for line in file:
#print line
#print(line)
battles = json.loads(line)

for battle in battles:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -246,10 +241,13 @@


#write teammates and encounter matrix to file
pickle.dump(teammateMatrix,teammatefile)
teammatefile.close()
pickle.dump(encounterMatrix,encounterfile)
encounterfile.close()
filename="Raw/moveset/"+tier+"/teammate"+specs+".pickle"
teammatefile=open(filename,'wb')
with open(filename, 'wb') as teammate_file:
pickle.dump(teammateMatrix, teammate_file)
filename="Raw/moveset/"+tier+"/encounterMatrix"+specs+".pickle"
with open(filename, 'wb') as encounter_file:
pickle.dump(encounterMatrix, encounter_file)
monsanto marked this conversation as resolved.
Show resolved Hide resolved

#sort by weighted usage
if tier in ['challengecup1v1','1v1']:
Expand Down Expand Up @@ -322,8 +320,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?
Expand Down Expand Up @@ -353,7 +351,7 @@
nbins = len(histogram)

for start in range(len(stallCounter)):
if stallCounter[start] >= histogram[0][0]-binSize/2:
if stallCounter[start][0] >= histogram[0][0]-binSize/2:
shrianshChari marked this conversation as resolved.
Show resolved Hide resolved
break

j=0
Expand All @@ -379,7 +377,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:
Expand Down
1 change: 0 additions & 1 deletion TA.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import string
import sys
#import ujson as json
import json
import math
import copy
Expand Down
30 changes: 15 additions & 15 deletions TierUpdate9Doubles.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -16,25 +16,25 @@ 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']

def main(months):
file = open('keylookup.json', 'rb')
keyLookup = json.load(file)
keyLookup = json.loads(file.read())
shrianshChari marked this conversation as resolved.
Show resolved Hide resolved
file.close()

rise = [0.99999999999,0.99515839608,0.04515839608][len(months)-1]
Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
Expand All @@ -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:])
Expand Down
26 changes: 13 additions & 13 deletions TierUpdate9LC.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -28,22 +28,22 @@ 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')
keyLookup = json.load(file)
keyLookup = json.loads(file.read())
file.close()

rise = [0.99999999999,0.99515839608,0.04515839608][len(months)-1]
Expand All @@ -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
Expand Down Expand Up @@ -98,7 +98,7 @@ def main(months):
for poke in dnuBanlist:
printme += keyLookup[poke]+', '
printme = printme[:-2]
print printme
print(printme)



Expand Down
30 changes: 15 additions & 15 deletions TierUpdate9NatDex.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -16,25 +16,25 @@ 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']

def main(months):
file = open('keylookup.json', 'rb')
keyLookup = json.load(file)
keyLookup = json.loads(file.read())
file.close()

rise = [0.08827751140,0.06715839608,0.04515839608][len(months)-1]
Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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
Expand All @@ -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:])
Expand Down
Loading