Session 7e: Grade adapter, normalize consolidation, ARCH-2 banners

This commit is contained in:
Kev
2026-06-10 03:37:07 -04:00
parent 6f4a353de9
commit 012c0ef47e
11 changed files with 571 additions and 60 deletions
+7 -18
View File
@@ -48,22 +48,11 @@ const espnSportPath = {
function sleep(ms) { return new Promise((r) => setTimeout(r, ms)); }
// DUP-1 (Session 7c): a near-twin lives in
// src/services/intelligence/trapDetection.js. This variant KEEPS digits
// because some legacy roster fields encode jersey numbers in the name
// string; the trap detector strips them. If those legacy fields ever
// go away, consolidate to a shared util in src/utils/.
function normalizeName(name) {
if (!name) return '';
return name
.normalize('NFD')
.replace(/[̀-ͯ]/g, '') // strip accents
.toLowerCase()
.replace(/\b(jr|sr|ii|iii|iv|v)\.?\b/g, '') // suffixes
.replace(/[^a-z0-9\s]/g, ' ') // punctuation (keeps digits)
.replace(/\s+/g, ' ') // collapse spaces
.trim();
}
// DUP-1 (Session 7e): consolidated into src/utils/normalize.js. The
// script keeps digits because legacy roster fields can encode jersey
// numbers in the name string.
const { normalizeName } = require('../src/utils/normalize');
const normalizeRosterName = (name) => normalizeName(name, { keepDigits: true });
async function fetchJSON(url, { params } = {}) {
const res = await axios.get(url, { params, timeout: 15_000 });
@@ -108,7 +97,7 @@ async function fetchMlbAllPlayers() {
return list.map((p) => ({
mlbam_id: String(p.id),
fullName: p.fullName,
normalized: normalizeName(p.fullName),
normalized: normalizeRosterName(p.fullName),
}));
}
@@ -129,7 +118,7 @@ async function processSport(sport, { dryRun }) {
for (const p of roster) {
allPlayers.push({
display_name: p.name,
normalized_name: normalizeName(p.name),
normalized_name: normalizeRosterName(p.name),
espn_id: p.id,
sport,
team_abbr: team.abbreviation,