gogo2/debug_dashboard.py
2025-05-26 16:02:40 +03:00

111 lines
3.5 KiB
Python

#!/usr/bin/env python3
"""
Debug Dashboard - Minimal version to test callback functionality
"""
import logging
import sys
from pathlib import Path
from datetime import datetime
# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
import dash
from dash import dcc, html, Input, Output
import plotly.graph_objects as go
# Setup logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
def create_debug_dashboard():
"""Create minimal debug dashboard"""
app = dash.Dash(__name__)
app.layout = html.Div([
html.H1("🔧 Debug Dashboard - Callback Test", className="text-center"),
html.Div([
html.H3(id="debug-time", className="text-center"),
html.H4(id="debug-counter", className="text-center"),
html.P(id="debug-status", className="text-center"),
dcc.Graph(id="debug-chart")
]),
dcc.Interval(
id='debug-interval',
interval=2000, # 2 seconds
n_intervals=0
)
])
@app.callback(
[
Output('debug-time', 'children'),
Output('debug-counter', 'children'),
Output('debug-status', 'children'),
Output('debug-chart', 'figure')
],
[Input('debug-interval', 'n_intervals')]
)
def update_debug_dashboard(n_intervals):
"""Debug callback function"""
try:
logger.info(f"🔧 DEBUG: Callback triggered, interval: {n_intervals}")
current_time = datetime.now().strftime("%H:%M:%S")
counter = f"Updates: {n_intervals}"
status = f"Callback working! Last update: {current_time}"
# Create simple test chart
fig = go.Figure()
fig.add_trace(go.Scatter(
x=list(range(max(0, n_intervals-10), n_intervals + 1)),
y=[i**2 for i in range(max(0, n_intervals-10), n_intervals + 1)],
mode='lines+markers',
name='Debug Data',
line=dict(color='#00ff88')
))
fig.update_layout(
title=f"Debug Chart - Update #{n_intervals}",
template="plotly_dark",
paper_bgcolor='#1e1e1e',
plot_bgcolor='#1e1e1e'
)
logger.info(f"✅ DEBUG: Returning data - time={current_time}, counter={counter}")
return current_time, counter, status, fig
except Exception as e:
logger.error(f"❌ DEBUG: Error in callback: {e}")
import traceback
logger.error(f"Traceback: {traceback.format_exc()}")
return "Error", "Error", "Callback failed", {}
return app
def main():
"""Run the debug dashboard"""
logger.info("🔧 Starting debug dashboard...")
try:
app = create_debug_dashboard()
logger.info("✅ Debug dashboard created")
logger.info("🚀 Starting debug dashboard on http://127.0.0.1:8053")
logger.info("This will test if Dash callbacks work at all")
logger.info("Press Ctrl+C to stop")
app.run(host='127.0.0.1', port=8053, debug=True)
except KeyboardInterrupt:
logger.info("Debug dashboard stopped by user")
except Exception as e:
logger.error(f"❌ Error: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
main()