-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview-generator.js
More file actions
executable file
·272 lines (222 loc) · 10.4 KB
/
preview-generator.js
File metadata and controls
executable file
·272 lines (222 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/usr/bin/env node
/**
* FC Pro Collection - Preview Generator
* Simulates trait distribution for first 100 test NFTs
*/
const fs = require('fs');
const path = require('path');
const LAYERS_DIR = '/Users/djm/claude-projects/GitHub/art-engine/layers';
const PREVIEW_COUNT = 100;
// Color codes for output
const colors = {
reset: '\x1b[0m',
bright: '\x1b[1m',
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m'
};
// Import functions from rarity verification
const { analyzeLayer, calculateProbabilities } = require('./rarity-verification.js');
function weightedRandomSelect(traitsWithProbs) {
const totalWeight = traitsWithProbs.reduce((sum, trait) => sum + trait.weight, 0);
let random = Math.random() * totalWeight;
for (const trait of traitsWithProbs) {
random -= trait.weight;
if (random <= 0) {
return trait;
}
}
// Fallback to last trait
return traitsWithProbs[traitsWithProbs.length - 1];
}
function generateSingleNFT(layerAnalysis, nftId) {
const selectedTraits = {};
// Generate traits for each layer
Object.entries(layerAnalysis).forEach(([layerName, layerData]) => {
const selectedTrait = weightedRandomSelect(layerData.traits);
selectedTraits[layerName] = {
name: selectedTrait.name,
weight: selectedTrait.weight,
probability: selectedTrait.probability
};
});
return {
id: nftId,
traits: selectedTraits
};
}
function analyzeGeneratedTraits(generatedNFTs) {
const traitCounts = {};
const layerStats = {};
// Initialize counters
generatedNFTs.forEach(nft => {
Object.entries(nft.traits).forEach(([layerName, trait]) => {
if (!traitCounts[layerName]) {
traitCounts[layerName] = {};
layerStats[layerName] = { total: 0, withTrait: 0, withoutTrait: 0 };
}
if (!traitCounts[layerName][trait.name]) {
traitCounts[layerName][trait.name] = 0;
}
traitCounts[layerName][trait.name]++;
layerStats[layerName].total++;
if (trait.name.includes('NON3')) {
layerStats[layerName].withoutTrait++;
} else {
layerStats[layerName].withTrait++;
}
});
});
return { traitCounts, layerStats };
}
function printPreviewResults(generatedNFTs, analysis) {
const { traitCounts, layerStats } = analysis;
console.log(`\n${colors.bright}${colors.green}═══════════════════════════════════════════════════════════════════════════════${colors.reset}`);
console.log(`${colors.bright}${colors.green}🎯 FC PRO COLLECTION - PREVIEW GENERATION (${PREVIEW_COUNT} NFTs)${colors.reset}`);
console.log(`${colors.bright}${colors.green}═══════════════════════════════════════════════════════════════════════════════${colors.reset}`);
// Print layer-by-layer statistics
Object.entries(layerStats).forEach(([layerName, stats]) => {
console.log(`\n${colors.bright}${colors.cyan}📁 ${layerName}${colors.reset}`);
if (stats.withoutTrait > 0) {
const withoutPercentage = (stats.withoutTrait / stats.total * 100).toFixed(1);
const withPercentage = (stats.withTrait / stats.total * 100).toFixed(1);
console.log(`${colors.yellow} Without ${layerName}: ${stats.withoutTrait}/${stats.total} (${withoutPercentage}%)${colors.reset}`);
console.log(`${colors.green} With ${layerName}: ${stats.withTrait}/${stats.total} (${withPercentage}%)${colors.reset}`);
} else {
console.log(`${colors.green} All NFTs have ${layerName} traits${colors.reset}`);
}
// Show most common traits
const sortedTraits = Object.entries(traitCounts[layerName])
.filter(([traitName]) => !traitName.includes('NON3'))
.sort(([,a], [,b]) => b - a)
.slice(0, 5);
if (sortedTraits.length > 0) {
console.log(`${colors.blue} Top traits:${colors.reset}`);
sortedTraits.forEach(([traitName, count]) => {
const percentage = (count / stats.total * 100).toFixed(1);
console.log(` ${traitName}: ${count} (${percentage}%)`);
});
}
});
// Identify rare combinations
console.log(`\n${colors.bright}${colors.magenta}💎 RARE TRAIT COMBINATIONS FOUND:${colors.reset}`);
const rareNFTs = generatedNFTs.filter(nft => {
// Check for ultra-rare body types
const bodyTrait = nft.traits['Body.skin.race'];
const hasUltraRareBody = bodyTrait && bodyTrait.probability < 1;
// Check for rare face decorations
const faceTrait = nft.traits['Face decoration'];
const hasRareFace = faceTrait && !faceTrait.name.includes('NON3');
// Check for costume
const costumeTrait = nft.traits['Costume'];
const hasCostume = costumeTrait && !costumeTrait.name.includes('NON3');
return hasUltraRareBody || hasRareFace || hasCostume;
});
if (rareNFTs.length > 0) {
rareNFTs.slice(0, 10).forEach(nft => {
console.log(`\n${colors.magenta} NFT #${nft.id}:${colors.reset}`);
Object.entries(nft.traits).forEach(([layerName, trait]) => {
if (trait.probability < 2 || layerName === 'Body.skin.race' ||
(layerName === 'Face decoration' && !trait.name.includes('NON3')) ||
(layerName === 'Costume' && !trait.name.includes('NON3'))) {
const rarity = trait.probability < 1 ? '💎 Ultra Rare' :
trait.probability < 5 ? '🔥 Very Rare' : '⭐ Rare';
console.log(` ${layerName}: ${trait.name} ${rarity} (${trait.probability.toFixed(1)}%)`);
}
});
});
} else {
console.log(` No ultra-rare combinations in this ${PREVIEW_COUNT} NFT sample`);
}
// Print collection insights
console.log(`\n${colors.bright}${colors.blue}📊 COLLECTION INSIGHTS:${colors.reset}`);
// Skin tone distribution
const bodyStats = traitCounts['Body.skin.race'];
if (bodyStats) {
const commonSkins = ['Black', 'Black 2', 'Pink', 'Tan', 'Tan 2', 'White'];
const commonSkinCount = commonSkins.reduce((sum, skin) => sum + (bodyStats[skin] || 0), 0);
const commonSkinPercentage = (commonSkinCount / PREVIEW_COUNT * 100).toFixed(1);
console.log(`🎨 Common skin tones: ${commonSkinCount}/${PREVIEW_COUNT} (${commonSkinPercentage}%)`);
}
// Accessory coverage
const accessoryLayers = [
{ layer: 'Face decoration', name: 'face decorations' },
{ layer: 'Earrings', name: 'earrings' },
{ layer: 'Glasses', name: 'glasses' },
{ layer: 'Hat', name: 'hats' },
{ layer: 'Friend', name: 'friends' }
];
accessoryLayers.forEach(({ layer, name }) => {
const stats = layerStats[layer];
if (stats && stats.withTrait !== undefined) {
const percentage = (stats.withTrait / stats.total * 100).toFixed(1);
console.log(`👕 NFTs with ${name}: ${stats.withTrait}/${stats.total} (${percentage}%)`);
}
});
console.log(`\n${colors.green}✅ Preview generation complete! Sample shows good trait distribution.${colors.reset}`);
}
function savePreviewData(generatedNFTs, analysis) {
const outputData = {
generatedAt: new Date().toISOString(),
previewCount: PREVIEW_COUNT,
nfts: generatedNFTs,
analysis: analysis,
summary: {
totalNFTs: generatedNFTs.length,
layerCount: Object.keys(analysis.layerStats).length,
rareNFTs: generatedNFTs.filter(nft => {
const bodyTrait = nft.traits['Body.skin.race'];
return bodyTrait && bodyTrait.probability < 1;
}).length
}
};
const outputPath = '/Users/djm/claude-projects/GitHub/FC-pro-collection/preview-results.json';
fs.writeFileSync(outputPath, JSON.stringify(outputData, null, 2));
console.log(`\n${colors.blue}💾 Preview data saved to: ${outputPath}${colors.reset}`);
}
function main() {
console.log(`${colors.bright}${colors.blue}🎯 FC Pro Collection - Preview Generator${colors.reset}`);
console.log(`${colors.blue}Generating ${PREVIEW_COUNT} sample NFTs to preview trait distribution...${colors.reset}`);
if (!fs.existsSync(LAYERS_DIR)) {
console.error(`${colors.red}❌ Error: Layers directory not found: ${LAYERS_DIR}${colors.reset}`);
process.exit(1);
}
// Analyze all layers
const layerDirectories = fs.readdirSync(LAYERS_DIR)
.map(dir => path.join(LAYERS_DIR, dir))
.filter(dir => fs.statSync(dir).isDirectory());
const layerAnalysis = {};
layerDirectories.forEach(layerPath => {
try {
const layerData = analyzeLayer(layerPath);
const traitsWithProbs = calculateProbabilities(layerData);
layerAnalysis[layerData.layerName] = {
...layerData,
traits: traitsWithProbs
};
} catch (error) {
console.error(`${colors.red}❌ Error analyzing layer ${path.basename(layerPath)}: ${error.message}${colors.reset}`);
}
});
// Generate sample NFTs
console.log(`\n${colors.yellow}🎲 Generating ${PREVIEW_COUNT} sample NFTs...${colors.reset}`);
const generatedNFTs = [];
for (let i = 1; i <= PREVIEW_COUNT; i++) {
const nft = generateSingleNFT(layerAnalysis, i);
generatedNFTs.push(nft);
}
// Analyze results
const analysis = analyzeGeneratedTraits(generatedNFTs);
// Print results
printPreviewResults(generatedNFTs, analysis);
// Save data
savePreviewData(generatedNFTs, analysis);
}
// Run the preview generator
if (require.main === module) {
main();
}
module.exports = { generateSingleNFT, analyzeGeneratedTraits };