-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfind-statistics.js
executable file
·420 lines (378 loc) · 13.6 KB
/
find-statistics.js
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Using the same directory structure as your other scripts
const directories = {
ships: path.join(__dirname, 'public/converted-json/ships'),
squadrons: path.join(__dirname, 'public/converted-json/squadrons'),
upgrades: path.join(__dirname, 'public/converted-json/upgrades'),
objectives: path.join(__dirname, 'public/converted-json/objectives'),
'legends-ships': path.join(__dirname, 'public/converted-json/legends-ships'),
'legends-squadrons': path.join(__dirname, 'public/converted-json/legends-squadrons'),
'legends-upgrades': path.join(__dirname, 'public/converted-json/legends-upgrades'),
'legacy-squadrons': path.join(__dirname, 'public/converted-json/legacy-squadrons'),
'legacy-upgrades': path.join(__dirname, 'public/converted-json/legacy-upgrades'),
'old-legacy-ships': path.join(__dirname, 'public/converted-json/old-legacy-ships'),
'old-legacy-squadrons': path.join(__dirname, 'public/converted-json/old-legacy-squadrons'),
'old-legacy-upgrades': path.join(__dirname, 'public/converted-json/old-legacy-upgrades'),
// 'arc-upgrades': path.join(__dirname, 'public/converted-json/arc-upgrades'),
// 'arc-ships': path.join(__dirname, 'public/converted-json/arc-ships'),
// 'arc-squadrons': path.join(__dirname, 'public/converted-json/arc-squadrons'),
// 'arc-objectives': path.join(__dirname, 'public/converted-json/arc-objectives'),
// 'amg-upgrades': path.join(__dirname, 'public/converted-json/amg-upgrades'),
// 'amg-ships': path.join(__dirname, 'public/converted-json/amg-ships'),
// 'amg-squadrons': path.join(__dirname, 'public/converted-json/amg-squadrons'),
// 'amg-objectives': path.join(__dirname, 'public/converted-json/amg-objectives')
};
// Initialize statistics object
const statistics = {
ships: {
total: 0,
byFaction: {},
bySize: {},
byHullValue: {},
speedDistribution: {
speed1: { exists: 0, doesntExist: 0 },
speed2: { exists: 0, doesntExist: 0 },
speed3: { exists: 0, doesntExist: 0 },
speed4: { exists: 0, doesntExist: 0 }
},
shieldDistribution: {
front: {},
rear: {},
left: {},
right: {},
left_aux: {},
right_aux: {}
},
traits: {},
pointCosts: {
min: Infinity,
max: -Infinity,
average: 0,
distribution: {}
},
defenseTokens: {
scatter: {},
evade: {},
brace: {},
redirect: {},
contain: {},
salvo: {}
},
commandValues: {},
squadronValues: {},
engineerValues: {},
upgradeSlots: {},
armamentDistribution: {
asa: { red: {}, blue: {}, black: {} },
front: { red: {}, blue: {}, black: {} },
rear: { red: {}, blue: {}, black: {} },
left: { red: {}, blue: {}, black: {} },
right: { red: {}, blue: {}, black: {} },
left_aux: { red: {}, blue: {}, black: {} },
right_aux: { red: {}, blue: {}, black: {} },
special: { red: {}, blue: {}, black: {} }
}
},
squadrons: {
total: 0,
byFaction: {},
byHullValue: {},
bySpeed: {},
defenseTokens: {
scatter: {},
evade: {},
brace: {}
},
armamentDistribution: {
antiSquadron: { red: {}, blue: {}, black: {} },
antiShip: { red: {}, blue: {}, black: {} }
},
abilities: {
adept: {},
aiBattery: {},
aiAntisquadron: {},
assault: 0,
bomber: 0,
cloak: 0,
counter: {},
dodge: {},
escort: 0,
grit: 0,
heavy: 0,
intel: 0,
relay: {},
rogue: 0,
scout: 0,
screen: 0,
snipe: {},
strategic: 0,
swarm: 0
},
pointCosts: {
min: Infinity,
max: -Infinity,
average: 0,
distribution: {}
},
uniqueCount: 0,
aceCount: 0
},
upgrades: {
total: 0,
byType: {},
byFaction: {},
pointCosts: {
min: Infinity,
max: -Infinity,
average: 0,
distribution: {}
},
uniqueCount: 0,
modificationCount: 0,
byRestriction: {
traits: {},
size: {},
disqualUpgrades: {},
disableUpgrades: {},
enableUpgrades: {},
flagshipCount: 0
},
startCommands: {
byType: {},
byIcon: {},
byAmount: {}
},
exhaustTypes: {
blank: 0,
recur: 0,
nonrecur: 0,
discard: 0
}
}
};
function updateValueCount(obj, value) {
obj[value] = (obj[value] || 0) + 1;
}
function processShipData(shipData) {
// Process chassis level data
updateValueCount(statistics.ships.bySize, shipData.size);
updateValueCount(statistics.ships.byHullValue, shipData.hull);
// Process speed data
for (let i = 1; i <= 4; i++) {
const speedKey = `speed${i}`;
if (shipData.speed[i] && shipData.speed[i].length > 0) {
statistics.ships.speedDistribution[speedKey].exists++;
} else {
statistics.ships.speedDistribution[speedKey].doesntExist++;
}
}
// Process shield data
Object.entries(shipData.shields).forEach(([zone, value]) => {
updateValueCount(statistics.ships.shieldDistribution[zone], value);
});
// Process models
Object.values(shipData.models).forEach(model => {
statistics.ships.total++;
updateValueCount(statistics.ships.byFaction, model.faction);
// Process traits
model.traits.forEach(trait => {
if (trait) updateValueCount(statistics.ships.traits, trait);
});
// Process points
updateValueCount(statistics.ships.pointCosts.distribution, model.points);
statistics.ships.pointCosts.min = Math.min(statistics.ships.pointCosts.min, model.points);
statistics.ships.pointCosts.max = Math.max(statistics.ships.pointCosts.max, model.points);
// Process defense tokens
Object.entries(model.tokens).forEach(([token, count]) => {
const tokenName = token.replace('def_', '');
updateValueCount(statistics.ships.defenseTokens[tokenName], count);
});
// Process command values
updateValueCount(statistics.ships.commandValues, model.values.command);
updateValueCount(statistics.ships.squadronValues, model.values.squadron);
updateValueCount(statistics.ships.engineerValues, model.values.engineer);
// Process upgrade slots
model.upgrades.forEach(upgrade => {
updateValueCount(statistics.ships.upgradeSlots, upgrade);
});
// Process armament
Object.entries(model.armament).forEach(([arc, [red, blue, black]]) => {
updateValueCount(statistics.ships.armamentDistribution[arc].red, red);
updateValueCount(statistics.ships.armamentDistribution[arc].blue, blue);
updateValueCount(statistics.ships.armamentDistribution[arc].black, black);
});
});
}
function processSquadronData(squadronData) {
Object.values(squadronData.squadrons).forEach(squadron => {
statistics.squadrons.total++;
updateValueCount(statistics.squadrons.byFaction, squadron.faction);
updateValueCount(statistics.squadrons.byHullValue, squadron.hull);
updateValueCount(statistics.squadrons.bySpeed, squadron.speed);
// Process defense tokens
Object.entries(squadron.tokens || {}).forEach(([token, count]) => {
const tokenName = token.replace('def_', '');
updateValueCount(statistics.squadrons.defenseTokens[tokenName], count);
});
// Process armament with safety checks
['antiSquadron', 'antiShip'].forEach((type) => {
const armamentKey = type === 'antiSquadron' ? 'anti-squadron' : 'anti-ship';
if (squadron.armament && Array.isArray(squadron.armament[armamentKey])) {
const [red = 0, blue = 0, black = 0] = squadron.armament[armamentKey];
updateValueCount(statistics.squadrons.armamentDistribution[type].red, red);
updateValueCount(statistics.squadrons.armamentDistribution[type].blue, blue);
updateValueCount(statistics.squadrons.armamentDistribution[type].black, black);
}
});
// Process abilities with safety check
if (squadron.abilities) {
Object.entries(squadron.abilities).forEach(([ability, value]) => {
if (typeof value === 'boolean') {
statistics.squadrons.abilities[ability] += value ? 1 : 0;
} else if (value !== undefined) {
updateValueCount(statistics.squadrons.abilities[ability], value);
}
});
}
// Process points
if (squadron.points !== undefined) {
updateValueCount(statistics.squadrons.pointCosts.distribution, squadron.points);
statistics.squadrons.pointCosts.min = Math.min(statistics.squadrons.pointCosts.min, squadron.points);
statistics.squadrons.pointCosts.max = Math.max(statistics.squadrons.pointCosts.max, squadron.points);
}
// Count uniques and aces
if (squadron.unique) statistics.squadrons.uniqueCount++;
if (squadron.ace) statistics.squadrons.aceCount++;
});
}
function processUpgradeData(upgradeData) {
Object.values(upgradeData.upgrades).forEach(upgrade => {
statistics.upgrades.total++;
updateValueCount(statistics.upgrades.byType, upgrade.type);
// Process factions
upgrade.faction.forEach(faction => {
updateValueCount(statistics.upgrades.byFaction, faction);
});
// Process points
updateValueCount(statistics.upgrades.pointCosts.distribution, upgrade.points);
statistics.upgrades.pointCosts.min = Math.min(statistics.upgrades.pointCosts.min, upgrade.points);
statistics.upgrades.pointCosts.max = Math.max(statistics.upgrades.pointCosts.max, upgrade.points);
// Count uniques and modifications
if (upgrade.unique) statistics.upgrades.uniqueCount++;
if (upgrade.modification) statistics.upgrades.modificationCount++;
// Process restrictions
if (upgrade.restrictions) {
upgrade.restrictions.traits?.forEach(trait => {
updateValueCount(statistics.upgrades.byRestriction.traits, trait);
});
upgrade.restrictions.size?.forEach(size => {
updateValueCount(statistics.upgrades.byRestriction.size, size);
});
if (upgrade.restrictions.flagship) {
statistics.upgrades.byRestriction.flagshipCount++;
}
}
// Process start commands
if (upgrade.start_command) {
updateValueCount(statistics.upgrades.startCommands.byType, upgrade.start_command.type);
upgrade.start_command.start_icon?.forEach(icon => {
updateValueCount(statistics.upgrades.startCommands.byIcon, icon);
});
updateValueCount(statistics.upgrades.startCommands.byAmount, upgrade.start_command.start_amount);
}
// Process exhaust types
if (upgrade.exhaust) {
statistics.upgrades.exhaustTypes[upgrade.exhaust.type]++;
}
});
}
function findStatistics(directory) {
const files = fs.readdirSync(directory);
files.forEach(file => {
const filePath = path.join(directory, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
findStatistics(filePath);
} else if (file.endsWith('.json')) {
try {
const data = JSON.parse(fs.readFileSync(filePath, 'utf8'));
if (data.ships) {
Object.values(data.ships).forEach(processShipData);
}
if (data.squadrons) {
processSquadronData(data);
}
if (data.upgrades) {
processUpgradeData(data);
}
} catch (error) {
console.error(`Error processing file: ${filePath}`, error);
}
}
});
}
function parseArgs() {
const args = process.argv.slice(2);
return {
base: args.length === 0 || args.includes('-base'),
legends: args.includes('-legends'),
legacy: args.includes('-legacy'),
oldLegacy: args.includes('-old-legacy'),
arc: args.includes('-arc')
};
}
// Main execution
const flags = parseArgs();
// Process directories based on flags
const selectedDirectories = {};
// Always include base game content
if (flags.base) {
selectedDirectories.ships = directories.ships;
selectedDirectories.squadrons = directories.squadrons;
selectedDirectories.upgrades = directories.upgrades;
selectedDirectories.objectives = directories.objectives;
}
if (flags.legends) {
selectedDirectories['legends-ships'] = directories['legends-ships'];
selectedDirectories['legends-squadrons'] = directories['legends-squadrons'];
selectedDirectories['legends-upgrades'] = directories['legends-upgrades'];
}
if (flags.legacy) {
selectedDirectories['legacy-ships'] = directories['legacy-ships'];
selectedDirectories['legacy-squadrons'] = directories['legacy-squadrons'];
selectedDirectories['legacy-upgrades'] = directories['legacy-upgrades'];
}
if (flags.oldLegacy) {
selectedDirectories['old-legacy-ships'] = directories['old-legacy-ships'];
selectedDirectories['old-legacy-squadrons'] = directories['old-legacy-squadrons'];
selectedDirectories['old-legacy-upgrades'] = directories['old-legacy-upgrades'];
}
if (flags.arc) {
selectedDirectories['arc-ships'] = directories['arc-ships'];
selectedDirectories['arc-squadrons'] = directories['arc-squadrons'];
selectedDirectories['arc-upgrades'] = directories['arc-upgrades'];
selectedDirectories['arc-objectives'] = directories['arc-objectives'];
}
// Process each selected directory
Object.values(selectedDirectories).forEach(directory => {
if (fs.existsSync(directory)) {
findStatistics(directory);
}
});
// Calculate averages
['ships', 'squadrons', 'upgrades'].forEach(type => {
if (statistics[type].total > 0) {
const totalPoints = Object.entries(statistics[type].pointCosts.distribution)
.reduce((sum, [points, count]) => sum + (Number(points) * count), 0);
statistics[type].pointCosts.average = totalPoints / statistics[type].total;
}
});
// Write the statistics to a file
fs.writeFileSync(
path.join(__dirname, 'public/statistics.json'),
JSON.stringify(statistics, null, 2)
);