mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-04-30 16:52:45 +08:00
feat: 重构TimeTab
This commit is contained in:
@@ -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-6,0=周日
|
||||
// 我们需要转换为 1-7,1=周一,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个)
|
||||
|
||||
@@ -12,6 +12,7 @@ export {
|
||||
getMemberActivity,
|
||||
getHourlyActivity,
|
||||
getDailyActivity,
|
||||
getWeekdayActivity,
|
||||
getMessageTypeDistribution,
|
||||
getTimeRange,
|
||||
getMemberNameHistory,
|
||||
|
||||
Reference in New Issue
Block a user