Item 7 — public accuracy reads the CLEAN ledger; BEAT CLOSE hidden until C4
Kev's call: the 30D accuracy surfaces must read TRUTH, not a cache that can't be filtered. My earlier degraded-row exclusion only touched getModelAggregate (Postgres); the public buckets/badge still read outcomeService (Redis outcome log), which counts degraded projection-0 outcomes and has no field to filter on. - /api/accuracy (AccuracyBadge) + /api/ledger/accuracy (buckets/ModelRecord) now source from the clean Postgres ledger aggregate via new ledgerService.getAccuracyView + accuracyBucketsFromAgg (model_value > 0 excludes degraded rows). Same response shapes → no frontend change. Redis outcome log is now read by nothing public; it can age out or be rebuilt. - BEAT CLOSE is a MEASURED-WRONG ZERO: captureClosing re-records the locked line as the "closing" line, so clv is flat on the whole sample and beat_close reads 0% (comparing a number to itself). Full write-up: specs/audit-data/ clv-capture-broken.md (the fix belongs to C4). Until then, beat_close_pct + clv_distribution are SUPPRESSED at the source (getModelAggregate, gated by clvCaptureReliable() / CLV_CAPTURE_RELIABLE=1). Every public surface already renders BEAT CLOSE only when non-null, so they all hide it now — no wrong zero anywhere. HIT RATE (real) is unaffected. Suite 271/3261 green, web build exit 0. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+11
-7
@@ -3,27 +3,31 @@
|
||||
/**
|
||||
* GET /api/accuracy (Session 55) — the system's track record.
|
||||
*
|
||||
* Public, cache-only read of the rolling accuracy record written by
|
||||
* outcomeService (settled snapshot grades vs real results). Powers the
|
||||
* dashboard "A-rated: 68% hit rate" pill and the grade-card accuracy line.
|
||||
* NEVER triggers settlement (that's the internal cron) → no API credits spent.
|
||||
* Public, cache-only read of the model's track record. Powers the AccuracyBadge
|
||||
* "A-RATED · X% HIT · 30D" pill and the grade-card accuracy line.
|
||||
*
|
||||
* Truth-Everywhere Part 2 (item 7) — sourced from the CLEAN Postgres ledger
|
||||
* aggregate (getAccuracyView: model_value > 0 excludes the degraded
|
||||
* projection-0 rows), NOT the Redis outcome log (which still counts them and
|
||||
* can't be filtered). Redis is a cache; when a cache can't be filtered, read
|
||||
* from truth. NEVER triggers settlement → no API credits spent.
|
||||
*/
|
||||
|
||||
const express = require('express');
|
||||
const { createRateLimit } = require('../middleware/rateLimit');
|
||||
const outcomeService = require('../services/outcomeService');
|
||||
const ledgerService = require('../services/ledgerService');
|
||||
|
||||
const router = express.Router();
|
||||
router.use(createRateLimit({ windowMs: 60_000, max: 60 }));
|
||||
|
||||
router.get('/', async (req, res) => {
|
||||
try {
|
||||
const acc = await outcomeService.getAccuracy();
|
||||
const acc = await ledgerService.getAccuracyView({});
|
||||
res.set('Cache-Control', 'public, max-age=300');
|
||||
return res.json(acc);
|
||||
} catch (err) {
|
||||
console.error('[accuracy]', err.message);
|
||||
return res.status(200).json({ overall: null, sports: {}, min_sample: outcomeService.MIN_SAMPLE, updated_at: null });
|
||||
return res.status(200).json({ overall: null, sports: {}, min_sample: 20, updated_at: null });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
+10
-3
@@ -41,11 +41,18 @@ function applyFilters(query, req) {
|
||||
}
|
||||
|
||||
router.get('/accuracy', async (req, res) => {
|
||||
// Truth-Everywhere Part 2 (item 7) — read the CLEAN Postgres ledger aggregate
|
||||
// (model_value > 0 excludes degraded rows), NOT the Redis outcome log (which
|
||||
// still counts degraded projection-0 outcomes and can't be filtered).
|
||||
try {
|
||||
const acc = await outcomeService.getAccuracy();
|
||||
const buckets = outcomeService.accuracyBuckets(acc.overall);
|
||||
const agg = await ledgerService.getModelAggregate({});
|
||||
const buckets = ledgerService.accuracyBucketsFromAgg(agg);
|
||||
const overall = {
|
||||
hits: agg.hits, misses: agg.misses, pushes: agg.pushes,
|
||||
total: agg.hits + agg.misses + agg.pushes, pct: agg.hit_pct ?? null,
|
||||
};
|
||||
res.set('Cache-Control', 'public, max-age=300');
|
||||
return res.json({ buckets, overall: acc.overall && acc.overall.overall, updated_at: acc.updated_at });
|
||||
return res.json({ buckets, overall, updated_at: null });
|
||||
} catch (err) {
|
||||
console.error('[ledger/accuracy]', err.message);
|
||||
return res.status(200).json({ buckets: [] });
|
||||
|
||||
Reference in New Issue
Block a user