From d21089ab696c3611093ba20d30d9177464f8c844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AF=BB=E6=AC=A2?= Date: Wed, 13 Mar 2024 10:32:20 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E7=BE=A4=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=96=B0=E5=A2=9E=E5=89=8D=E5=8D=81=E5=90=8D?= =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=95=B0=E5=8D=A0=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tasks/watergroup/month.go | 15 +++++++++++---- tasks/watergroup/week.go | 15 +++++++++++---- tasks/watergroup/year.go | 15 +++++++++++---- tasks/watergroup/yesterday.go | 15 +++++++++++---- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/tasks/watergroup/month.go b/tasks/watergroup/month.go index 971df23e..f3b8c81f 100644 --- a/tasks/watergroup/month.go +++ b/tasks/watergroup/month.go @@ -74,14 +74,16 @@ func dealMonth(gid string) { activity = fmt.Sprintf("%.2f", (float64(len(records))/float64(groupUsers))*100) } - // 计算消息总数、中位数 - var msgCount int64 - var medianCount int64 + // 计算消息总数、中位数、前十位消息总数 + var msgCount, medianCount, topTenCount int64 for idx, v := range records { msgCount += v.Count if idx == (len(records)/2)-1 { medianCount = v.Count } + if len(records) > 10 && idx < 10 { + topTenCount += v.Count + } } // 计算活跃用户人均消息条数 avgMsgCount := int(float64(msgCount) / float64(len(records))) @@ -90,7 +92,12 @@ func dealMonth(gid string) { notifyMsgs = append(notifyMsgs, " ") notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ %s本群 %d 位朋友共产生 %d 条发言", monthStr, len(records), msgCount)) if showActivity { - notifyMsgs = append(notifyMsgs, fmt.Sprintf("🎭 活跃度: %s%%,人均消息条数: %d,中位数: %d", activity, avgMsgCount, medianCount)) + m := fmt.Sprintf("🎭 活跃度: %s%%,人均消息条数: %d,中位数: %d", activity, avgMsgCount, medianCount) + // 计算前十占比 + if topTenCount > 0 { + m += fmt.Sprintf(",前十名占比: %.2f%%", float64(topTenCount)/float64(msgCount)*100) + } + notifyMsgs = append(notifyMsgs, m) } notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵") diff --git a/tasks/watergroup/week.go b/tasks/watergroup/week.go index b8df0c95..b4902c07 100644 --- a/tasks/watergroup/week.go +++ b/tasks/watergroup/week.go @@ -73,14 +73,16 @@ func dealWeek(gid string) { activity = fmt.Sprintf("%.2f", (float64(len(records))/float64(groupUsers))*100) } - // 计算消息总数、中位数 - var msgCount int64 - var medianCount int64 + // 计算消息总数、中位数、前十位消息总数 + var msgCount, medianCount, topTenCount int64 for idx, v := range records { msgCount += v.Count if idx == (len(records)/2)-1 { medianCount = v.Count } + if len(records) > 10 && idx < 10 { + topTenCount += v.Count + } } // 计算活跃用户人均消息条数 avgMsgCount := int(float64(msgCount) / float64(len(records))) @@ -89,7 +91,12 @@ func dealWeek(gid string) { notifyMsgs = append(notifyMsgs, " ") notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ 上周本群 %d 位朋友共产生 %d 条发言", len(records), msgCount)) if showActivity { - notifyMsgs = append(notifyMsgs, fmt.Sprintf("🎭 活跃度: %s%%,人均消息条数: %d,中位数: %d", activity, avgMsgCount, medianCount)) + m := fmt.Sprintf("🎭 活跃度: %s%%,人均消息条数: %d,中位数: %d", activity, avgMsgCount, medianCount) + // 计算前十占比 + if topTenCount > 0 { + m += fmt.Sprintf(",前十名占比: %.2f%%", float64(topTenCount)/float64(msgCount)*100) + } + notifyMsgs = append(notifyMsgs, m) } notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵") diff --git a/tasks/watergroup/year.go b/tasks/watergroup/year.go index aba255a1..8ea50ba7 100644 --- a/tasks/watergroup/year.go +++ b/tasks/watergroup/year.go @@ -73,14 +73,16 @@ func dealYear(gid string) { activity = fmt.Sprintf("%.2f", (float64(len(records))/float64(groupUsers))*100) } - // 计算消息总数、中位数 - var msgCount int64 - var medianCount int64 + // 计算消息总数、中位数、前十位消息总数 + var msgCount, medianCount, topTenCount int64 for idx, v := range records { msgCount += v.Count if idx == (len(records)/2)-1 { medianCount = v.Count } + if len(records) > 10 && idx < 10 { + topTenCount += v.Count + } } // 计算活跃用户人均消息条数 avgMsgCount := int(float64(msgCount) / float64(len(records))) @@ -97,7 +99,12 @@ func dealYear(gid string) { notifyMsgs = append(notifyMsgs, " ") notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ 去年本群 %d 位朋友共产生 %d 条发言", len(records), msgCount)) if showActivity { - notifyMsgs = append(notifyMsgs, fmt.Sprintf("🎭 活跃度: %s%%,人均消息条数: %d,中位数: %d", activity, avgMsgCount, medianCount)) + m := fmt.Sprintf("🎭 活跃度: %s%%,人均消息条数: %d,中位数: %d", activity, avgMsgCount, medianCount) + // 计算前十占比 + if topTenCount > 0 { + m += fmt.Sprintf(",前十名占比: %.2f%%", float64(topTenCount)/float64(msgCount)*100) + } + notifyMsgs = append(notifyMsgs, m) } notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵") diff --git a/tasks/watergroup/yesterday.go b/tasks/watergroup/yesterday.go index b932756a..e6b38638 100644 --- a/tasks/watergroup/yesterday.go +++ b/tasks/watergroup/yesterday.go @@ -75,14 +75,16 @@ func dealYesterday(gid string) { activity = fmt.Sprintf("%.2f", (float64(len(records))/float64(groupUsers))*100) } - // 计算消息总数、中位数 - var msgCount int64 - var medianCount int64 + // 计算消息总数、中位数、前十位消息总数 + var msgCount, medianCount, topTenCount int64 for idx, v := range records { msgCount += v.Count if idx == (len(records)/2)-1 { medianCount = v.Count } + if len(records) > 10 && idx < 10 { + topTenCount += v.Count + } } // 计算活跃用户人均消息条数 avgMsgCount := int(float64(msgCount) / float64(len(records))) @@ -91,7 +93,12 @@ func dealYesterday(gid string) { notifyMsgs = append(notifyMsgs, " ") notifyMsgs = append(notifyMsgs, fmt.Sprintf("🗣️ 昨日本群 %d 位朋友共产生 %d 条发言", len(records), msgCount)) if showActivity { - notifyMsgs = append(notifyMsgs, fmt.Sprintf("🎭 活跃度: %s%%,人均消息条数: %d,中位数: %d", activity, avgMsgCount, medianCount)) + m := fmt.Sprintf("🎭 活跃度: %s%%,人均消息条数: %d,中位数: %d", activity, avgMsgCount, medianCount) + // 计算前十占比 + if topTenCount > 0 { + m += fmt.Sprintf(",前十名占比: %.2f%%", float64(topTenCount)/float64(msgCount)*100) + } + notifyMsgs = append(notifyMsgs, m) } notifyMsgs = append(notifyMsgs, "\n🏵 活跃用户排行榜 🏵")