feat(stellar): implement Stellar Route Performance Forecasting Engine (Closes #530)#670
Merged
Merged
Conversation
|
@EmeditWeb 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! 🚀 |
2 tasks
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.
Description
Closes #530.
Adds a real Stellar Route Performance Forecasting Engine under
src/forecasting/routes/stellar/that replaces the existingMath.random()placeholder. The engine ingests historical route metrics, projects forward-looking latency using an exponential moving average, and projects reliability (success rate) using windowed proportions. It also classifies each prediction asimproving,stable, ordecliningand emits a 95% confidence interval plus a composite 0–100 confidence score that grows with sample size and tightens with smaller prediction intervals.Concept
Users lack visibility into expected future route behavior. This PR introduces an engine that analyzes historical Stellar route metrics and forecasts two key performance dimensions:
[0, 1], for upcoming transfers on a given route.Both predictions are accompanied by a trend direction and a confidence interval so downstream code (intelligence engines, dashboards, decision engines) can reason about expected behavior rather than relying on instantaneous probes.
Problem
Today there is no contract for predicting Stellar route performance from history. The existing service under
src/forecasting/routes/stellar/returnsMath.random()— useless for any consumer wanting to compare routes by future expected behavior.Changes Made
src/forecasting/routes/stellar/forecasting.service.tsMath.random()placeholder with a real NestJS-injectable forecasting engine,StellarRouteForecastingService.RouteMetricSampleingestion interface ({ routeId, timestamp, durationMs, success }) and per-route storage capped atmaxSamples(default 10 000), with chronological ordering.analyzeHistoricalMetrics(routeId, metrics)now:routeIdand the input array,NaN, negativedurationMs, invalidtimestamp, null elements),maxSamples,RouteHistoricalAnalysis(avg latency, success rate, p95, standard deviation, oldest/newest sample), ornullwhen every sample was invalid.predictLatencyTrends(routeId)returns aLatencyTrendForecastwith:emaAlpha, default 0.3),trend: 'improving' | 'stable' | 'declining'(positivetrendDelta⇒ latency decreased ⇒ improving).predictReliabilityTrends(routeId)returns aReliabilityTrendForecastwith:[0, 1],recentWindowSize()helper so latency and reliability compare against the same lookback.generateForecast(routeId)composes aRouteForecast:predictedLatency,predictedReliability,confidenceScore(0–100) kept for backwards compatibility,latency,reliability,historical.reset()andgetStoredSamples(routeId)(returns a defensive copy).emaAlpha ∈ (0, 1],trendThreshold ≥ 0, andrecentWindowRatio ∈ (0, 1).src/forecasting/routes/stellar/forecasting.service.spec.tsNaN, negative, invalid-timestamp, and null samples,routeId, non-array input, all-invalid returningnull,[0, 1],generateForecastzero-confidence contract on empty data, complete forecast when data is present,reset()and defensive-copy semantics ongetStoredSamples().src/forecasting/routes/stellar/index.tsexport * from './forecasting.service', so the new types are picked up automatically.Algorithms
durationMsseriesEMV ± 1.96·σ/√n(historical − recent) / historical > 0p ± 1.96·√(p(1−p)/n)clamped to [0, 1]recent − historicalBoth trends normalize so positive
trendDeltacorresponds toimproving(latency down, success up).Acceptance Criteria Met
StellarRouteForecastingServiceis a real, deterministic forecaster — noMath.random().npx jest src/forecasting).tsconfig.generateForecast(routeId)produces a typedRouteForecastwith confidence intervals and a confidence score when historical data is present, and a non-throwing zero-confidence result otherwise.How to Use
Out of Scope (intentionally)
apps/apiNestJS module and an HTTP endpoint (potential follow-up).