feat(management): 评分引擎——三类标准化/维度归一/样本保护/等级/四对比明细+期末active_friends接口修订

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-09 17:42:57 +08:00
parent b51b32a14b
commit c9f8c844d6
5 changed files with 507 additions and 12 deletions
@@ -120,26 +120,32 @@ async def test_period_sums_vs_daily_rows(make_session):
async def test_end_of_period_stock(make_session):
"""期末存量=每渠道最新 ≤end 行:窗 [0901,0903] 取 0901 行、
[0901,0905] 取 0905 行;channel=None 跨渠道相加(4+2=6)。"""
[0901,0905] 取 0905 行;channel=None 跨渠道相加(4+2=6)。
end_active_friends 同源同行:wechat 7 + whatsapp 3 → 10(评分
active_share 分子,与周期 distinct 的 active_friends 字段不同口径)。"""
s = make_session
await _seed_org(s)
s.add(_mday(20260901, new_customer_count=1, cooling_customer_count=2,
dormant_customer_count=3))
s.add(_mday(20260905, dormant_customer_count=4))
s.add(_mday(20260905, channel="whatsapp", dormant_customer_count=2))
dormant_customer_count=3, active_friends=7))
s.add(_mday(20260905, dormant_customer_count=4, active_friends=7))
s.add(_mday(20260905, channel="whatsapp", dormant_customer_count=2,
active_friends=3))
await s.commit()
m1 = await period_metrics(s, 20260901, 20260903, "wechat")
assert m1["u1"].new_customer == 1
assert m1["u1"].cooling_customer == 2
assert m1["u1"].dormant_customer == 3
assert m1["u1"].end_active_friends == 7 # 渠道内最新行(0901)的值
m2 = await period_metrics(s, 20260901, 20260905, "wechat")
assert m2["u1"].dormant_customer == 4 # wechat 渠道内最新行
assert m2["u1"].new_customer == 0
assert m2["u1"].end_active_friends == 7
m3 = await period_metrics(s, 20260901, 20260905, None)
assert m3["u1"].dormant_customer == 6 # wechat 4 + whatsapp 2
assert m3["u1"].end_active_friends == 10 # wechat 7 + whatsapp 3
async def test_distinct_active_cross_day(make_session):