From 163f3b96b3054749bcb5d988053e7ea598af2325 Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Sun, 4 Oct 2026 02:09:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=9B=AE=E5=BD=95=20F2b=20/?= =?UTF-8?q?=20B7=EF=BC=9A=E5=89=96=E6=9E=90=E6=8A=A5=E5=91=8A=E9=87=8C?= =?UTF-8?q?=E5=85=B3=E7=B3=BB=E7=9A=84=E7=BB=93=E8=AE=BA=E6=8C=89=E5=AE=9E?= =?UTF-8?q?=E9=99=85=E5=8F=98=E5=8C=96=E8=AF=B4=E2=80=94=E2=80=94=E5=8E=9F?= =?UTF-8?q?=E6=9C=AC=E5=B0=B1=E6=98=AF=E5=B7=B2=E9=AA=8C=E8=AF=81=E3=80=81?= =?UTF-8?q?=E8=BF=99=E6=AC=A1=E7=85=A7=E6=A0=B7=E6=A0=B8=E5=AE=9E=E7=9A=84?= =?UTF-8?q?=E5=86=99=E3=80=8C=E4=BB=8D=E4=B8=BA=E5=B7=B2=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=EF=BC=8C=E8=A6=86=E7=9B=96=E7=8E=87=20x=E3=80=8D=EF=BC=8C?= =?UTF-8?q?=E4=BB=8E=E6=8E=A8=E6=96=AD=E5=8D=87=E4=B8=8A=E6=9D=A5=E7=9A=84?= =?UTF-8?q?=E6=89=8D=E5=86=99=E3=80=8C=E5=8D=87=E4=B8=BA=E5=B7=B2=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E3=80=8D=EF=BC=8C=E5=B7=B2=E9=AA=8C=E8=AF=81=E9=99=8D?= =?UTF-8?q?=E5=9B=9E=E6=8E=A8=E6=96=AD=E7=9A=84=E5=86=99=E3=80=8C=E9=99=8D?= =?UTF-8?q?=E4=B8=BA=E6=8E=A8=E6=96=AD=E3=80=8D=EF=BC=9B=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=E6=9C=80=E5=B0=8F=E6=94=B9=E5=8A=A8=EF=BC=9A=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=E7=BB=93=E8=AE=BA=E5=A4=9A=E5=B8=A6=20previous=5Fstat?= =?UTF-8?q?us=EF=BC=88=E5=89=96=E6=9E=90=E5=89=8D=E7=9A=84=E7=8A=B6?= =?UTF-8?q?=E6=80=81=EF=BC=89=EF=BC=8Csummary=20=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=86=99=E3=80=8C=E4=BB=8D=E4=B8=BA=E6=9C=89=E7=A1=AE=E8=AF=81?= =?UTF-8?q?=E3=80=8D=EF=BC=9B=E8=A1=A5=E5=90=8E=E7=AB=AF=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E5=92=8C=E6=A3=80=E6=9F=A5=E8=84=9A=E6=9C=AC=E7=9A=84=E6=96=AD?= =?UTF-8?q?=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/data/catalog_profile.py | 9 ++++-- backend/tests/test_catalog_profile.py | 5 ++++ frontend/src/lib/terms.ts | 3 ++ frontend/src/pages/catalog/ProfileDialog.tsx | 30 +++++++++++++++----- frontend/src/types.ts | 2 ++ scripts/check-catalog.mjs | 16 +++++++++-- 6 files changed, 53 insertions(+), 12 deletions(-) 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 (
  • @@ -405,7 +421,7 @@ function RelationLine({ f }: { f: CatalogProfileRelationFinding }) { {' · '} {PT.sampled(f.sample, f.matched)}
    -
    {outcome.text}
    +
    {outcome.text}
  • ) } diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 8053d369..a89b1e58 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -2850,6 +2850,8 @@ export interface CatalogProfileRelationFinding { to_columns: string[] status: CatalogStatus confirmed: boolean + /** 剖析之前目录里这条关系的状态:报告按它说「升为已验证」还是「仍为已验证」。老服务端不给 */ + previous_status?: CatalogStatus | null coverage: number cardinality: CatalogCardinality | null /** 抽了几个不同的键值、在被指向表里对上几个 */ diff --git a/scripts/check-catalog.mjs b/scripts/check-catalog.mjs index 556c7088..5c65e48d 100644 --- a/scripts/check-catalog.mjs +++ b/scripts/check-catalog.mjs @@ -1248,6 +1248,9 @@ function profileReply(state, { ms = 0, extraCodes = false } = {}) { const visits = state.tables[S1].find((t) => t.name === 'visits') const notes = clone(visits.notes) const at = `${PROFILE_DAY}T03:00:00+00:00` + // 剖析之前这两条关系的状态(服务端 previous_status):第一次闸机关系是命名推断,再剖析一次时已经是已验证 + const before = (id) => visits.notes.relations.find((r) => r.id === id)?.status ?? null + const previous = { gate: before(GATE_REL), member: before(MEMBER_REL) } notes.relations = notes.relations.map((r) => (r.id === GATE_REL ? { ...r, source: 'profile', status: 'verified', coverage: 0.987, cardinality: 'many_to_one', updated_at: at, note: `数据剖析(${PROFILE_DAY}):子表抽样 300 个不同键值,父表对上 296 个,覆盖率 98.7%;被指向列是主键;子表一侧有重复值,多对一。`, @@ -1266,9 +1269,11 @@ function profileReply(state, { ms = 0, extraCodes = false } = {}) { table_name: 'visits', queries: 38, row_estimate: { rows: 182000, method: 'stats', at_least: null }, findings: [ { kind: 'relation', path: `relations.${GATE_REL}`, target: 'gate_id → gates.id', columns: ['gate_id'], to_table: 'gates', to_columns: ['id'], - status: 'verified', confirmed: false, coverage: 0.987, cardinality: 'many_to_one', sample: 300, matched: 296, summary: '覆盖率 98.7%,升为有确证' }, + status: 'verified', confirmed: false, previous_status: previous.gate, coverage: 0.987, cardinality: 'many_to_one', sample: 300, matched: 296, + summary: previous.gate === 'verified' ? '覆盖率 98.7%,仍为有确证' : '覆盖率 98.7%,升为有确证' }, { kind: 'relation', path: `relations.${MEMBER_REL}`, target: 'member_id → members.id', columns: ['member_id'], to_table: 'members', - to_columns: ['id'], status: 'proposed', confirmed: false, coverage: 0.62, cardinality: 'many_to_one', sample: 200, matched: 124, + to_columns: ['id'], status: 'proposed', confirmed: false, previous_status: previous.member, coverage: 0.62, cardinality: 'many_to_one', + sample: 200, matched: 124, summary: '抽样覆盖率 62%,保持推断' }, { kind: 'codes', path: 'columns.status.codes', column: 'status', values: [{ value: '1', rows: 171080 }, { value: '9', rows: 9100 }, { value: '2', rows: 1820 }], rows: 182000, status: 'proposed', summary: '3 个取值,1 个含义待填写' }, @@ -1558,6 +1563,13 @@ await section('数据目录 · 数据剖析', async () => { await page.locator('[data-profile-start]').click() await until(async () => (await profilePhase(page)) === 'done') check('窗口开着时完成:直接看报告,不另弹提示', (await toastBox.count()) <= 1) + // 重新剖析:闸机关系上一次已经核实成已验证,这次照样核实——写「仍为已验证」,不说「升为已验证」 + const gateAgain = profileBox(page).locator(`[data-profile-finding="relation"][data-path="relations.${GATE_REL}"] [data-profile-outcome]`) + check('重新剖析:原本就是已验证的关系写「仍为已验证,覆盖率 98.7%」,不说「升为」', (await gateAgain.innerText()) === '仍为已验证,覆盖率 98.7%' + && (await gateAgain.getAttribute('data-profile-outcome')) === 'same', await gateAgain.innerText()) + const memberAgain = profileBox(page).locator(`[data-profile-finding="relation"][data-path="relations.${MEMBER_REL}"] [data-profile-outcome]`) + check('……原本就是推断、这次仍不够的写「保持推断」', (await memberAgain.innerText()) === '保持推断:覆盖率不足,可能不是这条关系' + && (await memberAgain.getAttribute('data-profile-outcome')) === 'kept') // 点「填写含义」:报告收起、弹出那一列的码值;保存或取消之后回到报告,这一列改写成「含义已填写」,焦点落在下一列上 const fillLine = (col) => profileBox(page).locator(`[data-profile-finding="codes"][data-column="${col}"]`) await fillLine('status').locator('[data-profile-fill]').click()