168 lines
6.7 KiB
Python
168 lines
6.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
云顶之弈阵容推荐器 - 主程序
|
|
"""
|
|
import sys
|
|
import argparse
|
|
import logging
|
|
import os
|
|
|
|
from src.data_provider_demo import main as data_provider_demo
|
|
from src.recommendation_demo import main as recommendation_demo
|
|
from src.interface.cli import main as cli_main
|
|
from src.scoring.scoring_system import TeamScorer
|
|
from src.test_scoring import main as test_scoring
|
|
from src.web import run_server # 导入Web模块
|
|
from src.config import get_global_weights_config
|
|
|
|
# 配置日志
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
)
|
|
logger = logging.getLogger("TFT-Strategist")
|
|
|
|
def main():
|
|
"""主程序入口"""
|
|
parser = argparse.ArgumentParser(description="云顶之弈阵容推荐器")
|
|
|
|
# 添加子命令
|
|
subparsers = parser.add_subparsers(dest="command", help="可用命令")
|
|
|
|
# 数据提供模块演示
|
|
data_parser = subparsers.add_parser("data", help="数据提供模块演示")
|
|
|
|
# 阵容推荐模块演示
|
|
recommend_parser = subparsers.add_parser("recommend", help="阵容推荐模块演示")
|
|
recommend_parser.add_argument("--config", type=str, help="指定配置文件路径")
|
|
|
|
# 命令行界面
|
|
cli_parser = subparsers.add_parser("cli", help="交互式命令行界面")
|
|
cli_parser.add_argument("--population", type=int, help="阵容人口数量")
|
|
cli_parser.add_argument("--results", type=int, help="推荐结果数量")
|
|
cli_parser.add_argument("--level-weight", type=float, help="羁绊等级权重")
|
|
cli_parser.add_argument("--count-weight", type=float, help="羁绊数量权重")
|
|
cli_parser.add_argument("--cost-weight", type=float, help="棋子费用权重")
|
|
cli_parser.add_argument("--config", type=str, help="指定配置文件路径")
|
|
|
|
# 评分模块测试
|
|
scoring_parser = subparsers.add_parser("scoring", help="评分模块测试")
|
|
scoring_parser.add_argument("--config", type=str, help="指定配置文件路径")
|
|
|
|
# 权重配置管理(新增)
|
|
config_parser = subparsers.add_parser("config", help="权重配置管理")
|
|
config_parser.add_argument("--show", action="store_true", help="显示当前权重配置")
|
|
config_parser.add_argument("--set-synergy", nargs=2, metavar=("NAME", "WEIGHT"), help="设置羁绊权重")
|
|
config_parser.add_argument("--set-chess", nargs=2, metavar=("NAME", "WEIGHT"), help="设置棋子权重")
|
|
config_parser.add_argument("--set-base", nargs=2, metavar=("PARAM", "WEIGHT"), help="设置基础权重参数")
|
|
config_parser.add_argument("--config", type=str, help="指定配置文件路径")
|
|
|
|
# Web界面
|
|
web_parser = subparsers.add_parser("web", help="启动Web界面")
|
|
web_parser.add_argument("--host", type=str, default="0.0.0.0", help="服务器主机地址")
|
|
web_parser.add_argument("--port", type=int, default=5000, help="服务器端口")
|
|
web_parser.add_argument("--dev", action="store_true", help="开发模式")
|
|
web_parser.add_argument("--config", type=str, help="指定配置文件路径")
|
|
|
|
# 解析命令行参数
|
|
args = parser.parse_args()
|
|
|
|
# 根据子命令执行相应功能
|
|
if args.command == "data":
|
|
logger.info("启动数据提供模块演示")
|
|
# 调用数据提供模块演示函数
|
|
data_provider_demo()
|
|
|
|
elif args.command == "recommend":
|
|
logger.info("启动阵容推荐模块演示")
|
|
# 调用阵容推荐模块演示函数
|
|
recommendation_demo(config_path=getattr(args, 'config', None))
|
|
|
|
elif args.command == "cli":
|
|
logger.info("启动交互式命令行界面")
|
|
# 将命令行参数传递给cli_main函数
|
|
return cli_main(
|
|
population=args.population,
|
|
results=args.results,
|
|
level_weight=args.level_weight,
|
|
count_weight=args.count_weight,
|
|
cost_weight=args.cost_weight,
|
|
config_path=getattr(args, 'config', None)
|
|
)
|
|
|
|
elif args.command == "scoring":
|
|
logger.info("启动评分模块测试")
|
|
test_scoring(config_path=getattr(args, 'config', None))
|
|
|
|
elif args.command == "config":
|
|
# 获取权重配置
|
|
config_path = getattr(args, 'config', None)
|
|
weights_config = get_global_weights_config(config_path)
|
|
|
|
if args.show:
|
|
# 显示当前配置
|
|
print("\n=== 当前权重配置 ===")
|
|
|
|
# 基础权重
|
|
print("\n基础权重:")
|
|
for key, value in weights_config.get_base_weights().items():
|
|
print(f" {key}: {value}")
|
|
|
|
# 羁绊权重
|
|
print("\n羁绊权重:")
|
|
for key, value in sorted(weights_config.get_synergy_weights().items()):
|
|
print(f" {key}: {value}")
|
|
|
|
# 棋子权重
|
|
print("\n棋子权重:")
|
|
for key, value in sorted(weights_config.get_chess_weights().items()):
|
|
print(f" {key}: {value}")
|
|
|
|
# 羁绊等级权重
|
|
print("\n羁绊等级权重:")
|
|
for key, value in sorted(weights_config.get_synergy_level_weights().items(),
|
|
key=lambda x: int(x[0])):
|
|
print(f" {key}: {value}")
|
|
|
|
# 棋子费用权重
|
|
print("\n棋子费用权重:")
|
|
for key, value in sorted(weights_config.get_cost_weights().items(),
|
|
key=lambda x: int(x[0])):
|
|
print(f" {key}: {value}")
|
|
|
|
elif args.set_synergy:
|
|
# 设置羁绊权重
|
|
name, weight = args.set_synergy
|
|
weights_config.set_synergy_weight(name, float(weight))
|
|
print(f"已设置羁绊 [{name}] 的权重为 {weight}")
|
|
|
|
elif args.set_chess:
|
|
# 设置棋子权重
|
|
name, weight = args.set_chess
|
|
weights_config.set_chess_weight(name, float(weight))
|
|
print(f"已设置棋子 [{name}] 的权重为 {weight}")
|
|
|
|
elif args.set_base:
|
|
# 设置基础权重参数
|
|
param, weight = args.set_base
|
|
weights_config.set_base_weight(param, float(weight))
|
|
print(f"已设置基础权重参数 [{param}] 的值为 {weight}")
|
|
|
|
else:
|
|
config_parser.print_help()
|
|
|
|
elif args.command == "web":
|
|
logger.info("启动Web界面")
|
|
# 调用Web服务器
|
|
run_server(
|
|
host=args.host,
|
|
port=args.port,
|
|
dev_mode=args.dev,
|
|
config_path=getattr(args, 'config', None)
|
|
)
|
|
|
|
else:
|
|
parser.print_help()
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main()) |