@pkmn/stats 0.0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +1 -1
- package/README.md +11 -7
- package/build/aliases.json +1 -0
- package/build/binary.d.ts +138 -0
- package/build/binary.js +386 -0
- package/build/binary.js.map +1 -0
- package/build/classifier.d.ts +2 -2
- package/build/classifier.js +48 -42
- package/build/classifier.js.map +1 -1
- package/build/data.d.ts +39 -0
- package/build/data.js +126 -0
- package/build/data.js.map +1 -0
- package/build/display.d.ts +1 -1
- package/build/display.js +24 -14
- package/build/display.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +3 -1
- package/build/index.js.map +1 -1
- package/build/parser.d.ts +2 -2
- package/build/parser.js +59 -41
- package/build/parser.js.map +1 -1
- package/build/pkmn/data.d.ts +39 -0
- package/build/pkmn/data.js +126 -0
- package/build/pkmn/data.js.map +1 -0
- package/build/pkmn/index.d.ts +1 -0
- package/build/pkmn/index.js +18 -0
- package/build/pkmn/index.js.map +1 -0
- package/build/reports.d.ts +12 -3
- package/build/reports.js +30 -23
- package/build/reports.js.map +1 -1
- package/build/smogon/aliases.json +227 -0
- package/build/smogon/classifier.d.ts +12 -0
- package/build/smogon/classifier.js +556 -0
- package/build/smogon/classifier.js.map +1 -0
- package/build/smogon/display.d.ts +96 -0
- package/build/smogon/display.js +412 -0
- package/build/smogon/display.js.map +1 -0
- package/build/smogon/index.d.ts +6 -0
- package/build/smogon/index.js +19 -0
- package/build/smogon/index.js.map +1 -0
- package/build/smogon/parser.d.ts +57 -0
- package/build/smogon/parser.js +358 -0
- package/build/smogon/parser.js.map +1 -0
- package/build/smogon/reports.d.ts +51 -0
- package/build/smogon/reports.js +652 -0
- package/build/smogon/reports.js.map +1 -0
- package/build/smogon/stats.d.ts +119 -0
- package/build/smogon/stats.js +521 -0
- package/build/smogon/stats.js.map +1 -0
- package/build/smogon/test/integration.d.ts +30 -0
- package/build/smogon/test/integration.js +179 -0
- package/build/smogon/test/integration.js.map +1 -0
- package/build/smogon/test/integration.test.d.ts +1 -0
- package/build/smogon/test/integration.test.js +38 -0
- package/build/smogon/test/integration.test.js.map +1 -0
- package/build/smogon/test/parser.test.d.ts +1 -0
- package/build/smogon/test/parser.test.js +91 -0
- package/build/smogon/test/parser.test.js.map +1 -0
- package/build/smogon/util.d.ts +63 -0
- package/build/smogon/util.js +400 -0
- package/build/smogon/util.js.map +1 -0
- package/build/stats.d.ts +3 -3
- package/build/stats.js +34 -34
- package/build/stats.js.map +1 -1
- package/build/util.d.ts +7 -7
- package/build/util.js +45 -34
- package/build/util.js.map +1 -1
- package/package.json +11 -14
- package/src/aliases.json +1 -0
- package/src/binary.ts +514 -0
- package/src/classifier.ts +38 -37
- package/src/display.ts +12 -14
- package/src/index.ts +6 -17
- package/src/parser.ts +39 -22
- package/src/reports.ts +22 -21
- package/src/stats.ts +27 -24
- package/src/util.ts +40 -39
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Reports = void 0;
|
|
27
|
+
const data_1 = require("@pkmn/data");
|
|
28
|
+
const util = __importStar(require("./util"));
|
|
29
|
+
const round = (v, p = util.PRECISION) => util.round(v, p);
|
|
30
|
+
const USAGE_TIERS = {
|
|
31
|
+
singles: ['OU', 'UU', 'RU', 'NU', 'PU'],
|
|
32
|
+
doubles: ['DOU', 'DUU'],
|
|
33
|
+
nationaldex: ['ND'],
|
|
34
|
+
littlecup: ['LC'],
|
|
35
|
+
};
|
|
36
|
+
const TIERS = {
|
|
37
|
+
singles: [
|
|
38
|
+
'Uber', 'OU', 'UUBL', 'UU', 'RUBL', 'RU', 'NUBL', 'NU', 'PUBL', 'PU', 'ZUBL', 'ZU',
|
|
39
|
+
],
|
|
40
|
+
doubles: ['DUber', 'DOU', 'DUU', 'DNU'],
|
|
41
|
+
nationaldex: ['ND', 'NDBL'],
|
|
42
|
+
littlecup: ['LC', 'LCBL'],
|
|
43
|
+
};
|
|
44
|
+
const WEIGHTS = [[24], [20, 4], [20, 3, 1]];
|
|
45
|
+
const SUFFIXES = ['', 'suspecttest', 'alpha', 'beta'];
|
|
46
|
+
const MIN = [20, 0.5];
|
|
47
|
+
const legacy = true;
|
|
48
|
+
exports.Reports = new class {
|
|
49
|
+
usageReport(gen, format, stats) {
|
|
50
|
+
const sorted = Object.entries(stats.pokemon).filter(p => p[0] !== 'empty');
|
|
51
|
+
if (['challengecup1v1', '1v1'].includes(format)) {
|
|
52
|
+
sorted.sort((a, b) => b[1].usage.real - a[1].usage.real || a[0].localeCompare(b[0]));
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
sorted.sort((a, b) => b[1].usage.weighted - a[1].usage.weighted || a[0].localeCompare(b[0]));
|
|
56
|
+
}
|
|
57
|
+
let s = ` Total battles: ${stats.battles}\n`;
|
|
58
|
+
const avg = stats.battles
|
|
59
|
+
? util.roundStr(stats.usage.weighted / stats.battles / 12, 1e3)
|
|
60
|
+
: '0.0';
|
|
61
|
+
s += ` Avg. weight/team: ${avg}\n`;
|
|
62
|
+
s += ' + ---- + ------------------ + --------- + ------ + ------- + ------ + ------- + \n';
|
|
63
|
+
s += ' | Rank | Pokemon | Usage % | Raw | % | Real | % | \n';
|
|
64
|
+
s += ' + ---- + ------------------ + --------- + ------ + ------- + ------ + ------- + \n';
|
|
65
|
+
const total = {
|
|
66
|
+
raw: Math.max(1.0, stats.usage.raw),
|
|
67
|
+
real: Math.max(1.0, stats.usage.real),
|
|
68
|
+
weighted: Math.max(1.0, stats.usage.weighted),
|
|
69
|
+
};
|
|
70
|
+
for (const [i, entry] of sorted.entries()) {
|
|
71
|
+
const species = entry[0];
|
|
72
|
+
const usage = entry[1].usage;
|
|
73
|
+
if (usage.raw === 0)
|
|
74
|
+
break;
|
|
75
|
+
const rank = (i + 1).toFixed().padEnd(4);
|
|
76
|
+
const poke = util.displaySpecies(gen, species, legacy).padEnd(18);
|
|
77
|
+
const use = (((100 * usage.weighted) / total.weighted) * 6).toFixed(5).padStart(8);
|
|
78
|
+
const raw = usage.raw.toFixed().padEnd(6);
|
|
79
|
+
const rawp = (((100 * usage.raw) / total.raw) * 6).toFixed(3).padStart(6);
|
|
80
|
+
const real = usage.real.toFixed().padEnd(6);
|
|
81
|
+
const realp = (((100 * usage.real) / total.real) * 6).toFixed(3).padStart(6);
|
|
82
|
+
s += ` | ${rank} | ${poke} | ${use}% | ${raw} | ${rawp}% | ${real} | ${realp}% | \n`;
|
|
83
|
+
}
|
|
84
|
+
s += ' + ---- + ------------------ + --------- + ------ + ------- + ------ + ------- + \n';
|
|
85
|
+
return s;
|
|
86
|
+
}
|
|
87
|
+
leadsReport(gen, stats) {
|
|
88
|
+
let s = ` Total leads: ${stats.battles * 2}\n`;
|
|
89
|
+
s += ' + ---- + ------------------ + --------- + ------ + ------- + \n';
|
|
90
|
+
s += ' | Rank | Pokemon | Usage % | Raw | % | \n';
|
|
91
|
+
s += ' + ---- + ------------------ + --------- + ------ + ------- + \n';
|
|
92
|
+
const total = { raw: 0, weighted: 0 };
|
|
93
|
+
total.raw = Math.max(1.0, stats.lead.raw);
|
|
94
|
+
total.weighted = Math.max(1.0, stats.lead.weighted);
|
|
95
|
+
const sorted = Object.entries(stats.pokemon)
|
|
96
|
+
.filter(p => p[0] !== 'empty')
|
|
97
|
+
.sort((a, b) => b[1].lead.weighted - a[1].lead.weighted ||
|
|
98
|
+
b[1].lead.raw - a[1].lead.raw ||
|
|
99
|
+
a[0].localeCompare(b[0]));
|
|
100
|
+
for (const [i, entry] of sorted.entries()) {
|
|
101
|
+
const species = entry[0];
|
|
102
|
+
const usage = entry[1].lead;
|
|
103
|
+
if (usage.raw === 0)
|
|
104
|
+
break;
|
|
105
|
+
const rank = (i + 1).toFixed().padEnd(4);
|
|
106
|
+
const poke = util.displaySpecies(gen, species, legacy).padEnd(18);
|
|
107
|
+
const use = ((100 * usage.weighted) / total.weighted).toFixed(5).padStart(8);
|
|
108
|
+
const raw = usage.raw.toFixed().padEnd(6);
|
|
109
|
+
const pct = ((100 * usage.raw) / total.raw).toFixed(3).padStart(6);
|
|
110
|
+
s += ` | ${rank} | ${poke} | ${use}% | ${raw} | ${pct}% | \n`;
|
|
111
|
+
}
|
|
112
|
+
s += ' + ---- + ------------------ + --------- + ------ + ------- + \n';
|
|
113
|
+
return s;
|
|
114
|
+
}
|
|
115
|
+
movesetReports(gen, format, stats, cutoff = 1500, tag = null, min = MIN) {
|
|
116
|
+
const movesetStats = toMovesetStatistics(gen, format, stats, min[0]);
|
|
117
|
+
const basic = this.movesetReport(gen, format, stats, movesetStats, min);
|
|
118
|
+
const detailed = this.detailedMovesetReport(gen, format, stats, cutoff, tag, movesetStats, min[0]);
|
|
119
|
+
return { basic, detailed };
|
|
120
|
+
}
|
|
121
|
+
movesetReport(gen, format, stats, movesetStats, min = MIN) {
|
|
122
|
+
var _a, _b, _c;
|
|
123
|
+
movesetStats = movesetStats || toMovesetStatistics(gen, format, stats, min[0]);
|
|
124
|
+
gen = util.ignoreGen(gen, legacy);
|
|
125
|
+
const WIDTH = 40;
|
|
126
|
+
const heading = (n) => ` | ${n}`.padEnd(WIDTH + 2) + '| \n';
|
|
127
|
+
const other = (t, f = 1) => ` | Other ${Math.abs(f * 100 * (1 - t))
|
|
128
|
+
.toFixed(3)
|
|
129
|
+
.padStart(6)}%`.padEnd(WIDTH + 2) + '| \n';
|
|
130
|
+
const display = (n, w) => ` | ${n} ${(100 * w).toFixed(3).padStart(6)}%`.padEnd(WIDTH + 2) + '| \n';
|
|
131
|
+
const sep = ` +${'-'.repeat(WIDTH)}+ \n`;
|
|
132
|
+
let s = '';
|
|
133
|
+
for (const [species, moveset] of movesetStats.entries()) {
|
|
134
|
+
if (moveset.usage < 0.0001)
|
|
135
|
+
break; // 1/100th of a percent
|
|
136
|
+
const p = stats.pokemon[species];
|
|
137
|
+
s += sep;
|
|
138
|
+
s += ` | ${util.displaySpecies(gen, species, legacy)}`.padEnd(WIDTH + 2) + '| \n';
|
|
139
|
+
s += sep;
|
|
140
|
+
s += ` | Raw count: ${moveset['Raw count']}`.padEnd(WIDTH + 2) + '| \n';
|
|
141
|
+
const avg = p.saved.count ? util.roundStr(p.saved.weight / p.saved.count, 1e12) : '---';
|
|
142
|
+
s += ` | Avg. weight: ${avg}`.padEnd(WIDTH + 2) + '| \n';
|
|
143
|
+
const ceiling = Math.floor(moveset['Viability Ceiling'][1]);
|
|
144
|
+
s += ` | Viability Ceiling: ${ceiling}`.padEnd(WIDTH + 2) + '| \n';
|
|
145
|
+
s += sep;
|
|
146
|
+
let total = 0;
|
|
147
|
+
s += heading('Abilities');
|
|
148
|
+
for (const [i, ability] of Object.keys(moveset['Abilities']).entries()) {
|
|
149
|
+
if (i > 5) {
|
|
150
|
+
s += other(total);
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
const weight = moveset['Abilities'][ability] / p.raw.weight;
|
|
154
|
+
const o = gen.abilities.get(ability);
|
|
155
|
+
s += display((_a = (o === null || o === void 0 ? void 0 : o.name)) !== null && _a !== void 0 ? _a : ability, weight);
|
|
156
|
+
total += weight;
|
|
157
|
+
}
|
|
158
|
+
s += sep;
|
|
159
|
+
total = 0;
|
|
160
|
+
s += heading('Items');
|
|
161
|
+
for (const item of Object.keys(moveset['Items'])) {
|
|
162
|
+
if (total > 0.95) {
|
|
163
|
+
s += other(total);
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
const weight = moveset['Items'][item] / p.raw.weight;
|
|
167
|
+
const o = gen.items.get(item);
|
|
168
|
+
s += display(item === 'nothing' ? 'Nothing' : (_b = (o === null || o === void 0 ? void 0 : o.name)) !== null && _b !== void 0 ? _b : item, weight);
|
|
169
|
+
total += weight;
|
|
170
|
+
}
|
|
171
|
+
s += sep;
|
|
172
|
+
total = 0;
|
|
173
|
+
s += heading('Spreads');
|
|
174
|
+
for (const [i, spread] of Object.keys(moveset['Spreads']).entries()) {
|
|
175
|
+
if (total > 0.95 || i > 5) {
|
|
176
|
+
s += other(total);
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
const weight = moveset['Spreads'][spread] / p.raw.weight;
|
|
180
|
+
s += display(spread, weight);
|
|
181
|
+
total += weight;
|
|
182
|
+
}
|
|
183
|
+
s += sep;
|
|
184
|
+
total = 0;
|
|
185
|
+
s += heading('Moves');
|
|
186
|
+
for (const move of Object.keys(moveset['Moves'])) {
|
|
187
|
+
if (total > 0.95) {
|
|
188
|
+
s += other(total, 4);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
const weight = moveset['Moves'][move] / p.raw.weight;
|
|
192
|
+
const o = gen.moves.get(move);
|
|
193
|
+
s += display(move === '' ? 'Nothing' : (_c = (o === null || o === void 0 ? void 0 : o.name)) !== null && _c !== void 0 ? _c : move, weight);
|
|
194
|
+
total += weight / 4;
|
|
195
|
+
}
|
|
196
|
+
s += sep;
|
|
197
|
+
total = 0;
|
|
198
|
+
s += heading('Teammates');
|
|
199
|
+
for (const [i, teammate] of Object.keys(moveset['Teammates']).entries()) {
|
|
200
|
+
if (total > 0.95 || i > 11)
|
|
201
|
+
break;
|
|
202
|
+
const w = moveset['Teammates'][teammate];
|
|
203
|
+
if (w < 0.005 * p.raw.weight)
|
|
204
|
+
break;
|
|
205
|
+
const weight = w / p.raw.weight;
|
|
206
|
+
const val = 100 * weight;
|
|
207
|
+
const sign = Math.sign(val) ? '+' : '-';
|
|
208
|
+
s += ` | ${teammate} ${sign}${val.toFixed(3).padStart(5)}%`.padEnd(WIDTH + 2) + '| \n';
|
|
209
|
+
total += weight / 5;
|
|
210
|
+
}
|
|
211
|
+
s += sep;
|
|
212
|
+
s += heading('Checks and Counters');
|
|
213
|
+
for (const [i, cc] of Object.keys(moveset['Checks and Counters']).entries()) {
|
|
214
|
+
if (i > 11)
|
|
215
|
+
break;
|
|
216
|
+
const v = moveset['Checks and Counters'][cc];
|
|
217
|
+
if (v.score < min[1])
|
|
218
|
+
break;
|
|
219
|
+
const score = (100 * v.score).toFixed(3).padStart(6);
|
|
220
|
+
const vp = (100 * v.p).toFixed(2).padStart(3);
|
|
221
|
+
const vd = (100 * v.d).toFixed(2).padStart(3);
|
|
222
|
+
let line = ` | ${cc} ${score} (${vp}\u00b1${vd})`.padEnd(WIDTH + 1) + ' |\n';
|
|
223
|
+
const ko = (100 * v.koed) / v.n;
|
|
224
|
+
const koed = ko.toFixed(1).padStart(2);
|
|
225
|
+
const sw = (100 * v.switched) / v.n;
|
|
226
|
+
const switched = sw.toFixed(1).padStart(2);
|
|
227
|
+
// FIXME: Remove the \t and pad properly base on the 2 different lines, not 1.
|
|
228
|
+
line += ` |\t (${koed}% KOed / ${switched}% switched out)`;
|
|
229
|
+
if (ko < 10)
|
|
230
|
+
line += ' ';
|
|
231
|
+
if (sw < 10)
|
|
232
|
+
line += ' ';
|
|
233
|
+
s += line.padEnd(WIDTH + 2) + '| \n';
|
|
234
|
+
}
|
|
235
|
+
s += sep;
|
|
236
|
+
}
|
|
237
|
+
return s;
|
|
238
|
+
}
|
|
239
|
+
// FIXME: Just use names everywhere instead of a hybrid of names and IDs.
|
|
240
|
+
detailedMovesetReport(gen, format, stats, cutoff = 1500, tag = null, movesetStats, min = 20) {
|
|
241
|
+
movesetStats = movesetStats || toMovesetStatistics(gen, format, stats, min);
|
|
242
|
+
const info = {
|
|
243
|
+
metagame: format,
|
|
244
|
+
cutoff,
|
|
245
|
+
'cutoff deviation': 0,
|
|
246
|
+
'team type': tag,
|
|
247
|
+
'number of battles': stats.battles,
|
|
248
|
+
};
|
|
249
|
+
gen = util.ignoreGen(gen, legacy);
|
|
250
|
+
const data = {}; // eslint-disable-line
|
|
251
|
+
for (const [species, moveset] of movesetStats.entries()) {
|
|
252
|
+
if (moveset.usage < 0.0001)
|
|
253
|
+
break; // 1/100th of a percent
|
|
254
|
+
const m = { ...moveset };
|
|
255
|
+
m['Checks and Counters'] = forDetailed(m['Checks and Counters']);
|
|
256
|
+
data[util.displaySpecies(gen, species, legacy)] = m;
|
|
257
|
+
}
|
|
258
|
+
return JSON.stringify({ info, data });
|
|
259
|
+
}
|
|
260
|
+
metagameReport(stats) {
|
|
261
|
+
const metagame = stats.metagame;
|
|
262
|
+
const W = Math.max(1.0, stats.usage.weighted);
|
|
263
|
+
const tags = Object.entries(metagame.tags).sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
264
|
+
let s = '';
|
|
265
|
+
for (const [tag, weight] of tags) {
|
|
266
|
+
s += ` ${tag}`.padEnd(31, '.');
|
|
267
|
+
s += `${((100 * weight) / W).toFixed(5).padStart(8)}%\n`;
|
|
268
|
+
}
|
|
269
|
+
s += '\n';
|
|
270
|
+
if (!metagame.stalliness.length)
|
|
271
|
+
return s;
|
|
272
|
+
const { histogram, binSize, mean, total } = util.stallinessHistogram(metagame.stalliness);
|
|
273
|
+
let max = 0;
|
|
274
|
+
for (const h of histogram) {
|
|
275
|
+
if (h[1] > max)
|
|
276
|
+
max = h[1];
|
|
277
|
+
}
|
|
278
|
+
// Maximum number of blocks to go across
|
|
279
|
+
const MAX_BLOCKS = 30;
|
|
280
|
+
const blockSize = max / MAX_BLOCKS;
|
|
281
|
+
if (blockSize <= 0)
|
|
282
|
+
return s;
|
|
283
|
+
s += ` Stalliness (mean: ${mean.toFixed(3).padStart(6)})\n`;
|
|
284
|
+
for (const h of histogram) {
|
|
285
|
+
let line = ' |';
|
|
286
|
+
if (fmod(h[0], 2 * binSize) < binSize / 2) {
|
|
287
|
+
line = ' ';
|
|
288
|
+
if (h[0] > 0) {
|
|
289
|
+
line += '+';
|
|
290
|
+
}
|
|
291
|
+
else if (h[0] === 0) {
|
|
292
|
+
line += ' ';
|
|
293
|
+
}
|
|
294
|
+
line += `${h[0].toFixed(1).padStart(3)}|`;
|
|
295
|
+
}
|
|
296
|
+
s += line + '#'.repeat(Math.floor((h[1] + blockSize / 2) / blockSize)) + '\n';
|
|
297
|
+
}
|
|
298
|
+
s += ' more negative = more offensive, more positive = more stall\n';
|
|
299
|
+
s += ` one # = ${((100.0 * blockSize) / total).toFixed(2).padStart(5)}%\n`;
|
|
300
|
+
return s;
|
|
301
|
+
}
|
|
302
|
+
// TODO: Add support for Doubles and OM (other metagames)
|
|
303
|
+
async tierUpdateReport(gen, months, read, type = 'singles') {
|
|
304
|
+
gen = util.ignoreGen(gen, legacy);
|
|
305
|
+
const pokemon = new Map();
|
|
306
|
+
for (const [i, month] of months.entries()) {
|
|
307
|
+
const weight = WEIGHTS[months.length - 1][i];
|
|
308
|
+
for (const tier of USAGE_TIERS[type]) {
|
|
309
|
+
const reports = [];
|
|
310
|
+
for (const suffix of SUFFIXES) {
|
|
311
|
+
reports.push(maybeParseUsageReport(read(month, `gen8${usageTierName(tier)}${suffix}`)).then(r => [suffix, r]));
|
|
312
|
+
}
|
|
313
|
+
const n = {};
|
|
314
|
+
const u = {};
|
|
315
|
+
let ntot = 0;
|
|
316
|
+
for (const [suffix, report] of await Promise.all(reports)) {
|
|
317
|
+
if (report) {
|
|
318
|
+
[u[suffix], n[suffix]] = report;
|
|
319
|
+
ntot += n[suffix];
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
for (const suffix in u) {
|
|
323
|
+
for (const [p, usage] of u[suffix].entries()) {
|
|
324
|
+
const v = pokemon.get(p);
|
|
325
|
+
if (!v)
|
|
326
|
+
pokemon.set(p, usageTiers(type, 0));
|
|
327
|
+
if (p !== 'empty') {
|
|
328
|
+
v[tier] += (((weight * n[suffix]) / ntot) * usage) / 24;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
const tiers = usageTiers(type, []);
|
|
335
|
+
for (const [species, usage] of pokemon.entries()) {
|
|
336
|
+
for (const tier of USAGE_TIERS[type]) {
|
|
337
|
+
const ut = usage[tier];
|
|
338
|
+
if (ut > 0)
|
|
339
|
+
tiers[tier].push([species, ut]);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
let s = '';
|
|
343
|
+
for (const tier of USAGE_TIERS[type]) {
|
|
344
|
+
const sorted = tiers[tier].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]));
|
|
345
|
+
s += makeTable(gen, sorted, tier);
|
|
346
|
+
}
|
|
347
|
+
s += '\n';
|
|
348
|
+
const rise = [0.06696700846, 0.04515839608, 0.03406367107][months.length - 1];
|
|
349
|
+
const drop = [0.01717940145, 0.02284003156, 0.03406367107][months.length - 1];
|
|
350
|
+
if (type === 'nationaldex' || type === 'littlecup') {
|
|
351
|
+
const bl = [];
|
|
352
|
+
for (const [species, usage] of pokemon.entries()) {
|
|
353
|
+
if (usage[type === 'nationaldex' ? 'ND' : 'LC'] > drop) {
|
|
354
|
+
bl.push(species);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
s += '[b]National Dex UU Banlist:[/b] ';
|
|
358
|
+
s += bl.sort().map(p => gen.species.get(p).name).join(', ');
|
|
359
|
+
return s;
|
|
360
|
+
}
|
|
361
|
+
const { current, updated, NFE } = updateTiers(gen, pokemon, rise, drop, type === 'doubles');
|
|
362
|
+
const sorted = Array.from(current.entries()).sort((a, b) => a[0].localeCompare(b[0]));
|
|
363
|
+
for (const [id, tier] of sorted) {
|
|
364
|
+
const update = updated.get(id);
|
|
365
|
+
if (type !== 'doubles' && (tier === 'ZU' && NFE.has(id)))
|
|
366
|
+
continue;
|
|
367
|
+
if (tier !== update) {
|
|
368
|
+
const species = gen.species.get(id);
|
|
369
|
+
if (species.forme &&
|
|
370
|
+
(species.forme.startsWith('Mega') || species.forme.startsWith('Primal'))) {
|
|
371
|
+
const base = (0, data_1.toID)(species.baseSpecies);
|
|
372
|
+
// Skip if the base is already in a higher tier
|
|
373
|
+
const t = TIERS[type];
|
|
374
|
+
if (t.indexOf(updated.get(base)) < t.indexOf(update)) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
s += `${species.name} moved from ${tier} to ${update}\n`;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return s;
|
|
382
|
+
}
|
|
383
|
+
};
|
|
384
|
+
const SKIP = new Set([
|
|
385
|
+
'pichuspikyeared', 'unownb', 'unownc', 'unownd', 'unowne', 'unownf', 'unowng', 'unownh',
|
|
386
|
+
'unowni', 'unownj', 'unownk', 'unownl', 'unownm', 'unownn', 'unowno', 'unownp', 'unownq',
|
|
387
|
+
'unownr', 'unowns', 'unownt', 'unownu', 'unownv', 'unownw', 'unownx', 'unowny', 'unownz',
|
|
388
|
+
'unownem', 'unownqm', 'burmysandy', 'burmytrash', 'cherrimsunshine', 'shelloseast',
|
|
389
|
+
'gastrodoneast', 'deerlingsummer', 'deerlingautumn', 'deerlingwinter', 'sawsbucksummer',
|
|
390
|
+
'sawsbuckautumn', 'sawsbuckwinter', 'keldeoresolution', 'genesectdouse', 'genesectburn',
|
|
391
|
+
'genesectshock', 'genesectchill', 'basculinbluestriped', 'darmanitanzen', 'keldeoresolute',
|
|
392
|
+
'pikachucosplay',
|
|
393
|
+
]);
|
|
394
|
+
const BL = {
|
|
395
|
+
UU: new Set([
|
|
396
|
+
'hawlucha', 'dracozolt', 'diggersby', 'durant', 'weavile', 'ninetalesalola', 'gyarados',
|
|
397
|
+
'primarina', 'venusaur', 'haxorus', 'aegislash', 'conkeldurr', 'gengar', 'scolipede',
|
|
398
|
+
'lycanrocdusk',
|
|
399
|
+
]),
|
|
400
|
+
RU: new Set([
|
|
401
|
+
'barbaracle', 'pangoro', 'shiftry', 'slurpuff', 'chansey', 'indeedee', 'raichualola', 'linoone',
|
|
402
|
+
'sharpedo', 'zoroark', 'lucario', 'reuniclus', 'sirfetchd', 'heracross', 'sigilyph',
|
|
403
|
+
]),
|
|
404
|
+
NU: new Set([
|
|
405
|
+
'slurpuff', 'scrafty', 'haunter', 'linoone', 'chansey', 'indeedeef', 'porygon2', 'tauros',
|
|
406
|
+
'exeggutoralola', 'sneasel', 'snorlax', 'zygarde10', 'tyrantrum', 'kingdra',
|
|
407
|
+
]),
|
|
408
|
+
PU: new Set([
|
|
409
|
+
'arctozolt', 'arctovish', 'silvally', 'noctowl', 'silvallyground', 'silvallyfire',
|
|
410
|
+
'silvallyflying', 'silvallyfighting', 'scyther', 'magneton', 'porygon2', 'basculin',
|
|
411
|
+
'hitmontop', 'silvallypsychic', 'silvallyelectric', 'silvallygrass', 'rotomfrost', 'orbeetle',
|
|
412
|
+
'butterfree', 'golurk', 'flapple', 'thievul', 'sawk', 'galvantula', 'silvallydark', 'exeggutor',
|
|
413
|
+
'mesprit', 'guzzlord', 'magmortar', 'zygarde10', 'kingler', 'absol',
|
|
414
|
+
]),
|
|
415
|
+
ZU: new Set(['silvallyelectric', 'thwackey', 'ludicolo', 'musharna', 'grapploct', 'swoobat']),
|
|
416
|
+
};
|
|
417
|
+
function usageTiers(type = 'singles', t) {
|
|
418
|
+
switch (type) {
|
|
419
|
+
case 'singles': return { OU: t, UU: t, RU: t, NU: t, PU: t };
|
|
420
|
+
case 'doubles': return { DOU: t, DUU: t };
|
|
421
|
+
case 'nationaldex': return { ND: t };
|
|
422
|
+
default: return { LC: t };
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
function usageTierName(tier) {
|
|
426
|
+
switch (tier) {
|
|
427
|
+
case 'DOU': return 'doublesou';
|
|
428
|
+
case 'DUU': return 'doublesuu';
|
|
429
|
+
case 'ND': return 'nationaldex';
|
|
430
|
+
default: return (0, data_1.toID)(tier);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
function updateTiers(gen, pokemon, rise, drop, doubles) {
|
|
434
|
+
var _a;
|
|
435
|
+
const current = new Map();
|
|
436
|
+
const updated = new Map();
|
|
437
|
+
const NFE = new Set();
|
|
438
|
+
for (const species of gen.species) {
|
|
439
|
+
if (SKIP.has(species.id) ||
|
|
440
|
+
species.isNonstandard ||
|
|
441
|
+
!species.tier ||
|
|
442
|
+
species.tier === 'Illegal' ||
|
|
443
|
+
species.tier === 'Unreleased') {
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
let tier;
|
|
447
|
+
if (doubles) {
|
|
448
|
+
let old = (species.tier || species.doublesTier);
|
|
449
|
+
if (old[0] === '(')
|
|
450
|
+
old = old.slice(1, -1);
|
|
451
|
+
if (['NFE', 'LC'].includes(old))
|
|
452
|
+
NFE.add(species.id);
|
|
453
|
+
tier = TIERS.doubles.includes(old) ? old : 'DUU';
|
|
454
|
+
}
|
|
455
|
+
else {
|
|
456
|
+
let old = species.tier;
|
|
457
|
+
if (old[0] === '(' && old[1] !== 'P')
|
|
458
|
+
old = old.slice(1, -1);
|
|
459
|
+
if (old[0] === '(' && old[1] === 'P')
|
|
460
|
+
old = 'ZU';
|
|
461
|
+
if (['NFE', 'LC', 'LC Uber'].includes(old))
|
|
462
|
+
NFE.add(species.id);
|
|
463
|
+
tier = TIERS.singles.includes(old) ? old : 'ZU';
|
|
464
|
+
}
|
|
465
|
+
current.set(species.id, tier);
|
|
466
|
+
const uber = doubles ? 'DUber' : 'Uber';
|
|
467
|
+
if (tier === uber) {
|
|
468
|
+
updated.set(species.id, uber);
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
const update = pokemon.get(species.id);
|
|
472
|
+
if (!update) {
|
|
473
|
+
updated.set(species.id, tier);
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
if (updated.has(species.id))
|
|
477
|
+
continue;
|
|
478
|
+
const riseAndDrop = (r, d, b) => computeRiseAndDrop(species.id, update, updated, tier, rise, drop, {
|
|
479
|
+
rise: r,
|
|
480
|
+
drop: d,
|
|
481
|
+
ban: b,
|
|
482
|
+
});
|
|
483
|
+
if (doubles) {
|
|
484
|
+
if (riseAndDrop('DOU', 'DUU'))
|
|
485
|
+
continue;
|
|
486
|
+
if (riseAndDrop('DUU', 'DNU'))
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
else {
|
|
490
|
+
if (riseAndDrop('OU', 'UU', 'UUBL'))
|
|
491
|
+
continue;
|
|
492
|
+
if (riseAndDrop('UU', 'RU', 'RUBL'))
|
|
493
|
+
continue;
|
|
494
|
+
if (riseAndDrop('RU', 'NU', 'NUBL'))
|
|
495
|
+
continue;
|
|
496
|
+
if (riseAndDrop('NU', 'PU', 'PUBL'))
|
|
497
|
+
continue;
|
|
498
|
+
if (riseAndDrop('PU', 'ZU', 'ZUBL'))
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
if (!updated.has(species.id))
|
|
502
|
+
updated.set(species.id, doubles ? 'DNU' : 'ZU');
|
|
503
|
+
const newTier = updated.get(species.id);
|
|
504
|
+
if (newTier && ((_a = BL[newTier]) === null || _a === void 0 ? void 0 : _a.has(species.id))) {
|
|
505
|
+
updated.set(species.id, `${newTier}BL`);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return { current, updated, NFE };
|
|
509
|
+
}
|
|
510
|
+
function computeRiseAndDrop(species, update, updated, tier, rise, drop, tiers) {
|
|
511
|
+
if (update[tiers.rise] > rise) {
|
|
512
|
+
updated.set(species, tiers.rise);
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
if (tier === tiers.rise) {
|
|
516
|
+
if (update[tiers.rise] < drop) {
|
|
517
|
+
updated.set(species, tiers.drop);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
updated.set(species, tiers.rise);
|
|
521
|
+
}
|
|
522
|
+
return true;
|
|
523
|
+
}
|
|
524
|
+
if (tier === tiers.ban) {
|
|
525
|
+
updated.set(species, tiers.ban);
|
|
526
|
+
return true;
|
|
527
|
+
}
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
function fmod(a, b, f = 1e3) {
|
|
531
|
+
a = Math.round(a * f) / f;
|
|
532
|
+
b = Math.round(b * f) / f;
|
|
533
|
+
return (Math.abs(a * f) % (b * f)) / f;
|
|
534
|
+
}
|
|
535
|
+
function toMovesetStatistics(gen, format, stats, min = 20) {
|
|
536
|
+
const sorted = Object.entries(stats.pokemon);
|
|
537
|
+
const real = ['challengecup1v1', '1v1'].includes(format);
|
|
538
|
+
const total = Math.max(1.0, real ? stats.usage.real : stats.usage.weighted);
|
|
539
|
+
// FIXME: Sort without this stupid rounding to avoid incorrect ordering
|
|
540
|
+
const usage = (n) => round((n / total) * 6, 1e7);
|
|
541
|
+
if (['randombattle', 'challengecup', 'challengcup1v1', 'seasonal'].includes(format)) {
|
|
542
|
+
sorted.sort((a, b) => a[0].localeCompare(b[0]));
|
|
543
|
+
}
|
|
544
|
+
else if (real) {
|
|
545
|
+
sorted.sort((a, b) => usage(b[1].usage.real) - usage(a[1].usage.real) || a[0].localeCompare(b[0]));
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
sorted.sort((a, b) => usage(b[1].usage.weighted) - usage(a[1].usage.weighted) || a[0].localeCompare(b[0]));
|
|
549
|
+
}
|
|
550
|
+
gen = util.ignoreGen(gen, legacy);
|
|
551
|
+
const movesets = new Map();
|
|
552
|
+
for (const entry of sorted) {
|
|
553
|
+
const species = entry[0];
|
|
554
|
+
const pokemon = entry[1];
|
|
555
|
+
const gxes = [];
|
|
556
|
+
for (const player in pokemon.unique) {
|
|
557
|
+
const u = pokemon.unique[player];
|
|
558
|
+
if ('g' in u)
|
|
559
|
+
gxes.push(u.g);
|
|
560
|
+
}
|
|
561
|
+
const viability = util.computeViability(gxes);
|
|
562
|
+
movesets.set(species, {
|
|
563
|
+
'Raw count': pokemon.raw.count,
|
|
564
|
+
usage: usage(real ? pokemon.usage.real : pokemon.usage.weighted),
|
|
565
|
+
'Viability Ceiling': viability,
|
|
566
|
+
Abilities: util.toDisplayObject(pokemon.abilities, ability => {
|
|
567
|
+
var _a;
|
|
568
|
+
const o = gen.abilities.get(ability);
|
|
569
|
+
return (_a = (o === null || o === void 0 ? void 0 : o.name)) !== null && _a !== void 0 ? _a : ability;
|
|
570
|
+
}),
|
|
571
|
+
Items: util.toDisplayObject(pokemon.items, item => {
|
|
572
|
+
var _a;
|
|
573
|
+
if (item === 'nothing')
|
|
574
|
+
return 'Nothing';
|
|
575
|
+
const o = gen.items.get(item);
|
|
576
|
+
return (_a = (o === null || o === void 0 ? void 0 : o.name)) !== null && _a !== void 0 ? _a : item;
|
|
577
|
+
}),
|
|
578
|
+
Spreads: util.toDisplayObject(pokemon.spreads),
|
|
579
|
+
Happiness: util.toDisplayObject(pokemon.happinesses),
|
|
580
|
+
Moves: util.toDisplayObject(pokemon.moves, move => {
|
|
581
|
+
var _a;
|
|
582
|
+
if (move === '')
|
|
583
|
+
return 'Nothing';
|
|
584
|
+
const o = gen.moves.get(move);
|
|
585
|
+
return (_a = (o === null || o === void 0 ? void 0 : o.name)) !== null && _a !== void 0 ? _a : move;
|
|
586
|
+
}),
|
|
587
|
+
Teammates: getTeammates(gen, format, pokemon.teammates, pokemon.raw.weight, total, stats),
|
|
588
|
+
'Checks and Counters': util.getChecksAndCounters(pokemon.encounters, [s => util.displaySpecies(gen, s, legacy), es => es], min),
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
return movesets;
|
|
592
|
+
}
|
|
593
|
+
function getTeammates(gen, format, teammates, weight, total, stats) {
|
|
594
|
+
const real = ['challengecup1v1', '1v1'].includes(format);
|
|
595
|
+
const m = {};
|
|
596
|
+
for (const [id, w] of Object.entries(teammates)) {
|
|
597
|
+
const species = util.displaySpecies(gen, id, legacy);
|
|
598
|
+
const s = stats.pokemon[id];
|
|
599
|
+
if (!s) {
|
|
600
|
+
m[species] = 0;
|
|
601
|
+
continue;
|
|
602
|
+
}
|
|
603
|
+
const usage = ((real ? s.usage.real : s.usage.weighted) / total) * 6;
|
|
604
|
+
m[species] = w - round(weight) * round(usage, 1e7);
|
|
605
|
+
}
|
|
606
|
+
return util.toDisplayObject(m);
|
|
607
|
+
}
|
|
608
|
+
function forDetailed(cc) {
|
|
609
|
+
const obj = {};
|
|
610
|
+
for (const [k, v] of Object.entries(cc)) {
|
|
611
|
+
obj[k] = [round(v.n), round(v.p), round(v.d)];
|
|
612
|
+
}
|
|
613
|
+
return obj;
|
|
614
|
+
}
|
|
615
|
+
function makeTable(gen, pokemon, tier) {
|
|
616
|
+
let s = `[HIDE=${tier}][CODE]\n`;
|
|
617
|
+
s += `Combined usage for ${tier}\n`;
|
|
618
|
+
s += ' + ---- + ------------------ + ------- + \n';
|
|
619
|
+
s += ' | Rank | Pokemon | Percent | \n';
|
|
620
|
+
s += ' + ---- + ------------------ + ------- + \n';
|
|
621
|
+
for (const [i, pair] of pokemon.entries()) {
|
|
622
|
+
const [id, usage] = pair;
|
|
623
|
+
if (usage < 0.001)
|
|
624
|
+
break;
|
|
625
|
+
const rank = (i + 1).toFixed().padEnd(4);
|
|
626
|
+
const poke = util.displaySpecies(gen, id, legacy).padEnd(18);
|
|
627
|
+
const percent = (100 * usage).toFixed(3).padStart(6);
|
|
628
|
+
s += ` | ${rank} | ${poke} | ${percent}% |\n`;
|
|
629
|
+
}
|
|
630
|
+
s += ' + ---- + ------------------ + ------- + \n';
|
|
631
|
+
s += '[/CODE][/HIDE]\n';
|
|
632
|
+
return s;
|
|
633
|
+
}
|
|
634
|
+
async function maybeParseUsageReport(report) {
|
|
635
|
+
const r = await report;
|
|
636
|
+
return r ? parseUsageReport(r) : undefined;
|
|
637
|
+
}
|
|
638
|
+
function parseUsageReport(report) {
|
|
639
|
+
const usage = new Map();
|
|
640
|
+
const lines = report.split('\n');
|
|
641
|
+
const battles = Number(lines[0].slice(16));
|
|
642
|
+
for (let i = 5; i < lines.length; i++) {
|
|
643
|
+
const line = lines[i].split('|');
|
|
644
|
+
if (line.length < 3)
|
|
645
|
+
break;
|
|
646
|
+
const name = line[2].slice(1).trim();
|
|
647
|
+
const pct = Number(line[3].slice(1, line[3].indexOf('%'))) / 100;
|
|
648
|
+
usage.set((0, data_1.toID)(name), pct);
|
|
649
|
+
}
|
|
650
|
+
return [usage, battles];
|
|
651
|
+
}
|
|
652
|
+
//# sourceMappingURL=reports.js.map
|