1
0
forked from lxh/go-wxhelper

Merge pull request ' 群消息统计新增前十名消息数占比' (#31) from hotfix into main

Reviewed-on: lxh/go-wxhelper#31
This commit is contained in:
李寻欢 2024-03-13 10:33:15 +08:00
commit a414a98a51
4 changed files with 44 additions and 16 deletions

View File

@ -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🏵 活跃用户排行榜 🏵")

View File

@ -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🏵 活跃用户排行榜 🏵")

View File

@ -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🏵 活跃用户排行榜 🏵")

View File

@ -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🏵 活跃用户排行榜 🏵")