#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
增强版优先级算法测试脚本
"""

import sys
import os
from datetime import datetime

# 添加路径
sys.path.append(os.path.dirname(__file__))

try:
    from src.jixia.debates.enhanced_priority_algorithm import EnhancedPriorityAlgorithm
    print("✅ 算法导入成功！")
    
    # 创建算法实例
    algorithm = EnhancedPriorityAlgorithm()
    print("✅ 算法实例创建成功！")
    
    # 测试基本功能
    context = {
        "current_stage": "转",
        "stage_progress": 5,
        "max_progress": 36,
        "time_remaining": 0.7,
        "topic_keywords": ["投资", "AI", "风险"],
        "positive_team_score": 0.6,
        "negative_team_score": 0.4
    }
    
    recent_speeches = [
        {
            "speaker": "正1",
            "content": "根据最新数据显示，AI投资确实带来了显著的收益增长",
            "timestamp": datetime.now().isoformat(),
            "team": "positive"
        },
        {
            "speaker": "反1", 
            "content": "但是我们不能忽视其中的巨大风险，这种投资策略过于激进",
            "timestamp": datetime.now().isoformat(),
            "team": "negative"
        }
    ]
    
    available_speakers = ["正1", "正2", "正3", "正4", "反1", "反2", "反3", "反4"]
    
    # 测试优先级计算
    print("\n🧪 测试优先级计算...")
    for speaker in available_speakers[:4]:  # 测试前4个
        priority = algorithm.calculate_speaker_priority(speaker, context, recent_speeches)
        print(f"  {speaker}: {priority:.3f}")
    
    # 测试获取下一发言者
    print("\n🎯 测试获取下一发言者...")
    next_speaker, score, analysis = algorithm.get_next_speaker(available_speakers, context, recent_speeches)
    print(f"推荐发言者: {next_speaker}")
    print(f"优先级分数: {score:.3f}")
    
    # 测试算法状态
    print("\n📊 算法状态报告:")
    status = algorithm.get_algorithm_status()
    print(f"版本: {status['version']}")
    print(f"跟踪发言者数量: {status['total_speakers_tracked']}")
    print(f"算法组件: {status['algorithm_components']}")
    
    print("\n🎉 所有测试通过！增强版优先级算法 v2.1.0 运行正常！")
    
except ImportError as e:
    print(f"❌ 导入错误: {e}")
except Exception as e:
    print(f"❌ 运行错误: {e}")
    import traceback
    traceback.print_exc()