P2-9: leaderboard stat labels (SB/ER/TB) + FLAG the grade-degradation root cause

DISPLAY FIX (shipped): the league leaderboard rendered raw snake_case
("stolen_bases U0.5", "earned_runs U2.5"). New canonical short-label lib
web/src/lib/statAbbrev.js (one source, CommonJS + unit-tested) maps stat_type
to SB/ER/TB/HR/K/PTS/… and ExploreHub routes through it. Unknown ids upper-case
their words so raw snake_case can never leak again.

FLAG (reported, NOT silently changed — per the audit's instruction): the "B at
45% confidence" is a BACKEND grading issue, diagnosed against live snapshot:
- 25/25 grades mismatch their own confidence vs grade_thresholds.json (B shown
  at conf 55 = the B- band; a systematic one-sub-tier gap on every prop). The
  surfaced `confidence` is not the probability that derived the letter (likely
  the data-sufficiency penalty applied to display-only).
- 9/25 have projection=0 — the MLB feature path feeds 0 instead of refusing
  (S58 insufficient_data), which also produces the P1-7 broken edge_pct.
Full write-up + do-not list: specs/audit-data/mlb-grade-degradation.md. NOT
re-lettering or shifting thresholds on the frontend — that would hide the bug.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kev
2026-07-17 01:42:03 -04:00
parent 00537eb84c
commit 77e8937a56
4 changed files with 110 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
/**
* statAbbrev — the ONE canonical SHORT stat label ("total_bases" -> "TB").
*
* The compact, mono, grid-aligned surfaces (leaderboard, breadth, top signals)
* want abbreviations, not the long "Total Bases" form gradeAdapter.statLabel
* emits for the roomy grade card. Raw snake_case ("stolen_bases U0.5") is a
* display bug — every ranked/gridded surface routes stat_type through here.
*
* CommonJS so it's importable by .tsx (allowJs) AND unit-testable by Jest.
*/
'use strict';
const STAT_ABBREV = {
// MLB — batting
total_bases: 'TB', home_runs: 'HR', hits: 'H', rbi: 'RBI', runs: 'R',
stolen_bases: 'SB', doubles: '2B', triples: '3B', walks: 'BB', singles: '1B',
// MLB — pitching
strikeouts: 'K', hits_allowed: 'HA', earned_runs: 'ER', innings_pitched: 'IP',
outs: 'OUTS', walks_allowed: 'BB',
// NBA / WNBA
points: 'PTS', rebounds: 'REB', assists: 'AST', threes: '3PT', steals: 'STL',
blocks: 'BLK', pra: 'PRA', turnovers: 'TO', pr: 'PR', pa: 'PA', ra: 'RA',
// NHL / soccer (best-effort)
shots_on_goal: 'SOG', saves: 'SV', goals: 'G', shots: 'SH',
};
/** Short display label for a stat_type id; unknown ids upper-case the words. */
function statAbbrev(stat) {
if (!stat) return '';
if (STAT_ABBREV[stat]) return STAT_ABBREV[stat];
return String(stat).replace(/_/g, ' ').toUpperCase();
}
module.exports = { STAT_ABBREV, statAbbrev };