more acc stats and predictions storage. chart optimisation

This commit is contained in:
Dobromir Popov
2025-12-10 11:02:36 +02:00
parent 2fea288f62
commit 1d49269301
4 changed files with 229 additions and 12 deletions

View File

@@ -2904,10 +2904,54 @@ class TradingOrchestrator:
prediction['timestamp'] = datetime.now()
self.recent_transformer_predictions[symbol].append(prediction)
# EFFICIENT: Store prediction in database at source (before sending to UI)
self._store_prediction_in_database(symbol, prediction, 'transformer')
logger.debug(f"Stored transformer prediction for {symbol}: {prediction.get('action', 'N/A')}")
except Exception as e:
logger.error(f"Error storing transformer prediction: {e}")
def _store_prediction_in_database(self, symbol: str, prediction: Dict, model_type: str):
"""Store prediction in database for later retrieval and training"""
try:
# Extract data from prediction
timestamp = prediction.get('timestamp')
if isinstance(timestamp, datetime):
timestamp_str = timestamp.isoformat()
else:
timestamp_str = str(timestamp)
action = prediction.get('action', 'HOLD')
confidence = prediction.get('confidence', 0.0)
predicted_candle = prediction.get('predicted_candle', {})
predicted_price = prediction.get('predicted_price')
primary_timeframe = prediction.get('primary_timeframe', '1m')
# Store in database if available
if hasattr(self, 'database_manager') and self.database_manager:
try:
prediction_id = self.database_manager.store_prediction(
symbol=symbol,
timeframe=primary_timeframe,
timestamp=timestamp_str,
prediction_type=model_type,
action=action,
confidence=confidence,
predicted_candle=predicted_candle,
predicted_price=predicted_price
)
logger.debug(f"Stored {model_type} prediction in database: {prediction_id}")
except Exception as db_error:
# Fallback: log prediction if database fails
logger.info(f"[PREDICTION DB] {symbol} {primary_timeframe} {model_type} {action} {confidence:.2f} @ {timestamp_str}")
else:
# Fallback: log prediction if no database manager
logger.info(f"[PREDICTION LOG] {symbol} {primary_timeframe} {model_type} {action} {confidence:.2f} @ {timestamp_str}")
except Exception as e:
logger.debug(f"Error storing prediction in database: {e}") # Debug level to avoid spam
def clear_predictions(self, symbol: str):
"""Clear all stored predictions for a symbol (useful for backtests)"""
try: