fix display predictions only on the selected main chart

This commit is contained in:
Dobromir Popov
2025-12-10 01:18:34 +02:00
parent bf381a9649
commit e84eed2839
3 changed files with 51 additions and 28 deletions

View File

@@ -2863,45 +2863,66 @@ class ChartManager {
/**
* Update model predictions on charts
* Draws predictions ONLY on the primary timeframe (the one the model is predicting for)
* Other timeframes are just reference data for the model
*/
updatePredictions(predictions) {
if (!predictions) return;
try {
// Use the currently active timeframe from app state
// This ensures predictions appear on the chart the user is watching (e.g., '1s')
const timeframe = window.appState?.currentTimeframes?.[0] || '1m';
// CRITICAL: Only draw predictions on the PRIMARY timeframe
// The model uses other timeframes as reference, but predictions are for the primary timeframe only
const primaryTimeframe = predictions.transformer?.primary_timeframe ||
window.appState?.currentTimeframes?.[0] ||
'1m';
console.log(`[updatePredictions] Drawing predictions on primary timeframe: ${primaryTimeframe}`);
// Update only the primary timeframe
this._updatePredictionsForTimeframe(primaryTimeframe, predictions);
} catch (error) {
console.error('[updatePredictions] Error:', error);
}
}
/**
* Update predictions for a specific timeframe
* @private
*/
_updatePredictionsForTimeframe(timeframe, predictions) {
try {
const chart = this.charts[timeframe];
if (!chart) {
console.warn(`[updatePredictions] Chart not found for timeframe: ${timeframe}`);
console.debug(`[updatePredictions] Chart not found for timeframe: ${timeframe}`);
return;
}
// Throttle prediction updates to avoid flickering
const now = Date.now();
const lastUpdate = this.lastPredictionUpdate[timeframe] || 0;
// Create a simple hash of prediction data to detect actual changes
const predictionHash = JSON.stringify({
action: predictions.transformer?.action,
confidence: predictions.transformer?.confidence,
predicted_price: predictions.transformer?.predicted_price,
timestamp: predictions.transformer?.timestamp
});
// Skip update if:
// 1. Too soon since last update (throttle)
// 2. Predictions haven't actually changed
if (now - lastUpdate < this.predictionUpdateThrottle && predictionHash === this.lastPredictionHash) {
console.debug(`[updatePredictions] Skipping update (throttled or unchanged)`);
return;
}
this.lastPredictionUpdate[timeframe] = now;
this.lastPredictionHash = predictionHash;
console.log(`[updatePredictions] Timeframe: ${timeframe}, Predictions:`, predictions);
const now = Date.now();
const lastUpdate = this.lastPredictionUpdate[timeframe] || 0;
// Create a simple hash of prediction data to detect actual changes
const predictionHash = JSON.stringify({
action: predictions.transformer?.action,
confidence: predictions.transformer?.confidence,
predicted_price: predictions.transformer?.predicted_price,
timestamp: predictions.transformer?.timestamp
});
// Skip update if:
// 1. Too soon since last update (throttle)
// 2. Predictions haven't actually changed
if (now - lastUpdate < this.predictionUpdateThrottle && predictionHash === this.lastPredictionHash) {
console.debug(`[updatePredictions] Skipping update for ${timeframe} (throttled or unchanged)`);
return;
}
this.lastPredictionUpdate[timeframe] = now;
this.lastPredictionHash = predictionHash;
console.log(`[updatePredictions] Timeframe: ${timeframe}, Predictions:`, predictions);
const plotId = chart.plotId;
const plotElement = document.getElementById(plotId);