-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutils.mjs
52 lines (45 loc) · 1.68 KB
/
utils.mjs
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
import fs from 'node:fs/promises';
const readKillStats = async () => {
const filePath = './data/_global-total/kills.json';
const json = await fs.readFile(filePath);
const object = JSON.parse(json);
const entries = Object.entries(object);
const map = new Map(entries);
return map;
};
const GLOBAL_TOTAL_KILLS = await readKillStats();
export const createKillsPerCategoryMap = (creaturesPerCategory) => {
const GLOBAL_TOTAL_KILLS_PER_CATEGORY = new Map();
const categories = [...creaturesPerCategory.keys()];
for (const category of categories) {
GLOBAL_TOTAL_KILLS_PER_CATEGORY.set(category, new Map());
}
for (const [race, kills] of GLOBAL_TOTAL_KILLS) {
for (const category of categories) {
const creatures = creaturesPerCategory.get(category);
if (creatures.has(race)) {
GLOBAL_TOTAL_KILLS_PER_CATEGORY.get(category).set(race, kills);
}
}
}
for (const category of categories) {
const expectedCreatures = creaturesPerCategory.get(category);
const actualCreatures = new Set(
GLOBAL_TOTAL_KILLS_PER_CATEGORY.get(category).keys()
);
const expectedSize = expectedCreatures.size;
const actualSize = actualCreatures.size;
if (actualSize < expectedSize) {
const difference = new Set(
[...expectedCreatures].filter(creature => !actualCreatures.has(creature))
);
console.log(`Category ${category}: expected ${expectedSize} entries but got only ${actualSize}. Missing entries:`, difference);
}
}
return GLOBAL_TOTAL_KILLS_PER_CATEGORY;
};
export const writeMap = async (map, slug) => {
const object = Object.fromEntries(map);
const json = JSON.stringify(object, null, '\t');
await fs.writeFile(`./data/_global-total/${slug}-kills.json`, `${json}\n`);
};