🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-06-22 10:22:57 +00:00
parent 06927f89a0
commit 0bccb2f2c8

View File

@@ -478,7 +478,6 @@ class StatisticOutputTask(AsyncTask):
HFC_AVG_TIME_BY_ACTION: defaultdict(lambda: {"decision": 0, "action": 0, "total": 0}),
HFC_AVG_TIME_BY_VERSION: defaultdict(lambda: {"decision": 0, "action": 0, "total": 0}),
HFC_ACTIONS_BY_CHAT: defaultdict(lambda: defaultdict(int)), # 群聊×动作交叉统计
}
for period_key, _ in collect_period
}
@@ -493,11 +492,11 @@ class StatisticOutputTask(AsyncTask):
return stats
# 读取HFC统计数据
with open(hfc_stats_file, 'r', encoding='utf-8') as f:
with open(hfc_stats_file, "r", encoding="utf-8") as f:
hfc_data = json.load(f)
# 处理每个chat_id和版本的统计数据
for stats_key, chat_stats in hfc_data.items():
for _stats_key, chat_stats in hfc_data.items():
chat_id = chat_stats.get("chat_id", "unknown")
version = chat_stats.get("version", "unknown")
last_updated_str = chat_stats.get("last_updated")
@@ -507,7 +506,7 @@ class StatisticOutputTask(AsyncTask):
# 解析最后更新时间
try:
last_updated = datetime.fromisoformat(last_updated_str.replace('Z', '+00:00'))
last_updated = datetime.fromisoformat(last_updated_str.replace("Z", "+00:00"))
if last_updated.tzinfo:
last_updated = last_updated.replace(tzinfo=None)
except:
@@ -558,11 +557,26 @@ class StatisticOutputTask(AsyncTask):
# 累加时间统计(用于后续计算加权平均)
# 这里我们需要重新设计数据结构来存储累计值
if chat_id not in stats[period_key][HFC_AVG_TIME_BY_CHAT]:
stats[period_key][HFC_AVG_TIME_BY_CHAT][chat_id] = {"decision": 0, "action": 0, "total": 0, "count": 0}
stats[period_key][HFC_AVG_TIME_BY_CHAT][chat_id] = {
"decision": 0,
"action": 0,
"total": 0,
"count": 0,
}
if action_type not in stats[period_key][HFC_AVG_TIME_BY_ACTION]:
stats[period_key][HFC_AVG_TIME_BY_ACTION][action_type] = {"decision": 0, "action": 0, "total": 0, "count": 0}
stats[period_key][HFC_AVG_TIME_BY_ACTION][action_type] = {
"decision": 0,
"action": 0,
"total": 0,
"count": 0,
}
if version not in stats[period_key][HFC_AVG_TIME_BY_VERSION]:
stats[period_key][HFC_AVG_TIME_BY_VERSION][version] = {"decision": 0, "action": 0, "total": 0, "count": 0}
stats[period_key][HFC_AVG_TIME_BY_VERSION][version] = {
"decision": 0,
"action": 0,
"total": 0,
"count": 0,
}
# 累加加权值(时间*数量)
stats[period_key][HFC_AVG_TIME_BY_CHAT][chat_id]["decision"] += decision_time * total_records
@@ -570,7 +584,9 @@ class StatisticOutputTask(AsyncTask):
stats[period_key][HFC_AVG_TIME_BY_CHAT][chat_id]["total"] += total_time * total_records
stats[period_key][HFC_AVG_TIME_BY_CHAT][chat_id]["count"] += total_records
stats[period_key][HFC_AVG_TIME_BY_ACTION][action_type]["decision"] += action_decision_time * count
stats[period_key][HFC_AVG_TIME_BY_ACTION][action_type]["decision"] += (
action_decision_time * count
)
stats[period_key][HFC_AVG_TIME_BY_ACTION][action_type]["action"] += action_exec_time * count
stats[period_key][HFC_AVG_TIME_BY_ACTION][action_type]["total"] += action_total_time * count
stats[period_key][HFC_AVG_TIME_BY_ACTION][action_type]["count"] += count
@@ -593,7 +609,7 @@ class StatisticOutputTask(AsyncTask):
stats[period_key][stat_type][key] = {
"decision": time_data["decision"] / count,
"action": time_data["action"] / count,
"total": time_data["total"] / count
"total": time_data["total"] / count,
}
else:
stats[period_key][stat_type][key] = {"decision": 0, "action": 0, "total": 0}
@@ -652,7 +668,11 @@ class StatisticOutputTask(AsyncTask):
# 是字典类型,则进行合并
for sub_key, sub_val in val.items():
# 检查是否是HFC的嵌套字典时间数据
if key in [HFC_AVG_TIME_BY_CHAT, HFC_AVG_TIME_BY_ACTION, HFC_AVG_TIME_BY_VERSION] and isinstance(sub_val, dict):
if key in [
HFC_AVG_TIME_BY_CHAT,
HFC_AVG_TIME_BY_ACTION,
HFC_AVG_TIME_BY_VERSION,
] and isinstance(sub_val, dict):
# 对于HFC时间数据需要特殊处理
if sub_key not in stat["all_time"][key]:
stat["all_time"][key][sub_key] = {"decision": 0, "action": 0, "total": 0, "count": 0}
@@ -699,7 +719,7 @@ class StatisticOutputTask(AsyncTask):
"decision": time_data["decision"] / count,
"action": time_data["action"] / count,
"total": time_data["total"] / count,
"count": count # 保留count字段
"count": count, # 保留count字段
}
stat["all_time"][stat_type][key] = avg_data
else:
@@ -1170,15 +1190,16 @@ class StatisticOutputTask(AsyncTask):
try:
# 首先尝试从chat_stream获取真实群组名称
from src.chat.message_receive.chat_stream import get_chat_manager
chat_manager = get_chat_manager()
if chat_id in chat_manager.streams:
stream = chat_manager.streams[chat_id]
if stream.group_info and hasattr(stream.group_info, 'group_name'):
if stream.group_info and hasattr(stream.group_info, "group_name"):
group_name = stream.group_info.group_name
if group_name and group_name.strip():
return group_name.strip()
elif stream.user_info and hasattr(stream.user_info, 'user_nickname'):
elif stream.user_info and hasattr(stream.user_info, "user_nickname"):
user_name = stream.user_info.user_nickname
if user_name and user_name.strip():
return user_name.strip()
@@ -1364,11 +1385,7 @@ class StatisticOutputTask(AsyncTask):
sections = []
# 定义要显示的时间段及其描述(所有时间在最上方)
time_periods = [
("all_time", "全部时间"),
("last_24_hours", "最近24小时"),
("last_7_days", "最近7天")
]
time_periods = [("all_time", "全部时间"), ("last_24_hours", "最近24小时"), ("last_7_days", "最近7天")]
for period_key, period_desc in time_periods:
period_data = stat.get(period_key, {})