@pkmn/stats 0.3.0 → 0.4.0

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/build/index.js CHANGED
@@ -2896,14 +2896,14 @@ var Reports = new class {
2896
2896
  } else {
2897
2897
  sorted.sort((a, b) => b[1].usage.weighted - a[1].usage.weighted || a[0].localeCompare(b[0]));
2898
2898
  }
2899
- let s = ` Total battles: ${stats.battles}
2899
+ let s = `Total battles: ${stats.battles}
2900
2900
  `;
2901
2901
  const avg = stats.battles ? roundStr(stats.usage.weighted / stats.battles / 12, 1e3) : "0.0";
2902
- s += ` Avg. weight/team: ${avg}
2902
+ s += `Avg. weight/team: ${avg}
2903
2903
  `;
2904
- s += " + ---- + ------------------ + --------- + ------ + ------- + ------ + ------- + \n";
2905
- s += " | Rank | Pokemon | Usage % | Raw | % | Real | % | \n";
2906
- s += " + ---- + ------------------ + --------- + ------ + ------- + ------ + ------- + \n";
2904
+ s += "+ ---- + ------------------ + --------- + ------ + ------- + ------ + ------- + \n";
2905
+ s += "| Rank | Pokemon | Usage % | Raw | % | Real | % | \n";
2906
+ s += "+ ---- + ------------------ + --------- + ------ + ------- + ------ + ------- + \n";
2907
2907
  const total = {
2908
2908
  raw: Math.max(1, stats.usage.raw),
2909
2909
  real: Math.max(1, stats.usage.real),
@@ -2920,18 +2920,18 @@ var Reports = new class {
2920
2920
  const rawp = (100 * usage.raw / total.raw * 6).toFixed(3).padStart(6);
2921
2921
  const real = usage.real.toFixed().padEnd(6);
2922
2922
  const realp = (100 * usage.real / total.real * 6).toFixed(3).padStart(6);
2923
- s += ` | ${rank2} | ${poke} | ${use}% | ${raw} | ${rawp}% | ${real} | ${realp}% |
2923
+ s += `| ${rank2} | ${poke} | ${use}% | ${raw} | ${rawp}% | ${real} | ${realp}% |
2924
2924
  `;
2925
2925
  }
2926
- s += " + ---- + ------------------ + --------- + ------ + ------- + ------ + ------- + \n";
2926
+ s += "+ ---- + ------------------ + --------- + ------ + ------- + ------ + ------- + \n";
2927
2927
  return s;
2928
2928
  }
2929
2929
  leadsReport(gen, stats, legacy = true) {
2930
- let s = ` Total leads: ${stats.battles * 2}
2930
+ let s = `Total leads: ${stats.battles * 2}
2931
2931
  `;
2932
- s += " + ---- + ------------------ + --------- + ------ + ------- + \n";
2933
- s += " | Rank | Pokemon | Usage % | Raw | % | \n";
2934
- s += " + ---- + ------------------ + --------- + ------ + ------- + \n";
2932
+ s += "+ ---- + ------------------ + --------- + ------ + ------- + \n";
2933
+ s += "| Rank | Pokemon | Usage % | Raw | % | \n";
2934
+ s += "+ ---- + ------------------ + --------- + ------ + ------- + \n";
2935
2935
  const total = { raw: 0, weighted: 0 };
2936
2936
  total.raw = Math.max(1, stats.lead.raw);
2937
2937
  total.weighted = Math.max(1, stats.lead.weighted);
@@ -2947,10 +2947,10 @@ var Reports = new class {
2947
2947
  const use = (100 * usage.weighted / total.weighted).toFixed(5).padStart(8);
2948
2948
  const raw = usage.raw.toFixed().padEnd(6);
2949
2949
  const pct = (100 * usage.raw / total.raw).toFixed(3).padStart(6);
2950
- s += ` | ${rank2} | ${poke} | ${use}% | ${raw} | ${pct}% |
2950
+ s += `| ${rank2} | ${poke} | ${use}% | ${raw} | ${pct}% |
2951
2951
  `;
2952
2952
  }
2953
- s += " + ---- + ------------------ + --------- + ------ + ------- + \n";
2953
+ s += "+ ---- + ------------------ + --------- + ------ + ------- + \n";
2954
2954
  return s;
2955
2955
  }
2956
2956
  movesetReports(gen, format, stats, cutoff = 1500, tag2 = null, min = MIN, legacy = true) {
@@ -2964,23 +2964,24 @@ var Reports = new class {
2964
2964
  movesetStats = movesetStats || toMovesetStatistics(gen, format, stats, min[0]);
2965
2965
  gen = ignoreGen(gen, legacy);
2966
2966
  const WIDTH = 40;
2967
- const heading = (n) => ` | ${n}`.padEnd(WIDTH + 2) + "| \n";
2968
- const other = (t, f = 1) => ` | Other ${Math.abs(f * 100 * (1 - t)).toFixed(3).padStart(6)}%`.padEnd(WIDTH + 2) + "| \n";
2969
- const display = (n, w) => ` | ${n} ${(100 * w).toFixed(3).padStart(6)}%`.padEnd(WIDTH + 2) + "| \n";
2970
- const sep = ` +${"-".repeat(WIDTH)}+
2967
+ const padLine = (s2) => s2.padEnd(WIDTH + 1) + "|";
2968
+ const heading = (n) => padLine(`| ${n}`) + "\n";
2969
+ const display = (n, w) => padLine(`| ${n} ${(100 * w).toFixed(3)}%`) + "\n";
2970
+ const other = (t, f = 1) => padLine(`| Other ${Math.abs(f * 100 * (1 - t)).toFixed(3)}%`) + "\n";
2971
+ const sep = `+${"-".repeat(WIDTH)}+
2971
2972
  `;
2972
2973
  let s = "";
2973
2974
  for (const [species, moveset] of movesetStats.entries()) {
2974
2975
  if (moveset.usage < 1e-4) break;
2975
2976
  const p = stats.pokemon[species];
2976
2977
  s += sep;
2977
- s += ` | ${displaySpecies(gen, species, legacy)}`.padEnd(WIDTH + 2) + "| \n";
2978
+ s += padLine(`| ${displaySpecies(gen, species, legacy)}`) + "\n";
2978
2979
  s += sep;
2979
- s += ` | Raw count: ${moveset["Raw count"]}`.padEnd(WIDTH + 2) + "| \n";
2980
+ s += padLine(`| Raw count: ${moveset["Raw count"]}`) + "\n";
2980
2981
  const avg = p.saved.count ? roundStr(p.saved.weight / p.saved.count, 1e12) : "---";
2981
- s += ` | Avg. weight: ${avg}`.padEnd(WIDTH + 2) + "| \n";
2982
+ s += padLine(`| Avg. weight: ${avg}`) + "\n";
2982
2983
  const ceiling = Math.floor(moveset["Viability Ceiling"][1]);
2983
- s += ` | Viability Ceiling: ${ceiling}`.padEnd(WIDTH + 2) + "| \n";
2984
+ s += padLine(`| Viability Ceiling: ${ceiling}`) + "\n";
2984
2985
  s += sep;
2985
2986
  let total = 0;
2986
2987
  s += heading("Abilities");
@@ -3009,18 +3010,6 @@ var Reports = new class {
3009
3010
  }
3010
3011
  s += sep;
3011
3012
  total = 0;
3012
- s += heading("Tera Types");
3013
- for (const teraType of Object.keys(moveset["Tera Types"])) {
3014
- if (total > 0.95) {
3015
- s += other(total);
3016
- break;
3017
- }
3018
- const weight = moveset["Tera Types"][teraType] / p.raw.weight;
3019
- s += display(teraType[0].toUpperCase() + teraType.slice(1), weight);
3020
- total += weight;
3021
- }
3022
- s += sep;
3023
- total = 0;
3024
3013
  s += heading("Spreads");
3025
3014
  for (const [i, spread] of Object.keys(moveset["Spreads"]).entries()) {
3026
3015
  if (total > 0.95 || i > 5) {
@@ -3046,6 +3035,21 @@ var Reports = new class {
3046
3035
  }
3047
3036
  s += sep;
3048
3037
  total = 0;
3038
+ const entries = Object.entries(moveset["Tera Types"]);
3039
+ if (!(entries.length === 1 && (0, import_data5.toID)(entries[0][0]) === "nothing")) {
3040
+ s += heading("Tera Types");
3041
+ for (const teraType of Object.keys(moveset["Tera Types"])) {
3042
+ if (total > 0.95) {
3043
+ s += other(total);
3044
+ break;
3045
+ }
3046
+ const weight = moveset["Tera Types"][teraType] / p.raw.weight;
3047
+ s += display(teraType[0].toUpperCase() + teraType.slice(1), weight);
3048
+ total += weight;
3049
+ }
3050
+ s += sep;
3051
+ total = 0;
3052
+ }
3049
3053
  s += heading("Teammates");
3050
3054
  for (const [i, teammate] of Object.keys(moveset["Teammates"]).entries()) {
3051
3055
  if (total > 0.95 || i > 10) break;
@@ -3053,29 +3057,31 @@ var Reports = new class {
3053
3057
  if (w < 5e-3 * p.raw.weight) break;
3054
3058
  const weight = w / p.raw.weight;
3055
3059
  const val = 100 * weight;
3056
- s += ` | ${teammate} ${val.toFixed(3).padStart(5)}%`.padEnd(WIDTH + 2) + "| \n";
3060
+ s += padLine(`| ${teammate} ${val.toFixed(3)}%`) + "\n";
3057
3061
  total += weight / 5;
3058
3062
  }
3059
3063
  s += sep;
3060
- s += heading("Checks and Counters");
3061
- for (const [i, cc] of Object.keys(moveset["Checks and Counters"]).entries()) {
3062
- if (i > 11) break;
3063
- const v = moveset["Checks and Counters"][cc];
3064
- if (v.score < min[1]) break;
3065
- const score = (100 * v.score).toFixed(3).padStart(6);
3066
- const vp = (100 * v.p).toFixed(2).padStart(3);
3067
- const vd = (100 * v.d).toFixed(2).padStart(3);
3068
- let line = ` | ${cc} ${score} (${vp}\xB1${vd})`.padEnd(WIDTH + 1) + " |\n";
3069
- const ko = 100 * v.koed / v.n;
3070
- const koed = ko.toFixed(1).padStart(2);
3071
- const sw = 100 * v.switched / v.n;
3072
- const switched = sw.toFixed(1).padStart(2);
3073
- line += ` | (${koed}% KOed / ${switched}% switched out)`;
3074
- if (ko < 10) line += " ";
3075
- if (sw < 10) line += " ";
3076
- s += line.padEnd(WIDTH + 2) + "| \n";
3064
+ if (Object.values(moveset["Checks and Counters"]).some((entry) => entry.p - 4 * entry.d >= 0.5)) {
3065
+ s += heading("Checks and Counters");
3066
+ for (const [i, cc] of Object.keys(moveset["Checks and Counters"]).entries()) {
3067
+ if (i > 11) break;
3068
+ const v = moveset["Checks and Counters"][cc];
3069
+ if (v.score < min[1]) break;
3070
+ const score = (100 * v.score).toFixed(3);
3071
+ const vp = (100 * v.p).toFixed(2);
3072
+ const vd = (100 * v.d).toFixed(2);
3073
+ let line = `| ${cc} ${score} (${vp}\xB1${vd})`.padEnd(WIDTH + 1) + "|\n";
3074
+ const ko = 100 * v.koed / v.n;
3075
+ const koed = ko.toFixed(1);
3076
+ const sw = 100 * v.switched / v.n;
3077
+ const switched = sw.toFixed(1);
3078
+ line += `| (${koed}% KOed / ${switched}% switched out)`;
3079
+ if (ko < 10) line += " ";
3080
+ if (sw < 10) line += " ";
3081
+ s += line + "\n";
3082
+ }
3083
+ s += sep;
3077
3084
  }
3078
- s += sep;
3079
3085
  }
3080
3086
  return s;
3081
3087
  }
@@ -3107,8 +3113,8 @@ var Reports = new class {
3107
3113
  );
3108
3114
  let s = "";
3109
3115
  for (const [tag2, weight] of tags) {
3110
- s += ` ${tag2}`.padEnd(31, ".");
3111
- s += `${(100 * weight / W).toFixed(5).padStart(8)}%
3116
+ const dots = ".".repeat(Math.max(0, 18 - tag2.length));
3117
+ s += `${tag2}${dots}${(100 * weight / W * 6).toFixed(5)}%
3112
3118
  `;
3113
3119
  }
3114
3120
  s += "\n";
@@ -3121,23 +3127,23 @@ var Reports = new class {
3121
3127
  const MAX_BLOCKS = 30;
3122
3128
  const blockSize = max / MAX_BLOCKS;
3123
3129
  if (blockSize <= 0) return s;
3124
- s += ` Stalliness (mean: ${mean.toFixed(3).padStart(6)})
3130
+ s += `Stalliness (mean: ${mean.toFixed(3)})
3125
3131
  `;
3126
3132
  for (const h of histogram) {
3127
- let line = " |";
3133
+ let line = " |";
3128
3134
  if (fmod(h[0], 2 * binSize) < binSize / 2) {
3129
- line = " ";
3135
+ line = "";
3130
3136
  if (h[0] > 0) {
3131
3137
  line += "+";
3132
3138
  } else if (h[0] === 0) {
3133
3139
  line += " ";
3134
3140
  }
3135
- line += `${h[0].toFixed(1).padStart(3)}|`;
3141
+ line += `${h[0].toFixed(1)}|`;
3136
3142
  }
3137
- s += line + "#".repeat(Math.floor((h[1] + blockSize / 2) / blockSize)) + "\n";
3143
+ s += line + "#".repeat(Math.round(h[1] / blockSize)) + "\n";
3138
3144
  }
3139
- s += " more negative = more offensive, more positive = more stall\n";
3140
- s += ` one # = ${(100 * blockSize / total).toFixed(2).padStart(5)}%
3145
+ s += "more negative = more offensive, more positive = more stall\n";
3146
+ s += `one # = ${(100 * blockSize / total).toFixed(2)}%
3141
3147
  `;
3142
3148
  return s;
3143
3149
  }
@@ -3454,7 +3460,7 @@ function getTeammates(gen, teammates, stats, legacy = true) {
3454
3460
  function forDetailed(cc) {
3455
3461
  const obj = {};
3456
3462
  for (const [k, v] of Object.entries(cc)) {
3457
- obj[k] = [round3(v.n), round3(v.p), round3(v.d)];
3463
+ obj[k] = { n: round3(v.n), p: round3(v.p), d: round3(v.d) };
3458
3464
  }
3459
3465
  return obj;
3460
3466
  }
@@ -3982,6 +3988,7 @@ var FIX = {
3982
3988
  };
3983
3989
  var SPECIES = /\| (.*) [-+.0-9]+ \([-+.0-9]+±[-+.0-9]+\)/;
3984
3990
  var OUTCOME = /\|\W+\(([-+.0-9]+)% KOed \/ ([-+.0-9]+)% switched out\)/;
3991
+ var WEIGHT = /\d[\d.]*/;
3985
3992
  var Display2 = new class {
3986
3993
  fromStatistics(gen, format, stats, min = 20) {
3987
3994
  const N = (n) => {
@@ -4264,26 +4271,39 @@ function parseLeadsReport(report) {
4264
4271
  return { total, usage };
4265
4272
  }
4266
4273
  function partialParseMovesetReport(report) {
4274
+ var _a, _b, _c;
4267
4275
  const movesets = {};
4268
- let section = 0;
4269
- let i = 0;
4270
4276
  let species = "";
4271
4277
  let s = "";
4278
+ let inCC = false;
4279
+ let ccLine = 0;
4280
+ let sectionLines = 0;
4281
+ let prevSectionEmpty = false;
4272
4282
  for (const line of report.split("\n")) {
4273
- i++;
4274
- if (line.startsWith(" +")) {
4275
- section++;
4276
- i = 0;
4283
+ if (line.trimStart().startsWith("+")) {
4284
+ prevSectionEmpty = sectionLines === 0;
4285
+ inCC = false;
4286
+ ccLine = 0;
4287
+ sectionLines = 0;
4277
4288
  continue;
4278
4289
  }
4279
- if (section % 10 === 1) {
4280
- species = line.slice(3, line.indexOf(" "));
4290
+ sectionLines++;
4291
+ if (line.includes("Checks and Counters")) {
4292
+ inCC = true;
4293
+ ccLine = 0;
4294
+ continue;
4295
+ }
4296
+ if (sectionLines === 1 && prevSectionEmpty) {
4297
+ species = (_b = (_a = line.split("|")[1]) == null ? void 0 : _a.trim()) != null ? _b : "";
4298
+ continue;
4281
4299
  }
4282
- if (section % 10 === 2 && i === 2) {
4283
- movesets[species] = { weight: Number(line.slice(17, line.indexOf(" ", 17))), outcomes: {} };
4300
+ if (!movesets[species] && line.includes("Avg. weight")) {
4301
+ movesets[species] = { weight: Number((_c = WEIGHT.exec(line)) == null ? void 0 : _c[0]), outcomes: {} };
4302
+ continue;
4284
4303
  }
4285
- if (section % 10 === 9 && i >= 2) {
4286
- if (i % 2 === 0) {
4304
+ if (inCC) {
4305
+ ccLine++;
4306
+ if (ccLine % 2 === 1) {
4287
4307
  s = SPECIES.exec(line)[1];
4288
4308
  } else {
4289
4309
  const outcome = OUTCOME.exec(line);
@@ -4301,10 +4321,11 @@ function parseMetagameReport(report) {
4301
4321
  const lines = report.split("\n");
4302
4322
  let i = 0;
4303
4323
  for (; i < lines.length; i++) {
4304
- const d = lines[i].indexOf(".");
4324
+ const line = lines[i].trimStart();
4325
+ const d = line.indexOf(".");
4305
4326
  if (d < 0) break;
4306
- const tag2 = lines[i].slice(1, d);
4307
- const weight = Number(lines[i].slice(lines[i].search(/\d/), lines[i].lastIndexOf("%"))) / 100;
4327
+ const tag2 = line.slice(0, d);
4328
+ const weight = Number(line.slice(line.search(/\d/), line.lastIndexOf("%"))) / 100;
4308
4329
  tags[tag2] = weight;
4309
4330
  }
4310
4331
  i++;