diff --git a/backend/app/data/catalog_profile.py b/backend/app/data/catalog_profile.py index 710b657f..ddca91ba 100644 --- a/backend/app/data/catalog_profile.py +++ b/backend/app/data/catalog_profile.py @@ -910,10 +910,13 @@ async def _check_dates(cx: _Context, table: str, columns: list[str], total: int, def _relation_finding(o: _RelationOutcome, rel: dict[str, Any], *, status: str, confirmed: bool) -> dict[str, Any]: + """一条关系的核实结论。previous_status 是剖析之前目录里这条关系的状态:报告按它说「升为已验证」还是「仍为已验证」 + (重新剖析、目录没变时不能说升了)。""" + previous = rel.get("status") if confirmed: summary = "已人工确认,只补充覆盖率和基数" elif status == "verified": - summary = f"覆盖率 {_percent(o.coverage)},升为有确证" + summary = f"覆盖率 {_percent(o.coverage)}," + ("仍为有确证" if previous == "verified" else "升为有确证") elif o.coverage < catalog.PROFILE_VERIFY_COVERAGE: summary = f"抽样覆盖率 {_percent(o.coverage)},保持推断" else: @@ -921,8 +924,8 @@ def _relation_finding(o: _RelationOutcome, rel: dict[str, Any], *, status: str, return {"kind": "relation", "path": f"relations.{o.rid}", "target": o.target, "columns": list(rel.get("columns") or []), "to_table": rel.get("to_table"), "to_columns": list(rel.get("to_columns") or []), "status": status, "confirmed": confirmed, - "coverage": o.coverage, "cardinality": o.cardinality, "sample": o.sample, "matched": o.matched, - "summary": summary} + "previous_status": previous, "coverage": o.coverage, "cardinality": o.cardinality, "sample": o.sample, + "matched": o.matched, "summary": summary} def _codes_value(c: _CodesOutcome, item: dict[str, Any] | None) -> dict[str, str]: diff --git a/backend/tests/test_catalog_profile.py b/backend/tests/test_catalog_profile.py index c88d1c82..52af54ba 100644 --- a/backend/tests/test_catalog_profile.py +++ b/backend/tests/test_catalog_profile.py @@ -277,6 +277,11 @@ async def test_rerun_with_same_data_changes_nothing(client, make_source, scenic_ a, b = _table(first, "visits"), _table(second, "visits") assert (b["added"], b["updated"], b["removed"]) == (0, 0, 0) assert b["version"] == a["version"] + # 逐条结论按实际变化说:第一次是从推断升上来的,第二次原本就是已验证,不能再说「升为」 + gate_a = next(f for f in a["findings"] if f.get("columns") == ["gate_id"]) + gate_b = next(f for f in b["findings"] if f.get("columns") == ["gate_id"]) + assert (gate_a["previous_status"], gate_a["status"]) == ("proposed", "verified") and "升为有确证" in gate_a["summary"] + assert (gate_b["previous_status"], gate_b["status"]) == ("verified", "verified") and "仍为有确证" in gate_b["summary"] # ---------------------------------------------------------------- 安全约束 diff --git a/frontend/src/lib/terms.ts b/frontend/src/lib/terms.ts index 18f91d00..90af3fc9 100644 --- a/frontend/src/lib/terms.ts +++ b/frontend/src/lib/terms.ts @@ -2517,6 +2517,9 @@ export const CATALOG_UI_TEXT = { editMeanings: '修改含义', editMeaningsLabel: (col: string) => `修改含义:列 ${col} 的码值`, fillWhileEditing: '正在编辑这张表,保存或取消后再填写码值的含义', + // ---- 剖析报告里关系的结论:按这次的实际变化说(原本就是已验证的不说「升为」) + relationStillVerified: (coverage: string) => `仍为已验证,覆盖率 ${coverage}`, + relationLowered: (reason: string) => `降为推断:${reason}`, } // =========================================================================== diff --git a/frontend/src/pages/catalog/ProfileDialog.tsx b/frontend/src/pages/catalog/ProfileDialog.tsx index 5f17a779..3919c46f 100644 --- a/frontend/src/pages/catalog/ProfileDialog.tsx +++ b/frontend/src/pages/catalog/ProfileDialog.tsx @@ -1,6 +1,7 @@ import { useEffect, useMemo, useRef, useState } from 'react' import type { ReactNode } from 'react' -import { ArrowUpRight, CircleCheck, OctagonX, ScanSearch, ShieldAlert, TriangleAlert } from 'lucide-react' +import { ArrowDown, ArrowUp, ArrowUpRight, CircleCheck, Equal, Minus, OctagonX, ScanSearch, ShieldAlert, TriangleAlert, UserCheck } from 'lucide-react' +import type { LucideIcon } from 'lucide-react' import clsx from 'clsx' import type { CatalogProfileCodesFinding, CatalogProfileDateFinding, CatalogProfileOut, CatalogProfileRelationFinding, CatalogProfileSettings, @@ -386,12 +387,27 @@ function Group({ title, children }: { title: string; children: ReactNode }) { ) } +type RelationOutcome = 'confirmed' | 'raised' | 'same' | 'lowered' | 'kept' + +/** + * 一条关系这次剖析的结论,按实际变化说:原本就是已验证、这次照样核实的写「仍为已验证,覆盖率 x」,不能说「升为」—— + * 重新剖析、目录没变时报告头写「目录没有变化」,下面却说升了,自相矛盾。老服务端不给剖析前的状态,按升级说 + */ +function relationOutcome(f: CatalogProfileRelationFinding): { kind: RelationOutcome; text: string; tone: string; icon: LucideIcon } { + const reason = f.coverage < 0.95 ? PT.relationLowCoverage : PT.relationNotUnique + if (f.confirmed) return { kind: 'confirmed', text: PT.relationConfirmed, tone: STATUS_TONE.confirmed, icon: UserCheck } + if (f.status === 'verified') { + return f.previous_status === 'verified' + ? { kind: 'same', text: UT.relationStillVerified(coverageText(f.coverage)), tone: STATUS_TONE.verified, icon: Equal } + : { kind: 'raised', text: PT.relationVerified, tone: STATUS_TONE.verified, icon: ArrowUp } + } + return f.previous_status === 'verified' + ? { kind: 'lowered', text: UT.relationLowered(reason), tone: STATUS_TONE.proposed, icon: ArrowDown } + : { kind: 'kept', text: `${PT.relationKept}:${reason}`, tone: STATUS_TONE.proposed, icon: Minus } +} + function RelationLine({ f }: { f: CatalogProfileRelationFinding }) { - const outcome = f.confirmed - ? { text: PT.relationConfirmed, tone: 'var(--text-dim)' } - : f.status === 'verified' - ? { text: PT.relationVerified, tone: STATUS_TONE.verified } - : { text: `${PT.relationKept}:${f.coverage < 0.95 ? PT.relationLowCoverage : PT.relationNotUnique}`, tone: STATUS_TONE.proposed } + const outcome = relationOutcome(f) return (