Remove unnecessary debug outputs for production performance
This commit is contained in:
@@ -139,19 +139,29 @@ def start_simulation(simulation_id: str):
|
||||
try:
|
||||
# Run simulation with progress updates
|
||||
total_iterations = simulation.parameters.iterations
|
||||
last_update_time = time.time()
|
||||
update_interval = max(0.1, min(1.0, 1000 / total_iterations)) # Dynamic update interval
|
||||
|
||||
for i in range(total_iterations):
|
||||
if not simulation.is_running:
|
||||
break
|
||||
|
||||
snapshot = simulation.step()
|
||||
|
||||
# Emit progress update every 10 iterations or at milestones
|
||||
if i % 10 == 0 or i == total_iterations - 1:
|
||||
# Get distribution data for real-time chart updates
|
||||
bin_labels, bin_counts = simulation.get_wealth_histogram(10)
|
||||
# Emit progress update at dynamic intervals for better performance
|
||||
current_time = time.time()
|
||||
if (i % max(1, total_iterations // 100) == 0 or # Every 1% of iterations
|
||||
i == total_iterations - 1 or # Last iteration
|
||||
current_time - last_update_time >= update_interval): # Time-based update
|
||||
|
||||
# Debug logging
|
||||
print(f"DEBUG: Sending distribution data - labels: {bin_labels}, counts: {bin_counts}")
|
||||
# Get distribution data for real-time chart updates (but less frequently)
|
||||
distribution_data = None
|
||||
if i % max(1, total_iterations // 20) == 0 or i == total_iterations - 1:
|
||||
bin_labels, bin_counts = simulation.get_wealth_histogram(8) # Reduced bins for performance
|
||||
distribution_data = {
|
||||
'labels': bin_labels,
|
||||
'counts': bin_counts
|
||||
}
|
||||
|
||||
progress_data = {
|
||||
'simulation_id': simulation_id,
|
||||
@@ -161,18 +171,19 @@ def start_simulation(simulation_id: str):
|
||||
'total_wealth': snapshot.total_wealth,
|
||||
'gini_coefficient': snapshot.gini_coefficient,
|
||||
'capital_share': snapshot.capital_share,
|
||||
'wealth_concentration_top10': snapshot.wealth_concentration_top10,
|
||||
'distribution': {
|
||||
'labels': bin_labels,
|
||||
'counts': bin_counts
|
||||
}
|
||||
'wealth_concentration_top10': snapshot.wealth_concentration_top10
|
||||
}
|
||||
|
||||
# Only include distribution data when we have it
|
||||
if distribution_data:
|
||||
progress_data['distribution'] = distribution_data
|
||||
|
||||
socketio.emit('simulation_progress', progress_data,
|
||||
room=f'simulation_{simulation_id}')
|
||||
last_update_time = current_time
|
||||
|
||||
# Small delay to allow real-time visualization
|
||||
time.sleep(0.01)
|
||||
# Adaptive delay based on performance
|
||||
time.sleep(max(0.001, 0.01 * (total_iterations / 1000)))
|
||||
|
||||
# Mark as completed
|
||||
simulation.is_running = False
|
||||
@@ -367,7 +378,7 @@ def get_wealth_distribution(simulation_id: str):
|
||||
bin_labels, bin_counts = simulation.get_wealth_histogram(num_bins)
|
||||
|
||||
# Debug logging
|
||||
print(f"DEBUG: Distribution endpoint - labels: {bin_labels}, counts: {bin_counts}, bins: {num_bins}")
|
||||
# print(f"DEBUG: Distribution endpoint - labels: {bin_labels}, counts: {bin_counts}, bins: {num_bins}")
|
||||
|
||||
response_data = {
|
||||
'simulation_id': simulation_id,
|
||||
@@ -379,7 +390,7 @@ def get_wealth_distribution(simulation_id: str):
|
||||
}
|
||||
}
|
||||
|
||||
print(f"DEBUG: Distribution endpoint response: {response_data}")
|
||||
# print(f"DEBUG: Distribution endpoint response: {response_data}")
|
||||
return jsonify(response_data)
|
||||
|
||||
except Exception as e:
|
||||
|
@@ -191,10 +191,14 @@ def test_simulation():
|
||||
def debug_info():
|
||||
"""
|
||||
Debug endpoint to verify deployment and test functionality.
|
||||
|
||||
Returns:
|
||||
JSON response with debug information
|
||||
Only available in development mode.
|
||||
"""
|
||||
from flask import current_app
|
||||
|
||||
# Only allow debug endpoint in development mode
|
||||
if not current_app.config.get('DEVELOPMENT', False):
|
||||
return jsonify({'error': 'Debug endpoint not available in production'}), 403
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
from app.models.economic_model import EconomicSimulation, SimulationParameters
|
||||
|
Reference in New Issue
Block a user