Session 45: Snapshot pipeline + GameCard swap + live ticker (2100 tests)

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>
This commit is contained in:
Kev
2026-06-18 21:34:29 -04:00
parent 7969a4971a
commit f8b120c0aa
24 changed files with 1425 additions and 129 deletions
+37
View File
@@ -413,6 +413,43 @@ Built from the Claude Design "VYNDR Player Intelligence" bundle.
vyndr/GameCard (playerStrips/pitchers) is built for that and swaps in then.
Don't swap it before the grades cache is populated (cards would be blank).
## Snapshot Pipeline (Session 45 — the product model)
The on-demand "Read" grade flow is RETIRED. Grades are produced by a scheduled
snapshot, locked to the line, and read from cache.
- **`snapshotService.runSnapshot(sport)`** orchestrates EXISTING services (don't
rebuild): getOdds → gradeAndCacheSlate (captured via an injected cacheSet, so
we re-write an ENRICHED envelope) → classify archetype per player
(resolvePlayerStats + archetypeService) → attach `gradedAt {line,odds,timestamp}`
→ `computeLineDeltas` vs previous → write `snapshot:{sport}:latest|previous` +
`grades:{sport}` → `generateTickerEvents` → `ticker:items`. ALL deps injectable
→ unit-tested with zero network. `runAllSnapshots()` is the cron entrypoint.
- **Redis keys:** `snapshot:{sport}:latest` (current locked snapshot:
{grades, deltas}), `:previous` (for the next delta), `grades:{sport}` (enriched,
read by GameCard/Explore/leaders), `ticker:items` (capped 50 array).
- **Trigger is INTERNAL-ONLY:** `POST /api/internal/snapshot/:sport|/all` behind
`requireInternalAuth` (header `x-internal-key` == `VYNDR_INTERNAL_KEY`). `/all`
is registered BEFORE `/:sport` or Express captures "all" as a sport.
- **Cron:** `src/snapshotScheduler.js`, gated `SNAPSHOT_CRON=1`, UTC hours
14,19,22,1,3, armed in server.js (NOT app.js — app.js is imported by tests).
No new dependency. For multi-replica, use an external n8n cron hitting the
internal endpoint instead.
- **Read path:** `GET /api/snapshot/:sport` (public, cache-only, never triggers a
snapshot → can't drain PropLine). `GET /api/ticker` (public, merges
`TICKER_MANUAL` env pins).
- **GameCard swap:** the live Slate renders `vyndr/GameCard` (legacy GameCard kept
for TYPES only — `import type`). It overlays snapshot grades onto each game's
odds-derived props via `slateAdapter.buildPlayerStripsFromProps` (player name
once + archetype + locked grade + line-delta sub-line). Ungraded → "Awaiting
next scan", NO Read button. `StatStrip` renders the gradedAt/delta sub-line when
a prop carries `gradedAt`/`delta`/`awaiting` (snapshot mode), else the inline chip.
- **Ticker** (`vyndr/Ticker`) polls `/api/ticker` every 30s; the passed items are
the initial + graceful fallback (never blanks on fetch failure).
- **NBA/WNBA stats:** `espnStatsAdapter` is the FREE fallback when the Python
nba_api service is offline. `parseAthleteStats` is DEFENSIVE (null on any shape
it doesn't recognize → found:false). Its live ESPN shape may need prod tuning.
- **Env:** PROPLINE_API_KEY_1/2/3, VYNDR_INTERNAL_KEY, SNAPSHOT_CRON=1,
SNAPSHOT_HOURS_UTC (optional), TICKER_MANUAL (JSON array).
## Active Skills
- vyndr-voice (all user-facing output)
- prop-analysis (grading methodology)