Add: Advanced diagnostic tools for production debugging

New Diagnostic Endpoints:
- /test-simulation: Full simulation flow testing
- /api/test-websocket: WebSocket connectivity testing

Enhanced Browser Testing:
- testWebSocket(): Test real-time communication
- testDistributionChart(): Enhanced chart diagnostics
- WebSocket test message handler for live testing

Debugging Improvements:
- Real-time WebSocket message testing
- Manual chart update testing
- Complete simulation data flow validation
- End-to-end connectivity verification

These tools will help identify the exact failure point
in the wealth distribution histogram issue.
This commit is contained in:
2025-08-24 19:01:01 +00:00
parent 97e9e18ee5
commit dc6204068f
3 changed files with 162 additions and 0 deletions

View File

@@ -18,6 +18,42 @@ from app import simulation_manager
api_bp = Blueprint('api', __name__)
@api_bp.route('/test-websocket', methods=['GET'])
def test_websocket():
"""
Test WebSocket connectivity and emit test data.
Returns:
JSON response indicating WebSocket test status
"""
try:
# Emit a test message to all connected clients
test_data = {
'test': True,
'message': 'WebSocket test from server',
'timestamp': time.time(),
'distribution': {
'labels': ['Test $0-100', 'Test $100-200', 'Test $200-300'],
'counts': [3, 5, 2]
}
}
socketio.emit('websocket_test', test_data, broadcast=True)
return jsonify({
'status': 'success',
'message': 'WebSocket test message sent',
'test_data': test_data
})
except Exception as e:
current_app.logger.error(f"WebSocket test error: {str(e)}")
return jsonify({
'status': 'error',
'message': f'WebSocket test failed: {str(e)}'
}), 500
@api_bp.route('/simulation', methods=['POST'])
def create_simulation():
"""