-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.js
90 lines (80 loc) · 2.4 KB
/
history.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
const fs = require('fs');
const output = (label, won, lost) => {
console.log(label);
let total = won + lost;
console.log('Won: ' + won + ' ' + (total > 0 ? Math.round(won / total * 100) : '0') + '%');
console.log('Lost: ' + lost + ' ' + (total > 0 ? Math.round(lost / total * 100) : '0') + '%');
console.log('Total: ' + total);
console.log('');
}
const sort = (obj) => {
return Object.values(obj).sort((a, b) => (a.wins / (a.wins + a.loses)) - (b.wins / (b.wins + b.loses)));
}
let history = JSON.parse(fs.readFileSync(__dirname + '/data/history-1v1.json', 'utf8'));
// let history = JSON.parse(fs.readFileSync(__dirname + '/data/history-ffa.json', 'utf8'));
output(
'FFA',
history.reduce((p, c) => p + (c.won && c.mode === 'ffa' ? 1 : 0), 0),
history.reduce((p, c) => p + (!c.won && c.mode === 'ffa' ? 1 : 0), 0)
);
output(
'1v1',
history.reduce((p, c) => p + (c.won && c.mode === '1v1' ? 1 : 0), 0),
history.reduce((p, c) => p + (!c.won && c.mode === '1v1' ? 1 : 0), 0)
);
let statCounts = {};
for (let i = 0; i < history.length; i++) {
if (!history[i].stats) {
continue;
}
// let key = JSON.stringify(history[i].stats);
let key = history[i].stats.defendDistance;
if (!statCounts[key]) {
statCounts[key] = {
wins: 0,
loses: 0,
stats: key,
};
}
if (history[i].won) {
statCounts[key].wins++;
} else {
statCounts[key].loses++;
}
}
statCounts = sort(statCounts);
for (let i = 0; i < statCounts.length; i++) {
output(
statCounts[i].stats,
statCounts[i].wins,
statCounts[i].loses
);
}
// let playerCounts = {};
// for (let i = 0; i < history.length; i++) {
// if (!history[i].stats) {
// continue;
// }
// let key = JSON.stringify(history[i].scores.map(score => score.name).sort());
// if (!playerCounts[key]) {
// playerCounts[key] = {
// key: key,
// wins: 0,
// loses: 0,
// stats: history[i].scores,
// };
// }
// if (history[i].won) {
// playerCounts[key].wins++;
// } else {
// playerCounts[key].loses++;
// }
// }
// playerCounts = sort(playerCounts);
// for (let i = 0; i < playerCounts.length; i++) {
// output(
// playerCounts[i].key,
// playerCounts[i].wins,
// playerCounts[i].loses
// );
// }