feat(management): 评分引擎——三类标准化/维度归一/样本保护/等级/四对比明细+期末active_friends接口修订
Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -11,9 +11,12 @@
|
||||
owner:一员工多账号(wx1+wx2→u1,channel=None 时人人如此)的样本必须
|
||||
跨账号归并,逐 owner 取分位再映射会互相覆盖。fact 全库全期 ≤6.8万行,
|
||||
Python 侧聚合可行。
|
||||
- 期末存量(new/cooling/dormant):状态快照取「每 (user, channel) 最新
|
||||
≤end 行」——channel=None 时两渠道各取各的最新行再相加(直接取全渠道
|
||||
最大 day 的那一行会丢另一渠道的存量)。
|
||||
- 期末存量(new/cooling/dormant/end_active_friends):状态快照取
|
||||
「每 (user, channel) 最新 ≤end 行」——channel=None 时两渠道各取各的
|
||||
最新行再相加(直接取全渠道最大 day 的那一行会丢另一渠道的存量)。
|
||||
end_active_friends 与 new/cooling/dormant 同源同行(该渠道最新行的
|
||||
active_friends 列),供评分 active_share 用——区别于 active_friends
|
||||
字段的周期 distinct 口径。
|
||||
- active_rooms_avg = SUM(active_rooms)/全窗天数(含无数据日摊薄),
|
||||
非有数据天数——「日均负载」语义。
|
||||
- days_with_data = COUNT(DISTINCT day):单渠道时与 COUNT(*) 等价
|
||||
@@ -47,6 +50,7 @@ PeriodMetrics = namedtuple("PeriodMetrics", [
|
||||
"active_friends", # 期内 distinct(直查,非日值求和)
|
||||
"active_rooms_avg", # 日均(全窗天数摊薄)
|
||||
"new_customer", "cooling_customer", "dormant_customer", # 期末单日存量
|
||||
"end_active_friends", # 期末行 active_friends 跨渠道 SUM(active_share 分子)
|
||||
"reactivated_customer", # 期内求和
|
||||
"call_count", "call_seconds", "answered_call", "call_followup",
|
||||
])
|
||||
@@ -108,6 +112,7 @@ _ZERO: dict[str, object] = {
|
||||
"reply_2h_count": 0, "reply_24h_count": 0,
|
||||
"active_friends": 0, "active_rooms_sum": 0,
|
||||
"new_customer": 0, "cooling_customer": 0, "dormant_customer": 0,
|
||||
"end_active_friends": 0,
|
||||
"reactivated_customer": 0,
|
||||
"call_count": 0, "call_seconds": 0, "answered_call": 0, "call_followup": 0,
|
||||
}
|
||||
@@ -207,6 +212,7 @@ async def period_metrics(
|
||||
sa.func.sum(
|
||||
EmployeeMetricDaily.dormant_customer_count
|
||||
).label("dorm"),
|
||||
sa.func.sum(EmployeeMetricDaily.active_friends).label("af"),
|
||||
).where(sa.or_(*(
|
||||
sa.and_(
|
||||
EmployeeMetricDaily.user_id == uid,
|
||||
@@ -217,11 +223,12 @@ async def period_metrics(
|
||||
for uid, ch, d in latest
|
||||
))).group_by(EmployeeMetricDaily.user_id)
|
||||
)).all()
|
||||
for uid, nw, cool, dorm in stocks:
|
||||
for uid, nw, cool, dorm, af in stocks:
|
||||
a = acc[uid]
|
||||
a["new_customer"] = int(nw or 0)
|
||||
a["cooling_customer"] = int(cool or 0)
|
||||
a["dormant_customer"] = int(dorm or 0)
|
||||
a["end_active_friends"] = int(af or 0)
|
||||
|
||||
# ---- fact 分位 + 2h/24h 回复计数(同一过滤,Python 侧一次聚合) ----
|
||||
fr_conds = [FirstReplyFact.day.between(start_day, end_day)]
|
||||
@@ -305,6 +312,7 @@ async def period_metrics(
|
||||
new_customer=a["new_customer"],
|
||||
cooling_customer=a["cooling_customer"],
|
||||
dormant_customer=a["dormant_customer"],
|
||||
end_active_friends=a["end_active_friends"],
|
||||
reactivated_customer=a["reactivated_customer"],
|
||||
call_count=a["call_count"],
|
||||
call_seconds=a["call_seconds"],
|
||||
|
||||
Reference in New Issue
Block a user