@pkmn/stats 0.0.2 → 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 +90 -0
- 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 +45 -39
- 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 +16 -6
- 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 +55 -37
- 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 +2 -2
- package/build/reports.js +27 -20
- 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 +42 -32
- 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 +39 -39
package/src/display.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import {Generation, ID, toID} from '@pkmn/data';
|
|
2
2
|
import {
|
|
3
|
-
Usage,
|
|
4
|
-
Statistics,
|
|
5
|
-
UsageStatistics,
|
|
6
|
-
UniqueStatistics,
|
|
7
|
-
newUsage,
|
|
8
|
-
combineUnique,
|
|
3
|
+
Usage, Statistics, UsageStatistics, UniqueStatistics, newUsage, combineUnique,
|
|
9
4
|
} from './stats';
|
|
10
5
|
|
|
11
6
|
import * as util from './util';
|
|
@@ -73,6 +68,7 @@ export interface DetailedMovesetStatistics {
|
|
|
73
68
|
Spreads: { [spread: string]: number };
|
|
74
69
|
Happiness?: { [happiness: string]: number };
|
|
75
70
|
Moves: { [move: string]: number };
|
|
71
|
+
// FIXME: this changed 2021-04 from deltas to raw usage
|
|
76
72
|
Teammates: { [pokemon: string]: number };
|
|
77
73
|
// n = sum(POKE1_KOED...DOUBLE_SWITCH)
|
|
78
74
|
// p = POKE1_KOED + POKE1_SWITCHED_OUT / n
|
|
@@ -115,8 +111,8 @@ export const Display = new class {
|
|
|
115
111
|
pokemon[N(species)] = {
|
|
116
112
|
lead: calcUsage(p.lead, stats.lead), // BUG: remove for non singles?
|
|
117
113
|
usage,
|
|
118
|
-
unique: calcUsage(u.usage, unique.total),
|
|
119
|
-
win: calcUsage(p.win,
|
|
114
|
+
unique: calcUsage(u.usage, unique.total, 6),
|
|
115
|
+
win: calcUsage(p.win, p.usage),
|
|
120
116
|
|
|
121
117
|
count: p.raw.count,
|
|
122
118
|
weight: p.saved.count ? R(p.saved.weight / p.saved.count) : null,
|
|
@@ -137,7 +133,8 @@ export const Display = new class {
|
|
|
137
133
|
const o = gen.moves.get(move);
|
|
138
134
|
return (o?.name) ?? move;
|
|
139
135
|
}),
|
|
140
|
-
teammates: getTeammates(gen, format, p.teammates, p.raw.weight, total, stats),
|
|
136
|
+
// teammates: getTeammates(gen, format, p.teammates, p.raw.weight, total, stats),
|
|
137
|
+
teammates: getTeammates(gen, p.teammates, p.raw.weight, stats),
|
|
141
138
|
counters: util.getChecksAndCounters(p.encounters, [N, formatEncounterStatistics], min),
|
|
142
139
|
};
|
|
143
140
|
}
|
|
@@ -312,13 +309,13 @@ function toDisplayObject(
|
|
|
312
309
|
|
|
313
310
|
function getTeammates(
|
|
314
311
|
gen: Generation,
|
|
315
|
-
format: ID,
|
|
312
|
+
// format: ID,
|
|
316
313
|
teammates: { [id: string /* ID */]: number },
|
|
317
314
|
weight: number,
|
|
318
|
-
total: number,
|
|
315
|
+
// total: number,
|
|
319
316
|
stats: Statistics
|
|
320
317
|
): { [key: string]: number } {
|
|
321
|
-
const real = ['challengecup1v1', '1v1'].includes(format);
|
|
318
|
+
// const real = ['challengecup1v1', '1v1'].includes(format);
|
|
322
319
|
const m: { [species: string]: number } = {};
|
|
323
320
|
for (const [id, w] of Object.entries(teammates)) {
|
|
324
321
|
const species = gen.species.get(id)?.name;
|
|
@@ -328,8 +325,9 @@ function getTeammates(
|
|
|
328
325
|
m[species] = 0;
|
|
329
326
|
continue;
|
|
330
327
|
}
|
|
331
|
-
const usage = ((real ? s.usage.real : s.usage.weighted) / total) * 6;
|
|
332
|
-
m[species] = w - weight * usage;
|
|
328
|
+
// const usage = ((real ? s.usage.real : s.usage.weighted) / total) * 6;
|
|
329
|
+
// m[species] = w - weight * usage;
|
|
330
|
+
m[species] = w;
|
|
333
331
|
}
|
|
334
332
|
return toDisplayObject(m, weight);
|
|
335
333
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,26 +1,15 @@
|
|
|
1
|
+
export {Binary} from './binary';
|
|
1
2
|
export {Classifier} from './classifier';
|
|
2
3
|
export {Battle, Parser, Player, Pokemon, Rating, Team} from './parser';
|
|
3
4
|
export {Reports} from './reports';
|
|
4
5
|
export {
|
|
5
|
-
Display,
|
|
6
|
-
|
|
7
|
-
DisplayStatistics,
|
|
8
|
-
DisplayUsageStatistics,
|
|
9
|
-
LegacyDisplayUsageStatistics,
|
|
6
|
+
Display, DisplayMetagameStatistics, DisplayStatistics,
|
|
7
|
+
DisplayUsageStatistics, LegacyDisplayUsageStatistics,
|
|
10
8
|
} from './display';
|
|
11
9
|
export {
|
|
12
|
-
canonicalizeFormat,
|
|
13
|
-
genForFormat,
|
|
14
|
-
isNonSinglesFormat,
|
|
15
|
-
newGenerations,
|
|
16
|
-
Outcome,
|
|
10
|
+
canonicalizeFormat, genForFormat, isNonSinglesFormat, newGenerations, Outcome,
|
|
17
11
|
} from './util';
|
|
18
12
|
export {
|
|
19
|
-
MetagameStatistics,
|
|
20
|
-
|
|
21
|
-
Stats,
|
|
22
|
-
TaggedStatistics,
|
|
23
|
-
Usage,
|
|
24
|
-
UsageStatistics,
|
|
25
|
-
WeightedStatistics,
|
|
13
|
+
MetagameStatistics, Statistics, Stats, TaggedStatistics,
|
|
14
|
+
Usage, UsageStatistics, WeightedStatistics,
|
|
26
15
|
} from './stats';
|
package/src/parser.ts
CHANGED
|
@@ -66,7 +66,7 @@ const ROAR = new Set(['Roar', 'Whirlwind', 'Circle Throw', 'Dragon Tail']);
|
|
|
66
66
|
const UTURN = new Set(['U-Turn', 'U-turn', 'Volt Switch', 'Baton Pass']);
|
|
67
67
|
|
|
68
68
|
export const Parser = new class {
|
|
69
|
-
parse(gen: Generation, format: ID, raw: Log) {
|
|
69
|
+
parse(gen: Generation, format: ID, raw: Log, legacy = false) {
|
|
70
70
|
// https://github.com/Zarel/Pokemon-Showdown/commit/92a4f85e0abe9d3a9febb0e6417a7710cabdc303
|
|
71
71
|
if ((raw as unknown) === '"log"') throw new Error('Log = "log"');
|
|
72
72
|
|
|
@@ -90,12 +90,13 @@ export const Parser = new class {
|
|
|
90
90
|
endType: raw.endType,
|
|
91
91
|
} as unknown) as Battle;
|
|
92
92
|
for (const side of ['p1', 'p2'] as Array<'p1' | 'p2'>) {
|
|
93
|
-
const team =
|
|
93
|
+
const team =
|
|
94
|
+
this.canonicalizeTeam(gen, format, raw[side === 'p1' ? 'p1team' : 'p2team'], legacy);
|
|
94
95
|
|
|
95
|
-
// TODO: Stop tracking empty slots?
|
|
96
96
|
const mons = [];
|
|
97
97
|
for (let i = 0; i < 6; i++) {
|
|
98
98
|
const pokemon = team[i];
|
|
99
|
+
if (!legacy && !pokemon) continue;
|
|
99
100
|
idents[side].push(pokemon ? pokemon.name || pokemon.species : 'empty');
|
|
100
101
|
mons.push({
|
|
101
102
|
species: pokemon ? pokemon.species : ('empty' as ID),
|
|
@@ -110,7 +111,7 @@ export const Parser = new class {
|
|
|
110
111
|
rating: raw[side === 'p1' ? 'p1rating' : 'p2rating'] || undefined,
|
|
111
112
|
team: {
|
|
112
113
|
pokemon: mons,
|
|
113
|
-
classification: Classifier.classifyTeam(gen, team),
|
|
114
|
+
classification: Classifier.classifyTeam(gen, team, legacy),
|
|
114
115
|
},
|
|
115
116
|
};
|
|
116
117
|
if (winner !== 'tie') player.outcome = winner === side ? 'win' : 'loss';
|
|
@@ -208,7 +209,7 @@ export const Parser = new class {
|
|
|
208
209
|
const side = line[2].startsWith('p1') ? 'p1' : 'p2';
|
|
209
210
|
if (line[1] === 'replace') {
|
|
210
211
|
// NOTE: Ideally we'd be able to go back and fix the previously affected matchups
|
|
211
|
-
active[side] = identify(gen, name, side, battle, idents);
|
|
212
|
+
active[side] = identify(gen, name, side, battle, idents, legacy);
|
|
212
213
|
break;
|
|
213
214
|
}
|
|
214
215
|
|
|
@@ -221,8 +222,12 @@ export const Parser = new class {
|
|
|
221
222
|
if (!flags.ko.p1 && !flags.ko.p2) {
|
|
222
223
|
matchup[2] = Outcome.DOUBLE_SWITCH;
|
|
223
224
|
} else if (flags.ko.p1 && flags.ko.p2) {
|
|
224
|
-
|
|
225
|
-
|
|
225
|
+
if (legacy) {
|
|
226
|
+
battle[p].team.pokemon[active[p]!].kos++;
|
|
227
|
+
} else {
|
|
228
|
+
battle.p1.team.pokemon[active.p1].kos++;
|
|
229
|
+
battle.p2.team.pokemon[active.p2].kos++;
|
|
230
|
+
}
|
|
226
231
|
matchup[2] = Outcome.DOUBLE_DOWN;
|
|
227
232
|
} else {
|
|
228
233
|
// NOTE: includes hit-by-red-card-and-dies and roar-then-die-by-residual-damage
|
|
@@ -260,7 +265,7 @@ export const Parser = new class {
|
|
|
260
265
|
flags.hazard = true;
|
|
261
266
|
}
|
|
262
267
|
|
|
263
|
-
active[side] = identify(gen, name, side, battle, idents);
|
|
268
|
+
active[side] = identify(gen, name, side, battle, idents, legacy);
|
|
264
269
|
break;
|
|
265
270
|
}
|
|
266
271
|
}
|
|
@@ -269,9 +274,15 @@ export const Parser = new class {
|
|
|
269
274
|
return battle;
|
|
270
275
|
}
|
|
271
276
|
|
|
272
|
-
|
|
277
|
+
// TODO: use Team.canonicalize from @pkmn/sets
|
|
278
|
+
canonicalizeTeam(
|
|
279
|
+
gen: Generation,
|
|
280
|
+
format: ID,
|
|
281
|
+
team: Array<PokemonSet & {forcedLevel?: number}>,
|
|
282
|
+
legacy = false,
|
|
283
|
+
) {
|
|
273
284
|
const mray = util.isMegaRayquazaAllowed(format);
|
|
274
|
-
gen = util.ignoreGen(gen);
|
|
285
|
+
gen = util.ignoreGen(gen, legacy);
|
|
275
286
|
for (const pokemon of team) {
|
|
276
287
|
const item = pokemon.item && gen.items.get(pokemon.item);
|
|
277
288
|
pokemon.item = item ? item.id : 'nothing';
|
|
@@ -292,8 +303,8 @@ export const Parser = new class {
|
|
|
292
303
|
for (let i = 0; i < 4; i++) {
|
|
293
304
|
let move = toID(pokemon.moves[i]);
|
|
294
305
|
if (move === 'hiddenpower') {
|
|
295
|
-
|
|
296
|
-
|
|
306
|
+
const type = !legacy && pokemon.hpType
|
|
307
|
+
? pokemon.hpType : gen.types.getHiddenPower(ivs)!.type;
|
|
297
308
|
move = `${move}${toID(type)}` as ID;
|
|
298
309
|
}
|
|
299
310
|
pokemon.moves[i] = move;
|
|
@@ -302,14 +313,19 @@ export const Parser = new class {
|
|
|
302
313
|
pokemon.level = pokemon.forcedLevel || pokemon.level || 100;
|
|
303
314
|
const ability = pokemon.ability && gen.abilities.get(pokemon.ability);
|
|
304
315
|
pokemon.ability = ability ? ability.id : 'unknown';
|
|
305
|
-
pokemon.species =
|
|
316
|
+
pokemon.species =
|
|
317
|
+
util.getSpecies(gen, util.fromAlias(pokemon.species || pokemon.name), legacy).id;
|
|
306
318
|
if (mray && pokemon.species === 'rayquaza' && pokemon.moves.includes('dragonascent')) {
|
|
307
319
|
pokemon.species = 'rayquazamega';
|
|
308
320
|
pokemon.ability = 'deltastream';
|
|
309
321
|
} else if (pokemon.species === 'greninja' && pokemon.ability === 'battlebond') {
|
|
310
322
|
pokemon.species = 'greninjaash';
|
|
323
|
+
} else if (pokemon.species === 'zacian' && pokemon.ability === 'rustedsword') {
|
|
324
|
+
pokemon.species = 'zaciancrowned';
|
|
325
|
+
} else if (pokemon.species === 'zamazenta' && pokemon.ability === 'rustedshield') {
|
|
326
|
+
pokemon.species = 'zamazentacrowned';
|
|
311
327
|
} else {
|
|
312
|
-
const mega = util.getMegaEvolution(gen, pokemon);
|
|
328
|
+
const mega = util.getMegaEvolution(gen, pokemon, legacy);
|
|
313
329
|
if (mega) {
|
|
314
330
|
pokemon.species = mega.species;
|
|
315
331
|
pokemon.ability = mega.ability;
|
|
@@ -321,11 +337,10 @@ export const Parser = new class {
|
|
|
321
337
|
}
|
|
322
338
|
};
|
|
323
339
|
|
|
324
|
-
// FIXME: meloettapiroutte? darmanitanzen?
|
|
325
340
|
// prettier-ignore
|
|
326
341
|
const FORMES = new Set([
|
|
327
|
-
'greninjaash', 'zygardecomplete', 'mimikyubusted',
|
|
328
|
-
'
|
|
342
|
+
'greninjaash', 'zygardecomplete', 'mimikyubusted', 'mimikyubustedtotem',
|
|
343
|
+
'shayminsky', 'necrozmaultra', 'zaciancrowned', 'zamazentacrowned',
|
|
329
344
|
]);
|
|
330
345
|
|
|
331
346
|
function identify(
|
|
@@ -333,7 +348,8 @@ function identify(
|
|
|
333
348
|
name: string,
|
|
334
349
|
side: 'p1' | 'p2',
|
|
335
350
|
battle: Battle,
|
|
336
|
-
idents: { p1: string[]; p2: string[] }
|
|
351
|
+
idents: { p1: string[]; p2: string[] },
|
|
352
|
+
legacy: boolean,
|
|
337
353
|
) {
|
|
338
354
|
const team = battle[side].team.pokemon;
|
|
339
355
|
const names = idents[side];
|
|
@@ -361,13 +377,14 @@ function identify(
|
|
|
361
377
|
}
|
|
362
378
|
} else {
|
|
363
379
|
// Maybe its a pokemon name (or possibly an alias)?
|
|
364
|
-
let species = util.getSpecies(gen, util.fromAlias(name));
|
|
380
|
+
let species = util.getSpecies(gen, util.fromAlias(name), legacy);
|
|
365
381
|
let index = team.findIndex(p => p.species === species.id);
|
|
366
382
|
if (index !== -1) return index as Slot;
|
|
367
383
|
|
|
368
384
|
// Try undoing a forme change to see if that solves things?
|
|
369
|
-
if (util.isMega(species) || FORMES.has(species.id)
|
|
370
|
-
|
|
385
|
+
if (util.isMega(species, legacy) || FORMES.has(species.id) ||
|
|
386
|
+
!legacy && ['meloettapiroutte', 'darmanitanzen'].includes(species.id)) {
|
|
387
|
+
species = util.getBaseSpecies(gen, species.id, legacy);
|
|
371
388
|
}
|
|
372
389
|
index = team.findIndex(p => p.species.startsWith(species.id));
|
|
373
390
|
if (index !== -1) return index as Slot;
|
|
@@ -377,7 +394,7 @@ function identify(
|
|
|
377
394
|
p1: {team: battle.p1.team.pokemon.map(p => p.species), idents: idents.p1},
|
|
378
395
|
p2: {team: battle.p2.team.pokemon.map(p => p.species), idents: idents.p2},
|
|
379
396
|
};
|
|
380
|
-
// BUG: This occurs due to
|
|
397
|
+
// BUG: This occurs due to interactions between Illusion and Transform/Imposter (which is
|
|
381
398
|
// exclusively an issue in Hackmons formats). We don't have enough information in a single
|
|
382
399
|
// log line to be able to disambiguate this :(.
|
|
383
400
|
throw new Error(`Unable to locate ${side}'s '${name}' in ${JSON.stringify(state)}`);
|
package/src/reports.ts
CHANGED
|
@@ -56,6 +56,8 @@ const SUFFIXES = ['', 'suspecttest', 'alpha', 'beta'];
|
|
|
56
56
|
|
|
57
57
|
const MIN = [20, 0.5];
|
|
58
58
|
|
|
59
|
+
const legacy = true;
|
|
60
|
+
|
|
59
61
|
export const Reports = new class {
|
|
60
62
|
usageReport(gen: Generation, format: ID, stats: Statistics) {
|
|
61
63
|
const sorted = Object.entries(stats.pokemon).filter(p => p[0] !== 'empty');
|
|
@@ -86,7 +88,7 @@ export const Reports = new class {
|
|
|
86
88
|
if (usage.raw === 0) break;
|
|
87
89
|
|
|
88
90
|
const rank = (i + 1).toFixed().padEnd(4);
|
|
89
|
-
const poke = util.displaySpecies(gen, species).padEnd(18);
|
|
91
|
+
const poke = util.displaySpecies(gen, species, legacy).padEnd(18);
|
|
90
92
|
const use = (((100 * usage.weighted) / total.weighted) * 6).toFixed(5).padStart(8);
|
|
91
93
|
const raw = usage.raw.toFixed().padEnd(6);
|
|
92
94
|
const rawp = (((100 * usage.raw) / total.raw) * 6).toFixed(3).padStart(6);
|
|
@@ -122,7 +124,7 @@ export const Reports = new class {
|
|
|
122
124
|
if (usage.raw === 0) break;
|
|
123
125
|
|
|
124
126
|
const rank = (i + 1).toFixed().padEnd(4);
|
|
125
|
-
const poke = util.displaySpecies(gen, species).padEnd(18);
|
|
127
|
+
const poke = util.displaySpecies(gen, species, legacy).padEnd(18);
|
|
126
128
|
const use = ((100 * usage.weighted) / total.weighted).toFixed(5).padStart(8);
|
|
127
129
|
const raw = usage.raw.toFixed().padEnd(6);
|
|
128
130
|
const pct = ((100 * usage.raw) / total.raw).toFixed(3).padStart(6);
|
|
@@ -157,7 +159,7 @@ export const Reports = new class {
|
|
|
157
159
|
) {
|
|
158
160
|
movesetStats = movesetStats || toMovesetStatistics(gen, format, stats, min[0]);
|
|
159
161
|
|
|
160
|
-
gen = util.ignoreGen(gen);
|
|
162
|
+
gen = util.ignoreGen(gen, legacy);
|
|
161
163
|
const WIDTH = 40;
|
|
162
164
|
|
|
163
165
|
const heading = (n: string) => ` | ${n}`.padEnd(WIDTH + 2) + '| \n';
|
|
@@ -176,7 +178,7 @@ export const Reports = new class {
|
|
|
176
178
|
const p = stats.pokemon[species]!;
|
|
177
179
|
|
|
178
180
|
s += sep;
|
|
179
|
-
s += ` | ${util.displaySpecies(gen, species)}`.padEnd(WIDTH + 2) + '| \n';
|
|
181
|
+
s += ` | ${util.displaySpecies(gen, species, legacy)}`.padEnd(WIDTH + 2) + '| \n';
|
|
180
182
|
s += sep;
|
|
181
183
|
s += ` | Raw count: ${moveset['Raw count']}`.padEnd(WIDTH + 2) + '| \n';
|
|
182
184
|
const avg = p.saved.count ? util.roundStr(p.saved.weight / p.saved.count, 1e12) : '---';
|
|
@@ -239,13 +241,12 @@ export const Reports = new class {
|
|
|
239
241
|
total = 0;
|
|
240
242
|
s += heading('Teammates');
|
|
241
243
|
for (const [i, teammate] of Object.keys(moveset['Teammates']).entries()) {
|
|
242
|
-
if (total > 0.95 || i >
|
|
244
|
+
if (total > 0.95 || i > 10) break;
|
|
243
245
|
const w = moveset['Teammates'][teammate];
|
|
244
246
|
if (w < 0.005 * p.raw.weight) break;
|
|
245
247
|
const weight = w / p.raw.weight;
|
|
246
248
|
const val = 100 * weight;
|
|
247
|
-
|
|
248
|
-
s += ` | ${teammate} ${sign}${val.toFixed(3).padStart(5)}%`.padEnd(WIDTH + 2) + '| \n';
|
|
249
|
+
s += ` | ${teammate} ${val.toFixed(3).padStart(5)}%`.padEnd(WIDTH + 2) + '| \n';
|
|
249
250
|
total += weight / 5;
|
|
250
251
|
}
|
|
251
252
|
s += sep;
|
|
@@ -296,13 +297,13 @@ export const Reports = new class {
|
|
|
296
297
|
'number of battles': stats.battles,
|
|
297
298
|
};
|
|
298
299
|
|
|
299
|
-
gen = util.ignoreGen(gen);
|
|
300
|
+
gen = util.ignoreGen(gen, legacy);
|
|
300
301
|
const data: { [key: string]: object } = {}; // eslint-disable-line
|
|
301
302
|
for (const [species, moveset] of movesetStats.entries()) {
|
|
302
303
|
if (moveset.usage < 0.0001) break; // 1/100th of a percent
|
|
303
304
|
const m: any = {...moveset};
|
|
304
305
|
m['Checks and Counters'] = forDetailed(m['Checks and Counters']);
|
|
305
|
-
data[util.displaySpecies(gen, species)] = m;
|
|
306
|
+
data[util.displaySpecies(gen, species, legacy)] = m;
|
|
306
307
|
}
|
|
307
308
|
|
|
308
309
|
return JSON.stringify({info, data});
|
|
@@ -362,7 +363,7 @@ export const Reports = new class {
|
|
|
362
363
|
read: (month: string, format: string) => Promise<string | undefined>,
|
|
363
364
|
type: 'singles' | 'doubles' | 'nationaldex' | 'littlecup' = 'singles',
|
|
364
365
|
) {
|
|
365
|
-
gen = util.ignoreGen(gen);
|
|
366
|
+
gen = util.ignoreGen(gen, legacy);
|
|
366
367
|
|
|
367
368
|
const pokemon: Map<ID,
|
|
368
369
|
UsageTiers<number> |
|
|
@@ -651,7 +652,7 @@ function toMovesetStatistics(gen: Generation, format: ID, stats: Statistics, min
|
|
|
651
652
|
(a, b) => usage(b[1].usage.weighted) - usage(a[1].usage.weighted) || a[0].localeCompare(b[0])
|
|
652
653
|
);
|
|
653
654
|
}
|
|
654
|
-
gen = util.ignoreGen(gen);
|
|
655
|
+
gen = util.ignoreGen(gen, legacy);
|
|
655
656
|
|
|
656
657
|
const movesets: Map<ID, MovesetStatistics> = new Map();
|
|
657
658
|
for (const entry of sorted) {
|
|
@@ -683,10 +684,11 @@ function toMovesetStatistics(gen: Generation, format: ID, stats: Statistics, min
|
|
|
683
684
|
const o = gen.moves.get(move);
|
|
684
685
|
return (o?.name) ?? move;
|
|
685
686
|
}),
|
|
686
|
-
Teammates: getTeammates(gen, format, pokemon.teammates, pokemon.raw.weight, total, stats),
|
|
687
|
+
// Teammates: getTeammates(gen, format, pokemon.teammates, pokemon.raw.weight, total, stats),
|
|
688
|
+
Teammates: getTeammates(gen, pokemon.teammates, stats),
|
|
687
689
|
'Checks and Counters': util.getChecksAndCounters(
|
|
688
690
|
pokemon.encounters,
|
|
689
|
-
[s => util.displaySpecies(gen, s), es => es],
|
|
691
|
+
[s => util.displaySpecies(gen, s, legacy), es => es],
|
|
690
692
|
min
|
|
691
693
|
),
|
|
692
694
|
});
|
|
@@ -695,25 +697,24 @@ function toMovesetStatistics(gen: Generation, format: ID, stats: Statistics, min
|
|
|
695
697
|
return movesets;
|
|
696
698
|
}
|
|
697
699
|
|
|
700
|
+
// NOTE: https://www.smogon.com/forums/threads/gen-8-smogon-university-usage-statistics-discussion-thread.3657197/post-8841061
|
|
698
701
|
function getTeammates(
|
|
699
702
|
gen: Generation,
|
|
700
|
-
format: ID,
|
|
701
703
|
teammates: { [id: string /* ID */]: number },
|
|
702
|
-
weight: number,
|
|
703
|
-
total: number,
|
|
704
704
|
stats: Statistics
|
|
705
705
|
): { [key: string]: number } {
|
|
706
|
-
const real = ['challengecup1v1', '1v1'].includes(format);
|
|
706
|
+
// const real = ['challengecup1v1', '1v1'].includes(format);
|
|
707
707
|
const m: { [species: string]: number } = {};
|
|
708
708
|
for (const [id, w] of Object.entries(teammates)) {
|
|
709
|
-
const species = util.displaySpecies(gen, id);
|
|
709
|
+
const species = util.displaySpecies(gen, id, legacy);
|
|
710
710
|
const s = stats.pokemon[id];
|
|
711
711
|
if (!s) {
|
|
712
712
|
m[species] = 0;
|
|
713
713
|
continue;
|
|
714
714
|
}
|
|
715
|
-
const usage = ((real ? s.usage.real : s.usage.weighted) / total) * 6;
|
|
716
|
-
m[species] = w - round(weight) * round(usage, 1e7);
|
|
715
|
+
// const usage = ((real ? s.usage.real : s.usage.weighted) / total) * 6;
|
|
716
|
+
// m[species] = w - round(weight) * round(usage, 1e7);
|
|
717
|
+
m[species] = w;
|
|
717
718
|
}
|
|
718
719
|
return util.toDisplayObject(m);
|
|
719
720
|
}
|
|
@@ -740,7 +741,7 @@ function makeTable(
|
|
|
740
741
|
const [id, usage] = pair;
|
|
741
742
|
if (usage < 0.001) break;
|
|
742
743
|
const rank = (i + 1).toFixed().padEnd(4);
|
|
743
|
-
const poke = util.displaySpecies(gen, id).padEnd(18);
|
|
744
|
+
const poke = util.displaySpecies(gen, id, legacy).padEnd(18);
|
|
744
745
|
const percent = (100 * usage).toFixed(3).padStart(6);
|
|
745
746
|
s += ` | ${rank} | ${poke} | ${percent}% |\n`;
|
|
746
747
|
}
|
package/src/stats.ts
CHANGED
|
@@ -61,6 +61,8 @@ export interface MetagameStatistics {
|
|
|
61
61
|
|
|
62
62
|
const EMPTY: Set<ID> = new Set();
|
|
63
63
|
|
|
64
|
+
const NEUTRAL = new Set(['serious', 'docile', 'quirky', 'bashful']);
|
|
65
|
+
|
|
64
66
|
export const Stats = new class {
|
|
65
67
|
create() {
|
|
66
68
|
return {
|
|
@@ -79,18 +81,19 @@ export const Stats = new class {
|
|
|
79
81
|
battle: Battle,
|
|
80
82
|
cutoff: number,
|
|
81
83
|
stats?: Statistics,
|
|
82
|
-
|
|
84
|
+
legacy = false,
|
|
85
|
+
tag?: ID,
|
|
83
86
|
) {
|
|
84
87
|
const tagged: TaggedStatistics = {total: {}, tags: {}};
|
|
85
88
|
if (tag) {
|
|
86
89
|
tagged.tags[tag] = {};
|
|
87
90
|
tagged.tags[tag][cutoff] = stats || this.create();
|
|
88
|
-
this.updateTagged(gen, format, battle, [cutoff], tagged, new Set([tag]), true);
|
|
91
|
+
this.updateTagged(gen, format, battle, [cutoff], tagged, legacy, new Set([tag]), true);
|
|
89
92
|
return tagged.tags[tag][cutoff];
|
|
90
93
|
} else {
|
|
91
94
|
tagged.total = {};
|
|
92
95
|
tagged.total[cutoff] = stats || this.create();
|
|
93
|
-
this.updateTagged(gen, format, battle, [cutoff], tagged);
|
|
96
|
+
this.updateTagged(gen, format, battle, [cutoff], tagged, legacy);
|
|
94
97
|
return tagged.total[cutoff];
|
|
95
98
|
}
|
|
96
99
|
}
|
|
@@ -101,16 +104,17 @@ export const Stats = new class {
|
|
|
101
104
|
battle: Battle,
|
|
102
105
|
cutoffs: number[],
|
|
103
106
|
stats?: WeightedStatistics,
|
|
107
|
+
legacy = false,
|
|
104
108
|
tag?: ID
|
|
105
109
|
) {
|
|
106
110
|
const tagged: TaggedStatistics = {total: {}, tags: {}};
|
|
107
111
|
if (tag) {
|
|
108
112
|
tagged.tags[tag] = stats || {};
|
|
109
|
-
this.updateTagged(gen, format, battle, cutoffs, tagged, new Set([tag]), true);
|
|
113
|
+
this.updateTagged(gen, format, battle, cutoffs, tagged, legacy, new Set([tag]), true);
|
|
110
114
|
return tagged.tags[tag];
|
|
111
115
|
} else {
|
|
112
116
|
tagged.total = stats || {};
|
|
113
|
-
this.updateTagged(gen, format, battle, cutoffs, tagged);
|
|
117
|
+
this.updateTagged(gen, format, battle, cutoffs, tagged, legacy);
|
|
114
118
|
return tagged.total;
|
|
115
119
|
}
|
|
116
120
|
}
|
|
@@ -121,6 +125,7 @@ export const Stats = new class {
|
|
|
121
125
|
battle: Battle,
|
|
122
126
|
cutoffs: number[],
|
|
123
127
|
stats?: TaggedStatistics,
|
|
128
|
+
legacy = false,
|
|
124
129
|
tags = EMPTY,
|
|
125
130
|
tagsOnly = false
|
|
126
131
|
) {
|
|
@@ -132,7 +137,7 @@ export const Stats = new class {
|
|
|
132
137
|
|
|
133
138
|
const playerWeights: number[][] = [];
|
|
134
139
|
for (const player of [battle.p1, battle.p2]) {
|
|
135
|
-
const [ws, save] = getWeights(player, cutoffs);
|
|
140
|
+
const [ws, save] = getWeights(player, cutoffs, legacy);
|
|
136
141
|
const gxe = player.rating
|
|
137
142
|
? Math.round(100 * util.victoryChance(player.rating.rpr, player.rating.rprd, 1500, 130))
|
|
138
143
|
: undefined;
|
|
@@ -146,7 +151,7 @@ export const Stats = new class {
|
|
|
146
151
|
s = this.create();
|
|
147
152
|
stats.total[cutoff] = s;
|
|
148
153
|
}
|
|
149
|
-
updateStats(gen, player, wsm, gxe, save, short, s);
|
|
154
|
+
updateStats(gen, player, wsm, gxe, save, short, s, legacy);
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
for (const tag of tags) {
|
|
@@ -161,7 +166,7 @@ export const Stats = new class {
|
|
|
161
166
|
t[cutoff] = s;
|
|
162
167
|
}
|
|
163
168
|
if (player.team.classification.tags.has(tag)) {
|
|
164
|
-
updateStats(gen, player, wsm, gxe, save, short, s);
|
|
169
|
+
updateStats(gen, player, wsm, gxe, save, short, s, legacy);
|
|
165
170
|
}
|
|
166
171
|
}
|
|
167
172
|
}
|
|
@@ -237,11 +242,10 @@ export const Stats = new class {
|
|
|
237
242
|
}
|
|
238
243
|
};
|
|
239
244
|
|
|
240
|
-
function getWeights(player: Player, cutoffs: number[]
|
|
245
|
+
function getWeights(player: Player, cutoffs: number[], legacy: boolean) {
|
|
241
246
|
let save = false;
|
|
242
247
|
let rpr = 1500;
|
|
243
248
|
let rprd = 130;
|
|
244
|
-
// FIXME: StatCounter and batchMovesetCounter treat rprd === 0 differently :(
|
|
245
249
|
const valid = player.rating && player.rating.rprd !== 0;
|
|
246
250
|
if (valid) {
|
|
247
251
|
rpr = player.rating!.rpr;
|
|
@@ -255,14 +259,14 @@ function getWeights(player: Player, cutoffs: number[]): [Array<{ s: number; m: n
|
|
|
255
259
|
const weights = [];
|
|
256
260
|
for (const cutoff of cutoffs) {
|
|
257
261
|
const w = util.weighting(rpr, rprd, cutoff);
|
|
258
|
-
if (!valid) {
|
|
262
|
+
if (legacy && !valid) {
|
|
259
263
|
weights.push({s: w, m: util.weighting(1500, 130, cutoff)});
|
|
260
264
|
} else {
|
|
261
265
|
weights.push({s: w, m: w});
|
|
262
266
|
}
|
|
263
267
|
}
|
|
264
268
|
|
|
265
|
-
return [weights, save];
|
|
269
|
+
return [weights, save] as [Array<{ s: number; m: number }>, boolean];
|
|
266
270
|
}
|
|
267
271
|
|
|
268
272
|
function updateStats(
|
|
@@ -272,9 +276,10 @@ function updateStats(
|
|
|
272
276
|
gxe: number | undefined,
|
|
273
277
|
save: boolean,
|
|
274
278
|
short: boolean,
|
|
275
|
-
stats: Statistics
|
|
279
|
+
stats: Statistics,
|
|
280
|
+
legacy: boolean,
|
|
276
281
|
) {
|
|
277
|
-
gen = util.ignoreGen(gen);
|
|
282
|
+
gen = util.ignoreGen(gen, legacy);
|
|
278
283
|
const win = player.outcome === 'win';
|
|
279
284
|
for (const [index, pokemon] of player.team.pokemon.entries()) {
|
|
280
285
|
if (!short) {
|
|
@@ -291,8 +296,7 @@ function updateStats(
|
|
|
291
296
|
stats.metagame.stalliness.push([player.team.classification.stalliness, weights.s]);
|
|
292
297
|
}
|
|
293
298
|
if (pokemon.species === 'empty') {
|
|
294
|
-
|
|
295
|
-
if (!short) {
|
|
299
|
+
if (legacy && !short) {
|
|
296
300
|
updateTeammates(player.team.pokemon, index, pokemon.species, {}, stats, weights.s);
|
|
297
301
|
}
|
|
298
302
|
continue;
|
|
@@ -330,11 +334,10 @@ function updateStats(
|
|
|
330
334
|
const i = p.items[set.item];
|
|
331
335
|
p.items[set.item] = (i || 0) + weights.m;
|
|
332
336
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
const
|
|
336
|
-
const
|
|
337
|
-
const spread = getSpread(gen, nature, baseStats, pokemon.set);
|
|
337
|
+
const nature =
|
|
338
|
+
gen.natures.get(!legacy && NEUTRAL.has(set.nature) ? 'hardy' as ID : set.nature)!;
|
|
339
|
+
const baseStats = util.getSpecies(gen, pokemon.species, legacy).baseStats;
|
|
340
|
+
const spread = getSpread(gen, nature, baseStats, pokemon.set, legacy);
|
|
338
341
|
const s = p.spreads[spread];
|
|
339
342
|
p.spreads[spread] = (s || 0) + weights.m;
|
|
340
343
|
const computed = computeStats(gen, nature, baseStats, pokemon.set);
|
|
@@ -386,14 +389,14 @@ function getSpread<T>(
|
|
|
386
389
|
gen: Generation,
|
|
387
390
|
nature: Nature,
|
|
388
391
|
base: StatsTable,
|
|
389
|
-
pokemon: PokemonSet<T
|
|
392
|
+
pokemon: PokemonSet<T>,
|
|
393
|
+
legacy: boolean,
|
|
390
394
|
) {
|
|
391
395
|
const evs: number[] = [];
|
|
392
396
|
|
|
393
397
|
let stat: StatID;
|
|
394
398
|
for (stat in pokemon.evs) {
|
|
395
|
-
|
|
396
|
-
if (stat === 'def') {
|
|
399
|
+
if (!legacy || stat === 'def') {
|
|
397
400
|
const val = gen.stats.calc(
|
|
398
401
|
stat, base[stat], pokemon.ivs[stat], pokemon.evs[stat], pokemon.level, nature
|
|
399
402
|
);
|