predictions display

This commit is contained in:
Dobromir Popov
2025-12-08 22:59:16 +02:00
parent 5a4b0cf35b
commit 8c3dc5423e
3 changed files with 301 additions and 44 deletions

View File

@@ -70,15 +70,31 @@ class LiveUpdatesPolling {
.then(response => response.json())
.then(data => {
if (data.success) {
// Handle chart update
// Handle chart update (even if null, predictions should still be processed)
if (data.chart_update && this.onChartUpdate) {
this.onChartUpdate(data.chart_update);
}
// Handle prediction update
// CRITICAL FIX: Handle prediction update properly
// data.prediction is already in format { transformer: {...}, dqn: {...}, cnn: {...} }
if (data.prediction && this.onPredictionUpdate) {
// Log prediction data for debugging
console.log('[Live Updates] Received prediction data:', {
has_transformer: !!data.prediction.transformer,
has_dqn: !!data.prediction.dqn,
has_cnn: !!data.prediction.cnn,
transformer_action: data.prediction.transformer?.action,
transformer_confidence: data.prediction.transformer?.confidence,
has_predicted_candle: !!data.prediction.transformer?.predicted_candle
});
// Pass the prediction object directly (it's already in the correct format)
this.onPredictionUpdate(data.prediction);
} else if (!data.prediction) {
console.debug('[Live Updates] No prediction data in response');
}
} else {
console.debug('[Live Updates] Response not successful:', data);
}
})
.catch(error => {
@@ -148,24 +164,51 @@ document.addEventListener('DOMContentLoaded', function() {
};
window.liveUpdatesPolling.onPredictionUpdate = function(data) {
// CRITICAL FIX: data is already in format { transformer: {...}, dqn: {...}, cnn: {...} }
console.log('[Live Updates] Prediction received:', data);
// Update prediction visualization on charts
if (window.appState && window.appState.chartManager) {
// Store predictions for later use
if (!window.appState.chartManager.predictions) {
window.appState.chartManager.predictions = {};
}
// Update stored predictions
if (data.transformer) {
window.appState.chartManager.predictions['transformer'] = data.transformer;
}
if (data.dqn) {
window.appState.chartManager.predictions['dqn'] = data.dqn;
}
if (data.cnn) {
window.appState.chartManager.predictions['cnn'] = data.cnn;
}
// Update charts with predictions
window.appState.chartManager.updatePredictions(data);
}
// Update prediction display
// Update prediction display in UI
if (typeof updatePredictionDisplay === 'function') {
updatePredictionDisplay(data);
// updatePredictionDisplay expects a single prediction object, not the full data structure
// Pass the transformer prediction if available
if (data.transformer) {
updatePredictionDisplay(data.transformer);
}
}
// Add to prediction history
// Add to prediction history (use transformer prediction if available)
if (typeof predictionHistory !== 'undefined') {
predictionHistory.unshift(data);
if (predictionHistory.length > 5) {
predictionHistory = predictionHistory.slice(0, 5);
}
if (typeof updatePredictionHistory === 'function') {
updatePredictionHistory();
const predictionToAdd = data.transformer || data.dqn || data.cnn || data;
if (predictionToAdd) {
predictionHistory.unshift(predictionToAdd);
if (predictionHistory.length > 5) {
predictionHistory = predictionHistory.slice(0, 5);
}
if (typeof updatePredictionHistory === 'function') {
updatePredictionHistory();
}
}
}
};