Merge branch 'main' of https://git.1024tool.vip/zfc/guzhi
This commit is contained in:
commit
b46c1a349b
@ -12,15 +12,19 @@ from app.schemas.valuation import (
|
|||||||
)
|
)
|
||||||
from app.schemas.base import Success, SuccessExtra
|
from app.schemas.base import Success, SuccessExtra
|
||||||
from app.utils.app_user_jwt import get_current_app_user_id
|
from app.utils.app_user_jwt import get_current_app_user_id
|
||||||
|
from app.utils.calculation_engine.cultural_value_b2 import CulturalValueB2Calculator
|
||||||
from app.utils.calculation_engine.economic_value_b1.economic_value_b1 import EconomicValueB1Calculator
|
from app.utils.calculation_engine.economic_value_b1.economic_value_b1 import EconomicValueB1Calculator
|
||||||
from app.utils.calculation_engine.economic_value_b1.sub_formulas.basic_value_b11 import calculate_popularity_score, \
|
from app.utils.calculation_engine.economic_value_b1.sub_formulas.basic_value_b11 import calculate_popularity_score, \
|
||||||
calculate_infringement_score, calculate_patent_usage_score
|
calculate_infringement_score, calculate_patent_usage_score
|
||||||
from app.utils.calculation_engine.economic_value_b1.sub_formulas.traffic_factor_b12 import calculate_search_index_s1
|
from app.utils.calculation_engine.economic_value_b1.sub_formulas.traffic_factor_b12 import calculate_search_index_s1
|
||||||
|
from app.utils.calculation_engine.risk_adjustment_b3 import RiskAdjustmentB3Calculator
|
||||||
|
|
||||||
|
|
||||||
from app.models.esg import ESG
|
from app.models.esg import ESG
|
||||||
from app.models.industry import Industry
|
from app.models.industry import Industry
|
||||||
from app.models.policy import Policy
|
from app.models.policy import Policy
|
||||||
|
|
||||||
|
|
||||||
app_valuations_router = APIRouter(tags=["用户端估值评估"])
|
app_valuations_router = APIRouter(tags=["用户端估值评估"])
|
||||||
|
|
||||||
|
|
||||||
@ -35,8 +39,11 @@ async def calculate_valuation(
|
|||||||
根据用户提交的估值评估数据,调用计算引擎进行经济价值B1计算
|
根据用户提交的估值评估数据,调用计算引擎进行经济价值B1计算
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# 创建计算器实例
|
|
||||||
calculator = EconomicValueB1Calculator()
|
calculator_by_b1 = EconomicValueB1Calculator()
|
||||||
|
calculator_by_b2 = CulturalValueB2Calculator()
|
||||||
|
# 风险调整系数B3
|
||||||
|
calculator_by_b3 = RiskAdjustmentB3Calculator()
|
||||||
|
|
||||||
# 根据行业查询 ESG 基准分(优先用行业名称匹配,如用的是行业代码就把 name 改成 code)
|
# 根据行业查询 ESG 基准分(优先用行业名称匹配,如用的是行业代码就把 name 改成 code)
|
||||||
esg_obj = await ESG.filter(name=data.industry).first()
|
esg_obj = await ESG.filter(name=data.industry).first()
|
||||||
@ -50,17 +57,26 @@ async def calculate_valuation(
|
|||||||
# 根据行业查询 政策匹配度
|
# 根据行业查询 政策匹配度
|
||||||
policy_obj = await Policy.filter(name=data.industry).first()
|
policy_obj = await Policy.filter(name=data.industry).first()
|
||||||
policy_match_score = policy_obj.score
|
policy_match_score = policy_obj.score
|
||||||
# 提取计算参数
|
# 提取 经济价值B1 计算参数
|
||||||
input_data = _extract_calculation_params(data)
|
input_data_by_b1 = _extract_calculation_params_b1(data)
|
||||||
# ESG关联价值 ESG分 (0-10分)
|
# ESG关联价值 ESG分 (0-10分)
|
||||||
input_data["esg_score"] = esg_score
|
input_data_by_b1["esg_score"] = esg_score
|
||||||
# 行业修正系数I
|
# 行业修正系数I
|
||||||
input_data["industry_coefficient"] = fix_num_score
|
input_data_by_b1["industry_coefficient"] = fix_num_score
|
||||||
# 政策匹配度
|
# 政策匹配度
|
||||||
input_data["policy_match_score"] = policy_match_score
|
input_data_by_b1["policy_match_score"] = policy_match_score
|
||||||
|
|
||||||
# 调用计算引擎
|
# 提取 文化价值B2 计算参数
|
||||||
calculation_result = calculator.calculate_complete_economic_value_b1(input_data)
|
input_data_by_b2 = _extract_calculation_params_b2(data)
|
||||||
|
# 提取 风险调整系数B3 计算参数
|
||||||
|
input_data_by_b3 = _extract_calculation_params_b3(data)
|
||||||
|
|
||||||
|
# 调用 经济价值B1 计算引擎
|
||||||
|
calculation_result_by_b1 = calculator_by_b1.calculate_complete_economic_value_b1(input_data_by_b1)
|
||||||
|
# 调用 文化价值B2 计算引擎
|
||||||
|
calculation_result_by_b2 = calculator_by_b2.calculate_complete_cultural_value_b2(input_data_by_b2)
|
||||||
|
# 调用 风险调整系数B3 计算引擎
|
||||||
|
calculation_result_by_b3 = calculator_by_b3.calculate_complete_risky_value_b3(input_data_by_b3)
|
||||||
|
|
||||||
# 创建估值评估记录
|
# 创建估值评估记录
|
||||||
result = await user_valuation_controller.create_valuation(
|
result = await user_valuation_controller.create_valuation(
|
||||||
@ -78,7 +94,7 @@ async def calculate_valuation(
|
|||||||
raise HTTPException(status_code=400, detail=f"计算失败: {str(e)}")
|
raise HTTPException(status_code=400, detail=f"计算失败: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
def _extract_calculation_params(data: UserValuationCreate) -> Dict[str, Any]:
|
def _extract_calculation_params_b1(data: UserValuationCreate) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
从用户提交的数据中提取计算所需的参数
|
从用户提交的数据中提取计算所需的参数
|
||||||
|
|
||||||
@ -133,7 +149,7 @@ def _extract_calculation_params(data: UserValuationCreate) -> Dict[str, Any]:
|
|||||||
# 政策乘数B13相关参数
|
# 政策乘数B13相关参数
|
||||||
# 政策契合度评分P - 根据行业和资助情况计算
|
# 政策契合度评分P - 根据行业和资助情况计算
|
||||||
# 实施阶段
|
# 实施阶段
|
||||||
implementation_stage = data.implementation_stage
|
implementation_stage = data.application_maturity
|
||||||
# 资金支持
|
# 资金支持
|
||||||
funding_support = data.funding_status
|
funding_support = data.funding_status
|
||||||
|
|
||||||
@ -147,12 +163,67 @@ def _extract_calculation_params(data: UserValuationCreate) -> Dict[str, Any]:
|
|||||||
|
|
||||||
# 流量因子B12相关参数
|
# 流量因子B12相关参数
|
||||||
'search_index_s1': search_index_s1,
|
'search_index_s1': search_index_s1,
|
||||||
# 'industry_average_s2': industry_average_s2,
|
'industry_average_s2': industry_average_s2,
|
||||||
# 'social_media_spread_s3': social_media_spread_s3,
|
# 'social_media_spread_s3': social_media_spread_s3,
|
||||||
|
'likes':likes,
|
||||||
|
'comments':comments,
|
||||||
|
'shares':shares,
|
||||||
|
'followers':followers,
|
||||||
|
|
||||||
'click_count': int(data.click_count) or 100,
|
'click_count': int(data.click_count) or 100,
|
||||||
'view_count': int(data.link_views) or 100,
|
'view_count': int(data.link_views) or 100,
|
||||||
|
|
||||||
# 政策乘数B13相关参数
|
# 政策乘数B13相关参数
|
||||||
'implementation_stage': implementation_stage,
|
'implementation_stage': implementation_stage,
|
||||||
'funding_support':funding_support
|
'funding_support':funding_support
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 获取 文化价值B2 相关参数
|
||||||
|
def _extract_calculation_params_b2(data: UserValuationCreate) -> Dict[str, Any]:
|
||||||
|
"""
|
||||||
|
argrg:
|
||||||
|
data: 用户提交的估值评估数据
|
||||||
|
|
||||||
|
retus:
|
||||||
|
Dict: 计算所需的参数字典
|
||||||
|
"""
|
||||||
|
# 活态传承系数B21 县官参数
|
||||||
|
inheritor_level_coefficient = data.inheritor_level # 传承人等级
|
||||||
|
offline_sessions = int(data.offline_activities) #线下传习次数
|
||||||
|
# 以下调用API
|
||||||
|
douyin_views = "抖音播放量"
|
||||||
|
kuaishou_views= "快手播放量"
|
||||||
|
bilibili_views= "B站播放量"
|
||||||
|
# 跨界合作深度 品牌联名0.3,科技载体0.5,国家外交礼品1.0
|
||||||
|
cross_border_depth = float(data.cooperation_depth)
|
||||||
|
|
||||||
|
# 纹样基因值B22相关参数
|
||||||
|
|
||||||
|
historical_inheritance = "历史传承度HI信息未找到"
|
||||||
|
# 用户上传资产相关的纹样图片,系数识别处理,得出结构复杂度值 TODO 一下两项未实现配置 识别图片功能
|
||||||
|
structure_complexity = "结构复杂度SC"
|
||||||
|
normalized_entropy = "归一化信息熵H"
|
||||||
|
return {
|
||||||
|
"inheritor_level_coefficient": inheritor_level_coefficient,
|
||||||
|
"offline_sessions": offline_sessions,
|
||||||
|
"douyin_views": douyin_views,
|
||||||
|
"kuaishou_views": kuaishou_views,
|
||||||
|
"bilibili_views": bilibili_views,
|
||||||
|
"cross_border_depth": cross_border_depth,
|
||||||
|
"historical_inheritance": historical_inheritance,
|
||||||
|
"structure_complexity": structure_complexity,
|
||||||
|
"normalized_entropy": normalized_entropy,
|
||||||
|
}
|
||||||
|
|
||||||
|
# 获取 文化价值B2 相关参数
|
||||||
|
def _extract_calculation_params_b3(data: UserValuationCreate) -> Dict[str, Any]:
|
||||||
|
# 过去30天最高价格 过去30天最低价格 TODO 需要根据字样进行切分获取最高价和最低价 转换成 float 类型
|
||||||
|
highest_price,lowest_price= data.price_fluctuation
|
||||||
|
lawsuit_status = "无诉讼" # 诉讼状态 TODO (API获取)
|
||||||
|
inheritor_ages = data.inheritor_age_count # [45, 60, 75] # 传承人年龄列表
|
||||||
|
return {
|
||||||
|
"highest_price": highest_price,
|
||||||
|
"lowest_price": lowest_price,
|
||||||
|
"lawsuit_status": lawsuit_status,
|
||||||
|
"inheritor_ages": inheritor_ages,
|
||||||
|
}
|
||||||
|
|||||||
11
app/utils/calculation_engine/cultural_value_b2/__init__.py
Normal file
11
app/utils/calculation_engine/cultural_value_b2/__init__.py
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
from .cultural_value_b2 import CulturalValueB2Calculator
|
||||||
|
from .sub_formulas import (
|
||||||
|
LivingHeritageB21Calculator,
|
||||||
|
PatternGeneB22Calculator
|
||||||
|
)
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"CulturalValueB2Calculator",
|
||||||
|
"LivingHeritageB21Calculator",
|
||||||
|
"PatternGeneB22Calculator"
|
||||||
|
]
|
||||||
@ -0,0 +1,116 @@
|
|||||||
|
"""
|
||||||
|
文化价值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}")
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
"""
|
||||||
|
文化价值B2子公式包
|
||||||
|
1. living_heritage_b21: 活态传承系数B21计算
|
||||||
|
- 传承人等级系数:国家级(10分)、省级(7分)、市级(4分)、县级(2分)
|
||||||
|
- 教学传播频次:每月>10次(10分)、5-10次(7分)、1-4次(4分)
|
||||||
|
- 跨界合作深度:多类型高频(10分)、多类型中频(7分)、单类型高频(5分)
|
||||||
|
- 活态传承系数B21 = 传承人等级系数 × 0.4 + 教学传播频次 × 0.3 + 跨界合作深度 × 0.3
|
||||||
|
|
||||||
|
2. pattern_gene_b22: 纹样基因值B22计算
|
||||||
|
- 结构复杂度SC = Σ(元素权重 × 复杂度系数) / 总元素数
|
||||||
|
- 归一化信息熵H = -Σ(p_i × log2(p_i)) / log2(n)
|
||||||
|
- 历史传承度HI = 传承年限权重 × 0.4 + 文化意义权重 × 0.3 + 保护状况权重 × 0.3
|
||||||
|
- 纹样基因值B22 = (结构复杂度SC × 0.6 + 归一化信息熵H × 0.4) × 历史传承度HI × 10
|
||||||
|
- 文化价值B2 = 活态传承系数B21 × 0.6 + (纹样基因值B22 / 10) × 0.4
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .living_heritage_b21 import LivingHeritageB21Calculator
|
||||||
|
from .pattern_gene_b22 import PatternGeneB22Calculator
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"LivingHeritageB21Calculator",
|
||||||
|
"PatternGeneB22Calculator"
|
||||||
|
]
|
||||||
@ -0,0 +1,156 @@
|
|||||||
|
|
||||||
|
"""
|
||||||
|
活态传承系数B21计算模块
|
||||||
|
|
||||||
|
活态传承系数B21 = 传承人等级系数 × 0.4 + 教学传播频次 × 0.3 + 跨界合作深度 × 0.3
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 示例使用
|
||||||
|
if __name__ == "__main__":
|
||||||
|
calculator = LivingHeritageB21Calculator()
|
||||||
|
|
||||||
|
# 示例数据
|
||||||
|
inheritor_level = "国家级传承人" # 传承人等级 (用户填写)
|
||||||
|
cross_border_depth = 50.0
|
||||||
|
# 教学传播频次数据
|
||||||
|
offline_sessions = 10 # 线下传习次数(符合标准:传承人主导、时长≥2小时、参与人数≥5人)
|
||||||
|
douyin_views = 1000000 # 抖音播放量
|
||||||
|
kuaishou_views = 500000 # 快手播放量
|
||||||
|
bilibili_views = 200000 # 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
|
||||||
|
)
|
||||||
|
|
||||||
|
# 计算活态传承系数B21
|
||||||
|
living_heritage_b21 = calculator.calculate_living_heritage_b21(
|
||||||
|
inheritor_level_coefficient, teaching_frequency, cross_border_depth
|
||||||
|
)
|
||||||
|
|
||||||
|
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}")
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,143 @@
|
|||||||
|
|
||||||
|
"""
|
||||||
|
纹样基因值B22计算模块
|
||||||
|
|
||||||
|
纹样基因值B22 = (结构复杂度SC × 0.6 + 归一化信息熵H × 0.4) × 历史传承度HI × 10
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import math
|
||||||
|
from typing import Dict, List
|
||||||
|
|
||||||
|
|
||||||
|
class PatternGeneB22Calculator:
|
||||||
|
"""纹样基因值B22计算器"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
"""初始化计算器"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
def calculate_pattern_gene_b22(self,
|
||||||
|
structure_complexity: float,
|
||||||
|
normalized_entropy: float,
|
||||||
|
historical_inheritance: float) -> float:
|
||||||
|
"""
|
||||||
|
计算纹样基因值B22
|
||||||
|
|
||||||
|
|
||||||
|
纹样基因值B22 = (结构复杂度SC × 0.6 + 归一化信息熵H × 0.4) × 历史传承度HI × 10
|
||||||
|
|
||||||
|
args:
|
||||||
|
structure_complexity: 结构复杂度SC (系统计算)
|
||||||
|
normalized_entropy: 归一化信息熵H (系统计算)
|
||||||
|
historical_inheritance: 历史传承度HI (用户填写)
|
||||||
|
|
||||||
|
return:
|
||||||
|
float: 纹样基因值B22
|
||||||
|
"""
|
||||||
|
|
||||||
|
pattern_gene = ((structure_complexity * 0.6 +
|
||||||
|
normalized_entropy * 0.4) *
|
||||||
|
historical_inheritance * 10)
|
||||||
|
|
||||||
|
return pattern_gene
|
||||||
|
|
||||||
|
def calculate_structure_complexity(self, pattern_elements: List[Dict]) -> float:
|
||||||
|
"""
|
||||||
|
计算结构复杂度SC
|
||||||
|
|
||||||
|
结构复杂度 = Σ(元素权重 × 复杂度系数) / 总元素数
|
||||||
|
|
||||||
|
args:
|
||||||
|
pattern_elements: 纹样元素列表,每个元素包含 {type: str, weight: float, complexity: float} (用户填写)
|
||||||
|
|
||||||
|
return:
|
||||||
|
float: 结构复杂度SC
|
||||||
|
"""
|
||||||
|
if not pattern_elements:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
total_weighted_complexity = 0.0
|
||||||
|
total_weight = 0.0
|
||||||
|
|
||||||
|
for element in pattern_elements:
|
||||||
|
weight = element.get('weight', 1.0)
|
||||||
|
complexity = element.get('complexity', 0.0)
|
||||||
|
total_weighted_complexity += weight * complexity
|
||||||
|
total_weight += weight
|
||||||
|
|
||||||
|
if total_weight == 0:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
structure_complexity = total_weighted_complexity / total_weight
|
||||||
|
return structure_complexity
|
||||||
|
|
||||||
|
def calculate_normalized_entropy(self, pattern_data: List[float]) -> float:
|
||||||
|
"""
|
||||||
|
计算归一化信息熵H
|
||||||
|
|
||||||
|
归一化信息熵 = -Σ(p_i × log2(p_i)) / log2(n)
|
||||||
|
|
||||||
|
args:
|
||||||
|
pattern_data: 纹样数据列表 (用户填写)
|
||||||
|
|
||||||
|
return:
|
||||||
|
float: 归一化信息熵H
|
||||||
|
"""
|
||||||
|
if not pattern_data or len(pattern_data) <= 1:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
# 计算概率分布
|
||||||
|
total = sum(pattern_data)
|
||||||
|
if total == 0:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
probabilities = [x / total for x in pattern_data if x > 0]
|
||||||
|
|
||||||
|
# 计算信息熵
|
||||||
|
entropy = 0.0
|
||||||
|
for p in probabilities:
|
||||||
|
if p > 0:
|
||||||
|
entropy -= p * math.log2(p)
|
||||||
|
|
||||||
|
# 归一化
|
||||||
|
n = len(probabilities)
|
||||||
|
if n <= 1:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
normalized_entropy = entropy / math.log2(n)
|
||||||
|
return normalized_entropy
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# 示例使用
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
calculator = PatternGeneB22Calculator()
|
||||||
|
|
||||||
|
# 示例数据
|
||||||
|
pattern_elements = [
|
||||||
|
{'type': '几何图形', 'weight': 0.3, 'complexity': 0.7},
|
||||||
|
{'type': '植物纹样', 'weight': 0.4, 'complexity': 0.8},
|
||||||
|
{'type': '动物纹样', 'weight': 0.3, 'complexity': 0.6}
|
||||||
|
]
|
||||||
|
entropy_data = [0.3, 0.4, 0.3]
|
||||||
|
inheritance_years = 500 # 传承年数 (用户填写)
|
||||||
|
cultural_significance = "国家级" # 文化意义等级 (用户填写)
|
||||||
|
preservation_status = "良好" # 保护状况 (用户填写)
|
||||||
|
historical_inheritance = 100.0
|
||||||
|
|
||||||
|
# 计算各项指标
|
||||||
|
structure_complexity = calculator.calculate_structure_complexity(pattern_elements)
|
||||||
|
normalized_entropy = calculator.calculate_normalized_entropy(entropy_data)
|
||||||
|
|
||||||
|
|
||||||
|
# 计算纹样基因值B22
|
||||||
|
pattern_gene_b22 = calculator.calculate_pattern_gene_b22(
|
||||||
|
structure_complexity, normalized_entropy, historical_inheritance
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"结构复杂度SC: {structure_complexity:.4f}")
|
||||||
|
print(f"归一化信息熵H: {normalized_entropy:.4f}")
|
||||||
|
print(f"历史传承度HI: {historical_inheritance:.4f}")
|
||||||
|
print(f"纹样基因值B22: {pattern_gene_b22:.4f}")
|
||||||
@ -6,6 +6,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 相对导入(当作为包使用时)
|
# 相对导入(当作为包使用时)
|
||||||
from .sub_formulas.basic_value_b11 import BasicValueB11Calculator, calculate_popularity_score
|
from .sub_formulas.basic_value_b11 import BasicValueB11Calculator, calculate_popularity_score
|
||||||
@ -20,17 +21,17 @@ except ImportError:
|
|||||||
|
|
||||||
class EconomicValueB1Calculator:
|
class EconomicValueB1Calculator:
|
||||||
"""经济价值B1计算器"""
|
"""经济价值B1计算器"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""初始化计算器"""
|
"""初始化计算器"""
|
||||||
self.basic_value_calculator = BasicValueB11Calculator()
|
self.basic_value_calculator = BasicValueB11Calculator()
|
||||||
self.traffic_factor_calculator = TrafficFactorB12Calculator()
|
self.traffic_factor_calculator = TrafficFactorB12Calculator()
|
||||||
self.policy_multiplier_calculator = PolicyMultiplierB13Calculator()
|
self.policy_multiplier_calculator = PolicyMultiplierB13Calculator()
|
||||||
|
|
||||||
def calculate_economic_value_b1(self,
|
def calculate_economic_value_b1(self,
|
||||||
basic_value_b11: float,
|
basic_value_b11: float,
|
||||||
traffic_factor_b12: float,
|
traffic_factor_b12: float,
|
||||||
policy_multiplier_b13: float) -> float:
|
policy_multiplier_b13: float) -> float:
|
||||||
"""
|
"""
|
||||||
计算经济价值B1
|
计算经济价值B1
|
||||||
|
|
||||||
@ -46,11 +47,10 @@ class EconomicValueB1Calculator:
|
|||||||
float: 经济价值B1
|
float: 经济价值B1
|
||||||
"""
|
"""
|
||||||
economic_value = basic_value_b11 * (1 + traffic_factor_b12) * policy_multiplier_b13
|
economic_value = basic_value_b11 * (1 + traffic_factor_b12) * policy_multiplier_b13
|
||||||
|
|
||||||
return economic_value
|
return economic_value
|
||||||
|
|
||||||
def calculate_complete_economic_value_b1(self, input_data: Dict) -> Dict:
|
def calculate_complete_economic_value_b1(self, input_data: Dict) -> Dict:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
计算完整的经济价值B1,包含所有子公式
|
计算完整的经济价值B1,包含所有子公式
|
||||||
|
|
||||||
@ -61,47 +61,66 @@ class EconomicValueB1Calculator:
|
|||||||
Dict: 包含所有中间计算结果和最终结果的字典
|
Dict: 包含所有中间计算结果和最终结果的字典
|
||||||
"""
|
"""
|
||||||
# 财务价值F 近三年年均收益列表 [1,2,3]
|
# 财务价值F 近三年年均收益列表 [1,2,3]
|
||||||
financial_value = self.basic_value_calculator.calculate_financial_value_f()
|
financial_value = self.basic_value_calculator.calculate_financial_value_f(input_data["three_year_income"])
|
||||||
# 计算法律强度L patent_score: 专利分 (0-10分) (用户填写)
|
# 计算法律强度L patent_score: 专利分 (0-10分) (用户填写)
|
||||||
# popularity_score: 普及地域分 (0-10分) (用户填写)
|
# popularity_score: 普及地域分 (0-10分) (用户填写)
|
||||||
# infringement_score: 侵权分 (0-10分) (用户填写)
|
# infringement_score: 侵权分 (0-10分) (用户填写)
|
||||||
popularity_score = calculate_popularity_score()
|
|
||||||
legal_strength = self.basic_value_calculator.calculate_legal_strength_l()
|
legal_strength = self.basic_value_calculator.calculate_legal_strength_l(
|
||||||
|
input_data["patent_score"],
|
||||||
|
input_data["popularity_score"],
|
||||||
|
input_data["infringement_score"],
|
||||||
|
)
|
||||||
|
|
||||||
# 发展潜力 patent_score: 专利分 (0-10分) (用户填写)
|
# 发展潜力 patent_score: 专利分 (0-10分) (用户填写)
|
||||||
# esg_score: ESG分 (0-10分) (用户填写)
|
# esg_score: ESG分 (0-10分) (用户填写)
|
||||||
# innovation_ratio: 创新投入比 (研发费用/营收) * 100 (用户填写)
|
# innovation_ratio: 创新投入比 (研发费用/营收) * 100 (用户填写)
|
||||||
development_potential = self.basic_value_calculator.calculate_development_potential_d()
|
development_potential = self.basic_value_calculator.calculate_development_potential_d(
|
||||||
|
input_data["esg_score"],
|
||||||
|
input_data["patent_score"],
|
||||||
|
input_data["innovation_ratio"],
|
||||||
|
)
|
||||||
# 计算行业系数I target_industry_roe: 目标行业平均ROE (系统配置)
|
# 计算行业系数I target_industry_roe: 目标行业平均ROE (系统配置)
|
||||||
# benchmark_industry_roe: 基准行业ROE (系统配置)
|
# benchmark_industry_roe: 基准行业ROE (系统配置)
|
||||||
industry_coefficient = self.basic_value_calculator.calculate_industry_coefficient_i()
|
# industry_coefficient = self.basic_value_calculator.calculate_industry_coefficient_i(
|
||||||
|
#
|
||||||
|
# )
|
||||||
# 计算基础价值B11
|
# 计算基础价值B11
|
||||||
basic_value_b11 = self.basic_value_calculator.calculate_basic_value_b11(
|
basic_value_b11 = self.basic_value_calculator.calculate_basic_value_b11(
|
||||||
financial_value,
|
financial_value,
|
||||||
legal_strength,
|
legal_strength,
|
||||||
development_potential,
|
development_potential,
|
||||||
industry_coefficient
|
input_data["industry_coefficient"]
|
||||||
)
|
)
|
||||||
|
|
||||||
# 计算流量因子B12
|
# 计算流量因子B12
|
||||||
|
social_media_spread_s3 = self.traffic_factor_calculator.calculate_interaction_index(
|
||||||
|
input_data["likes"],
|
||||||
|
input_data["comments"],
|
||||||
|
input_data["shares"],
|
||||||
|
)
|
||||||
traffic_factor_b12 = self.traffic_factor_calculator.calculate_traffic_factor_b12(
|
traffic_factor_b12 = self.traffic_factor_calculator.calculate_traffic_factor_b12(
|
||||||
input_data['search_index_s1'],
|
input_data['search_index_s1'],
|
||||||
input_data['industry_average_s2'],
|
input_data['industry_average_s2'],
|
||||||
input_data['social_media_spread_s3']
|
social_media_spread_s3
|
||||||
)
|
)
|
||||||
|
|
||||||
# 计算政策乘数B13
|
# 计算政策乘数B13
|
||||||
|
policy_compatibility_score = self.policy_multiplier_calculator.calculate_policy_compatibility_score(
|
||||||
|
input_data["policy_match_score"],
|
||||||
|
input_data["implementation_stage"],
|
||||||
|
input_data["funding_support"])
|
||||||
policy_multiplier_b13 = self.policy_multiplier_calculator.calculate_policy_multiplier_b13(
|
policy_multiplier_b13 = self.policy_multiplier_calculator.calculate_policy_multiplier_b13(
|
||||||
input_data['policy_compatibility_score']
|
policy_compatibility_score
|
||||||
)
|
)
|
||||||
|
|
||||||
# 计算经济价值B1
|
# 计算经济价值B1
|
||||||
economic_value_b1 = self.calculate_economic_value_b1(
|
economic_value_b1 = self.calculate_economic_value_b1(
|
||||||
basic_value_b11,
|
basic_value_b11,
|
||||||
traffic_factor_b12,
|
traffic_factor_b12,
|
||||||
policy_multiplier_b13
|
policy_multiplier_b13
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'basic_value_b11': basic_value_b11,
|
'basic_value_b11': basic_value_b11,
|
||||||
'traffic_factor_b12': traffic_factor_b12,
|
'traffic_factor_b12': traffic_factor_b12,
|
||||||
@ -112,29 +131,82 @@ class EconomicValueB1Calculator:
|
|||||||
|
|
||||||
# 示例使用
|
# 示例使用
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
calculator = EconomicValueB1Calculator()
|
calculator = EconomicValueB1Calculator()
|
||||||
|
|
||||||
# 示例数据
|
# 示例数据
|
||||||
input_data = {
|
'''
|
||||||
|
{
|
||||||
# 基础价值B11相关参数
|
# 基础价值B11相关参数
|
||||||
'financial_value': 68.04, # 财务价值F
|
'three_year_income': three_year_income,
|
||||||
'legal_strength': 7.90, # 法律强度L
|
'patent_score': patent_score,
|
||||||
'development_potential': 6.00, # 发展潜力D
|
'popularity_score': popularity_score,
|
||||||
'industry_coefficient': 0.25, # 行业系数I
|
'infringement_score': infringement_score,
|
||||||
|
'innovation_ratio': innovation_ratio,
|
||||||
|
|
||||||
# 流量因子B12相关参数
|
# 流量因子B12相关参数
|
||||||
'search_index_s1': 4500.0, # 近30天搜索指数S1
|
'search_index_s1': search_index_s1,
|
||||||
'industry_average_s2': 5000.0, # 行业均值S2
|
'industry_average_s2': industry_average_s2,
|
||||||
'social_media_spread_s3': 1.07, # 社交媒体传播度S3
|
# 'social_media_spread_s3': social_media_spread_s3,
|
||||||
|
'likes':likes,
|
||||||
|
'comments':comments,
|
||||||
|
'shares':shares,
|
||||||
|
'followers':followers,
|
||||||
|
|
||||||
|
'click_count': int(data.click_count) or 100,
|
||||||
|
'view_count': int(data.link_views) or 100,
|
||||||
|
|
||||||
# 政策乘数B13相关参数
|
# 政策乘数B13相关参数
|
||||||
'policy_compatibility_score': 9.1 # 政策契合度评分P
|
'implementation_stage': implementation_stage,
|
||||||
|
'funding_support':funding_support
|
||||||
}
|
}
|
||||||
|
|
||||||
|
'''
|
||||||
|
input_data = {
|
||||||
|
# 基础价值B11相关参数
|
||||||
|
'three_year_income': [1000, 2000, 2222],
|
||||||
|
'patent_score': 1, # 专利分
|
||||||
|
'popularity_score': 4.0, # 普及地域分值
|
||||||
|
'infringement_score': 1.0, # 侵权分
|
||||||
|
'innovation_ratio': 600.0,
|
||||||
|
'esg_score':10.0,
|
||||||
|
'industry_coefficient':12.0,
|
||||||
|
|
||||||
|
# 流量因子B12相关参数
|
||||||
|
'search_index_s1': 4500.0,
|
||||||
|
'industry_average_s2': 5000.0,
|
||||||
|
# 'social_media_spread_s3': social_media_spread_s3,
|
||||||
|
'likes': 4, # 点赞
|
||||||
|
'comments': 5, # 评论
|
||||||
|
'shares': 6, # 转发
|
||||||
|
'followers': 7, # 粉丝数
|
||||||
|
|
||||||
|
'click_count': 1000,# 点击量
|
||||||
|
'view_count': 100, # 内容浏览量
|
||||||
|
|
||||||
|
# 政策乘数B13相关参数
|
||||||
|
'policy_match_score': 10.0, # 政策匹配度
|
||||||
|
'implementation_stage': 10.0, # 实施阶段评分
|
||||||
|
'funding_support': 10.0 # 资金支持度
|
||||||
|
}
|
||||||
|
# input_data = {
|
||||||
|
# # 基础价值B11相关参数
|
||||||
|
# 'financial_value': 68.04, # 财务价值F
|
||||||
|
# 'legal_strength': 7.90, # 法律强度L
|
||||||
|
# 'development_potential': 6.00, # 发展潜力D
|
||||||
|
# 'industry_coefficient': 0.25, # 行业系数I
|
||||||
|
#
|
||||||
|
# # 流量因子B12相关参数
|
||||||
|
# 'search_index_s1': 4500.0, # 近30天搜索指数S1
|
||||||
|
# 'industry_average_s2': 5000.0, # 行业均值S2
|
||||||
|
# 'social_media_spread_s3': 1.07, # 社交媒体传播度S3
|
||||||
|
#
|
||||||
|
# # 政策乘数B13相关参数
|
||||||
|
# 'policy_compatibility_score': 9.1 # 政策契合度评分P
|
||||||
|
# }
|
||||||
|
|
||||||
# 计算经济价值B1
|
# 计算经济价值B1
|
||||||
result = calculator.calculate_complete_economic_value_b1(input_data)
|
result = calculator.calculate_complete_economic_value_b1(input_data)
|
||||||
|
|
||||||
print("经济价值B1计算结果:")
|
print("经济价值B1计算结果:")
|
||||||
print(f"基础价值B11: {result['basic_value_b11']:.2f}")
|
print(f"基础价值B11: {result['basic_value_b11']:.2f}")
|
||||||
print(f"流量因子B12: {result['traffic_factor_b12']:.4f}")
|
print(f"流量因子B12: {result['traffic_factor_b12']:.4f}")
|
||||||
|
|||||||
@ -257,7 +257,7 @@ def calculate_infringement_score(infringement_status: str) -> float:
|
|||||||
|
|
||||||
# 示例使用
|
# 示例使用
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 创建计算器实例
|
|
||||||
calculator = BasicValueB11Calculator()
|
calculator = BasicValueB11Calculator()
|
||||||
|
|
||||||
# 示例数据
|
# 示例数据
|
||||||
|
|||||||
@ -106,7 +106,7 @@ class PolicyMultiplierB13Calculator:
|
|||||||
|
|
||||||
# 示例使用
|
# 示例使用
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 创建计算器实例
|
|
||||||
calculator = PolicyMultiplierB13Calculator()
|
calculator = PolicyMultiplierB13Calculator()
|
||||||
|
|
||||||
# 示例数据
|
# 示例数据
|
||||||
|
|||||||
@ -246,7 +246,7 @@ def calculate_search_index_s1(baidu_index: float,
|
|||||||
return search_index
|
return search_index
|
||||||
# 示例使用
|
# 示例使用
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 创建计算器实例
|
|
||||||
calculator = TrafficFactorB12Calculator()
|
calculator = TrafficFactorB12Calculator()
|
||||||
processor = PlatformDataProcessor()
|
processor = PlatformDataProcessor()
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
from .sub_formulas.risk_adjustment_b3 import RiskAdjustmentB3Calculator
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"RiskAdjustmentB3Calculator"
|
||||||
|
]
|
||||||
|
|
||||||
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
"""
|
||||||
|
1. risk_adjustment_b3: 风险调整系数B3计算
|
||||||
|
- 风险评分总和R = 市场风险 × 0.3 + 法律风险 × 0.4 + 传承风险 × 0.3
|
||||||
|
- 市场风险:资产商品价格波动率 (波动率≤5%:10分, 5-15%:5分, >15%:0分)
|
||||||
|
- 法律风险:侵权诉讼历史 (无诉讼:10分, 已解决:7分, 未解决:0分)
|
||||||
|
- 传承风险:传承人年龄 (≤50岁:10分, 50-70岁:5分, >70岁:0分)
|
||||||
|
- 风险调整系数B3 = 0.8 + 风险评分总和R × 0.4
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .risk_adjustment_b3 import RiskAdjustmentB3Calculator
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
"RiskAdjustmentB3Calculator"
|
||||||
|
]
|
||||||
|
|
||||||
@ -0,0 +1,206 @@
|
|||||||
|
"""
|
||||||
|
风险调整系数B3计算模块
|
||||||
|
|
||||||
|
风险调整系数B3 = 0.8 + 风险评分总和R × 0.4
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from typing import Dict, List
|
||||||
|
|
||||||
|
|
||||||
|
class RiskAdjustmentB3Calculator:
|
||||||
|
"""风险调整系数B3计算器"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def calculate_risk_adjustment_b3(self, risk_score_sum: float) -> float:
|
||||||
|
"""
|
||||||
|
计算风险调整系数B3
|
||||||
|
|
||||||
|
|
||||||
|
风险调整系数B3 = 0.8 + 风险评分总和R × 0.4
|
||||||
|
|
||||||
|
args:
|
||||||
|
risk_score_sum: 风险评分总和R (系统计算)
|
||||||
|
|
||||||
|
return:
|
||||||
|
float: 风险调整系数B3
|
||||||
|
"""
|
||||||
|
|
||||||
|
risk_adjustment = 0.8 + risk_score_sum * 0.4
|
||||||
|
|
||||||
|
return risk_adjustment
|
||||||
|
|
||||||
|
def calculate_risk_score_sum(self, market_risk: float, legal_risk: float, inheritance_risk: float) -> float:
|
||||||
|
"""
|
||||||
|
计算风险评分总和R
|
||||||
|
|
||||||
|
|
||||||
|
风险评分总和R = 市场风险 × 0.3 + 法律风险 × 0.4 + 传承风险 × 0.3
|
||||||
|
|
||||||
|
args:
|
||||||
|
market_risk: 市场风险 (用户填写)
|
||||||
|
legal_risk: 法律风险 (用户填写)
|
||||||
|
inheritance_risk: 传承风险 (用户填写)
|
||||||
|
|
||||||
|
return:
|
||||||
|
float: 风险评分总和R
|
||||||
|
"""
|
||||||
|
|
||||||
|
risk_score_sum = market_risk * 0.3 + legal_risk * 0.4 + inheritance_risk * 0.3
|
||||||
|
|
||||||
|
return risk_score_sum
|
||||||
|
|
||||||
|
def calculate_market_risk(self, highest_price: float, lowest_price: float) -> float:
|
||||||
|
"""
|
||||||
|
计算市场风险
|
||||||
|
|
||||||
|
用户填写近30天资产商品的最高价与最低价,系统自动计算波动率,波动率=近30日价格极差/均值,≤5%(10分)、5-15%(5分)、>15%(0分)
|
||||||
|
市场风险 = 资产商品的价格波动率
|
||||||
|
波动率 = 过去30天价格区间 / 过去30天平均价格
|
||||||
|
|
||||||
|
评分标准:
|
||||||
|
- 波动率 ≤5%: 10分
|
||||||
|
- 波动率 5-15%: 5分
|
||||||
|
- 波动率 >15%: 0分
|
||||||
|
|
||||||
|
args:
|
||||||
|
highest_price: 过去30天最高价格 (用户填写)
|
||||||
|
lowest_price: 过去30天最低价格 (用户填写)
|
||||||
|
|
||||||
|
return:
|
||||||
|
float: 市场风险评分 (0-10)
|
||||||
|
"""
|
||||||
|
if highest_price <= 0 or lowest_price <= 0:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
# 计算平均价格
|
||||||
|
average_price = (highest_price + lowest_price) / 2
|
||||||
|
|
||||||
|
# 计算价格区间
|
||||||
|
price_range = highest_price - lowest_price
|
||||||
|
|
||||||
|
# 计算波动率
|
||||||
|
volatility = price_range / average_price
|
||||||
|
|
||||||
|
# 根据波动率评分
|
||||||
|
if volatility <= 0.05: # ≤5%
|
||||||
|
return 10.0
|
||||||
|
elif volatility <= 0.15: # 5-15%
|
||||||
|
return 5.0
|
||||||
|
else: # >15%
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
def calculate_legal_risk(self, lawsuit_status: str) -> float:
|
||||||
|
"""
|
||||||
|
计算法律风险
|
||||||
|
|
||||||
|
|
||||||
|
法律风险 = 侵权诉讼历史
|
||||||
|
|
||||||
|
评分标准:
|
||||||
|
- 无诉讼: 10分
|
||||||
|
- 已解决诉讼: 7分
|
||||||
|
- 未解决诉讼: 0分
|
||||||
|
|
||||||
|
args:
|
||||||
|
lawsuit_status: 诉讼状态 (API获取)
|
||||||
|
|
||||||
|
return:
|
||||||
|
float: 法律风险评分 (0-10)
|
||||||
|
"""
|
||||||
|
lawsuit_scores = {
|
||||||
|
"无诉讼": 10.0,
|
||||||
|
"已解决诉讼": 7.0,
|
||||||
|
"未解决诉讼": 0.0
|
||||||
|
}
|
||||||
|
|
||||||
|
return lawsuit_scores.get(lawsuit_status, 0.0)
|
||||||
|
|
||||||
|
def calculate_inheritance_risk(self, inheritor_ages: List[int]) -> float:
|
||||||
|
"""
|
||||||
|
计算传承风险
|
||||||
|
用户填写该资产的所有受认证传承人年龄,若有多位受认证传承人则填写多位,传承人年龄≤50岁(10分)、50-70岁(5分)、>70岁(0分)
|
||||||
|
|
||||||
|
传承风险 = 传承人年龄
|
||||||
|
|
||||||
|
评分标准:
|
||||||
|
- 传承人年龄 ≤50岁: 10分
|
||||||
|
- 传承人年龄 50-70岁: 5分
|
||||||
|
- 传承人年龄 >70岁: 0分
|
||||||
|
|
||||||
|
如果有多个传承人,取最高分
|
||||||
|
|
||||||
|
args:
|
||||||
|
inheritor_ages: 传承人年龄列表 (用户填写)
|
||||||
|
|
||||||
|
return:
|
||||||
|
float: 传承风险评分 (0-10)
|
||||||
|
"""
|
||||||
|
if not inheritor_ages:
|
||||||
|
return 0.0
|
||||||
|
|
||||||
|
max_score = 0.0
|
||||||
|
|
||||||
|
for age in inheritor_ages:
|
||||||
|
if age <= 50:
|
||||||
|
score = 10.0
|
||||||
|
elif age <= 70:
|
||||||
|
score = 5.0
|
||||||
|
else:
|
||||||
|
score = 0.0
|
||||||
|
|
||||||
|
max_score = max(max_score, score)
|
||||||
|
|
||||||
|
return max_score
|
||||||
|
|
||||||
|
def calculate_complete_risky_value_b3(self, input_data: Dict) -> Dict:
|
||||||
|
# 计算各项风险评分
|
||||||
|
market_risk = calculator.calculate_market_risk(input_data[""], input_data["lowest_price"])
|
||||||
|
legal_risk = calculator.calculate_legal_risk(input_data["lawsuit_status"])
|
||||||
|
inheritance_risk = calculator.calculate_inheritance_risk(input_data["inheritor_ages"])
|
||||||
|
|
||||||
|
# 计算风险评分总和R
|
||||||
|
risk_score_sum = calculator.calculate_risk_score_sum(market_risk, legal_risk, inheritance_risk)
|
||||||
|
|
||||||
|
# 计算风险调整系数B3
|
||||||
|
risk_adjustment_b3 = calculator.calculate_risk_adjustment_b3(risk_score_sum)
|
||||||
|
return {
|
||||||
|
'risk_score_sum': risk_score_sum,
|
||||||
|
'risk_adjustment_b3': risk_adjustment_b3
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# 示例使用
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# 创建计算器实例
|
||||||
|
calculator = RiskAdjustmentB3Calculator()
|
||||||
|
|
||||||
|
# 示例数据
|
||||||
|
# 市场风险:过去30天价格数据
|
||||||
|
highest_price = 100.0 # 过去30天最高价格 (用户填写)
|
||||||
|
lowest_price = 95.0 # 过去30天最低价格 (用户填写)
|
||||||
|
|
||||||
|
# 法律风险:诉讼状态
|
||||||
|
lawsuit_status = "无诉讼" # 诉讼状态 (API获取)
|
||||||
|
|
||||||
|
# 传承风险:传承人年龄
|
||||||
|
inheritor_ages = [45, 60, 75] # 传承人年龄列表 (用户填写)
|
||||||
|
|
||||||
|
# 计算各项风险评分
|
||||||
|
market_risk = calculator.calculate_market_risk(highest_price, lowest_price)
|
||||||
|
legal_risk = calculator.calculate_legal_risk(lawsuit_status)
|
||||||
|
inheritance_risk = calculator.calculate_inheritance_risk(inheritor_ages)
|
||||||
|
|
||||||
|
# 计算风险评分总和R
|
||||||
|
risk_score_sum = calculator.calculate_risk_score_sum(market_risk, legal_risk, inheritance_risk)
|
||||||
|
|
||||||
|
# 计算风险调整系数B3
|
||||||
|
risk_adjustment_b3 = calculator.calculate_risk_adjustment_b3(risk_score_sum)
|
||||||
|
|
||||||
|
print(f"市场风险评分: {market_risk:.1f}")
|
||||||
|
print(f"法律风险评分: {legal_risk:.1f}")
|
||||||
|
print(f"传承风险评分: {inheritance_risk:.1f}")
|
||||||
|
print(f"风险评分总和R: {risk_score_sum:.4f}")
|
||||||
|
print(f"风险调整系数B3: {risk_adjustment_b3:.4f}")
|
||||||
Loading…
x
Reference in New Issue
Block a user