""" 测试阵容推荐功能 """ import json import requests def test_recommendation(): """ 测试阵容推荐功能 """ # 构建请求数据 data = { "population": 9, "num_results": 3, "base_weights": { "synergy_level_weight": 1.5, "synergy_count_weight": 0.8, "chess_cost_weight": 0.3 }, "synergy_weights": { "重装战士": 2.0, "斗士": 1.8 }, "chess_weights": { "盖伦": 2.0, "赛娜": 2.5 }, "required_synergies": [], "required_chess": [] } # 发送POST请求 url = "http://localhost:5000/api/recommend" headers = {"Content-Type": "application/json"} try: response = requests.post(url, json=data, headers=headers) # 检查响应状态码 if response.status_code == 200: result = response.json() print("请求成功!") print(f"状态: {result['status']}") print(f"推荐阵容数量: {len(result['results'])}") # 打印第一个阵容的详细信息 if result['results']: first_team = result['results'][0] print(f"\n第一个推荐阵容评分: {first_team['score']}") print("\n棋子列表:") for chess in first_team['chess_list']: print(f" {chess['name']} ({chess['cost']}费)") print("\n激活羁绊:") for synergy in first_team['active_synergies']: print(f" {synergy['name']} (等级 {synergy['level']})") else: print(f"请求失败: {response.status_code}") print(response.text) except Exception as e: print(f"发生错误: {str(e)}") if __name__ == "__main__": test_recommendation()