@davoodmehraban89 / VELYQOR / commits / 9025410
Fork 0

Intelligence, Advanced Charting & Trading Platform

feat: implement deterministic quality scoring

davoodmehraban89 committed Oct 5, 2026 at 16:37 UTC 9025410b677173d00469720f0d0819d8835e09e7
1 file changed +17
packages/market-domain/src/quality-score.mjs new
+17
@@ -0,0 +1,17 @@
1 +const BASE = Object.freeze({ GOOD: 100, DEGRADED: 80, STALE: 30, INVALID: 0 });
2 +
3 +export function qualityScore({ state, flags = [], ageRatio = 0 }) {
4 + if (!(state in BASE)) throw new RangeError(`unsupported quality state: ${state}`);
5 + if (!Array.isArray(flags)) throw new TypeError('flags must be an array');
6 + if (!Number.isFinite(ageRatio) || ageRatio < 0) throw new RangeError('ageRatio must be non-negative and finite');
7 + if (state === 'INVALID') return 0;
8 +
9 + let score = BASE[state];
10 + if (flags.includes('PROVIDER_DIVERGENCE')) score -= 15;
11 + if (flags.includes('STALE_SOURCE')) score -= 10;
12 + if (ageRatio >= 0.75 && ageRatio <= 1) score -= 10;
13 + if (ageRatio > 1) score -= Math.min(20, Math.floor(ageRatio - 1) * 5);
14 +
15 + if (state === 'STALE') score = Math.min(score, 30);
16 + return Math.max(0, Math.min(100, score));
17 +}