"""
活态传承系数B21计算模块

活态传承系数B21 = 传承人等级系数 × 0.4 + 教学传播频次 × 0.3 + 跨界合作深度 × 0.3

"""




class LivingHeritageB21Calculator:
    """活态传承系数B21计算器"""
    
    def __init__(self):
        """初始化计算器"""
        pass
    
    def calculate_living_heritage_b21(self,
                                     inheritor_level_coefficient: float,
                                     teaching_frequency: float,
                                     cross_border_depth: float) -> float:
        """
        计算活态传承系数B21
        
        
        活态传承系数B21 = 传承人等级系数 × 0.4 + 教学传播频次 × 0.3 + 跨界合作深度 × 0.3
        
        args:
            inheritor_level_coefficient: 传承人等级系数 (用户填写)
            teaching_frequency: 教学传播频次 (用户填写)
            cross_border_depth: 跨界合作深度 (用户填写)
            
       return:
            float: 活态传承系数B21
        """
        #
        living_heritage = (inheritor_level_coefficient * 0.4 + 
                          teaching_frequency * 0.3 + 
                          cross_border_depth * 0.3)
        
        return living_heritage
    
    def calculate_inheritor_level_coefficient(self, inheritor_level: str) -> float:
        """
        计算传承人等级系数
        
        传承人等级评分标准：
        - 国家级传承人: 1分
        - 省级传承人: 0.7分
        - 市级传承人: .44分

        
        args:
            inheritor_level: 传承人等级 (用户填写)
            
       return:
            float: 传承人等级系数
        """
        level_scores = {
            "国家级传承人": 1.0,
            "省级传承人": 0.7,
            "市级传承人": 0.4,
        }
        
        return level_scores.get(inheritor_level, 0.4)
    
    def calculate_teaching_frequency(self, 
                                   offline_sessions: int,
                                   douyin_views: int = 0,
                                   kuaishou_views: int = 0,
                                   bilibili_views: int = 0) -> float:
        """
        计算教学传播频次
        
        教学传播频次 = 线下传习次数 × 0.6 + 线上课程点击量（万） × 0.4
        
        线下传习次数统计规范：
        1) 单次活动标准：传承人主导、时长≥2小时、参与人数≥5人
        2) 频次计算：按自然年度累计，同一内容重复培训不计入
        
        线上课程折算：
        - 抖音/快手播放量按100:1折算为学习人次
        - B站课程按50:1折算
        
        args:
            offline_sessions: 线下传习次数（符合标准的活动次数）
            douyin_views: 抖音播放量
            kuaishou_views: 快手播放量  
            bilibili_views: B站播放量
            
        returns:
            float: 教学传播频次评分
        """
        # 线下传习次数权重计算
        offline_score = offline_sessions * 0.6
        
        # 线上课程点击量折算
        # 抖音/快手按100:1折算
        douyin_kuaishou_learning_sessions = (douyin_views + kuaishou_views) / 100
        # B站按50:1折算
        bilibili_learning_sessions = bilibili_views / 50
        
        # 线上总学习人次（万）
        online_learning_sessions_10k = (douyin_kuaishou_learning_sessions + bilibili_learning_sessions) / 10000
        
        # 线上课程权重计算
        online_score = online_learning_sessions_10k * 0.4
        
        # 总教学传播频次
        teaching_frequency = offline_score + online_score
        
        return teaching_frequency
def cross_border_depth_dict(border_depth: str) -> float:
    cross_border_depth_scores = {
        "品牌联名": 0.3,
        "科技载体": 0.5,
        "国家外交礼品": 1,
    }
    return cross_border_depth_scores.get(border_depth, 0.3)
    

# 示例使用
if __name__ == "__main__":
    calculator = LivingHeritageB21Calculator()
    
    # 示例数据
    inheritor_level = "国家级传承人"  # 传承人等级 (用户填写)
    cross_border_depth = 50.0
    # 教学传播频次数据
    offline_sessions = 20  # 线下传习次数（符合标准：传承人主导、时长≥2小时、参与人数≥5人）
    douyin_views = 10000000  # 抖音播放量
    kuaishou_views = 0  # 快手播放量
    bilibili_views = 0  # B站播放量
    

    
    # 计算各项指标
    inheritor_level_coefficient = calculator.calculate_inheritor_level_coefficient(inheritor_level)
    teaching_frequency = calculator.calculate_teaching_frequency(
        offline_sessions=offline_sessions,
        douyin_views=douyin_views,
        kuaishou_views=kuaishou_views,
        bilibili_views=bilibili_views
    )
    print(teaching_frequency)

    # 计算活态传承系数B21
    living_heritage_b21 = calculator.calculate_living_heritage_b21(
        1, teaching_frequency, 0.3
    )
    
    print(f"传承人等级系数: {inheritor_level_coefficient:.2f}")
    print(f"教学传播频次: {teaching_frequency:.2f}")
    print(f"  - 线下传习次数: {offline_sessions}次")
    print(f"  - 抖音播放量: {douyin_views:,}次")
    print(f"  - 快手播放量: {kuaishou_views:,}次") 
    print(f"  - B站播放量: {bilibili_views:,}次")
    print(f"跨界合作深度: {cross_border_depth:.2f}")
    print(f"活态传承系数B21: {living_heritage_b21:.4f}")


