This commit is contained in:
Dobromir Popov
2025-12-09 00:34:51 +02:00
parent 8c3dc5423e
commit d6ada4b416
5 changed files with 534 additions and 429 deletions

View File

@@ -102,6 +102,11 @@
checkActiveTraining();
}
// Check for active inference session (resume PnL and position state after page reload)
if (typeof checkActiveInference === 'function') {
checkActiveInference();
}
// Keyboard shortcuts for chart maximization
document.addEventListener('keydown', function(e) {
// ESC key to exit maximized mode

View File

@@ -234,6 +234,24 @@
activeTrainingId = data.session.training_id;
showTrainingStatus();
// CRITICAL FIX: Immediately restore training progress state
// Don't wait for first poll - restore current state now
if (data.session.current_epoch !== undefined) {
document.getElementById('training-epoch').textContent = data.session.current_epoch || 0;
}
if (data.session.total_epochs !== undefined) {
document.getElementById('training-total-epochs').textContent = data.session.total_epochs || 0;
}
if (data.session.current_loss !== undefined && data.session.current_loss !== null) {
document.getElementById('training-loss').textContent = data.session.current_loss.toFixed(4);
}
// Update progress bar immediately
if (data.session.current_epoch && data.session.total_epochs) {
const percentage = (data.session.current_epoch / data.session.total_epochs) * 100;
document.getElementById('training-progress-bar').style.width = percentage + '%';
}
// Populate annotation count and timeframe if available
if (data.session.annotation_count) {
document.getElementById('training-annotation-count').textContent = data.session.annotation_count;
@@ -242,6 +260,7 @@
document.getElementById('training-timeframe').textContent = data.session.timeframe.toUpperCase();
}
// Start polling for continued updates (will update GPU/CPU and future progress)
pollTrainingProgress(activeTrainingId);
} else {
console.log('No active training session');
@@ -252,6 +271,62 @@
});
}
function checkActiveInference() {
/**
* Check if there's an active real-time inference session on page load
* This allows resuming PnL tracking and position state after page reload
*/
fetch('/api/realtime-inference/signals')
.then(response => response.json())
.then(data => {
if (data.success) {
// Check if inference is active (signals endpoint returns data if active)
if (data.signals && data.signals.length > 0) {
console.log('Active inference session found, restoring state');
// Restore PnL and position state from metrics
if (data.metrics) {
// Update session PnL if available
if (data.metrics.session_pnl !== undefined) {
const sessionPnlEl = document.getElementById('session-pnl');
if (sessionPnlEl) {
const totalPnl = data.metrics.session_pnl || 0;
const pnlColor = totalPnl >= 0 ? 'text-success' : 'text-danger';
const pnlSign = totalPnl >= 0 ? '+' : '';
sessionPnlEl.textContent = `${pnlSign}$${totalPnl.toFixed(2)}`;
sessionPnlEl.className = `fw-bold ${pnlColor}`;
}
}
// Update position state if available
if (data.metrics.position_state) {
updatePositionStateDisplay(data.metrics.position_state, data.metrics.session_metrics || data.metrics);
}
}
// Restore live metrics (accuracy, loss) if available
if (data.metrics) {
if (data.metrics.accuracy !== undefined) {
const liveAccuracyEl = document.getElementById('live-accuracy');
if (liveAccuracyEl) {
liveAccuracyEl.textContent = (data.metrics.accuracy * 100).toFixed(1) + '%';
}
}
if (data.metrics.loss !== undefined) {
const liveLossEl = document.getElementById('live-loss');
if (liveLossEl) {
liveLossEl.textContent = data.metrics.loss.toFixed(4);
}
}
}
}
}
})
.catch(error => {
console.error('Error checking active inference:', error);
});
}
function loadAvailableModels() {
fetch('/api/available-models')
.then(response => response.json())