fix(management): drilldown生命周期历史改peer键控对齐批次A口径+comparisons键域统一+补测试
评审修正(I1/M1-M4/M6): - I1 lifecycle_customers 历史改 (channel,peer) 键控跨owner合并,归属仍由 Customer.owner_account_id 决定——与批次A _lifecycle_daily 同口径;新增 共享客户测试(历史在他人账号下仍全量呈现) - M3 employees 行 comparisons 键域统一为指标源名(config code→spec.metric 映射,active_friends_band/call_band 不再出现),与 sections 一致 - M4 未回复分支空 owners 先短路,免去无效 finalize 调用 - M1 employee_metrics._percentile 改公有 percentile 供同包复用,删除 api_assembly.percentile_nearest(存储层 _percentile 不同层保留) - M2 drilldown 内联 SQL(FirstReplyFact/PhoneCall)下沉 api_assembly (fr_fact_rows/user_calls_page),路由层无裸查询 - M6 补 start>end→422 断言;新增 config_source=db 测试(激活配置 min_days=9→五天数据员工翻 insufficient_sample,守护生效可见) tests/test_management_api.py: 21 passed;全量 721 passed Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
@@ -88,12 +88,13 @@ def baseline_window(start: int) -> tuple[int, int]:
|
||||
return _to_key(bs), _to_key(be)
|
||||
|
||||
|
||||
def _percentile(vals: list[int], q_num: int, q_den: int) -> int | None:
|
||||
def percentile(vals: list[int], q_num: int, q_den: int) -> int | None:
|
||||
"""最近邻秩分位 ceil(q·n) 的样本值,q=q_num/q_den(1/2、9/10)。
|
||||
|
||||
整数算术 rank=(q_num*n + q_den - 1)//q_den 对正整数 n 恒落在 [1,n]
|
||||
(与 math.ceil(q·n) 等价,与批次A _percentile 同口径);空列表→None
|
||||
(与 0 严格区分)。
|
||||
公有供同包 api_assembly(B4 服务趋势)复用;整数算术
|
||||
rank=(q_num*n + q_den - 1)//q_den 对正整数 n 恒落在 [1,n]
|
||||
(与 math.ceil(q·n) 等价,与批次A storage 层 _percentile 同口径——
|
||||
后者为不同层单独保留);空列表→None(与 0 严格区分)。
|
||||
"""
|
||||
if not vals:
|
||||
return None
|
||||
@@ -246,8 +247,8 @@ async def period_metrics(
|
||||
if uid is not None and uid in target:
|
||||
fr_by_user.setdefault(uid, []).append(int(fr))
|
||||
for uid, frs in fr_by_user.items():
|
||||
acc[uid]["fr_p50_ms"] = _percentile(frs, 1, 2)
|
||||
acc[uid]["fr_p90_ms"] = _percentile(frs, 9, 10)
|
||||
acc[uid]["fr_p50_ms"] = percentile(frs, 1, 2)
|
||||
acc[uid]["fr_p90_ms"] = percentile(frs, 9, 10)
|
||||
# 2h/24h 计数与分位同源同窗——回复率分子分母口径一致
|
||||
acc[uid]["reply_2h_count"] = sum(1 for fr in frs if fr <= 7_200_000)
|
||||
acc[uid]["reply_24h_count"] = sum(1 for fr in frs if fr <= 86_400_000)
|
||||
|
||||
Reference in New Issue
Block a user