Skip to content

Commit 649d420

Browse files
committed
fix(detail): improve combined recognition summaries
1 parent 9b2a3ca commit 649d420

2 files changed

Lines changed: 70 additions & 15 deletions

File tree

src/views/detail/components/detailRows.test.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,34 @@ describe('detailRows', () => {
3232
const rows = buildRecognitionDetailRows({
3333
box: null,
3434
detail: [
35-
{ name: 'Icon', algorithm: 'TemplateMatch', box: [1, 2, 3, 4] },
36-
{ name: 'Text', algorithm: 'OCR', box: null },
35+
{
36+
name: 'Icon',
37+
algorithm: 'TemplateMatch',
38+
box: [1, 2, 3, 4],
39+
detail: {
40+
all: [{ box: [1, 2, 3, 4], score: 0.9 }],
41+
filtered: [{ box: [1, 2, 3, 4], score: 0.9 }],
42+
best: { box: [1, 2, 3, 4], score: 0.9 },
43+
},
44+
},
45+
{
46+
name: 'Text',
47+
algorithm: 'OCR',
48+
box: null,
49+
detail: {
50+
all: [{ box: [5, 6, 7, 8], score: 0.8, text: 'NO' }],
51+
filtered: [],
52+
best: null,
53+
},
54+
},
3755
],
3856
}, 3)
3957

40-
expect(rows.map((row) => row.label)).toEqual(['命中状态', '子识别数量', '命中子识别数量', '子识别列表'])
58+
expect(rows.map((row) => row.label)).toEqual(['命中状态', '整体判定', '子识别 1', '子识别 2'])
4159
expect(rows[0].value).toBe('未命中')
42-
expect(rows[1].value).toBe(2)
43-
expect(rows[2].value).toBe(1)
44-
expect(rows[3].value).toContain('Icon (TemplateMatch) [1, 2, 3, 4]')
60+
expect(rows[1].value).toBe('未命中(1/2)')
61+
expect(rows[2].value).toBe('未命中 Text (OCR),all 1,filtered 0,best -')
62+
expect(rows[3].value).toBe('命中 Icon (TemplateMatch),box=[1, 2, 3, 4],all 1,filtered 1,best score=0.9')
4563
})
4664

4765
it('builds click action rows in action-specific order', () => {

src/views/detail/components/detailRows.ts

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,37 @@ const formatRecognitionResultSummary = (value: unknown) => {
4949
return parts.length > 0 ? parts.join(' | ') : formatDetailValue(value, 240)
5050
}
5151

52+
const formatCount = (value: unknown) => Array.isArray(value) ? String(value.length) : '-'
53+
54+
const formatChildBestSummary = (value: unknown) => {
55+
if (!isRecord(value)) return '-'
56+
const parts: string[] = []
57+
if (hasDetailValue(value.text)) parts.push(`text=${value.text}`)
58+
if (hasDetailValue(value.score)) parts.push(`score=${value.score}`)
59+
if (hasDetailValue(value.count)) parts.push(`count=${value.count}`)
60+
if (hasDetailValue(value.label)) parts.push(`label=${value.label}`)
61+
if (hasDetailValue(value.cls_index)) parts.push(`cls_index=${value.cls_index}`)
62+
if (Array.isArray(value.box) && parts.length === 0) parts.push(`box=[${value.box.join(', ')}]`)
63+
return parts.length > 0 ? parts.join(', ') : formatDetailValue(value, 120)
64+
}
65+
66+
const formatChildRecognitionSummary = (item: Record<string, any>) => {
67+
const hit = !!item.box
68+
const parts = [`${hit ? '命中' : '未命中'} ${item.name ?? '-'} (${item.algorithm ?? '-'})`]
69+
70+
if (Array.isArray(item.box)) {
71+
parts.push(`box=[${item.box.join(', ')}]`)
72+
}
73+
74+
if (isRecord(item.detail)) {
75+
parts.push(`all ${formatCount(item.detail.all)}`)
76+
parts.push(`filtered ${formatCount(item.detail.filtered)}`)
77+
parts.push(`best ${formatChildBestSummary(item.detail.best)}`)
78+
}
79+
80+
return parts.join(',')
81+
}
82+
5283
export const buildRecognitionDetailRows = (
5384
recognition: any,
5485
descriptionColumns: number,
@@ -62,19 +93,25 @@ export const buildRecognitionDetailRows = (
6293

6394
const detail = recognition.detail
6495
if (Array.isArray(detail)) {
65-
const hitChildren = detail.filter((item) => isRecord(item) && item.box).length
96+
const childRecognitions = detail.filter(isRecord)
97+
const hitChildren = childRecognitions.filter((item) => item.box).length
6698
rows.push(
67-
{ label: '子识别数量', value: detail.length },
68-
{ label: '命中子识别数量', value: hitChildren },
99+
{
100+
label: '整体判定',
101+
value: `${recognition.box ? '命中' : '未命中'}${hitChildren}/${detail.length})`,
102+
},
69103
)
70104

71-
const children = detail
72-
.filter(isRecord)
105+
childRecognitions
106+
.sort((left, right) => Number(!!left.box) - Number(!!right.box))
73107
.slice(0, 8)
74-
.map((item) => `${item.name ?? '-'} (${item.algorithm ?? '-'})${item.box ? ` [${item.box.join(', ')}]` : ''}`)
75-
if (children.length > 0) {
76-
rows.push({ label: '子识别列表', value: children.join('\n'), span: descriptionColumns })
77-
}
108+
.forEach((item, index) => {
109+
rows.push({
110+
label: `子识别 ${index + 1}`,
111+
value: formatChildRecognitionSummary(item),
112+
span: descriptionColumns,
113+
})
114+
})
78115
return rows
79116
}
80117

0 commit comments

Comments
 (0)