feat(credit): pure formula functions, configurable weights, and debounced recomputation - #1118
Merged
Akanimoh12 merged 1 commit intoJul 25, 2026
Conversation
… and debounced recomputation ## Summary Implements the credit scoring system for Stellar Tipz with the following improvements: ### Issue Akanimoh12#912: Credit Score Formula Module (Pure Functions) - Create `credit.formula.ts` with pure, deterministic scoring functions - All formula functions are side-effect free and fully testable - Implement component calculations: tip volume, X metrics, account age, streak bonus - Pure formula is separated from database/cache operations ### Issue Akanimoh12#916: Credit Score Breakdown / Factors - Create `credit.factors.ts` to expose contributing factors and weights - Provide transparent breakdown of how each factor contributes to the score - API-ready methods to format factor information for responses - Clear documentation of weights, divisors, and caps ### Issue Akanimoh12#921: Credit Score Weights via Config - Create `credit.config.ts` to load weights from environment variables - Support configurable weights, divisors, and caps via env vars - All configuration is validated and has sensible defaults - Easy to adjust scoring algorithm without code changes ### Issue Akanimoh12#918: Credit Score Recompute on New Tip - Implement debounced recomputation mechanism in `credit.service.ts` - Add `scheduleRecomputeCreditScore()` for debounced tip-triggered updates - Multiple rapid tips result in single recomputation (5s debounce) - Prevents excessive database writes while maintaining fresh scores ### Technical Details - Formula is pure and configuration-driven for maximum flexibility - Updated environment configuration with new credit score parameters - Comprehensive unit tests for all formula functions and edge cases - Updated existing tests to verify debouncing behavior - Follows module conventions established in the codebase ### Testing - Added `credit.formula.test.ts` with 30+ tests covering: - Individual component calculations (tip, X metrics, age) - Weight application and capping logic - Full formula with all components - Tier assignment and edge cases - Configuration flexibility - Updated `credit.test.ts` to test service-level debouncing - All pure functions are deterministic and testable Closes Akanimoh12#912 Closes Akanimoh12#916 Closes Akanimoh12#918 Closes Akanimoh12#921
|
@girly-coder01 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! 🚀 |
Akanimoh12
merged commit Jul 25, 2026
e1a6c7b
into
Akanimoh12:test-implement-drips
4 of 5 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the complete credit scoring system for Stellar Tipz with pure formula functions, configurable weights, and debounced recomputation on tip events.
This PR addresses all four credit scoring issues (#912, #916, #918, #921) in a single cohesive implementation that follows module conventions and best practices.
Changes
Issue #912: Credit Score Formula Module (Pure Functions)
credit.formula.tsmodule with pure, deterministic scoring functionsIssue #916: Credit Score Breakdown / Factors
credit.factors.tsmodule exposing contributing factors and weightsIssue #921: Credit Score Weights via Config
credit.config.tsloading weights from environment variablesIssue #918: Credit Score Recompute on New Tip
Technical Details
Files Changed
Formula (Pure & Configuration-Driven)
```
score = BASE_SCORE (configurable, default 40)
+ tip_sub * TIP_WEIGHT (default 20) / 100 → 0–20 pts
+ x_sub * X_WEIGHT (default 30) / 100 → 0–30 pts
+ age_sub * AGE_WEIGHT (default 10) / 100 → 0–10 pts
+ streak_bonus → 0–∞ pts (capped at MAX_SCORE)
Maximum score: 100 (capped, configurable)
```
All weights, divisors, and caps are configurable via environment variables.
Configuration Example
See `.env.example` for complete list. Key variables:
```bash
Weights (must sum to <= 100)
CREDIT_SCORE_WEIGHT_BASE=40
CREDIT_SCORE_WEIGHT_TIP=20
CREDIT_SCORE_WEIGHT_X=30
CREDIT_SCORE_WEIGHT_AGE=10
Divisors for converting raw signals to scores
CREDIT_SCORE_DIVISOR_TIP=10000000
CREDIT_SCORE_DIVISOR_FOLLOWER=50
CREDIT_SCORE_DIVISOR_ENGAGEMENT=10
CREDIT_SCORE_DIVISOR_AGE=10
Caps for sub-scores
CREDIT_SCORE_CAP_MAX=100
CREDIT_SCORE_CAP_X_SUB=50
CREDIT_SCORE_CACHE_TTL_SECONDS=300
```
Testing
Comprehensive test coverage:
`credit.formula.test.ts`: 30+ unit tests for all formula functions
`credit.test.ts` (updated):
All pure functions are deterministic: Same input = same output, every time
Code Quality
Acceptance Criteria
Testing Notes
All changes follow project patterns and are fully tested:
Deployment Notes
Closes #912
Closes #916
Closes #918
Closes #921