up zero
This commit is contained in:
parent
029c724801
commit
8c24ff4e54
@ -66,7 +66,7 @@ async def _perform_valuation_calculation(user_id: int, data: UserValuationCreate
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning("valuation.policy_fetch_timeout industry={} err={}", data.industry, repr(e))
|
logger.warning("valuation.policy_fetch_timeout industry={} err={}", data.industry, repr(e))
|
||||||
policy_match_score = getattr(policy_obj, 'score', 0.0) or 0.0
|
policy_match_score = getattr(policy_obj, 'score', 0.0) or 0.0
|
||||||
|
|
||||||
# 提取 经济价值B1 计算参数
|
# 提取 经济价值B1 计算参数
|
||||||
input_data_by_b1 = await _extract_calculation_params_b1(data)
|
input_data_by_b1 = await _extract_calculation_params_b1(data)
|
||||||
# ESG关联价值 ESG分 (0-10分)
|
# ESG关联价值 ESG分 (0-10分)
|
||||||
@ -79,7 +79,7 @@ async def _perform_valuation_calculation(user_id: int, data: UserValuationCreate
|
|||||||
# 侵权分 默认 6
|
# 侵权分 默认 6
|
||||||
try:
|
try:
|
||||||
judicial_data = universal_api.query_judicial_data(data.institution)
|
judicial_data = universal_api.query_judicial_data(data.institution)
|
||||||
_data = judicial_data["data"].get("target",None) # 诉讼标的
|
_data = judicial_data["data"].get("target", None) # 诉讼标的
|
||||||
if _data:
|
if _data:
|
||||||
infringement_score = 0.0
|
infringement_score = 0.0
|
||||||
else:
|
else:
|
||||||
@ -87,7 +87,7 @@ async def _perform_valuation_calculation(user_id: int, data: UserValuationCreate
|
|||||||
except:
|
except:
|
||||||
infringement_score = 0.0
|
infringement_score = 0.0
|
||||||
input_data_by_b1["infringement_score"] = infringement_score
|
input_data_by_b1["infringement_score"] = infringement_score
|
||||||
|
|
||||||
# 获取专利信息 TODO 参数
|
# 获取专利信息 TODO 参数
|
||||||
try:
|
try:
|
||||||
patent_data = universal_api.query_patent_info(data.industry)
|
patent_data = universal_api.query_patent_info(data.industry)
|
||||||
@ -103,7 +103,8 @@ async def _perform_valuation_calculation(user_id: int, data: UserValuationCreate
|
|||||||
# 验证 专利剩余年限
|
# 验证 专利剩余年限
|
||||||
# 发展潜力D相关参数 专利数量
|
# 发展潜力D相关参数 专利数量
|
||||||
# 查询匹配申请号的记录集合
|
# 查询匹配申请号的记录集合
|
||||||
matched = [item for item in data_list if isinstance(item, dict) and item.get("SQH") == getattr(data, 'patent_application_no', None)]
|
matched = [item for item in data_list if
|
||||||
|
isinstance(item, dict) and item.get("SQH") == getattr(data, 'patent_application_no', None)]
|
||||||
if matched:
|
if matched:
|
||||||
patent_count = calculate_patent_usage_score(len(matched))
|
patent_count = calculate_patent_usage_score(len(matched))
|
||||||
input_data_by_b1["patent_count"] = float(patent_count)
|
input_data_by_b1["patent_count"] = float(patent_count)
|
||||||
@ -123,7 +124,7 @@ async def _perform_valuation_calculation(user_id: int, data: UserValuationCreate
|
|||||||
input_data_by_b3["lawsuit_status"] = "已解决诉讼"
|
input_data_by_b3["lawsuit_status"] = "已解决诉讼"
|
||||||
else:
|
else:
|
||||||
input_data_by_b3["lawsuit_status"] = "未解决诉讼"
|
input_data_by_b3["lawsuit_status"] = "未解决诉讼"
|
||||||
|
|
||||||
# 提取 市场估值C 参数
|
# 提取 市场估值C 参数
|
||||||
input_data_by_c = await _extract_calculation_params_c(data)
|
input_data_by_c = await _extract_calculation_params_c(data)
|
||||||
|
|
||||||
@ -168,7 +169,7 @@ async def _perform_valuation_calculation(user_id: int, data: UserValuationCreate
|
|||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# 创建估值评估记录
|
# 创建估值评估记录
|
||||||
result = await user_valuation_controller.create_valuation(
|
result = await user_valuation_controller.create_valuation(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
@ -185,14 +186,14 @@ async def _perform_valuation_calculation(user_id: int, data: UserValuationCreate
|
|||||||
drp_result=drp_result,
|
drp_result=drp_result,
|
||||||
status='success' # 计算成功,设置为approved状态
|
status='success' # 计算成功,设置为approved状态
|
||||||
)
|
)
|
||||||
|
|
||||||
logger.info("valuation.background_calc_success user_id={} valuation_id={}", user_id, result.id)
|
logger.info("valuation.background_calc_success user_id={} valuation_id={}", user_id, result.id)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
logger.error("valuation.background_calc_failed user_id={} err={}", user_id, repr(e))
|
logger.error("valuation.background_calc_failed user_id={} err={}", user_id, repr(e))
|
||||||
|
|
||||||
# 计算失败时也创建记录,状态设置为failed
|
# 计算失败时也创建记录,状态设置为failed
|
||||||
try:
|
try:
|
||||||
result = await user_valuation_controller.create_valuation(
|
result = await user_valuation_controller.create_valuation(
|
||||||
@ -277,24 +278,24 @@ async def calculate_valuation(
|
|||||||
- 专利验证: 通过API验证专利有效性
|
- 专利验证: 通过API验证专利有效性
|
||||||
- 侵权记录: 通过API查询侵权诉讼历史
|
- 侵权记录: 通过API查询侵权诉讼历史
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 添加后台任务
|
# 添加后台任务
|
||||||
background_tasks.add_task(_perform_valuation_calculation, user_id, data)
|
background_tasks.add_task(_perform_valuation_calculation, user_id, data)
|
||||||
|
|
||||||
logger.info("valuation.task_queued user_id={} asset_name={} industry={}",
|
logger.info("valuation.task_queued user_id={} asset_name={} industry={}",
|
||||||
user_id, getattr(data, 'asset_name', None), getattr(data, 'industry', None))
|
user_id, getattr(data, 'asset_name', None), getattr(data, 'industry', None))
|
||||||
|
|
||||||
return Success(
|
return Success(
|
||||||
data={
|
data={
|
||||||
"task_status": "queued",
|
"task_status": "queued",
|
||||||
"message": "估值计算任务已提交,正在后台处理中",
|
"message": "估值计算任务已提交,正在后台处理中",
|
||||||
"user_id": user_id,
|
"user_id": user_id,
|
||||||
"asset_name": getattr(data, 'asset_name', None)
|
"asset_name": getattr(data, 'asset_name', None)
|
||||||
},
|
},
|
||||||
msg="估值计算任务已启动"
|
msg="估值计算任务已启动"
|
||||||
)
|
)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("valuation.task_queue_failed user_id={} err={}", user_id, repr(e))
|
logger.error("valuation.task_queue_failed user_id={} err={}", user_id, repr(e))
|
||||||
raise HTTPException(status_code=500, detail=f"任务提交失败: {str(e)}")
|
raise HTTPException(status_code=500, detail=f"任务提交失败: {str(e)}")
|
||||||
@ -312,7 +313,7 @@ async def _extract_calculation_params_b1(data: UserValuationCreate) -> Dict[str,
|
|||||||
"""
|
"""
|
||||||
# 基础价值B11相关参数
|
# 基础价值B11相关参数
|
||||||
# 财务价值所需数据 从近三年收益计算
|
# 财务价值所需数据 从近三年收益计算
|
||||||
three_year_income = data.three_year_income or [0, 0, 0]
|
three_year_income = [safe_float(income) for income in data.three_year_income]
|
||||||
|
|
||||||
# 法律强度L相关参数
|
# 法律强度L相关参数
|
||||||
# 普及地域分值 默认 7分
|
# 普及地域分值 默认 7分
|
||||||
@ -320,8 +321,8 @@ async def _extract_calculation_params_b1(data: UserValuationCreate) -> Dict[str,
|
|||||||
|
|
||||||
# 创新投入比 = (研发费用/营收) * 100
|
# 创新投入比 = (研发费用/营收) * 100
|
||||||
try:
|
try:
|
||||||
rd_investment = float(data.rd_investment or 0)
|
rd_investment = float(data.rd_investment) or 0
|
||||||
annual_revenue = float(data.annual_revenue or 1) # 避免除零
|
annual_revenue = float(data.annual_revenue) or 1# 避免除零
|
||||||
innovation_ratio = (rd_investment / annual_revenue) * 100 if annual_revenue > 0 else 0
|
innovation_ratio = (rd_investment / annual_revenue) * 100 if annual_revenue > 0 else 0
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
innovation_ratio = 0.0
|
innovation_ratio = 0.0
|
||||||
@ -367,6 +368,11 @@ async def _extract_calculation_params_b1(data: UserValuationCreate) -> Dict[str,
|
|||||||
implementation_stage = policy_calculator.calculate_implementation_stage_score(implementation_stage_str)
|
implementation_stage = policy_calculator.calculate_implementation_stage_score(implementation_stage_str)
|
||||||
funding_support = policy_calculator.calculate_funding_support_score(funding_support_str)
|
funding_support = policy_calculator.calculate_funding_support_score(funding_support_str)
|
||||||
|
|
||||||
|
# 获取线下账号 转发 点赞 评论信息 {kuaishou: {account: "123456789", likes: "33", comments: "33", shares: "33"}}
|
||||||
|
platform_accounts_data = data.platform_accounts
|
||||||
|
platform_key = next(iter(platform_accounts_data)) # 或 list(data.keys())[0]
|
||||||
|
info = platform_accounts_data[platform_key]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
# 基础价值B11相关参数
|
# 基础价值B11相关参数
|
||||||
'three_year_income': three_year_income,
|
'three_year_income': three_year_income,
|
||||||
@ -377,11 +383,11 @@ async def _extract_calculation_params_b1(data: UserValuationCreate) -> Dict[str,
|
|||||||
# 流量因子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': 0.0,
|
# 'social_media_spread_s3': 0.0,
|
||||||
# 这些社交数据暂未来源,置为0,后续接入API再填充
|
# 这些社交数据暂未来源,置为0,后续接入API再填充
|
||||||
'likes': 0,
|
'likes': safe_float(info["likes"]),
|
||||||
'comments': 0,
|
'comments': safe_float(info["comments"]),
|
||||||
'shares': 0,
|
'shares': safe_float(info["shares"]),
|
||||||
# followers 非当前计算用键,先移除避免干扰
|
# followers 非当前计算用键,先移除避免干扰
|
||||||
|
|
||||||
# click_count 与 view_count 目前未参与计算,先移除
|
# click_count 与 view_count 目前未参与计算,先移除
|
||||||
@ -411,10 +417,17 @@ async def _extract_calculation_params_b2(data: UserValuationCreate) -> Dict[str,
|
|||||||
inheritor_level_coefficient = living_heritage_calculator.calculate_inheritor_level_coefficient(inheritor_level)
|
inheritor_level_coefficient = living_heritage_calculator.calculate_inheritor_level_coefficient(inheritor_level)
|
||||||
|
|
||||||
offline_sessions = int(data.offline_activities) # 线下传习次数
|
offline_sessions = int(data.offline_activities) # 线下传习次数
|
||||||
|
platform_accounts_data = data.platform_accounts
|
||||||
|
rs = {}
|
||||||
|
for platform, info in platform_accounts_data.items():
|
||||||
|
rs[platform] = {
|
||||||
|
"likes": safe_float(info.get("likes")),
|
||||||
|
}
|
||||||
# 以下调用API douyin\bilibili\kuaishou
|
# 以下调用API douyin\bilibili\kuaishou
|
||||||
douyin_views = 0
|
douyin_views = safe_float(rs.get("douyin",None).get("likes",0)) if rs.get("douyin",None) else 0
|
||||||
kuaishou_views = 0
|
kuaishou_views = safe_float(rs.get("kuaishou",None).get("likes",0)) if rs.get("kuaishou",None) else 0
|
||||||
bilibili_views = 0
|
bilibili_views = safe_float(rs.get("bilibili",None).get("likes",0)) if rs.get("bilibili",None) else 0
|
||||||
|
|
||||||
# 跨界合作深度 品牌联名0.3,科技载体0.5,国家外交礼品1.0
|
# 跨界合作深度 品牌联名0.3,科技载体0.5,国家外交礼品1.0
|
||||||
cross_border_depth = float(data.cooperation_depth)
|
cross_border_depth = float(data.cooperation_depth)
|
||||||
|
|
||||||
@ -584,13 +597,13 @@ async def delete_valuation(
|
|||||||
user_id=current_user.id,
|
user_id=current_user.id,
|
||||||
valuation_id=valuation_id
|
valuation_id=valuation_id
|
||||||
)
|
)
|
||||||
|
|
||||||
if not result:
|
if not result:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND,
|
status_code=status.HTTP_404_NOT_FOUND,
|
||||||
detail="估值评估记录不存在或已被删除"
|
detail="估值评估记录不存在或已被删除"
|
||||||
)
|
)
|
||||||
|
|
||||||
return Success(data={"deleted": True}, msg="删除估值评估成功")
|
return Success(data={"deleted": True}, msg="删除估值评估成功")
|
||||||
except HTTPException:
|
except HTTPException:
|
||||||
raise
|
raise
|
||||||
@ -621,4 +634,11 @@ def calculate_total_years(data_list):
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return total_years
|
return total_years
|
||||||
|
|
||||||
|
|
||||||
|
def safe_float(v):
|
||||||
|
try:
|
||||||
|
return float(v)
|
||||||
|
except (ValueError, TypeError):
|
||||||
|
return 0.0
|
||||||
|
|||||||
@ -68,9 +68,9 @@ class TrafficFactorB12Calculator:
|
|||||||
return social_media_spread
|
return social_media_spread
|
||||||
|
|
||||||
def calculate_interaction_index(self,
|
def calculate_interaction_index(self,
|
||||||
likes: int,
|
likes: float,
|
||||||
comments: int,
|
comments: float,
|
||||||
shares: int) -> float:
|
shares: float) -> float:
|
||||||
"""
|
"""
|
||||||
计算互动量指数
|
计算互动量指数
|
||||||
|
|
||||||
|
|||||||
1
run.py
1
run.py
@ -11,3 +11,4 @@ if __name__ == "__main__":
|
|||||||
LOGGING_CONFIG["formatters"]["access"]["datefmt"] = "%Y-%m-%d %H:%M:%S"
|
LOGGING_CONFIG["formatters"]["access"]["datefmt"] = "%Y-%m-%d %H:%M:%S"
|
||||||
|
|
||||||
uvicorn.run("app:app", host="0.0.0.0", port=9999, reload=True, log_config=LOGGING_CONFIG)
|
uvicorn.run("app:app", host="0.0.0.0", port=9999, reload=True, log_config=LOGGING_CONFIG)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user