init
This commit is contained in:
44
tools/merge-dropstats.js
Normal file
44
tools/merge-dropstats.js
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env node
|
||||
// Fusionne plusieurs fichiers dropstats.json en un seul fichier combiné.
|
||||
// Usage : node merge-dropstats.js sortie.json fichier1.json fichier2.json [...]
|
||||
// ou : node merge-dropstats.js sortie.json dossier-contenant-les-jsons/*.json
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { emptyDropStats, mergeDropStatsInto, summarize } = require('../lib/dropstats');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
if (args.length < 2) {
|
||||
console.error('Usage: node merge-dropstats.js <sortie.json> <fichier1.json> [fichier2.json ...]');
|
||||
console.error('Exemple: node merge-dropstats.js fusion.json alice.json bob.json charlie.json');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const [outputPath, ...inputPaths] = args;
|
||||
const result = emptyDropStats();
|
||||
let filesOk = 0;
|
||||
|
||||
console.log(`Fusion de ${inputPaths.length} fichier(s)...\n`);
|
||||
|
||||
for (const inputPath of inputPaths) {
|
||||
try {
|
||||
const raw = fs.readFileSync(inputPath, 'utf8');
|
||||
const data = JSON.parse(raw);
|
||||
const added = mergeDropStatsInto(result, data);
|
||||
filesOk++;
|
||||
console.log(` ✓ ${path.basename(inputPath)} — +${added} kills`);
|
||||
} catch (e) {
|
||||
console.error(` ✗ ${path.basename(inputPath)} — erreur : ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
result.updatedAt = new Date().toISOString();
|
||||
fs.writeFileSync(outputPath, JSON.stringify(result, null, 2));
|
||||
|
||||
const stats = summarize(result);
|
||||
console.log('');
|
||||
console.log(`Fichiers fusionnés : ${filesOk}/${inputPaths.length}`);
|
||||
console.log(`Mobs suivis : ${stats.totalMobs}`);
|
||||
console.log(`Kills cumulés : ${stats.totalKills}`);
|
||||
console.log(`Combinaisons : ${stats.totalCombos}`);
|
||||
console.log(`Écrit dans : ${path.resolve(outputPath)}`);
|
||||
Reference in New Issue
Block a user