f8b120c0aa
The on-demand "Read" grade model is RETIRED. A scheduled pipeline pre-grades the
slate, locks grades to the line, tracks movement; the dashboard shows them already
there. Orchestrates existing services — nothing rebuilt.
- snapshotService.runSnapshot(sport): getOdds → gradeAndCacheSlate → classify
archetype per player → lock gradedAt → line deltas vs previous snapshot → write
snapshot:{sport}:latest/previous + grades:{sport} → ticker events. Fully
injectable, zero-network unit tests. runAllSnapshots = cron entrypoint.
- Internal trigger POST /api/internal/snapshot/:sport + /all (requireInternalAuth).
In-process cron (SNAPSHOT_CRON=1, UTC 14,19,22,1,3) in server.js, no new dep.
- Public reads: GET /api/snapshot/:sport (cache-only) + GET /api/ticker (merges
TICKER_MANUAL pins) + Next proxies.
- GameCard swap: live Slate renders vyndr/GameCard (legacy kept for types only),
overlays locked grades onto game props → player name once + archetype badge +
"Graded Xh ago at -115 · Current 2.5 · ▲ TOWARD +1.0". Ungraded → "Awaiting next
scan", NO Read button. On-demand onGrade flow deleted.
- Ticker polls /api/ticker every 30s, graceful fallback to hardcoded items.
- NBA/WNBA: espnStatsAdapter free fallback (defensive parse → found:false on shape
mismatch) wired into resolvePlayerStats after the offline Python service.
Env: PROPLINE_API_KEY_1/2/3, VYNDR_INTERNAL_KEY, SNAPSHOT_CRON=1, TICKER_MANUAL.
Backend 2061 -> 2100 tests (+39), 173 suites. Web build clean (exit 0).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
74 lines
3.0 KiB
JavaScript
74 lines
3.0 KiB
JavaScript
// Session 45 — ESPN NBA/WNBA stats fallback. parseAthleteStats is pure; the
|
|
// fetch path is exercised with an injected http client.
|
|
|
|
const espn = require('../../src/services/adapters/espnStatsAdapter');
|
|
const svc = require('../../src/services/playerIntelService');
|
|
|
|
describe('parseAthleteStats (defensive)', () => {
|
|
it('pulls per-game averages from the ESPN categories shape', () => {
|
|
const payload = {
|
|
statistics: { splits: { categories: [
|
|
{ stats: [
|
|
{ name: 'avgPoints', value: 28.1 },
|
|
{ name: 'avgRebounds', value: 8.2 },
|
|
{ name: 'avgAssists', value: 6.4 },
|
|
] },
|
|
] } },
|
|
};
|
|
const ci = espn.parseAthleteStats(payload);
|
|
expect(ci.ppg).toBe(28.1);
|
|
expect(ci.rpg).toBe(8.2);
|
|
expect(ci.apg).toBe(6.4);
|
|
});
|
|
|
|
it('returns null for an unrecognized / empty shape (graceful)', () => {
|
|
expect(espn.parseAthleteStats(null)).toBeNull();
|
|
expect(espn.parseAthleteStats({ nonsense: true })).toBeNull();
|
|
expect(espn.parseAthleteStats({ statistics: { splits: { categories: [{ stats: [{ name: 'foo', value: 1 }] }] } } })).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('getSeasonAverages (injected http)', () => {
|
|
it('resolves an athlete and parses stats', async () => {
|
|
const http = {
|
|
get: async (url) => {
|
|
if (url.includes('/search')) return { data: { items: [{ id: 123, displayName: 'Luka Doncic', team: { abbreviation: 'DAL' }, position: { abbreviation: 'G' } }] } };
|
|
return { data: { statistics: { splits: { categories: [{ stats: [{ name: 'avgPoints', value: 33 }, { name: 'avgAssists', value: 9 }] }] } } } };
|
|
},
|
|
};
|
|
const r = await espn.getSeasonAverages('Luka Doncic', 'nba', { http });
|
|
expect(r.found).toBe(true);
|
|
expect(r.team).toBe('DAL');
|
|
expect(r.classifierInput.ppg).toBe(33);
|
|
});
|
|
|
|
it('degrades to found:false when ESPN errors', async () => {
|
|
const http = { get: async () => { throw new Error('espn down'); } };
|
|
expect((await espn.getSeasonAverages('X', 'nba', { http })).found).toBe(false);
|
|
});
|
|
|
|
it('returns found:false for non-basketball sports', async () => {
|
|
expect((await espn.getSeasonAverages('X', 'mlb')).found).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('resolvePlayerStats wires the ESPN fallback for NBA', () => {
|
|
it('falls back to ESPN when nbaStatsClient is offline → classifies', async () => {
|
|
const r = await svc.resolvePlayerStats('Luka Doncic', 'nba', {
|
|
nbaClient: { getSeasonAvg: async () => { throw new Error('python offline'); } },
|
|
espnStats: { getSeasonAverages: async () => ({ found: true, team: 'DAL', position: 'G', classifierInput: { ppg: 33, apg: 9, rpg: 8 } }) },
|
|
});
|
|
expect(r.found).toBe(true);
|
|
expect(r.team).toBe('DAL');
|
|
expect(r.classifierInput.ppg).toBe(33);
|
|
});
|
|
|
|
it('found:false when both sources are empty', async () => {
|
|
const r = await svc.resolvePlayerStats('Nobody', 'nba', {
|
|
nbaClient: { getSeasonAvg: async () => null },
|
|
espnStats: { getSeasonAverages: async () => ({ found: false }) },
|
|
});
|
|
expect(r.found).toBe(false);
|
|
});
|
|
});
|