1 3 5
This commit is contained in:
parent
713787d020
commit
50e02dc37d
@ -1,5 +1,6 @@
|
||||
from random import random
|
||||
|
||||
from datetime import datetime
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from typing import Optional, List, Dict, Any
|
||||
import json
|
||||
@ -19,7 +20,7 @@ from app.utils.app_user_jwt import get_current_app_user_id, get_current_app_user
|
||||
from app.utils.calculation_engine import FinalValueACalculator
|
||||
from app.utils.calculation_engine.drp import DynamicPledgeRateCalculator
|
||||
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, calculate_patent_score
|
||||
from app.utils.calculation_engine.economic_value_b1.sub_formulas.traffic_factor_b12 import calculate_search_index_s1
|
||||
from app.log.log import logger
|
||||
from app.models.esg import ESG
|
||||
@ -100,6 +101,7 @@ async def calculate_valuation(
|
||||
- 专利验证: 通过API验证专利有效性
|
||||
- 侵权记录: 通过API查询侵权诉讼历史
|
||||
"""
|
||||
|
||||
try:
|
||||
start_ts = time.monotonic()
|
||||
logger.info("valuation.calc_start user_id={} asset_name={} industry={}", user_id,
|
||||
@ -110,6 +112,7 @@ async def calculate_valuation(
|
||||
industry_obj = None
|
||||
policy_obj = None
|
||||
|
||||
|
||||
try:
|
||||
esg_obj = await asyncio.wait_for(ESG.filter(name=data.industry).first(), timeout=2.0)
|
||||
except Exception as e:
|
||||
@ -141,9 +144,9 @@ async def calculate_valuation(
|
||||
# 侵权分 默认 6
|
||||
try:
|
||||
judicial_data = universal_api.query_judicial_data(data.institution)
|
||||
_data = judicial_data["data"]["count"]["ktggCount"]
|
||||
if _data > 0:
|
||||
infringement_score = 4.0
|
||||
_data = judicial_data["data"].get("target",None) # 诉讼标的
|
||||
if _data:
|
||||
infringement_score = 0.0
|
||||
else:
|
||||
infringement_score = 10.0
|
||||
except:
|
||||
@ -153,26 +156,27 @@ async def calculate_valuation(
|
||||
|
||||
try:
|
||||
patent_data = universal_api.query_patent_info(data.industry)
|
||||
patent_dict = patent_data if isinstance(patent_data, dict) else {}
|
||||
inner_data = patent_dict.get("data", {}) if isinstance(patent_dict.get("data", {}), dict) else {}
|
||||
data_list = inner_data.get("dataList", [])
|
||||
data_list = data_list if isinstance(data_list, list) else []
|
||||
# 验证 专利剩余年限
|
||||
# TODO 无法验证 专利剩余保护期>10年(10分),5-10年(7分),<5年(3分);
|
||||
|
||||
# 发展潜力D相关参数 专利数量
|
||||
# 查询匹配申请号的记录集合
|
||||
matched = [item for item in data_list if
|
||||
isinstance(item, dict) and item.get("SQH") == getattr(data, 'patent_application_no', None)]
|
||||
if matched:
|
||||
patent_count = calculate_patent_usage_score(len(matched))
|
||||
input_data_by_b1["patent_count"] = float(patent_count)
|
||||
else:
|
||||
input_data_by_b1["patent_count"] = 0.0
|
||||
input_data_by_b1["patent_score"] = 0
|
||||
except Exception as e:
|
||||
logger.warning("valuation.patent_api_error err={}", repr(e))
|
||||
input_data_by_b1["patent_count"] = 0.0
|
||||
input_data_by_b1["patent_score"] = 0.0
|
||||
|
||||
patent_dict = patent_data if isinstance(patent_data, dict) else {}
|
||||
inner_data = patent_dict.get("data", {}) if isinstance(patent_dict.get("data", {}), dict) else {}
|
||||
data_list = inner_data.get("dataList", [])
|
||||
data_list = data_list if isinstance(data_list, list) else []
|
||||
# 验证 专利剩余年限
|
||||
# 发展潜力D相关参数 专利数量
|
||||
# 查询匹配申请号的记录集合
|
||||
matched = [item for item in data_list if isinstance(item, dict) and item.get("SQH") == getattr(data, 'patent_application_no', None)]
|
||||
if matched:
|
||||
patent_count = calculate_patent_usage_score(len(matched))
|
||||
input_data_by_b1["patent_count"] = float(patent_count)
|
||||
else:
|
||||
input_data_by_b1["patent_count"] = 0.0
|
||||
|
||||
patent_score = calculate_patent_score(calculate_total_years(data_list))
|
||||
input_data_by_b1["patent_score"] = patent_score
|
||||
|
||||
# 提取 文化价值B2 计算参数
|
||||
input_data_by_b2 = await _extract_calculation_params_b2(data)
|
||||
@ -557,3 +561,26 @@ async def get_my_valuation_statistics(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"获取统计信息失败: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
def calculate_total_years(data_list):
|
||||
current_date = datetime.now().date()
|
||||
total_years = 0
|
||||
date_count = 0
|
||||
for item in data_list:
|
||||
if "SQRQ" in item and item["SQRQ"]:
|
||||
try:
|
||||
# 解析日期字符串
|
||||
sqrq_date = datetime.strptime(item["SQRQ"], "%Y-%m-%d").date()
|
||||
|
||||
# 计算与当前日期的差值(年,包含小数)
|
||||
date_diff = current_date - sqrq_date
|
||||
years_diff = date_diff.days / 365.25
|
||||
|
||||
total_years += years_diff
|
||||
date_count += 1
|
||||
|
||||
except ValueError as e:
|
||||
return 0
|
||||
|
||||
return total_years
|
||||
@ -76,8 +76,9 @@ class EconomicValueB1Calculator:
|
||||
# esg_score: ESG分 (0-10分) (用户填写)
|
||||
# innovation_ratio: 创新投入比 (研发费用/营收) * 100 (用户填写)
|
||||
development_potential = self.basic_value_calculator.calculate_development_potential_d(
|
||||
input_data["esg_score"],
|
||||
|
||||
input_data["patent_count"],
|
||||
input_data["esg_score"],
|
||||
input_data["innovation_ratio"],
|
||||
)
|
||||
# 计算行业系数I target_industry_roe: 目标行业平均ROE (系统配置)
|
||||
|
||||
@ -284,7 +284,7 @@ if __name__ == "__main__":
|
||||
view_count = 200
|
||||
|
||||
# 计算各项指标
|
||||
search_index_s1 = calculator.calculate_search_index_s1(baidu_index, wechat_index, weibo_index)
|
||||
search_index_s1 = calculate_search_index_s1(baidu_index, wechat_index, weibo_index)
|
||||
interaction_index, coverage_index = processor.calculate_multi_platform_interaction(platform_data)
|
||||
conversion_efficiency = calculator.calculate_conversion_efficiency(click_count, view_count)
|
||||
social_media_spread_s3 = calculator.calculate_social_media_spread_s3(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user