Files
vyndr/tests/unit/engineIntelFields.test.js
T
builtbykev 80683e71b4 Session 43: Data pipeline + audit fixes + depth chart foundation (2045 tests)
P0 fixes + wiring real data into the S42 Player Intelligence architecture.

- P0 dropdown z-index: the nav's backdrop-filter stacking context let the
  Ticker/HeartbeatBar paint over the avatar/More dropdowns and eat clicks.
  nav now position:relative zIndex:2; menus zIndex:100. Avatar Settings ->
  /settings.
- Real MLB stats: mlbStatsAdapter.searchPlayer + getPlayerStats (name->id->
  season+gamelog). playerIntelService.resolvePlayerStats normalizes into the
  archetype classifier; getPlayerIntel returns found:true + real season +
  archetype classified from real stats. NBA via nbaStatsClient (degrades).
- Game cards: slateAdapter.groupPropsByPlayer (playerStrips, name once) +
  mapPitchers (MLB probables), folded into mapScheduleToGameCards. Legacy
  GameCard line grid renders BookChip (brand colors) not grey text.
- Grade card intel: analyzeViaEngine1.buildIntelFields computes stat-context +
  form/usage/matchup/rest from the existing feature vector (zero extra I/O);
  gradeAdapter lights up the card sections. Archetype deferred (needs season
  line at grade time).
- Depth chart foundation: depthChartService (getLineup/getDepthChart/
  getCascadeProjection) + /api/stats/lineup|depth|cascade, graceful + injectable.
- Mobile: player hero name overflow-wrap + 24px on <=640px (was clipping).

Backend 2011 -> 2045 tests (+34), 163 suites. Web build clean (exit 0).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 15:38:06 -04:00

52 lines
2.2 KiB
JavaScript

// Session 43 — engine attaches grade-card intelligence fields (stat context +
// VYNDR intelligence) from the feature vector, and gradeAdapter maps them.
const { __internals } = require('../../src/services/intelligence/analyzeViaEngine1');
const { buildIntelFields, computeFormScore, matchupGradeFromRank } = __internals;
const { mapScanToGradeResult } = require('../../web/src/lib/gradeAdapter');
describe('computeFormScore', () => {
it('trends above 70 when recent > baseline (hot)', () => {
expect(computeFormScore({ l5_avg: 30, l20_avg: 24 })).toBeGreaterThan(70);
});
it('trends below 70 when recent < baseline (cold)', () => {
expect(computeFormScore({ l5_avg: 18, l20_avg: 26 })).toBeLessThan(70);
});
it('undefined when there is no recent average', () => {
expect(computeFormScore({})).toBeUndefined();
});
});
describe('matchupGradeFromRank', () => {
it('maps normalized opponent rank to a letter grade', () => {
expect(matchupGradeFromRank(0.9)).toBe('A');
expect(matchupGradeFromRank(0.55)).toBe('B+');
expect(matchupGradeFromRank(0.1)).toBe('C');
expect(matchupGradeFromRank(undefined)).toBeUndefined();
});
});
describe('buildIntelFields', () => {
it('builds stat context + form/usage/matchup/rest from features', () => {
const f = buildIntelFields({ l20_avg: 26.9, l10_avg: 28.4, l5_avg: 30.1, usage_rate: 31.2, opp_rank_stat: 0.7, rest_days: 2 });
expect(f.season_avg).toBe(26.9);
expect(f.last10_avg).toBe(28.4);
expect(f.form).toBeGreaterThan(70);
expect(f.usage).toBe('31.2%');
expect(f.matchup_grade).toBe('A');
expect(f.rest).toBe('2d rest');
});
it('omits fields with no data (so the card sections self-hide)', () => {
expect(buildIntelFields({})).toEqual({});
});
it('feeds straight into the grade card via gradeAdapter', () => {
const engineLike = { player: 'Wemby', stat: 'points', line: 26.5, grade: 'A', ...buildIntelFields({ l20_avg: 26.9, l10_avg: 28.4, l5_avg: 30, usage_rate: 31.2, opp_rank_stat: 0.7 }) };
const card = mapScanToGradeResult(engineLike);
expect(card.statContext).toMatchObject({ season: '26.9', last10: '28.4' });
expect(card.vyndrIntel.matchup).toBe('A');
expect(card.vyndrIntel.usage).toBe('31.2%');
});
});