Fix Markov simulation chart display issue

- Fix circular import issue by moving simulation_manager to app/__init__.py
- Enhance get_wealth_evolution to include inequality metrics data
- Add get_inequality_evolution method for complete chart data
- Update API to return top10_shares and capital_shares in evolution data
- Modify onSimulationComplete to fetch and populate charts with complete data
- Fix simulation threading to properly mark completion state
- Add test script to verify chart data generation

The charts now properly display simulation results by fetching complete
evolution data when simulation completes, resolving the empty diagrams issue.
This commit is contained in:
2025-08-24 19:44:24 +02:00
parent bec913a599
commit 27e185c2a6
10 changed files with 106 additions and 9 deletions

34
test_charts.py Normal file
View File

@@ -0,0 +1,34 @@
import requests
import json
import time
# Test simulation workflow
data = {'r_rate': 0.05, 'g_rate': 0.03, 'num_agents': 50, 'iterations': 200}
# Create simulation
create_resp = requests.post('http://localhost:5000/api/simulation', json=data)
sim_id = create_resp.json()['simulation_id']
print('Created simulation:', sim_id)
# Start simulation
start_resp = requests.post(f'http://localhost:5000/api/simulation/{sim_id}/start')
print('Started simulation:', start_resp.json()['status'])
# Wait for completion
time.sleep(3)
# Get evolution data
data_resp = requests.get(f'http://localhost:5000/api/simulation/{sim_id}/data?include_evolution=true')
result = data_resp.json()
print('\nFinal metrics:')
print(f' Iterations: {len(result["evolution"]["iterations"])}')
print(f' Final Gini: {result["evolution"]["gini_coefficients"][-1]:.3f}')
print(f' Final Total Wealth: ${result["evolution"]["total_wealth"][-1]:.2f}')
print(f' Top 10% data points: {len(result["evolution"].get("top10_shares", []))}')
print(f' Capital share data points: {len(result["evolution"].get("capital_shares", []))}')
if len(result["evolution"]["gini_coefficients"]) > 0:
print('\n✅ Charts should now be populated with data!')
else:
print('\n❌ No data available for charts')