3.3 KiB
3.3 KiB
Hover Info Restoration Fix - Complete
Problem Identified
The candle prediction hover info was missing, which previously showed:
- Prediction accuracy percentage
- Direction correctness (✓ or ✗)
- Predicted vs Actual OHLCV values with percentage errors
- Overall validation status
Root Cause Analysis
- Backend: Accuracy data wasn't being calculated and stored for predictions
- API: Live updates endpoint wasn't providing accuracy data with predictions
- Frontend: Ghost candles weren't receiving accuracy data for tooltips
Fixes Applied
1. Backend Accuracy Calculation
Added _calculate_prediction_accuracy() method that computes:
{
'accuracy': 87.5, # Overall accuracy percentage
'directionCorrect': True, # Direction prediction correctness
'avgPctError': 12.5, # Average percentage error
'actualCandle': [3320.1, 3325.4, 3318.2, 3322.8, 1250.5], # Actual OHLCV
'pctErrors': { # Individual field errors
'open': 0.8, 'high': 1.2, 'low': 0.5, 'close': 0.9, 'volume': 15.2
}
}
2. Accuracy Data Storage
- Added
prediction_accuracy_cacheto store accuracy data by prediction ID - Accuracy is calculated when predictions are validated
- Cache is used to provide accuracy data for hover tooltips
3. Enhanced Live Updates API
Updated /api/live-updates to include accuracy data:
- Calculates accuracy on-the-fly when predicted and actual candles match
- Includes accuracy data in transformer predictions
- Caches accuracy for future retrieval
4. Frontend Ghost Candle Enhancement
- Ghost candles now store accuracy data when created
- Added
updateGhostCandleAccuracy()method to update existing ghost candles - Enhanced tooltip creation to show rich accuracy information
5. Validation Integration
Updated /api/train-validated-prediction to:
- Calculate accuracy when predictions are validated
- Store accuracy data in cache for hover display
- Link accuracy to specific predictions by timestamp
Expected Hover Info Display
For Unvalidated Predictions:
PREDICTED CANDLE
O: 3320.15 H: 3325.42
L: 3318.23 C: 3322.61
Direction: UP
Status: AWAITING VALIDATION...
For Validated Predictions:
PREDICTED CANDLE
O: 3320.15 H: 3325.42
L: 3318.23 C: 3322.61
Direction: UP
--- VALIDATION ---
Accuracy: 87.5%
Direction: CORRECT ✓
Avg Error: 1.25%
ACTUAL vs PREDICTED:
Open: 3320.89 vs 3320.15 (0.8%)
High: 3326.12 vs 3325.42 (1.2%)
Low: 3318.45 vs 3318.23 (0.5%)
Close: 3323.18 vs 3322.61 (0.9%)
Volume: 1285.2 vs 1250.5 (15.2%)
Data Flow
- Prediction Made: Model generates prediction with candle data
- Ghost Candle Created: Added to chart with "AWAITING VALIDATION" status
- Actual Candle Arrives: System compares predicted vs actual
- Accuracy Calculated: Percentage errors and direction correctness computed
- Tooltip Updated: Hover info shows detailed validation results
Verification Steps
- Start inference: Make predictions and see ghost candles
- Hover over ghost candles: Should show prediction details
- Wait for validation: Tooltips should update with accuracy data
- Check accuracy: Hover should show predicted vs actual comparison
The hover info system now provides complete visibility into prediction accuracy and validation results, helping you understand model performance at the individual prediction level!