"""报告获取测试脚本""" import requests import json # 配置 CLOUD_URL = "http://127.0.0.1:5000/api/report" API_KEY = "edge_device_key_001" DEVICE_ID = "test_edge_device_001" def test_report(): """测试报告获取""" print("="*60) print("📊 云端报告获取测试") print("="*60) url = f"{CLOUD_URL}/{DEVICE_ID}" headers = {"Authorization": f"Bearer {API_KEY}"} print(f"URL: {url}") print(f"设备ID: {DEVICE_ID}") print("-" * 60) try: response = requests.get(url, headers=headers, timeout=30) print(f"\n状态码: {response.status_code}") if response.status_code == 200: report = response.json() print("\n📄 报告摘要:") print(f" 设备ID: {report.get('device_id')}") period = report.get('period', {}) print(f" 分析周期: {period.get('start')} ~ {period.get('end')}") print(f" 数据天数: {period.get('days')}") print(f" 最新风险评分: {report.get('latest_risk_score', 0):.3f}") print(f" 风险等级: {report.get('risk_level')}") if 'medical_advice' in report and report['medical_advice']: print(f"\n 医学建议:") for advice in report['medical_advice']: print(f" - {advice}") print("\n✅ 报告获取成功!") print(f"\n完整报告路径: {report.get('report_path')}") # 保存到本地 local_path = f"artifacts/cloud/report_{DEVICE_ID}.json" with open(local_path, "w", encoding='utf-8') as f: json.dump(report, f, indent=2, ensure_ascii=False) print(f"本地副本: {local_path}") print("="*60) return True else: print(f"\n❌ 获取失败: {response.json().get('error')}") return False except Exception as e: print(f"\n❌ 请求失败: {e}") return False if __name__ == '__main__': success = test_report() exit(0 if success else 1)