Session 47: Name normalization + grade intel + ticker polish (2149 tests)

- Name normalization completed: NICKNAMES table (Matt↔Matthew, Mike↔Michael...)
  resolved in nameKey, parenthetical team-tag strip "(STL)", verified accent-fold
  (Iván/Ivan, José/Jose). Slate strip now DISPLAYS the normalized de-dotted name
  ("AJ Ewing" not "A.J. Ewing") via buildPlayerStripsFromProps.
- Complete MLB VYNDR INTELLIGENCE: mlbGameLogFeatures derives rest_days (days off
  between latest games; 0=B2B) + ab_per_game (usage). buildIntelFields renders
  usage as "X AB/G", rest as B2B/Xd, matchup from bvp_advantage fallback.
- Ticker SCAN dedup: pushTickerItems keeps one SCAN per sport (sport field or
  text-prefix parse for legacy); MOVE/GRADE preserved; cap 50.
- BOMBER threshold prorated for mid-season (hr>=15 strong / >=10 mod) so June
  sluggers classify BOMBER not FLEX/DRIVER.

Backend 2122 -> 2149 tests (+27), 179 suites. Web build clean (exit 0).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kev
2026-06-19 01:45:36 -04:00
parent c8fc9f577e
commit 78db55d499
13 changed files with 346 additions and 32 deletions
+4 -2
View File
@@ -343,8 +343,10 @@ function scoreMLB(s) {
ops = num(s.ops), runs = num(s.runs), kRate = num(s.k_rate), doubles = num(s.doubles);
return {
// BOMBER is the single power archetype — fires for any high-HR bat (incl.
// high-strikeout sluggers like Judge), so power hitters classify as BOMBER.
BOMBER: hr >= 20 ? 0.6 + hr / 60 : hr >= 15 ? 0.3 : 0,
// high-strikeout sluggers like Judge). Session 47: thresholds prorated for
// mid-season HR totals (a 15-HR June pace is full-season slugger territory),
// so power leads over DRIVER for a slugger who also drives in runs.
BOMBER: hr >= 15 ? 0.6 + hr / 60 : hr >= 10 ? 0.35 : 0,
BRUSH: avg >= 0.28 && kRate < 16 ? 0.6 + (avg - 0.25) * 2 : avg >= 0.29 ? 0.4 : 0,
DRIVER: rbi >= 50 && hr >= 12 ? 0.5 + rbi / 200 : 0,
GHOST: sb >= 15 ? 0.6 + sb / 60 : sb >= 10 ? 0.35 : 0,
@@ -319,11 +319,14 @@ function buildIntelFields(features = {}, opts = {}) {
if (Number.isFinite(features.usage_rate)) out.usage = `${round1(features.usage_rate)}%`;
else if (Number.isFinite(features.minutes_per_game)) out.usage = `${Math.round(features.minutes_per_game)} min`;
else if (Number.isFinite(features.ab_per_game)) out.usage = `${round1(features.ab_per_game)} AB/G`; // MLB usage equivalent
else if (ps.usage) out.usage = String(ps.usage);
const matchup = matchupGradeFromRank(features.opp_rank_stat);
const matchup = matchupGradeFromRank(features.opp_rank_stat)
|| (Number.isFinite(features.bvp_advantage) ? (features.bvp_advantage > 0.05 ? 'A' : features.bvp_advantage > 0 ? 'B+' : 'C') : null);
if (matchup) out.matchup_grade = matchup;
if (Number.isFinite(features.rest_days)) out.rest = `${features.rest_days}d rest`;
if (Number.isFinite(features.rest_days)) out.rest = features.rest_days === 0 ? 'B2B' : `${features.rest_days}d rest`;
return out;
}
+17
View File
@@ -118,6 +118,23 @@ function mlbGameLogFeatures(res, statType) {
} else if (out.l10_avg != null) {
out.l20_avg = out.l10_avg; // baseline so form has a reference
}
// Session 47 — complete VYNDR INTELLIGENCE for MLB:
// - rest_days: days between the two most recent games (0 = back-to-back).
// - ab_per_game: at-bats per game, the MLB "usage" equivalent.
const dated = logs.filter((g) => g && g.date);
if (dated.length >= 2) {
const last = new Date(dated[dated.length - 1].date).getTime();
const prev = new Date(dated[dated.length - 2].date).getTime();
const gap = Math.round((last - prev) / 86_400_000);
// rest_days = days OFF (0 = played the day before = B2B), matching the
// NBA convention buildIntelFields uses. Consecutive calendar days → 0.
if (Number.isFinite(gap) && gap >= 1 && gap <= 14) out.rest_days = gap - 1;
}
const ab = parseFloat(res.season && res.season.atBats);
if (Number.isFinite(ab) && Number.isFinite(games) && games > 0) {
out.ab_per_game = ab / games;
}
return out;
}
+19 -2
View File
@@ -115,7 +115,7 @@ const isTopGrade = (g) => g === 'A+' || g === 'A';
function generateTickerEvents(sport, grades, deltas, ts) {
const events = [];
events.push({
tag: 'SCAN', color: 'var(--g-a)', ts,
tag: 'SCAN', color: 'var(--g-a)', ts, sport, // sport tag → dedupe one SCAN per sport
text: `${sport.toUpperCase()} slate scanned · ${grades.length} props graded`,
});
for (const g of grades.filter((x) => isTopGrade(x.grade)).slice(0, 6)) {
@@ -136,11 +136,28 @@ function generateTickerEvents(sport, grades, deltas, ts) {
return events;
}
// Session 47 — a SCAN event's sport, from the event field or its text prefix
// (defends ticker items written before the `sport` field existed).
function scanSportOf(e) {
if (e.tag !== 'SCAN') return null;
if (e.sport) return String(e.sport).toLowerCase();
const m = String(e.text || '').match(/^([a-z]+)\s+slate scanned/i);
return m ? m[1].toLowerCase() : null;
}
async function pushTickerItems(events, deps) {
if (!events || events.length === 0) return;
const existing = await deps.cacheGet('ticker:items');
const arr = Array.isArray(existing) ? existing : [];
const merged = [...events, ...arr].slice(0, TICKER_CAP);
// Keep only the LATEST SCAN per sport: drop existing SCAN events for any sport
// that has a fresh SCAN in this batch. MOVE/GRADE events are time-specific and
// preserved.
const freshScanSports = new Set(events.map(scanSportOf).filter(Boolean));
const pruned = arr.filter((e) => {
const sp = scanSportOf(e);
return !(sp && freshScanSports.has(sp));
});
const merged = [...events, ...pruned].slice(0, TICKER_CAP);
await deps.cacheSet('ticker:items', merged, TICKER_TTL);
}