同步:完善质量分析工作台并更新主题字体
同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。 补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。 统一午夜黑及其他主题的控件细节、中文和业务数字字体。 排除本地业务数据、凭据、预览、发布与验收产物。 验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
This commit is contained in:
@@ -2,6 +2,16 @@ import { sanitizeAnalysisDisplayText } from './analysisDisplayText.ts';
|
||||
import { parseAnalysisVisuals, combineStageDefectVisuals, visualPeriodSummary, visualScopeSummary, type AnalysisVisual } from './analysisVisualsModel.ts';
|
||||
|
||||
export type NarrativeKind = 'overview' | 'stage' | 'department' | 'group' | 'product' | 'category' | 'defect' | 'trend' | 'composition' | 'crosscheck' | 'action' | 'other';
|
||||
export interface FocusProductRow {
|
||||
product: string;
|
||||
stage?: 'black' | 'bright' | 'all';
|
||||
scrapDelta: string;
|
||||
rateChange: string;
|
||||
rateLabel: string;
|
||||
basis: string;
|
||||
detail: string;
|
||||
evidenceRefs: string[];
|
||||
}
|
||||
export interface NarrativeSection {
|
||||
id: string;
|
||||
title: string;
|
||||
@@ -11,6 +21,7 @@ export interface NarrativeSection {
|
||||
tables: string[];
|
||||
visuals: AnalysisVisual[];
|
||||
evidenceRefs: string[];
|
||||
focusProducts?: FocusProductRow[];
|
||||
}
|
||||
export interface AnalysisNarrativeModel {
|
||||
sections: NarrativeSection[];
|
||||
@@ -61,6 +72,81 @@ export function narrativeParts(markdown: string): { narrative: string; tables: s
|
||||
return { narrative: prose.join('\n').trim(), tables };
|
||||
}
|
||||
|
||||
/** Only the deterministic report's exact table contract is eligible for a compact summary. */
|
||||
function productTableCells(line: string): string[] {
|
||||
const source = line.trim().replace(/^\|/, '').replace(/(?<!\\)\|$/, '');
|
||||
return source.split(/(?<!\\)\|/).map(cell => cell.trim().replaceAll('\\|', '|'));
|
||||
}
|
||||
|
||||
function focusProductCandidates(sections: NarrativeSection[]): Array<Omit<FocusProductRow, 'detail'>> {
|
||||
const candidates: Array<Omit<FocusProductRow, 'detail'>> = [];
|
||||
const number = /^(?:[+−-]?(?:\d{1,3}(?:,\d{3})+|\d+)(?:\.\d+)?|—)$/;
|
||||
for (const section of sections) {
|
||||
if (section.kind !== 'product' || !/(重点产品|产品率变化线索)/.test(section.title)) continue;
|
||||
const order = section.title.match(/[((]按(报废增量|当前报废重量|合格率降幅),本次返回前\d+[))]/)?.[1];
|
||||
if (!order) continue;
|
||||
const stage = section.title.startsWith('黑片') ? '黑片' : section.title.startsWith('亮片') ? '亮片' : '';
|
||||
for (const table of section.tables) {
|
||||
const lines = table.split('\n');
|
||||
const headers = productTableCells(lines[0] || '');
|
||||
const rateLabel = headers[2]?.match(/^(综合率|黑片合格率|亮片合格率):比较期→本期 \/ 变化$/)?.[1];
|
||||
const tableRefs = refs(lines.filter(line => !line.trim().startsWith('|')).join('\n'));
|
||||
if (headers.length !== 4 || headers[0] !== '规格' || headers[1] !== '本期报废 / 增量(kg)'
|
||||
|| headers[3] !== '阶段投入:比较期→本期(kg)' || !rateLabel || tableRefs.length !== 1) continue;
|
||||
for (const line of lines.slice(2)) {
|
||||
if (!line.trim().startsWith('|')) break;
|
||||
const cells = productTableCells(line);
|
||||
if (cells.length !== 4 || !cells[0] || !cells[3]) continue;
|
||||
const weights = cells[1].split(/\s*\/\s*/);
|
||||
const rateParts = cells[2].split(';');
|
||||
if (weights.length !== 2 || !weights.every(value => number.test(value)) || rateParts.length !== 2
|
||||
|| !/^(?:[\d,.]+%|—)→(?:[\d,.]+%|—)$/.test(rateParts[0])
|
||||
|| !/^(?:(?:上升|下降)[\d,.]+个百分点|持平|不可比)$/.test(rateParts[1])) continue;
|
||||
candidates.push({ product: cells[0], stage: stage === '黑片' ? 'black' : stage === '亮片' ? 'bright' : rateLabel === '黑片合格率' ? 'black' : rateLabel === '亮片合格率' ? 'bright' : 'all', scrapDelta: weights[1], rateChange: rateParts[1], rateLabel,
|
||||
basis: `${stage ? `${stage} · ` : ''}按${order}排序${order === '合格率降幅' ? ',仅作率变化线索' : ''}`,
|
||||
evidenceRefs: tableRefs });
|
||||
}
|
||||
}
|
||||
}
|
||||
return candidates;
|
||||
}
|
||||
|
||||
/** Move selected, cited product facts near the conclusion without changing their order or numbers. */
|
||||
function bringFocusProductsForward(sections: NarrativeSection[]): NarrativeSection[] {
|
||||
const candidates = focusProductCandidates(sections);
|
||||
if (!candidates.length) return sections;
|
||||
const focusProducts: FocusProductRow[] = [];
|
||||
const remaining = sections.map(section => {
|
||||
if (section.kind !== 'action') return section;
|
||||
let fenced = false;
|
||||
let moved = false;
|
||||
const lines = section.narrative.split('\n').filter(line => {
|
||||
if (/^\s*```/.test(line)) fenced = !fenced;
|
||||
if (fenced) return true;
|
||||
const detail = line.match(/^\s*[-*+]\s+(.+)$/)?.[1];
|
||||
if (!detail) return true;
|
||||
const detailRefs = refs(detail);
|
||||
const matches = candidates.filter(row => detail.startsWith(`${row.product}:`)
|
||||
&& detailRefs.length === 1 && row.evidenceRefs[0] === detailRefs[0]
|
||||
&& detail.includes(`增量${row.scrapDelta} kg`) && detail.includes(row.rateChange));
|
||||
// A shared reference with more than one possible row is not enough to choose a scope.
|
||||
if (matches.length !== 1) return true;
|
||||
focusProducts.push({ ...matches[0], detail });
|
||||
moved = true;
|
||||
return false;
|
||||
});
|
||||
if (!moved) return section;
|
||||
const narrative = lines.join('\n').trim();
|
||||
const stillHasAction = /^\s*(?:[-*+]\s+|\d+[.)]\s+)/m.test(narrative);
|
||||
return { ...section, narrative, ...(stillHasAction ? {} : { title: '', kind: 'other' as const }) };
|
||||
}).filter(section => section.narrative || section.tables.length || section.visuals.length);
|
||||
if (!focusProducts.length) return sections;
|
||||
const insertAt = Math.max(0, remaining.findIndex(section => section.kind === 'overview') + 1);
|
||||
remaining.splice(insertAt, 0, { id: 'focus-product-summary', title: '重点产品', kind: 'product', markdown: '',
|
||||
narrative: '', tables: [], visuals: [], evidenceRefs: [...new Set(focusProducts.flatMap(row => row.evidenceRefs))], focusProducts });
|
||||
return remaining;
|
||||
}
|
||||
|
||||
function visualKind(visual: AnalysisVisual): NarrativeKind {
|
||||
const key = (visual as AnalysisVisual & { sectionKey?: string }).sectionKey;
|
||||
if (key?.startsWith('category_')) return 'category';
|
||||
@@ -117,7 +203,7 @@ function sectionScore(section: NarrativeSection, visual: AnalysisVisual, primary
|
||||
return score;
|
||||
}
|
||||
|
||||
export function buildAnalysisNarrative(answer: string, rawVisuals: unknown, question = ''): AnalysisNarrativeModel {
|
||||
export function buildAnalysisNarrative(answer: string, rawVisuals: unknown, question = '', additionalEvidenceRefs: string[] = []): AnalysisNarrativeModel {
|
||||
const safe = sanitizeAnalysisDisplayText(answer).replaceAll('\r\n', '\n').replaceAll('\r', '\n');
|
||||
const visuals = combineStageDefectVisuals(parseAnalysisVisuals(rawVisuals).visuals);
|
||||
const scopeDepth = (visual: AnalysisVisual) => ['department','group','product','category','defect'].filter(key => visual.scope[key]).length;
|
||||
@@ -152,7 +238,7 @@ export function buildAnalysisNarrative(answer: string, rawVisuals: unknown, ques
|
||||
else sections.push({ id: `section-${sections.length + 1}`, title, kind, markdown: '', narrative: '', tables: [], visuals: [visual], evidenceRefs: visual.evidenceRefs });
|
||||
}
|
||||
}
|
||||
const allRefs = [...new Set([...refs(safe), ...visuals.flatMap(visual => visual.evidenceRefs)])];
|
||||
const allRefs = [...new Set([...additionalEvidenceRefs, ...refs(safe), ...visuals.flatMap(visual => visual.evidenceRefs)])];
|
||||
const evidenceLabels = Object.fromEntries(allRefs.map((ref, index) => [ref, `依据 ${index + 1}`]));
|
||||
const evidence = allRefs.map(ref => {
|
||||
const charts = visuals.filter(visual => visual.evidenceRefs.includes(ref));
|
||||
@@ -169,5 +255,5 @@ export function buildAnalysisNarrative(answer: string, rawVisuals: unknown, ques
|
||||
: main?.metric === 'composite_rate' ? '质量变化分析' : '质量数据分析';
|
||||
const title = period && (broad || cleanQuestion.length > 40 || /用.*图|展示|查看/.test(cleanQuestion))
|
||||
? `${period} ${topic}` : cleanQuestion || '质量分析报告';
|
||||
return { sections, evidence, evidenceLabels, period, scope, title };
|
||||
return { sections: bringFocusProductsForward(sections), evidence, evidenceLabels, period, scope, title };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user