mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 20:01:04 +00:00
fix(analysis_application_service): 解决增量分析传参错误导致用户称号失效的问题
This commit is contained in:
@@ -15,6 +15,7 @@ import time
|
||||
import uuid
|
||||
from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -56,7 +57,7 @@ class IncrementalBatch:
|
||||
user_stats: dict[str, dict] = field(default_factory=dict)
|
||||
|
||||
# 表情统计
|
||||
emoji_stats: dict[str, int] = field(default_factory=dict)
|
||||
emoji_stats: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
# LLM 分析结果
|
||||
topics: list[dict] = field(default_factory=list)
|
||||
@@ -178,7 +179,7 @@ class IncrementalState:
|
||||
user_activities: dict[str, dict] = field(default_factory=dict)
|
||||
|
||||
# 表情统计
|
||||
emoji_counts: dict[str, int] = field(default_factory=dict)
|
||||
emoji_counts: dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
# 汇总统计
|
||||
total_message_count: int = 0
|
||||
@@ -247,7 +248,7 @@ class IncrementalState:
|
||||
users.append(
|
||||
{
|
||||
"user_id": user_id,
|
||||
"name": data.get("name", user_id),
|
||||
"name": data.get("nickname", data.get("name", user_id)),
|
||||
"message_count": data.get("message_count", 0),
|
||||
"char_count": data.get("char_count", 0),
|
||||
}
|
||||
|
||||
@@ -52,6 +52,22 @@ class IAnalysisProvider(ABC):
|
||||
user_activity: dict,
|
||||
umo: str | None = None,
|
||||
top_users: list[dict] | None = None,
|
||||
topic_enabled: bool = True,
|
||||
user_title_enabled: bool = True,
|
||||
golden_quote_enabled: bool = True,
|
||||
) -> tuple[list[SummaryTopic], list[UserTitle], list[GoldenQuote], TokenUsage]:
|
||||
"""并发分析所有内容"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
async def analyze_incremental_concurrent(
|
||||
self,
|
||||
messages: list[dict],
|
||||
umo: str | None = None,
|
||||
topics_per_batch: int = 3,
|
||||
quotes_per_batch: int = 3,
|
||||
topic_enabled: bool = True,
|
||||
golden_quote_enabled: bool = True,
|
||||
) -> tuple[list[SummaryTopic], list[GoldenQuote], TokenUsage]:
|
||||
"""增量模式并发分析"""
|
||||
pass
|
||||
|
||||
@@ -83,7 +83,8 @@ class IncrementalMergeService:
|
||||
)
|
||||
|
||||
# 合并用户统计(按用户累加消息数、字符数等)
|
||||
for user_id, stats in batch.user_stats.items():
|
||||
for raw_user_id, stats in batch.user_stats.items():
|
||||
user_id = str(raw_user_id)
|
||||
if user_id not in state.user_activities:
|
||||
state.user_activities[user_id] = {
|
||||
"nickname": stats.get("nickname", stats.get("name", user_id)),
|
||||
@@ -122,9 +123,9 @@ class IncrementalMergeService:
|
||||
if batch_last > existing.get("last_message_time", 0):
|
||||
existing["last_message_time"] = batch_last
|
||||
|
||||
# 更新昵称(使用最新批次的昵称)
|
||||
# 更新昵称(使用最新批次的有效昵称)
|
||||
nickname = stats.get("nickname", stats.get("name", ""))
|
||||
if nickname:
|
||||
if nickname and str(nickname).strip():
|
||||
existing["nickname"] = nickname
|
||||
|
||||
# 合并表情统计(按键累加)
|
||||
@@ -136,7 +137,11 @@ class IncrementalMergeService:
|
||||
current_val = {}
|
||||
|
||||
for sub_key, sub_count in count.items():
|
||||
current_val[sub_key] = current_val.get(sub_key, 0) + sub_count
|
||||
# 确保 current_val 是字典且 sub_count 是数字
|
||||
if isinstance(current_val, dict):
|
||||
current_val[sub_key] = (
|
||||
current_val.get(sub_key, 0) + sub_count
|
||||
)
|
||||
|
||||
state.emoji_counts[emoji_key] = current_val
|
||||
else:
|
||||
@@ -356,11 +361,17 @@ class IncrementalMergeService:
|
||||
EmojiStatistics: 表情统计实例
|
||||
"""
|
||||
emoji_counts = state.emoji_counts
|
||||
|
||||
# 显式提取并检查类型,辅助 Pylance 类型推断
|
||||
face_details = emoji_counts.get("face_details")
|
||||
if not isinstance(face_details, dict):
|
||||
face_details = {}
|
||||
|
||||
return EmojiStatistics(
|
||||
face_count=emoji_counts.get("face_count", 0),
|
||||
mface_count=emoji_counts.get("mface_count", 0),
|
||||
bface_count=emoji_counts.get("bface_count", 0),
|
||||
sface_count=emoji_counts.get("sface_count", 0),
|
||||
other_emoji_count=emoji_counts.get("other_emoji_count", 0),
|
||||
face_details=emoji_counts.get("face_details", {}),
|
||||
face_details=face_details,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user