diff --git a/.gitignore b/.gitignore index ce34c1b..b9fb8be 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,8 @@ *.blend1 *.json +.idea +__pycache__ NFTRecord.json -3D_Model_Test.blend \ No newline at end of file +3D_Model_Test.blend +.Ds_Store \ No newline at end of file diff --git a/src/generators_and_sorters/DNA_Generator.py b/src/generators_and_sorters/DNA_Generator.py index 57dab72..ed7105c 100644 --- a/src/generators_and_sorters/DNA_Generator.py +++ b/src/generators_and_sorters/DNA_Generator.py @@ -34,6 +34,8 @@ class bcolors: time_start = time.time() +print("") + def stripColorFromName(name): return "_".join(name.split("_")[:-1]) @@ -221,7 +223,7 @@ def returnData(): combinations = combinations*i if combinations == 0: - print(bcolors.FAIL + "ERROR:" + bcolors.RESET) + print(bcolors.ERROR + "ERROR:" + bcolors.RESET) print("The number of all possible combinations is equal to 0. Please review your collection hierarchy \n " "and ensure it is formatted correctly.") print("Please review README.md for more information.") @@ -233,10 +235,10 @@ def returnData(): numBatches = combinations/nftsPerBatch if numBatches < 1: - print(bcolors.Fail + "ERROR:" + bcolors.RESET) - print("The number of NFTs Per Batch (NFTsPerBatch variable in config.py) is to high") - print("There are a total of " + combinations + " possible NFT combinations") - print("and you've requested " + nftsPerBatch + " NFTs per batch.") + print(bcolors.ERROR + "ERROR:" + bcolors.RESET) + print("The number of NFTs Per Batch (nftsPerBatch variable in config.py) is to high.") + print("There are a total of " + str(combinations) + " possible NFT combinations and you've requested " + + str(nftsPerBatch) + " NFTs per batch.") print("Lower the number of NFTs per batch in config.py or increase the number of \nattributes and/or variants" " in your .blend file.") @@ -263,8 +265,6 @@ def generateNFT_DNA(possibleCombinations): ''' Returns batchDataDictionary containing the number of NFT cominations, hierarchy, and the DNAList. ''' - batchDataDictionary = {} - listOptionVariant = [] if not enableMaxNFTs: print("-----------------------------------------------------------------------------") @@ -275,6 +275,8 @@ def generateNFT_DNA(possibleCombinations): print("Generating " + str(maxNFTs) + " combinations of DNA...") print("") + batchDataDictionary = {} + listOptionVariant = [] DNAList = [] if not enableRarity: @@ -312,44 +314,7 @@ def generateNFT_DNA(possibleCombinations): if enableRarity: possibleCombinations = maxNFTs - - for i in hierarchy: - numChild = len(hierarchy[i]) - possibleNums = list(range(1, numChild + 1)) - listOptionVariant.append(possibleNums) - - for x in range(maxNFTs): - dnaStr = "" - for i in hierarchy: - number_List_Of_i = [] - rarity_List_Of_i = [] - count = 0 - ifZeroBool = None - - for k in hierarchy[i]: - number = hierarchy[i][k]["number"] - number_List_Of_i.append(number) - - rarity = hierarchy[i][k]["rarity"] - rarity_List_Of_i.append(float(rarity)) - - count += 1 - - for x in rarity_List_Of_i: - if x == 0: - ifZeroBool = True - elif x != 0: - ifZeroBool = False - - if ifZeroBool == True: - variantByNum = random.choices(number_List_Of_i, k = 1) - elif ifZeroBool == False: - variantByNum = random.choices(number_List_Of_i, weights = rarity_List_Of_i, k = 1) - - dnaStr += '-' + str(variantByNum[0]) - - dnaPushToList = ''.join(dnaStr.split('-', 1)) - DNAList.append(dnaPushToList) + Rarity_Sorter.sortRarityWeights(hierarchy, listOptionVariant, DNAList) #Data stored in batchDataDictionary: batchDataDictionary["numNFTsGenerated"] = possibleCombinations diff --git a/src/generators_and_sorters/Rarity_Sorter.py b/src/generators_and_sorters/Rarity_Sorter.py index c392cd7..5fc8570 100644 --- a/src/generators_and_sorters/Rarity_Sorter.py +++ b/src/generators_and_sorters/Rarity_Sorter.py @@ -22,9 +22,55 @@ from src.main.config import * importlib.reload(DNA_Generator) from src.generators_and_sorters.DNA_Generator import * -def sortRarityWeights(DataDictionary): +def sortRarityWeights(hierarchy, listOptionVariant, DNAList,): ''' Sorts through DataDictionary and appropriately weights each variant based on their rarity percentage set in Blender ("rarity" in DNA_Generator). Then ''' - return DataDictionary \ No newline at end of file + + for i in hierarchy: + numChild = len(hierarchy[i]) + possibleNums = list(range(1, numChild + 1)) + listOptionVariant.append(possibleNums) + + for x in range(maxNFTs): + def createDNA(): + dnaStr1 = "" + for i in hierarchy: + number_List_Of_i = [] + rarity_List_Of_i = [] + count = 0 + ifZeroBool = None + + for k in hierarchy[i]: + number = hierarchy[i][k]["number"] + number_List_Of_i.append(number) + + rarity = hierarchy[i][k]["rarity"] + rarity_List_Of_i.append(float(rarity)) + + count += 1 + + for x in rarity_List_Of_i: + if x == 0: + ifZeroBool = True + elif x != 0: + ifZeroBool = False + + if ifZeroBool == True: + variantByNum = random.choices(number_List_Of_i, k=1) + elif ifZeroBool == False: + variantByNum = random.choices(number_List_Of_i, weights=rarity_List_Of_i, k=1) + + dnaStr1 += '-' + str(variantByNum[0]) + return dnaStr1 + + dnaStr = createDNA() + + if dnaStr not in DNAList: + dnaPushToList = ''.join(dnaStr.split('-', 1)) + else: + createDNA() + + DNAList.append(dnaPushToList) + return \ No newline at end of file diff --git a/src/generators_and_sorters/__pycache__/DNA_Generator.cpython-39.pyc b/src/generators_and_sorters/__pycache__/DNA_Generator.cpython-39.pyc index d902a5f..a3a579e 100644 Binary files a/src/generators_and_sorters/__pycache__/DNA_Generator.cpython-39.pyc and b/src/generators_and_sorters/__pycache__/DNA_Generator.cpython-39.pyc differ diff --git a/src/generators_and_sorters/__pycache__/Rarity_Sorter.cpython-39.pyc b/src/generators_and_sorters/__pycache__/Rarity_Sorter.cpython-39.pyc index cf5d732..a4aa94c 100644 Binary files a/src/generators_and_sorters/__pycache__/Rarity_Sorter.cpython-39.pyc and b/src/generators_and_sorters/__pycache__/Rarity_Sorter.cpython-39.pyc differ