Add verify script: integrity check + weighted spawn sample
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env node
|
||||
/** verify.js — read-back + integrity check for ghost-roster.db */
|
||||
const Database = require('better-sqlite3');
|
||||
const path = require('path');
|
||||
const db = new Database(process.argv[2] || path.join(__dirname, 'ghost-roster.db'), { readonly: true });
|
||||
|
||||
const fk = db.pragma('foreign_key_check');
|
||||
console.log('FK violations:', fk.length ? fk : 'none');
|
||||
console.log('ghosts: ', db.prepare('SELECT COUNT(*) c FROM roster_ghosts').get().c);
|
||||
console.log('abilities:', db.prepare('SELECT COUNT(*) c FROM roster_abilities').get().c);
|
||||
console.log('locations:', db.prepare('SELECT COUNT(*) c FROM roster_locations').get().c);
|
||||
console.log('by color: ', db.prepare('SELECT color, COUNT(*) c FROM roster_ghosts GROUP BY color').all());
|
||||
console.log('by rarity:', db.prepare('SELECT rarity, COUNT(*) c FROM roster_ghosts GROUP BY rarity_tier ORDER BY rarity_tier').all());
|
||||
console.log('\nrarity-weighted spawn sample (10 draws):');
|
||||
const pool = db.prepare(`SELECT id, name, color, rarity FROM roster_ghosts`).all();
|
||||
const W = { Common: 50, Rare: 30, Epic: 15, Legendary: 5 };
|
||||
const weighted = pool.flatMap(g => Array(W[g.rarity]).fill(g));
|
||||
for (let i = 0; i < 10; i++) {
|
||||
const g = weighted[Math.floor(Math.random() * weighted.length)];
|
||||
console.log(` ${g.color.padEnd(6)} ${g.rarity.padEnd(9)} ${g.name}`);
|
||||
}
|
||||
db.close();
|
||||
Reference in New Issue
Block a user