Jon-Becker / nft-generator-py

This tool allows users to generate sets of unique images and metadata using weighted layer collections.
MIT License
301 stars 127 forks source link

Trait counter #37

Closed mwkemo closed 2 years ago

mwkemo commented 2 years ago

I added code to count and write used traits to JSON file.

from collections import Counter

all_token_rarity = []
for layer in config["layers"]:
  all_token_rarity.append({ layer["name"]: Counter(image[layer["name"]] for image in all_images) })

with open('./metadata/all-rarity.json', 'w') as outfile:
   json.dump(all_token_rarity, outfile, indent=4)

Maybe someone find it useful.

Jon-Becker commented 2 years ago

What exactly would this do?

If you open a PR, let me know and I'll try it out and merge it :)

mwkemo commented 2 years ago

Actually I wrote this code to check if weights worked correctly, and they do work as expected :). In the end I found it useful to use it on a website so others can see which traits are rare. The code goes through all of the layer groups and counts all used layers for each individual layer group, nothing special.

This is JSON output file with 20 NFTs generated. ```JSON [ { "Background": { "Sky blue": 3, "Olive green": 3, "Gray": 3, "Blue electric radial": 2, "Blue marine": 4, "Orange": 1, "Eggshell": 1, "Sauvignon": 1, "Green": 1, "Light red": 1 } }, { "Base": { "Lime green": 2, "Green": 1, "Swamper": 2, "Turquoise": 4, "Whitey": 2, "Electric blue": 2, "Rainbow": 2, "Cardinal": 1, "Toady": 1, "Purple Rain": 1, "Dynasty": 2 } }, { "Clothes": { "Convict": 1, "Leather jacket": 1, "Hawaii shirt": 1, "Hoodless": 3, "Hoodie cubism": 1, "Night robe gold": 1, "Skeleton": 1, "Teddy pyjama": 2, "Night robe": 2, "Fur coat": 1, "Tracksuit": 1, "USA tee": 1, "Hillbilly denim": 1, "Teddy Pyjama Blue": 1, "Hillbilly gold": 1, "Mafia": 1 } }, { "Head": { "Military": 1, "Rasta": 1, "Ethereumka": 1, "Birthday hat": 1, "Sombrero": 2, "Baseball cap tricolor": 1, "Surgeon": 1, "Miner": 1, "Santa": 1, "Rockabilly": 1, "Chav": 1, "Dreads": 1, "Sherlock": 2, "Chief": 1, "Lad": 1, "Cowboy": 1, "Fedora": 1, "Headband": 1 } }, { "Glasses": { "3D": 1, "Amphibian": 2, "Lennons": 1, "FU": 2, "Zorro": 2, "Spiral": 1, "FU gold": 2, "Cool shades red": 5, "Biker": 1, "Cool shades": 2, "Goldstar": 1 } }, { "Face": { "Thermometer": 2, "Doobie": 2, "Cigar": 1, "Bandit": 3, "Baby pacifier gold": 1, "Curly mustaches": 1, "Smoker": 1, "Frogger": 1, "Confetti": 1, "Godfather stache": 1, "Frack": 3, "Baby pacifier": 1, "Covid mask": 1, "Tobacco pipe": 1 } }, { "Eyes": { "Chaos": 3, "Black Eye": 4, "Patch": 3, "Ylikedat": 1, "Laser eyes": 4, "Yellow gaze": 2, "Sleepy": 3 } }, { "Pattern": { "Tiger": 6, "Blotchy": 6, "Tiger funk": 2, "Spotty": 6 } }, { "Accessory": { "Gold chain USD": 5, "Dog tags": 3, "Baller ring": 6, "Flower necklace": 4, "Nose ring": 1, "Bull ring": 1 } } ] ```
Jon-Becker commented 2 years ago

I'll include it in v2.1.

Thanks for contributing!

Jon-Becker commented 2 years ago

Implemented.