mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
- Some improvements to the structure of PerSetTracking.py
- Stats about Standard Format printed, similar to Distinct
This commit is contained in:
@@ -5,33 +5,85 @@ pathToMtgData = "mtg-data.txt"
|
||||
############IMPLEMENTATION FOLLOWS############
|
||||
import os,sys,fnmatch,re
|
||||
|
||||
if not os.path.exists(pathToMtgData) :
|
||||
def getSetByFormat(requestedFormat):
|
||||
# Parse out Standard sets from the Format file
|
||||
formatLocation = os.path.join(sys.path[0], 'blockdata', 'formats.txt')
|
||||
with open(formatLocation) as formatFile:
|
||||
formats = formatFile.readlines()
|
||||
|
||||
for format in formats:
|
||||
if requestedFormat not in format:
|
||||
continue
|
||||
parsed = format.split('|')
|
||||
for p in parsed:
|
||||
if not p.startswith('Sets:'):
|
||||
continue
|
||||
|
||||
sets = p.strip().split(':')[1]
|
||||
return sets.split(', ')
|
||||
|
||||
return []
|
||||
|
||||
def printCardSet(implementedSet, missingSet, fileName, setCoverage=None, printImplemented=False, printMissing=True):
|
||||
# Add another file that will print out whichever set is requested
|
||||
# Convert back to lists so they can be sorted
|
||||
impCount = len(implementedSet)
|
||||
misCount = len(missingSet)
|
||||
totalCount = impCount + misCount
|
||||
|
||||
filePath = os.path.join(sys.path[0], "PerSetTrackingResults", fileName)
|
||||
with open(filePath, "w") as outfile:
|
||||
if setCoverage:
|
||||
outfile.write(' '.join(setCoverage))
|
||||
outfile.write('\n')
|
||||
outfile.write("Implemented (Missing) / Total = Percentage Implemented\n")
|
||||
outfile.write("%d (%d) / %d = %.2f %%\n" % (impCount, misCount, totalCount, float(impCount)/totalCount*100))
|
||||
|
||||
# If you really need to, we can print implemented cards
|
||||
if printImplemented:
|
||||
implemented = list(implementedSet)
|
||||
implemented.sort()
|
||||
outfile.write("\nImplemented (%d):" % impCount)
|
||||
for s in implemented:
|
||||
outfile.write("\n%s" % s)
|
||||
outfile.write("\n")
|
||||
|
||||
# By default Missing will print, but you can disable it
|
||||
if printMissing:
|
||||
missing = list(missingSet)
|
||||
missing.sort()
|
||||
outfile.write("\nMissing (%d):" % misCount)
|
||||
for s in missing:
|
||||
outfile.write("\n%s" % s)
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not os.path.exists(pathToMtgData) :
|
||||
print("This script requires the text version of Arch's mtg-data to be present.You can download it from slightlymagic.net's forum and either place the text version next to this script or edit this script and provide the path to the file at the top.")
|
||||
print("Press Enter to exit")
|
||||
raw_input("")
|
||||
sys.exit()
|
||||
|
||||
if not os.path.isdir(sys.path[0] + os.sep + 'PerSetTrackingResults') :
|
||||
if not os.path.isdir(sys.path[0] + os.sep + 'PerSetTrackingResults') :
|
||||
os.mkdir(sys.path[0] + os.sep + 'PerSetTrackingResults')
|
||||
|
||||
forgeFolderFiles = []
|
||||
forgeCards = []
|
||||
mtgDataCards = {}
|
||||
setCodes = []
|
||||
setCodeToName = {}
|
||||
forgeCardCount = 0
|
||||
mtgDataCardCount = 0
|
||||
setCodeCount = 0
|
||||
forgeFolderFiles = []
|
||||
forgeCards = []
|
||||
mtgDataCards = {}
|
||||
setCodes = []
|
||||
setCodeToName = {}
|
||||
forgeCardCount = 0
|
||||
mtgDataCardCount = 0
|
||||
setCodeCount = 0
|
||||
|
||||
hasFetchedSets = False
|
||||
hasFetchedCardName = False
|
||||
tmpName = ""
|
||||
line = ""
|
||||
prevline = ""
|
||||
hasFetchedSets = False
|
||||
hasFetchedCardName = False
|
||||
tmpName = ""
|
||||
line = ""
|
||||
prevline = ""
|
||||
|
||||
#Parse mtg-data
|
||||
print("Parsing mtg-data")
|
||||
with open(pathToMtgData) as mtgdata :
|
||||
#Parse mtg-data
|
||||
print("Parsing mtg-data")
|
||||
with open(pathToMtgData) as mtgdata :
|
||||
for line in mtgdata :
|
||||
if not hasFetchedSets :
|
||||
if line != "\n" :
|
||||
@@ -57,9 +109,9 @@ with open(pathToMtgData) as mtgdata :
|
||||
|
||||
prevline = line
|
||||
|
||||
#Parse Forge
|
||||
print("Parsing Forge")
|
||||
for root, dirnames, filenames in os.walk("cardsfolder"):
|
||||
#Parse Forge
|
||||
print("Parsing Forge")
|
||||
for root, dirnames, filenames in os.walk("cardsfolder"):
|
||||
for fileName in fnmatch.filter(filenames, '*.txt'):
|
||||
with open(os.path.join(root, fileName)) as currentForgeCard :
|
||||
tmpname = currentForgeCard.readline()
|
||||
@@ -67,23 +119,27 @@ for root, dirnames, filenames in os.walk("cardsfolder"):
|
||||
tmpname = tmpname.rstrip()
|
||||
forgeCards.append(tmpname)
|
||||
|
||||
#Compare datasets and output results
|
||||
print("Comparing datasets and outputting results.")
|
||||
totalData = {}
|
||||
currentMissing = []
|
||||
currentImplemented = []
|
||||
allMissing = set()
|
||||
allImplemented = set()
|
||||
total = 0
|
||||
percentage = 0
|
||||
#Compare datasets and output results
|
||||
print("Comparing datasets and outputting results.")
|
||||
totalData = {}
|
||||
currentMissing = []
|
||||
currentImplemented = []
|
||||
allMissing = set()
|
||||
allImplemented = set()
|
||||
standardMissing = set()
|
||||
standardImplemented = set()
|
||||
total = 0
|
||||
percentage = 0
|
||||
|
||||
ignoredSet = [ 'ASTRAL', 'ATH', 'BD', 'BR', 'DD2', 'DDC', 'DDD', 'DDE', 'DDF',
|
||||
standardSets = getSetByFormat('Standard')
|
||||
|
||||
ignoredSet = [ 'ASTRAL', 'ATH', 'BD', 'BR', 'DD2', 'DDC', 'DDD', 'DDE', 'DDF',
|
||||
'DDG', 'DDH', 'DDI', 'DDJ', 'DKM', 'DRB', 'EVG', 'H09', 'ME2',
|
||||
'ME3', 'ME4', 'MED', 'PD2', 'PD3', 'SDC', 'UGL', 'UNH',
|
||||
'V09', 'V10', 'V11', 'V12',]
|
||||
|
||||
for currentSet in setCodes :
|
||||
# Ignore the following sets for tab calculation
|
||||
for currentSet in setCodes :
|
||||
# Ignore any sets that we don't tabulate
|
||||
if currentSet in ignoredSet: continue
|
||||
for key in mtgDataCards.keys() :
|
||||
setList = mtgDataCards[key]
|
||||
@@ -113,17 +169,21 @@ for currentSet in setCodes :
|
||||
totalData[currentSet] = (len(currentImplemented),len(currentMissing),total,percentage)
|
||||
allMissing |= set(currentMissing)
|
||||
allImplemented |= set(currentImplemented)
|
||||
if currentSet in standardSets:
|
||||
standardMissing |= set(currentMissing)
|
||||
standardImplemented |= set(currentImplemented)
|
||||
|
||||
del currentMissing[:]
|
||||
del currentImplemented[:]
|
||||
|
||||
#sort sets by percentage completed
|
||||
totalDataList = sorted(totalData.items(), key=lambda (key,entry): entry[3], reverse=True)
|
||||
#sort sets by percentage completed
|
||||
totalDataList = sorted(totalData.items(), key=lambda (key,entry): entry[3], reverse=True)
|
||||
|
||||
totalPercentage = 0
|
||||
totalMissing = 0
|
||||
totalImplemented = 0
|
||||
fullTotal = 0
|
||||
with open(sys.path[0] + os.sep + "PerSetTrackingResults" + os.sep + "CompleteStats.txt", "w") as statsfile:
|
||||
totalPercentage = 0
|
||||
totalMissing = 0
|
||||
totalImplemented = 0
|
||||
fullTotal = 0
|
||||
with open(sys.path[0] + os.sep + "PerSetTrackingResults" + os.sep + "CompleteStats.txt", "w") as statsfile:
|
||||
statsfile.write("Set: Implemented (Missing) / Total = Percentage Implemented\n")
|
||||
for k,dataKey in totalDataList :
|
||||
totalImplemented += dataKey[0]
|
||||
@@ -134,26 +194,7 @@ with open(sys.path[0] + os.sep + "PerSetTrackingResults" + os.sep + "CompleteSta
|
||||
statsfile.write("\n")
|
||||
statsfile.write("Total over all sets: " + str(totalImplemented) + " (" + str(totalMissing) + ") / " + str(fullTotal))
|
||||
|
||||
# Add another file that will print out distinct cards implemented/missing
|
||||
# Convert back to lists so they can be sorted
|
||||
impCount = len(allImplemented)
|
||||
misCount = len(allMissing)
|
||||
#implemented = list(allImplemented)
|
||||
#implemented.sort()
|
||||
missing = list(allMissing)
|
||||
missing.sort()
|
||||
totalCount = impCount+misCount
|
||||
with open(sys.path[0] + os.sep + "PerSetTrackingResults" + os.sep + "DistinctStats.txt", "w") as distinctfile:
|
||||
distinctfile.write("Distinct: Implemented (Missing) / Total = Percentage Implemented\n")
|
||||
distinctfile.write("%d (%d) / %d = %.2f %%\n" % (impCount, misCount, totalCount, float(impCount)/totalCount*100))
|
||||
printCardSet(allImplemented, allMissing, "DistinctStats.txt")
|
||||
printCardSet(standardImplemented, standardMissing, "FormatStandard.txt", setCoverage=standardSets)
|
||||
|
||||
# Currently only print missing cards, implemented cards are less important
|
||||
#distinctfile.write("\nImplemented (%d):" % impCount)
|
||||
#for s in implemented:
|
||||
# distinctfile.write("\n%s" % s)
|
||||
|
||||
distinctfile.write("\nMissing (%d):" % misCount)
|
||||
for s in missing:
|
||||
distinctfile.write("\n%s" % s)
|
||||
|
||||
print "Done!"
|
||||
print "Done!"
|
||||
Reference in New Issue
Block a user