gogo2/debug_dashboard_issue.py
Dobromir Popov 7e4b29fdc2 pivot points
2025-05-29 21:03:26 +03:00

142 lines
4.5 KiB
Python

#!/usr/bin/env python3
"""
Debug Dashboard Data Flow
Check if the dashboard is receiving data and updating properly.
"""
import sys
import logging
import time
import requests
import json
from pathlib import Path
# Add project root to path
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))
from core.config import get_config, setup_logging
from core.data_provider import DataProvider
# Setup logging
setup_logging()
logger = logging.getLogger(__name__)
def test_data_provider():
"""Test if data provider is working"""
logger.info("=== TESTING DATA PROVIDER ===")
try:
# Test data provider
data_provider = DataProvider()
# Test current price
logger.info("Testing current price retrieval...")
current_price = data_provider.get_current_price('ETH/USDT')
logger.info(f"Current ETH/USDT price: ${current_price}")
# Test historical data
logger.info("Testing historical data retrieval...")
df = data_provider.get_historical_data('ETH/USDT', '1m', limit=5, refresh=True)
if df is not None and not df.empty:
logger.info(f"Historical data: {len(df)} rows")
logger.info(f"Latest price: ${df['close'].iloc[-1]:.2f}")
logger.info(f"Latest timestamp: {df.index[-1]}")
else:
logger.error("No historical data available!")
return True
except Exception as e:
logger.error(f"Data provider test failed: {e}")
return False
def test_dashboard_api():
"""Test if dashboard API is responding"""
logger.info("=== TESTING DASHBOARD API ===")
try:
# Test main dashboard page
response = requests.get("http://127.0.0.1:8050", timeout=5)
logger.info(f"Dashboard main page status: {response.status_code}")
if response.status_code == 200:
logger.info("Dashboard is responding")
# Check if there are any JavaScript errors in the page
content = response.text
if 'error' in content.lower():
logger.warning("Possible errors found in dashboard HTML")
return True
else:
logger.error(f"Dashboard returned status {response.status_code}")
return False
except Exception as e:
logger.error(f"Dashboard API test failed: {e}")
return False
def test_dashboard_callbacks():
"""Test dashboard callback updates"""
logger.info("=== TESTING DASHBOARD CALLBACKS ===")
try:
# Test the callback endpoint (this would need to be exposed)
# For now, just check if the dashboard is serving content
# Wait a bit and check again
time.sleep(2)
response = requests.get("http://127.0.0.1:8050", timeout=5)
if response.status_code == 200:
logger.info("Dashboard callbacks appear to be working")
return True
else:
logger.error("Dashboard callbacks may be stuck")
return False
except Exception as e:
logger.error(f"Dashboard callback test failed: {e}")
return False
def main():
"""Run all diagnostic tests"""
logger.info("DASHBOARD DIAGNOSTIC TOOL")
logger.info("=" * 50)
results = {
'data_provider': test_data_provider(),
'dashboard_api': test_dashboard_api(),
'dashboard_callbacks': test_dashboard_callbacks()
}
logger.info("=" * 50)
logger.info("DIAGNOSTIC RESULTS:")
for test_name, result in results.items():
status = "PASS" if result else "FAIL"
logger.info(f" {test_name}: {status}")
if all(results.values()):
logger.info("All tests passed - issue may be browser-side")
logger.info("Try refreshing the dashboard at http://127.0.0.1:8050")
else:
logger.error("Issues detected - check logs above")
logger.info("Recommendations:")
if not results['data_provider']:
logger.info(" - Check internet connection")
logger.info(" - Verify Binance API is accessible")
if not results['dashboard_api']:
logger.info(" - Restart the dashboard")
logger.info(" - Check if port 8050 is blocked")
if not results['dashboard_callbacks']:
logger.info(" - Dashboard may be frozen")
logger.info(" - Consider restarting")
if __name__ == "__main__":
main()