feat: 重构TimeTab

This commit is contained in:
digua
2025-11-28 17:34:47 +08:00
parent 035db60645
commit 72605a6ef4
11 changed files with 354 additions and 115 deletions

View File

@@ -7,6 +7,7 @@ import type {
MemberActivity,
HourlyActivity,
DailyActivity,
WeekdayActivity,
MessageType,
RepeatAnalysis,
RepeatStatItem,
@@ -520,6 +521,54 @@ export function getRepeatAnalysis(sessionId: string, filter?: TimeFilter): Repea
}
}
/**
* 获取星期活跃度分布
* 返回周一到周日的消息统计
*/
export function getWeekdayActivity(sessionId: string, filter?: TimeFilter): WeekdayActivity[] {
const db = openDatabase(sessionId)
if (!db) return []
try {
const { clause, params } = buildTimeFilter(filter)
const clauseWithSystem = buildSystemMessageFilter(clause)
// SQLite strftime('%w') 返回 0-60=周日
// 我们需要转换为 1-71=周一7=周日
const rows = db
.prepare(
`
SELECT
CASE
WHEN CAST(strftime('%w', msg.ts, 'unixepoch', 'localtime') AS INTEGER) = 0 THEN 7
ELSE CAST(strftime('%w', msg.ts, 'unixepoch', 'localtime') AS INTEGER)
END as weekday,
COUNT(*) as messageCount
FROM message msg
JOIN member m ON msg.sender_id = m.id
${clauseWithSystem}
GROUP BY weekday
ORDER BY weekday
`
)
.all(...params) as Array<{ weekday: number; messageCount: number }>
// 补全所有星期1-7
const result: WeekdayActivity[] = []
for (let w = 1; w <= 7; w++) {
const found = rows.find((r) => r.weekday === w)
result.push({
weekday: w,
messageCount: found ? found.messageCount : 0,
})
}
return result
} finally {
db.close()
}
}
/**
* 获取口头禅分析数据
* 统计每个成员最常说的内容前5个

View File

@@ -12,6 +12,7 @@ export {
getMemberActivity,
getHourlyActivity,
getDailyActivity,
getWeekdayActivity,
getMessageTypeDistribution,
getTimeRange,
getMemberNameHistory,