mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 13:38:43 +00:00
refactor(增量分析): 从按天存储改为滑动窗口批次架构
- IncrementalBatch: 独立批次实体,每次增量分析产生一个,按批次独立存储到KV - IncrementalState: 聚合视图,不再持久化,报告时由merge_batches合并产生 - IncrementalStore: 批次索引+数据KV持久化,支持按时间窗口查询和过期清理 - IncrementalMergeService: 新增merge_batches方法,负责批次合并和话题/金句去重 - AnalysisApplicationService: 增量分析存独立批次,最终报告按窗口查询合并 - AutoScheduler: 报告发送后清理2×窗口外的过期批次 - main.py: /增量状态命令改为滑动窗口查询展示 - 消除天然日期隔离问题,24h图表展示完整数据
This commit is contained in:
@@ -739,7 +739,7 @@ class QQGroupDailyAnalysis(Star):
|
||||
@filter.command("增量状态", alias={"incremental_status"})
|
||||
@filter.permission_type(PermissionType.ADMIN)
|
||||
async def incremental_status(self, event: AstrMessageEvent):
|
||||
"""查看当前增量分析状态"""
|
||||
"""查看当前增量分析状态(滑动窗口)"""
|
||||
group_id = self._get_group_id_from_event(event)
|
||||
if not group_id:
|
||||
yield event.plain_result("❌ 请在群聊中使用此命令")
|
||||
@@ -749,23 +749,42 @@ class QQGroupDailyAnalysis(Star):
|
||||
yield event.plain_result("ℹ️ 增量分析模式未启用,请在插件配置中开启")
|
||||
return
|
||||
|
||||
import datetime as dt_mod
|
||||
import time as time_mod
|
||||
|
||||
today_str = dt_mod.datetime.now().strftime("%Y-%m-%d")
|
||||
state = await self.incremental_store.get_state(group_id, today_str)
|
||||
# 计算滑动窗口范围
|
||||
analysis_days = self.config_manager.get_analysis_days()
|
||||
window_end = time_mod.time()
|
||||
window_start = window_end - (analysis_days * 24 * 3600)
|
||||
|
||||
if not state or state.total_analysis_count == 0:
|
||||
yield event.plain_result(f"📊 今日 ({today_str}) 尚无增量分析数据")
|
||||
# 查询窗口内的批次
|
||||
batches = await self.incremental_store.query_batches(
|
||||
group_id, window_start, window_end
|
||||
)
|
||||
|
||||
if not batches:
|
||||
from datetime import datetime
|
||||
|
||||
start_str = datetime.fromtimestamp(window_start).strftime("%m-%d %H:%M")
|
||||
end_str = datetime.fromtimestamp(window_end).strftime("%m-%d %H:%M")
|
||||
yield event.plain_result(
|
||||
f"📊 滑动窗口 ({start_str} ~ {end_str}) 内尚无增量分析数据"
|
||||
)
|
||||
return
|
||||
|
||||
# 合并批次获取聚合视图
|
||||
state = self.incremental_merge_service.merge_batches(
|
||||
batches, window_start, window_end
|
||||
)
|
||||
summary = state.get_summary()
|
||||
|
||||
yield event.plain_result(
|
||||
f"📊 增量分析状态 ({today_str})\n"
|
||||
f"• 分析次数: {summary['total_analysis_count']}\n"
|
||||
f"• 累计消息: {summary['total_message_count']}\n"
|
||||
f"📊 增量分析状态 (窗口: {summary['window']})\n"
|
||||
f"• 分析次数: {summary['total_analyses']}\n"
|
||||
f"• 累计消息: {summary['total_messages']}\n"
|
||||
f"• 话题数: {summary['topics_count']}\n"
|
||||
f"• 金句数: {summary['quotes_count']}\n"
|
||||
f"• 参与者: {summary['participant_count']}"
|
||||
f"• 参与者: {summary['participants']}\n"
|
||||
f"• 高峰时段: {summary['peak_hours']}"
|
||||
)
|
||||
|
||||
def _get_group_id_from_event(self, event: AstrMessageEvent) -> str | None:
|
||||
|
||||
Reference in New Issue
Block a user