models metrics and utilisation

This commit is contained in:
Dobromir Popov
2025-06-25 21:21:55 +03:00
parent 3da454efb7
commit 8c914ac188
2 changed files with 171 additions and 25 deletions

View File

@ -202,6 +202,45 @@ class DashboardComponentManager:
logger.error(f"Error formatting system status: {e}")
return [html.P(f"Error: {str(e)}", className="text-danger small")]
def _format_cnn_pivot_prediction(self, model_info):
"""Format CNN pivot prediction for display"""
try:
pivot_prediction = model_info.get('pivot_prediction')
if not pivot_prediction:
return html.Div()
pivot_type = pivot_prediction.get('pivot_type', 'UNKNOWN')
predicted_price = pivot_prediction.get('predicted_price', 0)
confidence = pivot_prediction.get('confidence', 0)
time_horizon = pivot_prediction.get('time_horizon_minutes', 0)
# Color coding for pivot types
if 'RESISTANCE' in pivot_type:
pivot_color = "text-danger"
pivot_icon = "fas fa-arrow-up"
elif 'SUPPORT' in pivot_type:
pivot_color = "text-success"
pivot_icon = "fas fa-arrow-down"
else:
pivot_color = "text-warning"
pivot_icon = "fas fa-arrows-alt-h"
return html.Div([
html.Div([
html.I(className=f"{pivot_icon} me-1 {pivot_color}"),
html.Span("Next Pivot: ", className="text-muted small"),
html.Span(f"${predicted_price:.2f}", className=f"small fw-bold {pivot_color}")
], className="mb-1"),
html.Div([
html.Span(f"{pivot_type.replace('_', ' ')}", className=f"small {pivot_color}"),
html.Span(f" ({confidence:.0%}) in ~{time_horizon}m", className="text-muted small")
])
], className="mt-1 p-1", style={"backgroundColor": "rgba(255,255,255,0.02)", "borderRadius": "3px"})
except Exception as e:
logger.debug(f"Error formatting CNN pivot prediction: {e}")
return html.Div()
def format_cob_data(self, cob_snapshot, symbol):
"""Format COB data for display"""
try:
@ -364,23 +403,32 @@ class DashboardComponentManager:
], className="form-check form-switch")
], className="d-flex align-items-center mb-1"),
# Model metrics
# Model metrics
html.Div([
# Last prediction
html.Div([
# Last prediction
html.Div([
html.Span("Last: ", className="text-muted small"),
html.Span(f"{pred_action}",
className=f"small fw-bold {'text-success' if pred_action == 'BUY' else 'text-danger' if pred_action == 'SELL' else 'text-muted'}"),
html.Span(f" ({pred_confidence:.1f}%)", className="text-muted small"),
html.Span(f" @ {pred_time}", className="text-muted small")
], className="mb-1"),
# 5MA Loss
html.Div([
html.Span("5MA Loss: ", className="text-muted small"),
html.Span(f"{loss_5ma:.4f}", className=f"small fw-bold {loss_class}")
])
])
html.Span("Last: ", className="text-muted small"),
html.Span(f"{pred_action}",
className=f"small fw-bold {'text-success' if pred_action == 'BUY' else 'text-danger' if pred_action == 'SELL' else 'text-muted'}"),
html.Span(f" ({pred_confidence:.1f}%)", className="text-muted small"),
html.Span(f" @ {pred_time}", className="text-muted small")
], className="mb-1"),
# Loss metrics with improvement tracking
html.Div([
html.Span("Current Loss: ", className="text-muted small"),
html.Span(f"{loss_5ma:.4f}", className=f"small fw-bold {loss_class}")
] + ([
html.Span(" | Initial: ", className="text-muted small"),
html.Span(f"{model_info.get('initial_loss', 0):.4f}", className="text-muted small")
] if model_info.get('initial_loss') else []) + ([
html.Span(" | ", className="text-muted small"),
html.Span(f"{model_info.get('improvement', 0):.1f}%", className="small text-success")
] if model_info.get('improvement', 0) > 0 else []), className="mb-1"),
# CNN Pivot Prediction (if available)
*([self._format_cnn_pivot_prediction(model_info)] if model_info.get('pivot_prediction') else [])
])
], className="border rounded p-2 mb-2",
style={"backgroundColor": "rgba(255,255,255,0.05)" if is_active else "rgba(128,128,128,0.1)"})