Files
WeChatDataAnalysis/tests/test_wrapped_reply_speed.py
2977094657 625526ff3b feat(wrapped): 新增回复速度卡片 #3(秒回置顶关心)
- 新增年度总结卡片 #3:回复速度/置顶关心统计与排行\n- 前端新增 Card03 渲染与交互(含抽奖揭晓/Top 列表)\n- 更新年度总结卡片清单并加入评分单测
2026-02-03 16:31:04 +08:00

74 lines
2.0 KiB
Python

import unittest
from pathlib import Path
import sys
# Ensure "src/" is importable when running tests from repo root.
ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT / "src"))
class TestWrappedReplySpeedScoring(unittest.TestCase):
def test_score_prefers_more_chat_when_speed_similar(self):
from wechat_decrypt_tool.wrapped.cards.card_03_reply_speed import _ConvAgg, _score_conv
tau = 30 * 60 # 30min, keep in sync with production default
# A: 秒回,但聊天很少
a = _ConvAgg(
username="wxid_a",
incoming=3,
outgoing=3,
replies=3,
sum_gap=30,
sum_gap_capped=30,
min_gap=5,
max_gap=15,
)
# B: 稍慢,但聊天明显更多
b = _ConvAgg(
username="wxid_b",
incoming=50,
outgoing=50,
replies=50,
sum_gap=3000, # avg 60s
sum_gap_capped=3000,
min_gap=10,
max_gap=120,
)
self.assertGreater(_score_conv(agg=b, tau_seconds=tau), _score_conv(agg=a, tau_seconds=tau))
def test_score_penalizes_extremely_slow_reply(self):
from wechat_decrypt_tool.wrapped.cards.card_03_reply_speed import _ConvAgg, _score_conv
tau = 30 * 60
fast_few = _ConvAgg(
username="wxid_fast",
incoming=5,
outgoing=5,
replies=5,
sum_gap=50, # avg 10s
sum_gap_capped=50,
min_gap=1,
max_gap=20,
)
slow_many = _ConvAgg(
username="wxid_slow",
incoming=80,
outgoing=80,
replies=80,
sum_gap=80 * 7200, # avg 2h
sum_gap_capped=80 * 7200,
min_gap=60,
max_gap=100000,
)
self.assertGreater(_score_conv(agg=fast_few, tau_seconds=tau), _score_conv(agg=slow_many, tau_seconds=tau))
if __name__ == "__main__":
unittest.main()