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 with distribution data_resp = requests.get(f'http://localhost:5000/api/simulation/{sim_id}/data?include_evolution=true&include_distribution=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", []))}') # Test wealth distribution if 'distribution' in result: dist_data = result['distribution'] print(f'\nWealth Distribution:') print(f' Bins: {dist_data.get("bins", 0)}') print(f' Labels: {len(dist_data.get("labels", []))}') print(f' Counts: {len(dist_data.get("counts", []))}') if dist_data.get('labels') and dist_data.get('counts'): print('\n Distribution Histogram:') for label, count in zip(dist_data['labels'], dist_data['counts']): bar = '█' * max(1, count // 2) # Visual bar representation print(f' {label:<20} {count:>3} agents {bar}') print('\n✅ Wealth distribution chart should now work!') else: print('\n❌ No distribution data available') else: print('\n❌ No distribution data in response') # Test dedicated distribution endpoint print('\nTesting dedicated distribution endpoint...') dist_resp = requests.get(f'http://localhost:5000/api/simulation/{sim_id}/distribution?bins=8') if dist_resp.status_code == 200: dist_result = dist_resp.json() hist_data = dist_result.get('histogram', {}) print(f' Total agents: {hist_data.get("total_agents", 0)}') print(f' Bins: {hist_data.get("bins", 0)}') print(f' Labels count: {len(hist_data.get("labels", []))}') print(f' Counts sum: {sum(hist_data.get("counts", []))}') print('\n✅ Distribution endpoint working!') else: print(f'\n❌ Distribution endpoint failed: {dist_resp.status_code}') if len(result["evolution"]["gini_coefficients"]) > 0: print('\n🎯 All charts should now be populated with data!') else: print('\n❌ No data available for charts')