今日更新数据
This commit is contained in:
@@ -794,8 +794,107 @@ class IntegratedProductSystem:
|
||||
conn.close()
|
||||
logger.info("数据库连接已关闭")
|
||||
|
||||
def reanalyze_invalid_difficulty_scores(self):
|
||||
"""重新分析difficulty_score为1的行,确保难度评分准确"""
|
||||
logger.info("=== 开始重新分析无效难度评分 ===")
|
||||
|
||||
conn = None
|
||||
try:
|
||||
# 连接数据库
|
||||
conn = self.connect_to_database()
|
||||
cursor = conn.cursor()
|
||||
|
||||
# 查询difficulty_score为1的记录
|
||||
cursor.execute("""
|
||||
SELECT id, original_name, product_intro, development_difficulty, ai_response
|
||||
FROM product_analysis
|
||||
WHERE difficulty_score = 1
|
||||
""")
|
||||
|
||||
invalid_records = cursor.fetchall()
|
||||
logger.info(f"找到 {len(invalid_records)} 条difficulty_score为1的记录需要重新分析")
|
||||
|
||||
if not invalid_records:
|
||||
logger.info("没有发现需要重新分析的无效难度评分记录")
|
||||
return
|
||||
|
||||
# 为每个无效记录重新分析难度
|
||||
updated_count = 0
|
||||
for i, (analysis_id, name, introduction, development_difficulty, ai_response) in enumerate(invalid_records, 1):
|
||||
logger.info(f"重新分析记录 {i}/{len(invalid_records)}: {name}")
|
||||
|
||||
# 调用AI API重新分析产品难度
|
||||
logger.info(f"重新调用Ollama API分析产品难度: {name}")
|
||||
|
||||
# 构建请求数据 - 使用Ollama API格式,专门用于难度分析
|
||||
prompt = f"这个是【{name}】,简介内容是【{introduction}】。请重新分析这个产品的开发难度,特别是对于一个人加上AI辅助能否开发这个产品,请详细回答。返回的内容是产品名称/产品简介/开发难度。返回的例子一:notion/这个是笔记产品等等/一个人开发难度较高"
|
||||
|
||||
data = {
|
||||
"model": "qwen3:8b",
|
||||
"prompt": prompt,
|
||||
"stream": False
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
|
||||
try:
|
||||
# 调用Ollama API
|
||||
response = requests.post(
|
||||
self.api_url,
|
||||
headers=headers,
|
||||
data=json.dumps(data, ensure_ascii=False),
|
||||
timeout=60
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
new_ai_response = result.get("response", "").strip()
|
||||
logger.success(f"成功重新分析产品 '{name}'")
|
||||
|
||||
# 解析新的响应,获取难度分数
|
||||
_, new_difficulty, new_difficulty_score = self.parse_ai_response(new_ai_response)
|
||||
|
||||
# 特别处理很难的情况,确保分数在70-90之间
|
||||
difficulty_lower = new_difficulty.lower()
|
||||
if any(keyword in difficulty_lower for keyword in ['高', '很难', '非常难', '复杂', '困难']):
|
||||
if new_difficulty_score < 70:
|
||||
new_difficulty_score = max(70, min(90, new_difficulty_score + 60))
|
||||
logger.info(f"调整很难产品的难度分数为: {new_difficulty_score} (70-90区间)")
|
||||
|
||||
# 更新数据库记录
|
||||
cursor.execute("""
|
||||
UPDATE product_analysis
|
||||
SET development_difficulty = ?,
|
||||
difficulty_score = ?,
|
||||
ai_response = ?
|
||||
WHERE id = ?
|
||||
""", (new_difficulty, new_difficulty_score, new_ai_response, analysis_id))
|
||||
|
||||
conn.commit()
|
||||
updated_count += 1
|
||||
logger.success(f"成功更新产品 '{name}' 的难度分数为 {new_difficulty_score}")
|
||||
else:
|
||||
logger.error(f"API调用失败: {response.status_code}, {response.text}")
|
||||
except Exception as e:
|
||||
logger.error(f"重新分析产品 '{name}' 失败: {e}")
|
||||
|
||||
# 避免API调用过于频繁
|
||||
if i < len(invalid_records):
|
||||
time.sleep(2)
|
||||
|
||||
logger.success(f"无效难度评分重新分析完成! 成功更新 {updated_count} 条记录")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"重新分析无效难度评分过程中出错: {e}")
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
logger.info("数据库连接已关闭")
|
||||
|
||||
async def run_full_workflow_async(self, max_products=None, analyze_only=False):
|
||||
"""异步运行完整工作流程:抓取+分析+补充缺失分数+更新关注数"""
|
||||
"""异步运行完整工作流程:抓取+分析+补充缺失分数+更新关注数+重新分析无效难度评分"""
|
||||
logger.info("=== 开始全功能产品系统工作流程 ===")
|
||||
|
||||
# 初始化数据库
|
||||
@@ -820,6 +919,10 @@ class IntegratedProductSystem:
|
||||
logger.info("步骤4: 开始分析并更新产品关注数...")
|
||||
self.analyze_follower_counts()
|
||||
|
||||
# 步骤5: 重新分析invalid难度评分
|
||||
logger.info("步骤5: 开始重新分析invalid难度评分...")
|
||||
self.reanalyze_invalid_difficulty_scores()
|
||||
|
||||
logger.success("=== 全功能产品系统工作流程完成 ===")
|
||||
|
||||
def run_full_workflow(self, max_products=None, analyze_only=False):
|
||||
|
||||
Reference in New Issue
Block a user