Session 23: All-day intelligence layer — schedule, game lines, streaks, hot lists, stat filtering, ParlayAPI dead (1567 tests)

This commit is contained in:
Kev
2026-06-12 11:16:58 -04:00
parent 6ab49d4c37
commit 0538205fab
32 changed files with 2276 additions and 2 deletions
+43
View File
@@ -0,0 +1,43 @@
/**
* /api/streaks/:sport (Session 23)
*
* Computed player streaks from cached game logs. NO API calls — reads
* warm Redis logs and runs the pure streaks engine over them. Supports
* `?stat=points` to narrow to one category, and `?limit=N`.
*
* Response: { sport, stat, streaks: [...], source: 'computed' }
*
* An empty `streaks` array is a valid, non-error state — the platform
* leans on the other layers (schedule, game lines, props) when no logs
* are warm yet.
*/
const express = require('express');
const streaksService = require('../services/streaksService');
const { loadRosterLogs } = require('../services/rosterLogs');
const router = express.Router();
const MISSION_HEADER = { 'X-VYNDR-Mission': 'Streaks are the heartbeat' };
const SUPPORTED = new Set(['nba', 'wnba', 'mlb', 'nfl', 'soccer']);
router.get('/:sport', async (req, res) => {
const sport = String(req.params.sport || '').toLowerCase();
if (!SUPPORTED.has(sport)) {
return res.status(404).set(MISSION_HEADER).json({ error: `No streaks for sport: ${sport}` });
}
const stat = req.query.stat ? String(req.query.stat).toLowerCase() : 'all';
const limit = req.query.limit ? Math.max(0, parseInt(req.query.limit, 10) || 0) : 0;
try {
const roster = await loadRosterLogs(sport);
const streaks = streaksService.computeStreaks(roster, sport, { stat, limit });
return res.set(MISSION_HEADER).json({ sport, stat, streaks, source: 'computed' });
} catch (err) {
console.error(`[streaks/${sport}]`, err.message);
return res.set(MISSION_HEADER).json({ sport, stat, streaks: [], source: 'computed' });
}
});
module.exports = router;