Added checks to DNA_Generator.py

Brought back Duplicate and Rarity checker from previous build.
pull/78/head
Torrin Leonard 2022-03-13 21:27:18 -04:00
rodzic d68b54121d
commit 4531d56098
3 zmienionych plików z 117 dodań i 6 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
bl_info = {
"name": "Blend_My_NFTs",
"author": "Torrin Leonard, This Cozy Studio Inc",
"version": (2, 0, 0),
"version": (2, 1, 0),
"blender": (3, 0, 0),
"location": "View3D",
"description": "Blend_My_NFTs UI Edition",

107
main/Checks.py 100644
Wyświetl plik

@ -0,0 +1,107 @@
# Purpose:
# The purpose of this file is to check the NFTRecord.json for duplicate NFT DNA and returns any found in the console.
# It also checks the percentage each variant is chosen in the NFTRecord, then compares it with its rarity percentage
# set in the .blend file.
# This file is provided for transparency. The accuracy of the rarity values you set in your .blend file as outlined in
# the README.md file are dependent on the maxNFTs, and the maximum number of combinations of your NFT collection.
import bpy
import os
import sys
import json
import importlib
from collections import Counter
from collections import defaultdict
class bcolors:
"""
The colour of console messages.
"""
OK = '\033[92m' # GREEN
WARNING = '\033[93m' # YELLOW
ERROR = '\033[91m' # RED
RESET = '\033[0m' # RESET COLOR
# Rarity Check
def check_Rarity(hierarchy, DNAList, save_path):
numNFTsGenerated = len(DNAList)
attributeNames = []
numDict = defaultdict(list)
hierarchy.keys()
for i in DNAList:
dnaSplitList = i.split("-")
for j, k in zip(dnaSplitList, hierarchy.keys()):
numDict[k].append(j)
numDict = dict(numDict)
for i in numDict:
count = dict(Counter(numDict[i]))
numDict[i] = count
fullNumName = {}
for i in hierarchy:
fullNumName[i] = {}
for j in hierarchy[i]:
variantNum = hierarchy[i][j]["number"]
fullNumName[i][variantNum] = j
completeData = {}
for i, j in zip(fullNumName, numDict):
x = {}
for k in fullNumName[i]:
for l in numDict[j]:
if l == k:
name = fullNumName[i][k]
num = numDict[j][l]
x[name] = [(str(round(((num/numNFTsGenerated)*100), 2)) + "%"), str(num)]
completeData[i] = x
print(completeData)
print(bcolors.OK + "Rarity Checker is active. These are the percentages for each variant per attribute you set in your .blend file:" + bcolors.RESET)
for i in completeData:
print(i + ":")
for j in completeData[i]:
print(" " + j + ": " + completeData[i][j][0] + " Occurrences: " + completeData[i][j][1])
jsonMetaData = json.dumps(completeData, indent=1, ensure_ascii=True)
with open(os.path.join(save_path, "RarityData.json"), 'w') as outfile:
outfile.write(jsonMetaData + '\n')
path = os.path.join(save_path, "RarityData.json")
print(bcolors.OK + f"Rarity Data has been saved to {path}." + bcolors.RESET)
def check_Duplicates(DNAList):
"""Checks if there are duplicates in DNAList before NFTRecord.json is sent to JSON file."""
duplicates = 0
seen = set()
for x in DNAList:
if x in seen:
print(x)
duplicates += 1
seen.add(x)
print(f"NFTRecord.json contains {duplicates} duplicate NFT DNA.")
if __name__ == '__main__':
check_Rarity()
check_Duplicates()

Wyświetl plik

@ -11,9 +11,11 @@ import random
import importlib
from functools import partial
from . import Rarity, Logic
from . import Rarity, Logic, Checks
importlib.reload(Rarity)
importlib.reload(Logic)
importlib.reload(Checks)
enableGeneration = False
colorList = []
@ -337,7 +339,6 @@ def generateNFT_DNA(nftName, maxNFTs, nftsPerBatch, save_path, logicFile, enable
return DNAListReturn
DNAList = create_DNAList()
print(f"DNAList = {DNAList}")
# Messages:
if len(DNAList) < maxNFTs:
@ -352,7 +353,7 @@ def generateNFT_DNA(nftName, maxNFTs, nftsPerBatch, save_path, logicFile, enable
DataDictionary["hierarchy"] = hierarchy
DataDictionary["DNAList"] = DNAList
return DataDictionary, possibleCombinations, DNAList
return DataDictionary, possibleCombinations
def send_To_Record_JSON(nftName, maxNFTs, nftsPerBatch, save_path, enableRarity, enableLogic, logicFile, Blend_My_NFTs_Output):
"""
@ -362,15 +363,18 @@ def send_To_Record_JSON(nftName, maxNFTs, nftsPerBatch, save_path, enableRarity,
repeate DNA.
"""
DataDictionary, possibleCombinations, DNAList = generateNFT_DNA(nftName, maxNFTs, nftsPerBatch, save_path, logicFile, enableRarity, enableLogic)
DataDictionary, possibleCombinations = generateNFT_DNA(nftName, maxNFTs, nftsPerBatch, save_path, logicFile, enableRarity, enableLogic)
NFTRecord_save_path = os.path.join(Blend_My_NFTs_Output, "NFTRecord.json")
Checks.check_Rarity(DataDictionary["hierarchy"], DataDictionary["DNAList"], os.path.join(save_path, "Blend_My_NFTs Output"))
Checks.check_Duplicates(DataDictionary["DNAList"])
try:
ledger = json.dumps(DataDictionary, indent=1, ensure_ascii=True)
with open(NFTRecord_save_path, 'w') as outfile:
outfile.write(ledger + '\n')
print(f"{bcolors.OK}{len(DNAList)} NFT DNA saved to {NFTRecord_save_path}\n"
print(f"{bcolors.OK}{len(DataDictionary['DNAList'])} NFT DNA saved to {NFTRecord_save_path}\n"
f"NFT DNA Successfully created. {bcolors.RESET}")
except: