Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print the rarity score for each NFT item #1148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions utils/rarity.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,58 @@ for (var layer in rarityData) {
// show two decimal places in percent
rarityData[layer][attribute].occurrence =
`${rarityData[layer][attribute].occurrence} in ${editionSize} editions (${chance} %)`;

rarityData[layer][attribute].chance = chance / 100;
}
}

// print out rarity data
console.log();
console.log("Traits Rarity Data ========");
console.log("===========================");
console.log();
for (var layer in rarityData) {
console.log(`Trait type: ${layer}`);
for (var trait in rarityData[layer]) {
console.log(rarityData[layer][trait]);
}
console.log();
}

// output a sorted list by NFT rarity score
NFTrarity = []
data.forEach((element) => {

score = 0;
element.attributes.forEach((attrib) => {
layer = rarityData[attrib["trait_type"]];
objIndex = layer.findIndex((meta => meta.trait == attrib["value"]));
trait = layer[objIndex];

score = score + 1 / trait.chance;
});

NFTrarity.push({
"edition": element.edition,
"score": score
});
});

console.log("NFT Rarity Ranking ========");
console.log("===========================");
NFTrarity.sort((a, b) => (a.score > b.score) ? -1 : 1);
// console.log(NFTrarity);

scoreFile = 'NftItemsRarityScore.log';
fs.writeFileSync(scoreFile, "NFT Rarity Ranking ======== \n Edition, Score\n");
NFTrarity.forEach((element) => {
line = `${element.edition},${element.score}\n`;
fs.appendFile(scoreFile, line, (err) => {
if (err) {
console.log(err);
}
else {
console.log(element);
}
});
});