mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-14 01:38:13 +00:00
- Improved PerSetTracking.py to generate Release stats file, and to read Formats from /res/blockdata/formats.txt
This commit is contained in:
@@ -3,41 +3,93 @@
|
|||||||
############IMPLEMENTATION FOLLOWS############
|
############IMPLEMENTATION FOLLOWS############
|
||||||
import os,sys,fnmatch,re
|
import os,sys,fnmatch,re
|
||||||
|
|
||||||
pathToMtgData = os.path.join(sys.path[0], "mtg-data.txt")
|
# TODO Move these somewhere else?
|
||||||
|
ignoredSet = [ 'ASTRAL', 'ATH', 'BD', 'BR', 'CM1', 'DD2', 'DDC', 'DDD', 'DDE', 'DDF',
|
||||||
|
'DDG', 'DDH', 'DDI', 'DDJ', 'DDK', 'DDL', 'DDM', 'DDN', 'DKM', 'DRB', 'DREAM', 'EVG', 'H09', 'MD1', 'ME2',
|
||||||
|
'ME3', 'ME4', 'MED', 'PD2', 'PD3', 'SDC', 'UG', 'UGL', 'UNH', 'V09', 'V10', 'V11', 'V12',
|
||||||
|
'V13', 'V14', '', 'DD3_DVD']
|
||||||
|
|
||||||
def getSetByFormat(requestedFormat):
|
toolsDir = os.path.abspath(os.path.dirname( __file__ ))
|
||||||
# Parse out Standard sets from the Format file
|
resDir = os.path.abspath(os.path.join(toolsDir, '..', 'res'))
|
||||||
formatLocation = os.path.join(sys.path[0], 'formats.txt')
|
pathToMtgData = os.path.join(toolsDir, "mtg-data.txt")
|
||||||
|
|
||||||
|
def initializeFormats():
|
||||||
|
formats = {}
|
||||||
|
formatLocation = os.path.join(resDir, 'blockdata', 'formats.txt')
|
||||||
|
print "Looking for formats in ", formatLocation
|
||||||
with open(formatLocation) as formatFile:
|
with open(formatLocation) as formatFile:
|
||||||
formats = formatFile.readlines()
|
while formatFile:
|
||||||
|
try:
|
||||||
|
line = formatFile.readline().strip()
|
||||||
|
if not line:
|
||||||
|
# this should only happen when the file is done processing if we did things correctly?
|
||||||
|
break
|
||||||
|
|
||||||
for format in formats:
|
format = line[1:-1]
|
||||||
if requestedFormat not in format:
|
formats[format] = {}
|
||||||
continue
|
except:
|
||||||
parsed = format.split('|')
|
break
|
||||||
for p in parsed:
|
|
||||||
if not p.startswith('Sets:'):
|
# Pull valid sets
|
||||||
|
while line != '':
|
||||||
|
line = formatFile.readline().strip()
|
||||||
|
if line.startswith('Sets:'):
|
||||||
|
sets = line.split(':')[1]
|
||||||
|
formats[format]['sets'] = sets.split(', ')
|
||||||
|
elif line.startswith('Banned'):
|
||||||
|
banned = line.split(':')[1]
|
||||||
|
formats[format]['banned'] = sets.split('; ')
|
||||||
|
|
||||||
|
print formats
|
||||||
|
return formats
|
||||||
|
|
||||||
|
def writeToFiles(text, files):
|
||||||
|
for f in files:
|
||||||
|
if f:
|
||||||
|
f.write(text)
|
||||||
|
|
||||||
|
def printOverallEditions(totalDataList, setCodeToName, releaseFile=None):
|
||||||
|
totalPercentage = 0
|
||||||
|
totalMissing = 0
|
||||||
|
totalImplemented = 0
|
||||||
|
fullTotal = 0
|
||||||
|
if releaseFile:
|
||||||
|
releaseFile.write("[spoiler=Overall Editions]\n")
|
||||||
|
with open(os.path.join(toolsDir, "PerSetTrackingResults", "CompleteStats.txt"), "w") as statsfile:
|
||||||
|
files = [statsfile, releaseFile]
|
||||||
|
writeToFiles("Set: Implemented (Missing) / Total = Percentage Implemented\n", files)
|
||||||
|
for k,dataKey in totalDataList :
|
||||||
|
totalImplemented += dataKey[0]
|
||||||
|
totalMissing += dataKey[1]
|
||||||
|
fullTotal += dataKey[2]
|
||||||
|
if dataKey[2] == 0:
|
||||||
|
print "SetCode unknown", k
|
||||||
continue
|
continue
|
||||||
|
writeToFiles(setCodeToName[k].lstrip() + ": " + str(dataKey[0]) + " (" + str(dataKey[1]) + ") / " + str(dataKey[2]) + " = " + str(round(dataKey[3], 2)) + "%\n", files)
|
||||||
|
totalPercentage = totalImplemented / fullTotal
|
||||||
|
writeToFiles("\nTotal over all sets: " + str(totalImplemented) + " (" + str(totalMissing) + ") / " + str(fullTotal) + "\n", files)
|
||||||
|
|
||||||
sets = p.strip().split(':')[1]
|
if releaseFile:
|
||||||
return sets.split(', ')
|
releaseFile.write("[/spoiler]\n\n")
|
||||||
|
|
||||||
return []
|
def printCardSet(implementedSet, missingSet, fileName, setCoverage=None, printImplemented=False, printMissing=True, releaseFile=None):
|
||||||
|
|
||||||
def printCardSet(implementedSet, missingSet, fileName, setCoverage=None, printImplemented=False, printMissing=True):
|
|
||||||
# Add another file that will print out whichever set is requested
|
# Add another file that will print out whichever set is requested
|
||||||
# Convert back to lists so they can be sorted
|
# Convert back to lists so they can be sorted
|
||||||
impCount = len(implementedSet)
|
impCount = len(implementedSet)
|
||||||
misCount = len(missingSet)
|
misCount = len(missingSet)
|
||||||
totalCount = impCount + misCount
|
totalCount = impCount + misCount
|
||||||
|
|
||||||
filePath = os.path.join(sys.path[0], "PerSetTrackingResults", fileName)
|
if releaseFile:
|
||||||
|
releaseFile.write("[spoiler=%s]\n" % fileName)
|
||||||
|
|
||||||
|
filePath = os.path.join(toolsDir, "PerSetTrackingResults", fileName)
|
||||||
with open(filePath, "w") as outfile:
|
with open(filePath, "w") as outfile:
|
||||||
|
files = [outfile, releaseFile]
|
||||||
if setCoverage:
|
if setCoverage:
|
||||||
outfile.write(' '.join(setCoverage))
|
writeToFiles(' '.join(setCoverage), files)
|
||||||
outfile.write('\n')
|
writeToFiles('\n', files)
|
||||||
outfile.write("Implemented (Missing) / Total = Percentage Implemented\n")
|
writeToFiles("Implemented (Missing) / Total = Percentage Implemented\n", files)
|
||||||
outfile.write("%d (%d) / %d = %.2f %%\n" % (impCount, misCount, totalCount, float(impCount)/totalCount*100))
|
writeToFiles("%d (%d) / %d = %.2f %%\n" % (impCount, misCount, totalCount, float(impCount)/totalCount*100), files)
|
||||||
|
|
||||||
# If you really need to, we can print implemented cards
|
# If you really need to, we can print implemented cards
|
||||||
if printImplemented:
|
if printImplemented:
|
||||||
@@ -51,14 +103,17 @@ def printCardSet(implementedSet, missingSet, fileName, setCoverage=None, printIm
|
|||||||
if printMissing:
|
if printMissing:
|
||||||
missing = list(missingSet)
|
missing = list(missingSet)
|
||||||
missing.sort()
|
missing.sort()
|
||||||
outfile.write("\nMissing (%d):" % misCount)
|
writeToFiles("\nMissing (%d):" % misCount, files)
|
||||||
for s in missing:
|
for s in missing:
|
||||||
outfile.write("\n%s" % s)
|
writeToFiles("\n%s" % s, files)
|
||||||
|
|
||||||
outfile.write("\n")
|
writeToFiles("\n", files)
|
||||||
|
|
||||||
|
if releaseFile:
|
||||||
|
releaseFile.write("[/spoiler]\n\n")
|
||||||
|
|
||||||
def printDistinctOracle(missingSet, fileName):
|
def printDistinctOracle(missingSet, fileName):
|
||||||
filePath = os.path.join(sys.path[0], "PerSetTrackingResults", fileName)
|
filePath = os.path.join(toolsDir, "PerSetTrackingResults", fileName)
|
||||||
missing = list(missingSet)
|
missing = list(missingSet)
|
||||||
missing.sort()
|
missing.sort()
|
||||||
with open(filePath, "w") as outfile:
|
with open(filePath, "w") as outfile:
|
||||||
@@ -76,8 +131,8 @@ if __name__ == '__main__':
|
|||||||
raw_input("")
|
raw_input("")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if not os.path.isdir(sys.path[0] + os.sep + 'PerSetTrackingResults') :
|
if not os.path.isdir(toolsDir + os.sep + 'PerSetTrackingResults') :
|
||||||
os.mkdir(sys.path[0] + os.sep + 'PerSetTrackingResults')
|
os.mkdir(toolsDir + os.sep + 'PerSetTrackingResults')
|
||||||
|
|
||||||
forgeFolderFiles = []
|
forgeFolderFiles = []
|
||||||
forgeCards = []
|
forgeCards = []
|
||||||
@@ -133,7 +188,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
#Parse Forge
|
#Parse Forge
|
||||||
print("Parsing Forge")
|
print("Parsing Forge")
|
||||||
cardsfolderLocation = os.path.join(sys.path[0], '..', 'res', 'cardsfolder')
|
cardsfolderLocation = os.path.join(resDir, 'cardsfolder')
|
||||||
for root, dirnames, filenames in os.walk(cardsfolderLocation):
|
for root, dirnames, filenames in os.walk(cardsfolderLocation):
|
||||||
for fileName in fnmatch.filter(filenames, '*.txt'):
|
for fileName in fnmatch.filter(filenames, '*.txt'):
|
||||||
with open(os.path.join(root, fileName)) as currentForgeCard :
|
with open(os.path.join(root, fileName)) as currentForgeCard :
|
||||||
@@ -149,28 +204,24 @@ if __name__ == '__main__':
|
|||||||
currentImplemented = []
|
currentImplemented = []
|
||||||
allMissing = set()
|
allMissing = set()
|
||||||
allImplemented = set()
|
allImplemented = set()
|
||||||
|
formats = initializeFormats()
|
||||||
|
unknownFormat = {'sets': []}
|
||||||
|
|
||||||
standardSets = getSetByFormat('Standard')
|
standardSets = formats.get('Standard', unknownFormat)['sets']
|
||||||
standardMissing = set()
|
standardMissing = set()
|
||||||
standardImplemented = set()
|
standardImplemented = set()
|
||||||
|
|
||||||
modernSets = getSetByFormat('Modern')
|
modernSets = formats.get('Modern', unknownFormat)['sets']
|
||||||
modernMissing = set()
|
modernMissing = set()
|
||||||
modernImplemented = set()
|
modernImplemented = set()
|
||||||
|
|
||||||
extendedSets = getSetByFormat('Extended')
|
#extendedSets = formats.get('Extended', unknownFormat)['sets']
|
||||||
extendedMissing = set()
|
#extendedMissing = set()
|
||||||
extendedImplemented = set()
|
#extendedImplemented = set()
|
||||||
|
|
||||||
total = 0
|
total = 0
|
||||||
percentage = 0
|
percentage = 0
|
||||||
|
|
||||||
|
|
||||||
ignoredSet = [ 'ASTRAL', 'ATH', 'BD', 'BR', 'CM1', 'DD2', 'DDC', 'DDD', 'DDE', 'DDF',
|
|
||||||
'DDG', 'DDH', 'DDI', 'DDJ', 'DDK', 'DDL', 'DDM', 'DDN', 'DKM', 'DRB', 'DREAM', 'EVG', 'H09', 'MD1', 'ME2',
|
|
||||||
'ME3', 'ME4', 'MED', 'PD2', 'PD3', 'SDC', 'UG', 'UGL', 'UNH', 'V09', 'V10', 'V11', 'V12',
|
|
||||||
'V13', 'V14', '']
|
|
||||||
|
|
||||||
for currentSet in setCodes :
|
for currentSet in setCodes :
|
||||||
# Ignore any sets that we don't tabulate
|
# Ignore any sets that we don't tabulate
|
||||||
if currentSet in ignoredSet: continue
|
if currentSet in ignoredSet: continue
|
||||||
@@ -188,7 +239,8 @@ if __name__ == '__main__':
|
|||||||
currentMissing.sort()
|
currentMissing.sort()
|
||||||
currentImplemented.sort()
|
currentImplemented.sort()
|
||||||
|
|
||||||
with open(sys.path[0] + os.sep + "PerSetTrackingResults" + os.sep + "set_" + currentSet.strip() + ".txt", "w") as output :
|
# Output each edition file on it's own
|
||||||
|
with open(toolsDir + os.sep + "PerSetTrackingResults" + os.sep + "set_" + currentSet.strip() + ".txt", "w") as output :
|
||||||
output.write("Implemented (" + str(len(currentImplemented)) + "):\n")
|
output.write("Implemented (" + str(len(currentImplemented)) + "):\n")
|
||||||
for everyImplemented in currentImplemented :
|
for everyImplemented in currentImplemented :
|
||||||
output.write(everyImplemented + '\n')
|
output.write(everyImplemented + '\n')
|
||||||
@@ -209,9 +261,9 @@ if __name__ == '__main__':
|
|||||||
if currentSet in modernSets:
|
if currentSet in modernSets:
|
||||||
modernMissing |= set(currentMissing)
|
modernMissing |= set(currentMissing)
|
||||||
modernImplemented |= set(currentImplemented)
|
modernImplemented |= set(currentImplemented)
|
||||||
if currentSet in extendedSets:
|
#if currentSet in extendedSets:
|
||||||
extendedMissing |= set(currentMissing)
|
# extendedMissing |= set(currentMissing)
|
||||||
extendedImplemented |= set(currentImplemented)
|
# extendedImplemented |= set(currentImplemented)
|
||||||
|
|
||||||
|
|
||||||
del currentMissing[:]
|
del currentMissing[:]
|
||||||
@@ -220,27 +272,15 @@ if __name__ == '__main__':
|
|||||||
#sort sets by percentage completed
|
#sort sets by percentage completed
|
||||||
totalDataList = sorted(totalData.items(), key=lambda k: k[1][3], reverse=True)
|
totalDataList = sorted(totalData.items(), key=lambda k: k[1][3], reverse=True)
|
||||||
|
|
||||||
totalPercentage = 0
|
releaseOutput = open(os.path.join(toolsDir, "PerSetTrackingResults", "ReleaseStats.txt"), "w")
|
||||||
totalMissing = 0
|
|
||||||
totalImplemented = 0
|
|
||||||
fullTotal = 0
|
|
||||||
|
|
||||||
with open(os.path.join(sys.path[0], "PerSetTrackingResults", "CompleteStats.txt"), "w") as statsfile:
|
printCardSet(allImplemented, allMissing, "DistinctStats.txt", releaseFile=releaseOutput)
|
||||||
statsfile.write("Set: Implemented (Missing) / Total = Percentage Implemented\n")
|
printOverallEditions(totalDataList, setCodeToName, releaseFile=releaseOutput)
|
||||||
for k,dataKey in totalDataList :
|
printCardSet(standardImplemented, standardMissing, "FormatStandard.txt", setCoverage=standardSets, releaseFile=releaseOutput)
|
||||||
totalImplemented += dataKey[0]
|
#printCardSet(extendedImplemented, extendedMissing, "FormatExtended.txt", setCoverage=extendedSets)
|
||||||
totalMissing += dataKey[1]
|
printCardSet(modernImplemented, modernMissing, "FormatModern.txt", setCoverage=modernSets, releaseFile=releaseOutput)
|
||||||
fullTotal += dataKey[2]
|
|
||||||
statsfile.write(setCodeToName[k].lstrip() + ": " + str(dataKey[0]) + " (" + str(dataKey[1]) + ") / " + str(dataKey[2]) + " = " + str(round(dataKey[3], 2)) + "%\n")
|
|
||||||
totalPercentage = totalImplemented / fullTotal
|
|
||||||
statsfile.write("\n")
|
|
||||||
statsfile.write("Total over all sets: " + str(totalImplemented) + " (" + str(totalMissing) + ") / " + str(fullTotal))
|
|
||||||
statsfile.write("\n")
|
|
||||||
|
|
||||||
printCardSet(allImplemented, allMissing, "DistinctStats.txt")
|
|
||||||
printCardSet(standardImplemented, standardMissing, "FormatStandard.txt", setCoverage=standardSets)
|
|
||||||
printCardSet(extendedImplemented, extendedMissing, "FormatExtended.txt", setCoverage=extendedSets)
|
|
||||||
printCardSet(modernImplemented, modernMissing, "FormatModern.txt", setCoverage=modernSets)
|
|
||||||
printDistinctOracle(allMissing, "DistinctOracle.txt")
|
printDistinctOracle(allMissing, "DistinctOracle.txt")
|
||||||
|
|
||||||
|
releaseOutput.close()
|
||||||
|
|
||||||
print ("Done!")
|
print ("Done!")
|
||||||
|
|||||||
Reference in New Issue
Block a user