"""
文化价值B2

文化价值B2 = 活态传承系数B21 × 0.6 + (纹样基因值B22 / 10) × 0.4

"""

from typing import Dict, List, Optional
try:
    # 相对导入（当作为包使用时）
    from .sub_formulas.living_heritage_b21 import LivingHeritageB21Calculator
    from .sub_formulas.pattern_gene_b22 import PatternGeneB22Calculator
except ImportError:
    # 绝对导入（当直接运行时）
    from sub_formulas.living_heritage_b21 import LivingHeritageB21Calculator
    from sub_formulas.pattern_gene_b22 import PatternGeneB22Calculator


class CulturalValueB2Calculator:
    """文化价值B2计算器"""
    
    def __init__(self):
        """初始化计算器"""
        self.living_heritage_calculator = LivingHeritageB21Calculator()
        self.pattern_gene_calculator = PatternGeneB22Calculator()
    
    def calculate_cultural_value_b2(self,
                                   living_heritage_b21: float,
                                   pattern_gene_b22: float) -> float:
        """
        计算文化价值B2
        文化价值B2 = 活态传承系数B21 × 0.6 + (纹样基因值B22 / 10) × 0.4
        
        args:
            living_heritage_b21: 活态传承系数B21 (系统计算)
            pattern_gene_b22: 纹样基因值B22 (系统计算)
            
        return:
            float: 文化价值B2
        """
        cultural_value = living_heritage_b21 * 0.6 + (pattern_gene_b22 / 10) * 0.4
        
        return cultural_value
    
    def calculate_complete_cultural_value_b2(self, input_data: Dict) -> Dict:
        """
        计算完整的文化价值B2，包含所有子公式
        
        args:
            input_data: 输入数据字典，包含所有必要的参数
            
        return:
            Dict: 包含所有中间计算结果和最终结果的字典
        """
        # 计算活态传承系数B21
        teaching_frequency = self.living_heritage_calculator.calculate_teaching_frequency(
            input_data["offline_sessions"],
            input_data["douyin_views"],
            input_data["kuaishou_views"],
            input_data["bilibili_views"]
        )
        living_heritage_b21 = self.living_heritage_calculator.calculate_living_heritage_b21(
            input_data['inheritor_level_coefficient'],
            teaching_frequency,
            input_data['cross_border_depth']
        )
        
        # 计算纹样基因值B22
        pattern_gene_b22 = self.pattern_gene_calculator.calculate_pattern_gene_b22(
            input_data['structure_complexity'],
            input_data['normalized_entropy'],
            input_data['historical_inheritance']
        )
        
        # 计算文化价值B2
        cultural_value_b2 = self.calculate_cultural_value_b2(
            living_heritage_b21,
            pattern_gene_b22
        )
        
        return {
            'living_heritage_b21': living_heritage_b21,
            'pattern_gene_b22': pattern_gene_b22,
            'cultural_value_b2': cultural_value_b2
        }


# 示例使用
if __name__ == "__main__":

    calculator = CulturalValueB2Calculator()
    
    # 示例数据
    input_data = {
        # 活态传承系数B21相关参数
        'inheritor_level_coefficient': 10.0,  # 传承人等级系数
        'teaching_frequency': 7.0,            # 教学传播频次
        'cross_border_depth': 7.0,            # 跨界合作深度

        "offline_sessions": 1,
        "douyin_views": 2,
        "kuaishou_views": 3,
        "bilibili_views": 4,
        # 纹样基因值B22相关参数
        'structure_complexity': 0.75,         # 结构复杂度SC
        'normalized_entropy': 0.85,          # 归一化信息熵H
        'historical_inheritance': 0.80        # 历史传承度HI
    }
    
    # 计算文化价值B2
    result = calculator.calculate_complete_cultural_value_b2(input_data)
    
    print("文化价值B2计算结果:")
    print(f"活态传承系数B21: {result['living_heritage_b21']:.4f}")
    print(f"纹样基因值B22: {result['pattern_gene_b22']:.4f}")
    print(f"文化价值B2: {result['cultural_value_b2']:.4f}")
