From 25b2d3840ab995b4c666915023ccae3eb2401bd8 Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Mon, 28 Jul 2025 12:15:26 +0300 Subject: [PATCH] ui fix --- web/clean_dashboard.py | 117 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 7 deletions(-) diff --git a/web/clean_dashboard.py b/web/clean_dashboard.py index 5a223c1..6c6cd48 100644 --- a/web/clean_dashboard.py +++ b/web/clean_dashboard.py @@ -1135,9 +1135,13 @@ class CleanTradingDashboard: def handle_clear_session(n_clicks): """Handle clear session button""" if n_clicks: - self._clear_session() - # Return a visual confirmation that the session was cleared - return [html.I(className="fas fa-check me-1 text-success"), "Cleared"] + try: + self._clear_session() + # Return a visual confirmation that the session was cleared + return [html.I(className="fas fa-check me-1 text-success"), "Session Cleared!"] + except Exception as e: + logger.error(f"Error in clear session callback: {e}") + return [html.I(className="fas fa-exclamation-triangle me-1 text-warning"), "Clear Failed"] return [html.I(className="fas fa-trash me-1"), "Clear Session"] @self.app.callback( @@ -5449,6 +5453,16 @@ class CleanTradingDashboard: if hasattr(self, 'dashboard_cache'): self.dashboard_cache = {} + # Clear any success rate or performance caches + if hasattr(self, '_performance_cache'): + self._performance_cache = {} + + if hasattr(self, '_success_rate_cache'): + self._success_rate_cache = {} + + if hasattr(self, '_win_rate_cache'): + self._win_rate_cache = {} + # Clear persistent trade log files self._clear_trade_logs() @@ -5463,10 +5477,17 @@ class CleanTradingDashboard: # Force refresh of dashboard components self._force_dashboard_refresh() - logger.info("✅ Session data and trade logs cleared successfully") + logger.info("=" * 60) + logger.info("✅ SESSION CLEAR COMPLETED SUCCESSFULLY") + logger.info("=" * 60) logger.info("📊 Session P&L reset to $0.00") logger.info("📈 All positions closed") logger.info("📋 Trade history cleared") + logger.info("🎯 Success rate calculations reset") + logger.info("📈 Model performance metrics reset") + logger.info("🔄 All caches cleared") + logger.info("📁 Trade log files cleared") + logger.info("=" * 60) except Exception as e: logger.error(f"❌ Error clearing session: {e}") @@ -5578,47 +5599,129 @@ class CleanTradingDashboard: # Use the orchestrator's built-in clear method if available if hasattr(self.orchestrator, 'clear_session_data'): self.orchestrator.clear_session_data() + logger.info("✅ Used orchestrator's built-in clear_session_data method") else: # Fallback to manual clearing if hasattr(self.orchestrator, 'recent_decisions'): self.orchestrator.recent_decisions = {} + logger.info("✅ Cleared recent_decisions") if hasattr(self.orchestrator, 'recent_dqn_predictions'): for symbol in self.orchestrator.recent_dqn_predictions: self.orchestrator.recent_dqn_predictions[symbol].clear() + logger.info("✅ Cleared recent_dqn_predictions") if hasattr(self.orchestrator, 'recent_cnn_predictions'): for symbol in self.orchestrator.recent_cnn_predictions: self.orchestrator.recent_cnn_predictions[symbol].clear() + logger.info("✅ Cleared recent_cnn_predictions") if hasattr(self.orchestrator, 'prediction_accuracy_history'): for symbol in self.orchestrator.prediction_accuracy_history: self.orchestrator.prediction_accuracy_history[symbol].clear() + logger.info("✅ Cleared prediction_accuracy_history") logger.info("Orchestrator state cleared (fallback method)") + # Clear model performance tracking (critical for success rate calculations) + if hasattr(self.orchestrator, 'model_performance'): + # Reset all model performance metrics + for model_name in self.orchestrator.model_performance: + self.orchestrator.model_performance[model_name] = { + 'correct': 0, + 'total': 0, + 'accuracy': 0.0, + 'price_predictions': {'total': 0, 'accurate': 0, 'avg_error': 0.0} + } + logger.info("✅ Reset model_performance tracking (accuracy calculations)") + + # Clear model statistics if they exist + if hasattr(self.orchestrator, 'model_statistics'): + for model_name in self.orchestrator.model_statistics: + if hasattr(self.orchestrator.model_statistics[model_name], 'accuracy'): + self.orchestrator.model_statistics[model_name].accuracy = None + if hasattr(self.orchestrator.model_statistics[model_name], 'correct'): + self.orchestrator.model_statistics[model_name].correct = 0 + if hasattr(self.orchestrator.model_statistics[model_name], 'total'): + self.orchestrator.model_statistics[model_name].total = 0 + logger.info("✅ Reset model_statistics accuracy tracking") + + # Clear any cached performance metrics + if hasattr(self.orchestrator, '_cached_performance'): + self.orchestrator._cached_performance = {} + + if hasattr(self.orchestrator, '_last_performance_update'): + self.orchestrator._last_performance_update = {} + + logger.info("✅ Orchestrator state and performance metrics cleared completely") + except Exception as e: logger.error(f"Error clearing orchestrator state: {e}") def _clear_trading_executor_state(self): """Clear trading executor state and positions""" try: + # Clear positions and orders if hasattr(self.trading_executor, 'current_positions'): self.trading_executor.current_positions = {} + if hasattr(self.trading_executor, 'positions'): + self.trading_executor.positions = {} + + if hasattr(self.trading_executor, 'open_orders'): + self.trading_executor.open_orders = {} + + # Clear trade history and records (critical for success rate calculations) if hasattr(self.trading_executor, 'trade_history'): self.trading_executor.trade_history = [] + logger.info("✅ Cleared trade_history") + if hasattr(self.trading_executor, 'trade_records'): + self.trading_executor.trade_records = [] + logger.info("✅ Cleared trade_records (used for success rate)") + + # Clear P&L and fee tracking if hasattr(self.trading_executor, 'session_pnl'): self.trading_executor.session_pnl = 0.0 if hasattr(self.trading_executor, 'total_fees'): self.trading_executor.total_fees = 0.0 - if hasattr(self.trading_executor, 'open_orders'): - self.trading_executor.open_orders = {} + if hasattr(self.trading_executor, 'daily_pnl'): + self.trading_executor.daily_pnl = 0.0 - logger.info("Trading executor state cleared") + if hasattr(self.trading_executor, 'daily_loss'): + self.trading_executor.daily_loss = 0.0 + + if hasattr(self.trading_executor, 'daily_trades'): + self.trading_executor.daily_trades = 0 + + # Clear consecutive loss tracking (affects success rate calculations) + if hasattr(self.trading_executor, 'consecutive_losses'): + self.trading_executor.consecutive_losses = 0 + logger.info("✅ Reset consecutive_losses counter") + + # Reset safety feature state + if hasattr(self.trading_executor, 'safety_triggered'): + self.trading_executor.safety_triggered = False + logger.info("✅ Reset safety_triggered flag") + + # Reset profitability multiplier to default + if hasattr(self.trading_executor, 'profitability_reward_multiplier'): + self.trading_executor.profitability_reward_multiplier = getattr( + self.trading_executor, 'default_profitability_multiplier', 1.0 + ) + logger.info("✅ Reset profitability_reward_multiplier") + + # Clear any cached statistics + if hasattr(self.trading_executor, '_cached_stats'): + self.trading_executor._cached_stats = {} + + if hasattr(self.trading_executor, '_last_stats_update'): + self.trading_executor._last_stats_update = None + + logger.info("✅ Trading executor state cleared completely") + logger.info("📊 Success rate calculations will start fresh") except Exception as e: logger.error(f"Error clearing trading executor state: {e}")