54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Recalculate all ELO ratings and partnership stats
|
|
*
|
|
* This script rebuilds all player stats and partnership stats from scratch
|
|
* by processing all matches in chronological order.
|
|
*/
|
|
|
|
const { PrismaClient } = require('@prisma/client');
|
|
const { recalculateAllElo } = require('../src/lib/elo-utils');
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('Starting ELO recalculation...');
|
|
console.log('This will delete all existing stats and rebuild them from match history.');
|
|
console.log('');
|
|
|
|
try {
|
|
// Confirm before proceeding
|
|
const readline = require('readline').createInterface({
|
|
input: process.stdin,
|
|
output: process.stdout
|
|
});
|
|
|
|
const confirm = await new Promise(resolve => {
|
|
readline.question('Are you sure you want to proceed? (yes/no): ', resolve);
|
|
});
|
|
readline.close();
|
|
|
|
if (confirm.toLowerCase() !== 'yes') {
|
|
console.log('Operation cancelled.');
|
|
return;
|
|
}
|
|
|
|
console.log('Recalculating stats...');
|
|
const result = await recalculateAllElo(prisma);
|
|
|
|
console.log('\nRecalculation complete!');
|
|
console.log(`- Matches processed: ${result.matchesProcessed}`);
|
|
console.log(`- Players updated: ${result.playersUpdated}`);
|
|
console.log(`- Partnerships updated: ${result.partnershipsUpdated}`);
|
|
|
|
} catch (error) {
|
|
console.error('Error during recalculation:', error);
|
|
process.exit(1);
|
|
} finally {
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
main();
|