Skip to content

fix(scoring): reduce spike sensitivity and cap retentionRate#56

Open
daree-dev wants to merge 1 commit into
Kalebtron1:mainfrom
daree-dev:fix/42-scoring-algorithm
Open

fix(scoring): reduce spike sensitivity and cap retentionRate#56
daree-dev wants to merge 1 commit into
Kalebtron1:mainfrom
daree-dev:fix/42-scoring-algorithm

Conversation

@daree-dev
Copy link
Copy Markdown
Contributor

Closes #42

What changed

Before: timeWeight = 1/(daysAgo+1) — a single large deposit made today could dominate the entire score. retentionRate had no upper bound, so a balance that grew beyond total deposits inflated the score. No score ceiling existed.

After:

Change Before After
Time decay 1/(daysAgo+1) — aggressive, spike-sensitive 1/(1+daysAgo/30) — soft 30-day half-life
Volume metric Raw weighted sum Normalized by totalDeposited (range 0–1)
Retention rate Unbounded Capped at 1
Score ceiling None Hard cap at 1000 (Platino max)

How to review

  1. Run npm run test — all 9 tests should pass.
  2. Run npm run build — should compile cleanly.
  3. To reproduce manually: POST /api/calculate-score with:
    • Spike case: { address, totalDeposited: 10200 } on a wallet with one 10 000 XLM deposit today and two 100 XLM deposits 60/90 days ago → score should be in Plata tier (50–149), not Oro.
    • Grown balance: same history but totalDeposited: 5000 with balance 8000 → metrics.retention should be 1.00, not 1.6.

Test data

8 regression tests added in src/test/calculate-score.test.ts covering:

  • Eligibility gate (< 3 txs → score 0)
  • Spike tier cap
  • retentionRate cap at 1
  • Score equality when balance > totalDeposited
  • Drain penalty (balance < 10% → score much lower)
  • Score ceiling (never exceeds 1000)
  • Tier threshold mapping

…on1#42)

- Replace 1/(daysAgo+1) time decay with soft 30-day half-life:
  weight = 1 / (1 + daysAgo/30). Old formula let a single large
  recent deposit dominate; new formula keeps older deposits relevant.
- Normalize weightedVolume by totalDeposited so score reflects
  consistency rather than raw deposit size.
- Cap retentionRate at 1 to prevent a grown balance from inflating score.
- Add hard score ceiling at 1000 (Platino max).
- Export computeFinancialReputation for unit testing.
- Add 8 regression tests covering: eligibility gate, spike tier cap,
  retentionRate cap, drain penalty, score ceiling, tier mapping.

Closes Kalebtron1#42
@vercel
Copy link
Copy Markdown

vercel Bot commented May 28, 2026

@daree-dev is attempting to deploy a commit to the alankcr1-6443's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@daree-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mejorar algoritmo de scoring

1 participant