Session 59: Addendum + work-order 1.6 + Phase 2 + Phase 3 (2352 tests)
Overnight sprint for the Saturday 10 AM ET deploy gate — day one of the
public ledger record locks against freshly posted lines.
Task A — ledger team/opponent (migration 020, applied at 0 rows):
populated in both write paths from the real feed; opponent only when the
player's team matches a game participant (never guessed). Roadmap: Phase
4.5 WNBA ESPN-boxscore settlement (due ~Jul 24) + Phase 5 per-tier
calibration logged.
Task B — work-order 1.6 CLOSED (canonical player keys):
- searchPlayer resolves via nameKey; the old matcher deleted accents
("Sanchez" with acute -> "snchez") and substring-guessed onto the WRONG
player (the mismatched last-10 bug). Ambiguous -> null, never guess.
- Slate JOIN INVARIANT: a graded prop whose player's real team isn't in
the game is dropped (TB player can't render under MIL@PIT) — locked by
tests that fail the suite on regression.
- grades:{sport} TTL 2h -> 6h (expired between 5h cron gaps — the real
cause of /team "No active props" for slate players).
Task C — Phase 2 slate UX: tabs are THE filter (URL ?sport=, deep-linkable,
duplicate legacy tablist removed); cards cap at 6 graded props sorted
A+->F with ALL N READS in-place expander; waiting states show the real
next pipeline run ("Grades post ~6:00 PM ET").
Task D — Phase 3 mobile P0: root cause of vanished 390px nav was HIDE_ON
including '/' (landing had zero navigation) — fixed; html/body overflow-x
contained; GAME LINES collapses to best-line summary + "N BOOKS" expander
below 640px; venue drops before time/pitchers ever truncate.
Live verification: raw ESPN today STILL returns the Jun 13 NYK@SA Finals
game without a date pin; the pinned fetch returns 0 games, 0 off-date.
Backend 2327 -> 2352 tests (202 suites), web build exit 0.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -129,22 +129,40 @@ async function getBatterVsPitcher(batterId, pitcherId, group = 'hitting') {
|
||||
return splits.length > 0 ? (splits[0].stat || null) : null;
|
||||
}
|
||||
|
||||
const normName = (n) => String(n == null ? '' : n).toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||
const { nameKey } = require('../../utils/playerName');
|
||||
|
||||
/**
|
||||
* Resolve a player name → MLB person record (Session 43). Pulls the season
|
||||
* player list (cached 24h — heavy but rarely changes) and matches by
|
||||
* normalized full name. Returns { id, fullName, team, teamId, position } or
|
||||
* null. Needed because every other adapter method keys on playerId.
|
||||
* Resolve a player name → MLB person record (Session 43; rebuilt Session 59,
|
||||
* work-order 1.6). Pulls the season player list (cached 24h) and matches on
|
||||
* the CANONICAL nameKey — accent-folded, suffix/nickname-resolved — so
|
||||
* "Sánchez" ≡ "Sanchez" and "Matt" ≡ "Matthew" resolve to ONE player.
|
||||
*
|
||||
* The old matcher lower-cased and stripped non-[a-z0-9], which DELETED
|
||||
* accented letters ("Sánchez" → "snchez" ≠ "sanchez") and then fell back to
|
||||
* a raw substring match that could silently return the WRONG player — the
|
||||
* audit's "last-10 opponents don't match his team" bug. The fallback now
|
||||
* requires a UNIQUE same-last-name + same-first-initial candidate; anything
|
||||
* ambiguous returns null (a missing profile beats another player's log).
|
||||
*/
|
||||
async function searchPlayer(name, season = DEFAULT_SEASON) {
|
||||
const target = normName(name);
|
||||
if (!target) return null;
|
||||
const targetKey = nameKey(name);
|
||||
if (!targetKey) return null;
|
||||
const url = `${BASE}/sports/1/players?season=${season}`;
|
||||
const data = await fetchWithCache(url, `mlbstats:players:${season}`, 24 * 3600);
|
||||
const people = (data && Array.isArray(data.people)) ? data.people : [];
|
||||
const hit = people.find((p) => normName(p.fullName) === target)
|
||||
|| people.find((p) => normName(p.fullName).includes(target) && target.length >= 6);
|
||||
let hit = people.find((p) => nameKey(p.fullName) === targetKey);
|
||||
if (!hit) {
|
||||
const parts = targetKey.split(' ');
|
||||
const first = parts[0] || '';
|
||||
const last = parts[parts.length - 1] || '';
|
||||
if (first && last && first !== last) {
|
||||
const cands = people.filter((p) => {
|
||||
const k = nameKey(p.fullName).split(' ');
|
||||
return k[k.length - 1] === last && k[0] && k[0][0] === first[0];
|
||||
});
|
||||
if (cands.length === 1) hit = cands[0]; // unique or nothing — never guess
|
||||
}
|
||||
}
|
||||
if (!hit) return null;
|
||||
return {
|
||||
id: hit.id,
|
||||
@@ -234,5 +252,5 @@ module.exports = {
|
||||
getTeams,
|
||||
resolveTeam,
|
||||
getTeamRoster,
|
||||
__internals: { BASE, TTL, extractSplits, ymd, DEFAULT_SEASON, normName },
|
||||
__internals: { BASE, TTL, extractSplits, ymd, DEFAULT_SEASON },
|
||||
};
|
||||
|
||||
@@ -73,6 +73,33 @@ const sideOf = (direction) =>
|
||||
// fabricated zero line/odds is exactly what the data-semantics rule forbids).
|
||||
const numOrNull = (v) => (v == null || !Number.isFinite(Number(v)) ? null : Number(v));
|
||||
|
||||
// Nickname token (last word, lowercased) — the stable cross-source team
|
||||
// identifier ("New York Yankees" ↔ "Yankees" ↔ "NYY" won't match, but
|
||||
// full-name feeds match full-name feeds; abbr feeds match abbr feeds).
|
||||
const nickToken = (name) => {
|
||||
const w = String(name || '').trim().split(/\s+/);
|
||||
return (w[w.length - 1] || '').toLowerCase().replace(/[^a-z]/g, '');
|
||||
};
|
||||
const teamsMatch = (a, b) => {
|
||||
if (!a || !b) return false;
|
||||
const sa = String(a).toLowerCase(), sb = String(b).toLowerCase();
|
||||
return sa === sb || nickToken(a) === nickToken(b);
|
||||
};
|
||||
|
||||
/**
|
||||
* Session 59 — team/opponent from the REAL feed. The player's team comes
|
||||
* from the stats resolve (g.team); the opponent is the other side of the
|
||||
* prop's game IF the team matches one of its participants. No match →
|
||||
* opponent stays null — never guessed.
|
||||
*/
|
||||
function teamOpponentFor(g, prop) {
|
||||
const team = g && g.team ? String(g.team) : null;
|
||||
if (!team || !prop) return { team, opponent: null };
|
||||
if (teamsMatch(team, prop.home_team)) return { team, opponent: prop.away_team || null };
|
||||
if (teamsMatch(team, prop.away_team)) return { team, opponent: prop.home_team || null };
|
||||
return { team, opponent: null };
|
||||
}
|
||||
|
||||
/** Index odds props by nameKey|stat for lock/closing lookups. */
|
||||
function indexProps(props) {
|
||||
const map = {};
|
||||
@@ -114,7 +141,10 @@ function rowsFromSnapshot(sport, grades, oddsProps, nowIso) {
|
||||
const prop = byKey[`${nameKey(player)}|${stat}`] || null;
|
||||
const gradedTs = locked.timestamp || nowIso;
|
||||
const gameDate = dateET(prop && prop.game_time) || dateET(gradedTs) || todayET();
|
||||
const { team, opponent } = teamOpponentFor(g, prop);
|
||||
rows.push({
|
||||
team,
|
||||
opponent,
|
||||
user_id: null,
|
||||
player_key: nameKey(player),
|
||||
player_name: normalizeName(player).display || player,
|
||||
@@ -375,5 +405,6 @@ module.exports = {
|
||||
__internals: {
|
||||
rowsFromSnapshot, computeClv, clvResultOf, indexProps, gameIdFor,
|
||||
dateET, sideOf, oddsForSide, isConfigured, CONFLICT,
|
||||
teamOpponentFor, teamsMatch,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
|
||||
const SNAP_TTL = 6 * 3600; // 6h — a snapshot is valid until the next run
|
||||
const GRADES_TTL = 2 * 3600; // matches gradeSlateService
|
||||
const TICKER_TTL = 24 * 3600;
|
||||
const TICKER_CAP = 50;
|
||||
const DELTA_NOISE = 0.5; // ignore movements smaller than this
|
||||
@@ -264,12 +263,17 @@ async function runSnapshot(sport, opts = {}) {
|
||||
const oddsByKey = indexOdds(props);
|
||||
const players = [...new Set(graded.map((g) => g.player || g.player_name).filter(Boolean))];
|
||||
const archByPlayer = {};
|
||||
// Session 59 — capture the player's REAL team from the same stats resolve
|
||||
// (statsapi/ESPN), never guessed. Feeds the ledger team/opponent columns
|
||||
// and the slate join guard (a prop only attaches to its own game).
|
||||
const teamByPlayer = {};
|
||||
await mapLimit(players, STATS_CONCURRENCY, async (player) => {
|
||||
try {
|
||||
const stats = await deps.resolveStats(player, sp);
|
||||
if (stats && stats.found) {
|
||||
const c = deps.classify(sp, stats.classifierInput || {});
|
||||
archByPlayer[player] = c.primary ? c.primary.name : null;
|
||||
if (stats.team) teamByPlayer[player] = stats.team;
|
||||
}
|
||||
} catch { /* graceful — no badge */ }
|
||||
});
|
||||
@@ -278,6 +282,7 @@ async function runSnapshot(sport, opts = {}) {
|
||||
...g,
|
||||
gradedAt: gradedAtFor(g, oddsByKey, ts),
|
||||
archetype: archByPlayer[g.player || g.player_name] || null,
|
||||
team: teamByPlayer[g.player || g.player_name] || g.team || null,
|
||||
}));
|
||||
|
||||
// Line deltas vs the previous snapshot's locked lines.
|
||||
@@ -288,7 +293,11 @@ async function runSnapshot(sport, opts = {}) {
|
||||
if (prev) await deps.cacheSet(`snapshot:${sp}:previous`, prev, SNAP_TTL);
|
||||
const snapshot = { sport: sp, updated_at: ts, grades: enriched, deltas, gradeCount: enriched.length };
|
||||
await deps.cacheSet(`snapshot:${sp}:latest`, snapshot, SNAP_TTL);
|
||||
await deps.cacheSet(`grades:${sp}`, { grades: enriched, updated_at: ts, source: (odds && odds.provider) || 'odds-api' }, GRADES_TTL);
|
||||
// Session 59 — grades:{sport} must outlive the gap between cron runs (up to
|
||||
// 5h) or team rosters / Explore / leaders go dark mid-day. SNAP_TTL (6h),
|
||||
// NOT the legacy 2h gradeSlateService TTL — that gap was why /team showed
|
||||
// "No active props" for players who were on the slate (audit 2.4).
|
||||
await deps.cacheSet(`grades:${sp}`, { grades: enriched, updated_at: ts, source: (odds && odds.provider) || 'odds-api' }, SNAP_TTL);
|
||||
|
||||
// Ticker exhaust.
|
||||
const events = generateTickerEvents(sp, enriched, deltas, ts);
|
||||
|
||||
Reference in New Issue
Block a user