mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-24 23:06:51 +00:00
解决年度报告导出失败 #252;集成WechatVisualization的功能并支持词云排除 #259
This commit is contained in:
@@ -11,6 +11,7 @@ interface WorkerConfig {
|
||||
resourcesPath?: string
|
||||
userDataPath?: string
|
||||
logEnabled?: boolean
|
||||
excludeWords?: string[]
|
||||
}
|
||||
|
||||
const config = workerData as WorkerConfig
|
||||
@@ -29,6 +30,7 @@ async function run() {
|
||||
dbPath: config.dbPath,
|
||||
decryptKey: config.decryptKey,
|
||||
wxid: config.myWxid,
|
||||
excludeWords: config.excludeWords,
|
||||
onProgress: (status: string, progress: number) => {
|
||||
parentPort?.postMessage({
|
||||
type: 'dualReport:progress',
|
||||
|
||||
@@ -1195,6 +1195,7 @@ function registerIpcHandlers() {
|
||||
const logEnabled = cfg.get('logEnabled')
|
||||
const friendUsername = payload?.friendUsername
|
||||
const year = payload?.year ?? 0
|
||||
const excludeWords = cfg.get('wordCloudExcludeWords') || []
|
||||
|
||||
if (!friendUsername) {
|
||||
return { success: false, error: '缺少好友用户名' }
|
||||
@@ -1209,7 +1210,7 @@ function registerIpcHandlers() {
|
||||
|
||||
return await new Promise((resolve) => {
|
||||
const worker = new Worker(workerPath, {
|
||||
workerData: { year, friendUsername, dbPath, decryptKey, myWxid: wxid, resourcesPath, userDataPath, logEnabled }
|
||||
workerData: { year, friendUsername, dbPath, decryptKey, myWxid: wxid, resourcesPath, userDataPath, logEnabled, excludeWords }
|
||||
})
|
||||
|
||||
const cleanup = () => {
|
||||
|
||||
@@ -116,7 +116,7 @@ class AnnualReportService {
|
||||
}
|
||||
const suffixMatch = trimmed.match(/^(.+)_([a-zA-Z0-9]{4})$/)
|
||||
const cleaned = suffixMatch ? suffixMatch[1] : trimmed
|
||||
|
||||
|
||||
return cleaned
|
||||
}
|
||||
|
||||
@@ -499,7 +499,7 @@ class AnnualReportService {
|
||||
}
|
||||
}
|
||||
|
||||
this.reportProgress('加载扩展统计... (初始化)', 30, onProgress)
|
||||
this.reportProgress('加载扩展统计...', 30, onProgress)
|
||||
const extras = await wcdbService.getAnnualReportExtras(sessionIds, actualStartTime, actualEndTime, peakDayBegin, peakDayEnd)
|
||||
if (extras.success && extras.data) {
|
||||
this.reportProgress('加载扩展统计... (解析热力图)', 32, onProgress)
|
||||
|
||||
@@ -42,6 +42,7 @@ interface ConfigSchema {
|
||||
notificationPosition: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left'
|
||||
notificationFilterMode: 'all' | 'whitelist' | 'blacklist'
|
||||
notificationFilterList: string[]
|
||||
wordCloudExcludeWords: string[]
|
||||
}
|
||||
|
||||
export class ConfigService {
|
||||
@@ -94,7 +95,8 @@ export class ConfigService {
|
||||
notificationEnabled: true,
|
||||
notificationPosition: 'top-right',
|
||||
notificationFilterMode: 'all',
|
||||
notificationFilterList: []
|
||||
notificationFilterList: [],
|
||||
wordCloudExcludeWords: []
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { parentPort } from 'worker_threads'
|
||||
import { wcdbService } from './wcdbService'
|
||||
|
||||
|
||||
export interface DualReportMessage {
|
||||
content: string
|
||||
isSentByMe: boolean
|
||||
@@ -58,6 +59,8 @@ export interface DualReportData {
|
||||
} | null
|
||||
stats: DualReportStats
|
||||
topPhrases: Array<{ phrase: string; count: number }>
|
||||
myExclusivePhrases: Array<{ phrase: string; count: number }>
|
||||
friendExclusivePhrases: Array<{ phrase: string; count: number }>
|
||||
heatmap?: number[][]
|
||||
initiative?: { initiated: number; received: number }
|
||||
response?: { avg: number; fastest: number; count: number }
|
||||
@@ -499,10 +502,11 @@ class DualReportService {
|
||||
dbPath: string
|
||||
decryptKey: string
|
||||
wxid: string
|
||||
excludeWords?: string[]
|
||||
onProgress?: (status: string, progress: number) => void
|
||||
}): Promise<{ success: boolean; data?: DualReportData; error?: string }> {
|
||||
try {
|
||||
const { year, friendUsername, dbPath, decryptKey, wxid, onProgress } = params
|
||||
const { year, friendUsername, dbPath, decryptKey, wxid, excludeWords, onProgress } = params
|
||||
this.reportProgress('正在连接数据库...', 5, onProgress)
|
||||
const conn = await this.ensureConnectedWithConfig(dbPath, decryptKey, wxid)
|
||||
if (!conn.success || !conn.cleanedWxid || !conn.rawWxid) return { success: false, error: conn.error }
|
||||
@@ -714,11 +718,58 @@ class DualReportService {
|
||||
if (myTopCount >= 0) stats.myTopEmojiCount = myTopCount
|
||||
if (friendTopCount >= 0) stats.friendTopEmojiCount = friendTopCount
|
||||
|
||||
const topPhrases = (cppData.phrases || []).map((p: any) => ({
|
||||
if (friendTopCount >= 0) stats.friendTopEmojiCount = friendTopCount
|
||||
|
||||
const excludeSet = new Set(excludeWords || [])
|
||||
|
||||
const filterPhrases = (list: any[]) => {
|
||||
return (list || []).filter((p: any) => !excludeSet.has(p.phrase))
|
||||
}
|
||||
|
||||
const cleanPhrases = filterPhrases(cppData.phrases)
|
||||
const cleanMyPhrases = filterPhrases(cppData.myPhrases)
|
||||
const cleanFriendPhrases = filterPhrases(cppData.friendPhrases)
|
||||
|
||||
const topPhrases = cleanPhrases.map((p: any) => ({
|
||||
phrase: p.phrase,
|
||||
count: p.count
|
||||
}))
|
||||
|
||||
// 计算专属词汇:一方频繁使用而另一方很少使用的词
|
||||
const myPhraseMap = new Map<string, number>()
|
||||
const friendPhraseMap = new Map<string, number>()
|
||||
for (const p of cleanMyPhrases) {
|
||||
myPhraseMap.set(p.phrase, p.count)
|
||||
}
|
||||
for (const p of cleanFriendPhrases) {
|
||||
friendPhraseMap.set(p.phrase, p.count)
|
||||
}
|
||||
|
||||
// 专属词汇:该方使用占比 >= 75% 且至少出现 2 次
|
||||
const myExclusivePhrases: Array<{ phrase: string; count: number }> = []
|
||||
const friendExclusivePhrases: Array<{ phrase: string; count: number }> = []
|
||||
|
||||
for (const [phrase, myCount] of myPhraseMap) {
|
||||
const friendCount = friendPhraseMap.get(phrase) || 0
|
||||
const total = myCount + friendCount
|
||||
if (myCount >= 2 && total > 0 && myCount / total >= 0.75) {
|
||||
myExclusivePhrases.push({ phrase, count: myCount })
|
||||
}
|
||||
}
|
||||
for (const [phrase, friendCount] of friendPhraseMap) {
|
||||
const myCount = myPhraseMap.get(phrase) || 0
|
||||
const total = myCount + friendCount
|
||||
if (friendCount >= 2 && total > 0 && friendCount / total >= 0.75) {
|
||||
friendExclusivePhrases.push({ phrase, count: friendCount })
|
||||
}
|
||||
}
|
||||
|
||||
// 按频率排序,取前 20
|
||||
myExclusivePhrases.sort((a, b) => b.count - a.count)
|
||||
friendExclusivePhrases.sort((a, b) => b.count - a.count)
|
||||
if (myExclusivePhrases.length > 20) myExclusivePhrases.length = 20
|
||||
if (friendExclusivePhrases.length > 20) friendExclusivePhrases.length = 20
|
||||
|
||||
const reportData: DualReportData = {
|
||||
year: reportYear,
|
||||
selfName: myName,
|
||||
@@ -731,6 +782,8 @@ class DualReportService {
|
||||
yearFirstChat,
|
||||
stats,
|
||||
topPhrases,
|
||||
myExclusivePhrases,
|
||||
friendExclusivePhrases,
|
||||
heatmap: cppData.heatmap,
|
||||
initiative: cppData.initiative,
|
||||
response: cppData.response,
|
||||
|
||||
Reference in New Issue
Block a user