Commit bf2fcff1 by 江名洋

fix(analysis): 调整指标提取逻辑与列名映射

1 parent 18dd7d2a
......@@ -74,24 +74,11 @@ def extract_target_rates(store_row) -> dict:
优先使用模板中的显式数值列(需达标转化率_整车延保等),
没有显式值时从兜底指标文本解析。
"""
# 显式数值列优先
explicit_yb = store_row.get("需达标转化率_整车延保")
explicit_axb = store_row.get("需达标转化率_安心包")
explicit_bat = store_row.get("需达标转化率_电池")
has_explicit = all(
v is not None and not (isinstance(v, float) and pd.isna(v))
for v in [explicit_yb, explicit_axb, explicit_bat]
)
if has_explicit:
return {
"整车延保": _safe_float(explicit_yb),
"安心包": _safe_float(explicit_axb),
"电池延保": _safe_float(explicit_bat),
}
def _has_val(v):
return v is not None and not (isinstance(v, float) and pd.isna(v))
# 兜底:从文本解析
# 兜底默认值:从文本解析
baodi = store_row.get("兜底指标", "")
baodi_type = str(store_row.get("兜底类型", "交付"))
rule_type = detect_rule_type(str(baodi) if not pd.isna(baodi) else "")
targets = dict(RULE_TARGETS.get(rule_type, RULE_TARGETS["default"]))
......@@ -100,6 +87,17 @@ def extract_target_rates(store_row) -> dict:
targets["安心包"] = 0.0
targets["整车延保"] = _safe_float(_extract_number(baodi, r"触客成交率[不]*低于(\d+)%", 50)) / 100.0
# 显式数值列优先(逐个覆盖,缺失的保留文本解析默认值)
explicit_yb = store_row.get("需达标转化率_整车延保")
explicit_axb = store_row.get("需达标转化率_安心包")
explicit_bat = store_row.get("需达标转化率_电池")
if _has_val(explicit_yb):
targets["整车延保"] = _safe_float(explicit_yb)
if _has_val(explicit_axb):
targets["安心包"] = _safe_float(explicit_axb)
if _has_val(explicit_bat):
targets["电池延保"] = _safe_float(explicit_bat)
for k in targets:
targets[k] = _safe_float(targets[k], RULE_TARGETS["default"].get(k, 0.0))
......@@ -199,11 +197,11 @@ class AnalysisService:
col_names = {
0: "门店名", 1: "兜底指标", 2: "兜底类型",
3: "特殊情况1", 4: "特殊情况2",
5: "区域(省)", 6: "直营与否",
7: "区域运营", 8: "飞行督导", 9: "线上运营",
10: "需达标转化率_整车延保", 11: "需达标转化率_安心包", 12: "需达标转化率_电池",
13: "预计赔付单价_整车", 14: "预计赔付单价_安心包", 15: "预计赔付单价_电池",
16: "兜底截止日期", 17: "策略组更新记录",
5: "需达标转化率_整车延保", 6: "需达标转化率_安心包", 7: "需达标转化率_电池",
8: "预计赔付单价_整车", 9: "预计赔付单价_安心包", 10: "预计赔付单价_电池",
11: "兜底截止日期", 12: "策略组更新记录",
13: "区域(省)", 14: "直营与否",
15: "区域运营", 16: "飞行督导", 17: "线上运营",
}
df = df.rename(columns=col_names)
for c in col_names.values():
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!