修复:DSH 自主查询、图片直显与报告稳定性
允许 Agent 在循环中查目录、修正查询和提问,保留实时权限检查及模型原始回答。 统一相同查询证据与图表资源;排名补齐阶段指标,修正 OR 重量筛选,并限制模型明细输入。 增加运行恢复、图表自适应坐标轴与两位小数,修复报告主图选择、重复图及边缘标签。 验证:独立副本通过 162 项 Python、73 项前端及 21 项后端测试,前端构建通过。 线上已用原 8 题复测,并追加两轮双期对比;TOP100 与组合筛选分别核对 100 行和 20 行。
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
buildAnalysisVisualExportOption,
|
||||
combineStageDefectVisuals,
|
||||
formatVisualValue,
|
||||
distinctAnalysisVisuals,
|
||||
parseAnalysisVisuals,
|
||||
renderVisualTableHtml,
|
||||
visualCategoryLabel,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
} from '../src/analysisVisualsModel.ts';
|
||||
import { buildAnalysisNarrative } from '../src/analysisReportModel.ts';
|
||||
import { buildConclusionDocument, checkedConclusionComparison } from '../src/analysisConclusionModel.ts';
|
||||
import { analysisChartReferences } from '../src/analysisChartReferences.ts';
|
||||
|
||||
function visual(overrides = {}) {
|
||||
return {
|
||||
@@ -136,7 +138,7 @@ test('weight ranking export retains the all-scope denominator label and readable
|
||||
assert.deepEqual(report.xAxis.data.map(name=>name.replaceAll('\n','')),names);
|
||||
assert.equal(report.xAxis.axisLabel.rotate,0);
|
||||
assert.ok(report.grid.height>=240);
|
||||
assert.equal(report.series[1].label.formatter({dataIndex:9,data:55}),'55%');
|
||||
assert.equal(report.series[1].label.formatter({dataIndex:9,data:55}),'55.00%');
|
||||
assert.deepEqual(report.series[0].data,input.series[0].values);
|
||||
});
|
||||
|
||||
@@ -189,11 +191,11 @@ test('same-scope black and bright defect changes become one stage-colored chart'
|
||||
assert.equal(combineStageDefectVisuals(combined).length, 2);
|
||||
});
|
||||
|
||||
test('ratio charts use 0 to 100 percent and convert raw ratios only for plotting', () => {
|
||||
test('ratio trends adapt to their data and convert raw ratios only for plotting', () => {
|
||||
const parsed = parseAnalysisVisuals([visual()]);
|
||||
const option = buildAnalysisVisualOption(parsed.visuals[0]);
|
||||
assert.equal(option.yAxis.min, 0);
|
||||
assert.equal(option.yAxis.max, 100);
|
||||
assert.ok(option.yAxis.min < 82 && option.yAxis.min > 80);
|
||||
assert.ok(option.yAxis.max > 84 && option.yAxis.max < 86);
|
||||
assert.deepEqual(option.series[0].data, [82, 84]);
|
||||
assert.equal(formatVisualValue(0.8425, 'ratio'), '84.25%');
|
||||
});
|
||||
@@ -207,15 +209,15 @@ test('stage scrap rates preserve values above 100 percent and expand every ratio
|
||||
assert.ok(buildAnalysisVisualOption(parsed.visuals[0]).yAxis.max > 123);
|
||||
assert.ok(buildAnalysisVisualExportOption(parsed.visuals[0], 1280, 'standalone').option.yAxis.max > 123);
|
||||
assert.ok(buildAnalysisVisualExportOption(parsed.visuals[0], 1280, 'report').option.yAxis.max > 123);
|
||||
assert.equal(formatVisualValue(1.23, 'ratio'), '123%');
|
||||
assert.equal(formatVisualValue(1.23, 'ratio'), '123.00%');
|
||||
}
|
||||
const horizontal = parseAnalysisVisuals([scrapRate('black', [1.23, 0.94], { type: 'bar' })]).visuals[0];
|
||||
assert.ok(buildAnalysisVisualOption(horizontal).xAxis.max > 123);
|
||||
assert.ok(buildAnalysisVisualExportOption(horizontal, 1280, 'report').option.xAxis.max > 123);
|
||||
|
||||
const below100 = parseAnalysisVisuals([scrapRate('black', [0.91, 0.84])]).visuals[0];
|
||||
assert.equal(buildAnalysisVisualOption(below100).yAxis.max, 100);
|
||||
assert.equal(buildAnalysisVisualExportOption(below100, 1280, 'report').option.yAxis.max, 100);
|
||||
assert.ok(buildAnalysisVisualOption(below100).yAxis.max > 91);
|
||||
assert.equal(buildAnalysisVisualExportOption(below100, 1280, 'report').option.yAxis.max, buildAnalysisVisualOption(below100).yAxis.max);
|
||||
});
|
||||
|
||||
test('formal black and composite rates above 100 percent remain visible in live and exported charts', () => {
|
||||
@@ -303,7 +305,7 @@ test('negative percentage point changes remain signed and keep a zero baseline',
|
||||
assert.equal(option.xAxis.scale, false);
|
||||
assert.equal(option.xAxis.max, undefined);
|
||||
assert.equal(formatVisualValue(-2.75, 'pp'), '-2.75 pp');
|
||||
assert.equal(formatVisualValue(0.5, 'pp'), '+0.5 pp');
|
||||
assert.equal(formatVisualValue(0.5, 'pp'), '+0.50 pp');
|
||||
});
|
||||
|
||||
test('legacy rate-drop charts normalize once and chat tables and exports use current minus prior', () => {
|
||||
@@ -339,8 +341,8 @@ test('legacy rate-drop charts normalize once and chat tables and exports use cur
|
||||
const chart = buildAnalysisVisualOption(model);
|
||||
assert.deepEqual(chart.series[0].data, [-2.5, 4]);
|
||||
const table = renderVisualTableHtml(legacy);
|
||||
assert.match(table, /-2\.5 pp/);
|
||||
assert.match(table, /\+4 pp/);
|
||||
assert.match(table, /-2\.50 pp/);
|
||||
assert.match(table, /\+4\.00 pp/);
|
||||
const exported = buildAnalysisVisualExportOption(model, 1280, 'report');
|
||||
assert.deepEqual(exported.option.series[0].data, [-2.5, 4]);
|
||||
|
||||
@@ -577,7 +579,7 @@ test('heatmap omits null cells, plots actual zero, and uses a sign-neutral diver
|
||||
assert.equal(exported.option.xAxis.data[0], '2026-08');
|
||||
const ratio = parseAnalysisVisuals([visual({ type: 'heatmap' })]).visuals[0];
|
||||
const ratioOption = buildAnalysisVisualOption(ratio);
|
||||
assert.match(ratioOption.tooltip.formatter({ data: [1, 0, 84] }), /84%/);
|
||||
assert.match(ratioOption.tooltip.formatter({ data: [1, 0, 84] }), /84\.00%/);
|
||||
assert.doesNotMatch(ratioOption.tooltip.formatter({ data: [1, 0, 84] }), /8400/);
|
||||
});
|
||||
|
||||
@@ -602,20 +604,20 @@ test('donut accepts only a complete official mutually-exclusive category set and
|
||||
const option = buildAnalysisVisualOption(model);
|
||||
assert.equal(option.series[0].type, 'pie');
|
||||
assert.deepEqual(option.series[0].data.map(item => item.value), [0, 2, 8]);
|
||||
assert.match(option.graphic[0].style.text, /10 kg/);
|
||||
assert.match(option.graphic[0].style.text, /10\.00 kg/);
|
||||
assert.match(option.graphic[1].style.text, /不代表正式总报废占比/);
|
||||
assert.match(option.series[0].label.formatter({ dataIndex: 1 }), /20%/);
|
||||
assert.match(option.series[0].label.formatter({ dataIndex: 1 }), /20\.00%/);
|
||||
const table = renderVisualTableHtml(model);
|
||||
assert.match(table, /占比以本图所列类别重量合计为分母/);
|
||||
assert.match(table, /20%/);
|
||||
assert.match(table, /20\.00%/);
|
||||
|
||||
const exported = buildAnalysisVisualExportOption(model);
|
||||
assert.equal(exported.option.series[0].type, 'pie');
|
||||
assert.equal(exported.option.grid, undefined);
|
||||
assert.equal(exported.option.legend.show, true);
|
||||
assert.match(exported.option.title.subtext, /不代表正式总报废占比/);
|
||||
assert.match(exported.option.graphic.elements.map(item => item.style.text || '').join('\n'), /责废:0 kg/);
|
||||
assert.match(exported.option.graphic.elements[0].style.text, /10 kg/);
|
||||
assert.match(exported.option.graphic.elements.map(item => item.style.text || '').join('\n'), /责废:0\.00 kg/);
|
||||
assert.match(exported.option.graphic.elements[0].style.text, /10\.00 kg/);
|
||||
assert.equal(exported.option.series[0].center[0], 640);
|
||||
assert.ok(exported.height > 600);
|
||||
|
||||
@@ -718,9 +720,9 @@ test('Pareto is an official-category dual-axis chart with computed listed-catego
|
||||
const tooltip = option.tooltip.formatter([
|
||||
{ dataIndex: 1, seriesIndex: 0 }, { dataIndex: 1, seriesIndex: 1 },
|
||||
]);
|
||||
assert.match(tooltip, /报废重量:2 kg/);
|
||||
assert.match(tooltip, /本图类别占比:20%/);
|
||||
assert.match(tooltip, /累计占本图已列类别合计:100%/);
|
||||
assert.match(tooltip, /报废重量:2\.00 kg/);
|
||||
assert.match(tooltip, /本图类别占比:20\.00%/);
|
||||
assert.match(tooltip, /累计占本图已列类别合计:100\.00%/);
|
||||
assert.doesNotMatch(tooltip, /正式总报废/);
|
||||
|
||||
const exported = buildAnalysisVisualExportOption(model);
|
||||
@@ -881,7 +883,7 @@ test('declining waterfall total remains negative and hides unused total labels',
|
||||
}
|
||||
});
|
||||
|
||||
test('kg and pp chart labels round to two decimals while tooltips and tables keep source precision', () => {
|
||||
test('kg and pp labels tooltips and tables show two decimals while source data retains precision', () => {
|
||||
const model = parseAnalysisVisuals([visual({ type: 'column', unit: 'pp',
|
||||
categories: [{ key: 'up', label: '改善' }, { key: 'down', label: '下降' }],
|
||||
series: [{ key: 'change', label: '变化', values: [2.34567, -1.23456] }],
|
||||
@@ -890,14 +892,14 @@ test('kg and pp chart labels round to two decimals while tooltips and tables kee
|
||||
assert.equal(option.series[0].data[0].value, 2.34567);
|
||||
assert.equal(option.series[0].label.formatter({ dataIndex: 0 }), '+2.35 pp');
|
||||
assert.equal(option.series[0].label.formatter({ dataIndex: 1 }), '-1.23 pp');
|
||||
assert.match(option.tooltip.formatter([{ dataIndex: 0, seriesIndex: 0 }]), /2.34567 pp/);
|
||||
assert.match(renderVisualTableHtml(model), /2\.34567 pp/);
|
||||
assert.match(option.tooltip.formatter([{ dataIndex: 0, seriesIndex: 0 }]), /2\.35 pp/);
|
||||
assert.match(renderVisualTableHtml(model), /2\.35 pp/);
|
||||
|
||||
const ring = parseAnalysisVisuals([donut({ series: [{ key: 'source_defect_weight', label: '类别重量', values: [2.34567, 3, 4] }] })]).visuals[0];
|
||||
const ringOption = buildAnalysisVisualOption(ring);
|
||||
assert.match(ringOption.series[0].label.formatter({ dataIndex: 0 }), /2\.35 kg/);
|
||||
assert.match(ringOption.tooltip.formatter([{ dataIndex: 0, seriesIndex: 0 }]), /2.34567 kg/);
|
||||
assert.match(renderVisualTableHtml(ring), /2\.34567 kg/);
|
||||
assert.match(ringOption.tooltip.formatter([{ dataIndex: 0, seriesIndex: 0 }]), /2\.35 kg/);
|
||||
assert.match(renderVisualTableHtml(ring), /2\.35 kg/);
|
||||
});
|
||||
|
||||
test('report export fully wraps long donut, Pareto, and trend category names', () => {
|
||||
@@ -991,15 +993,52 @@ test('scrap-rate data and export unit labels preserve the requested indicator',
|
||||
});
|
||||
|
||||
|
||||
test('low scrap-rate trends use a readable zero-based percentage axis without changing values', () => {
|
||||
test('low scrap-rate trends adapt within their range without changing values', () => {
|
||||
const item = parseAnalysisVisuals([scrapRate('black', [.03657, .02995])]).visuals[0];
|
||||
const option = buildAnalysisVisualOption(item);
|
||||
assert.equal(option.yAxis.min, 0);
|
||||
assert.ok(option.yAxis.min >= 0 && option.yAxis.min < 2.995);
|
||||
assert.ok(option.yAxis.max > 3.657 && option.yAxis.max < 20);
|
||||
assert.deepEqual(item.series[0].values, [.03657, .02995]);
|
||||
assert.equal(buildAnalysisVisualExportOption(item, 1280, 'report').option.yAxis.max, option.yAxis.max);
|
||||
const zero = parseAnalysisVisuals([scrapRate('bright', [0, 0])]).visuals[0];
|
||||
assert.ok(buildAnalysisVisualOption(zero).yAxis.max > 0);
|
||||
const goodRate = parseAnalysisVisuals([visual({ metric: 'black_rate', stage: 'black', requiredFields: ['black_good_weight', 'black_total_weight'], series: [{ key: 'black_rate', label: '黑片合格率', values: [.03657, .02995] }] })]).visuals[0];
|
||||
assert.equal(buildAnalysisVisualOption(goodRate).yAxis.max, 100);
|
||||
assert.ok(buildAnalysisVisualOption(goodRate).yAxis.max > 3.657 && buildAnalysisVisualOption(goodRate).yAxis.max < 5);
|
||||
});
|
||||
|
||||
test('chart references bind only authorized current-turn visuals and never guess among multiple trends', () => {
|
||||
const item = visual({ sectionKey: 'trend' });
|
||||
assert.deepEqual(analysisChartReferences([item], 'turn-1'), { 'chart:visual-1': 'visual-1', 'chart:quality-trend-turn-1': 'visual-1' });
|
||||
assert.deepEqual(analysisChartReferences([item], 'other-turn'), {});
|
||||
const pair = analysisChartReferences([item, { ...item, id: 'second', series: [{ key: 'other', label: '另一指标', values: [.99, .98] }] }], 'turn-1');
|
||||
assert.equal(pair['chart:quality-trend-turn-1'], undefined);
|
||||
assert.equal(pair['chart:second'], 'second');
|
||||
const duplicate = { ...item, id: 'repeated', evidenceRefs: ['another-proof'] };
|
||||
const parsed = parseAnalysisVisuals([item, duplicate]).visuals;
|
||||
assert.equal(distinctAnalysisVisuals(parsed).length, 1);
|
||||
assert.equal(analysisChartReferences([item, duplicate], 'turn-1')['chart:repeated'], 'visual-1');
|
||||
assert.equal(distinctAnalysisVisuals(parseAnalysisVisuals([item, { ...duplicate, scope: { department: '不同产业部' } }]).visuals).length, 2);
|
||||
});
|
||||
|
||||
test('adaptive trends cover every series, preserve missing values, and keep non-trend bars zero based', () => {
|
||||
for (const values of [[.9517, .9670], [.98, .98], [0, 0], [1, 1], [1.24, 1.27], [null, .97]]) {
|
||||
const item = parseAnalysisVisuals([visual({ metric: 'composite_rate', series: [{ key: 'rate', label: '率', values }] })]).visuals[0];
|
||||
const before = JSON.stringify(item.series);
|
||||
const live = buildAnalysisVisualOption(item).yAxis;
|
||||
for (const context of ['standalone', 'report', 'agent-document']) {
|
||||
const exported = buildAnalysisVisualExportOption(item, 1280, context).option.yAxis;
|
||||
assert.equal(exported.min, live.min); assert.equal(exported.max, live.max);
|
||||
}
|
||||
assert.ok(live.max > live.min);
|
||||
for (const value of values.filter(value => value !== null)) assert.ok(live.min <= value * 100 && live.max >= value * 100);
|
||||
assert.equal(JSON.stringify(item.series), before);
|
||||
}
|
||||
const item = parseAnalysisVisuals([visual({ series: [{ key: 'a', label: '甲', values: [.95, null] }, { key: 'b', label: '乙', values: [.99, .98] }] })]).visuals[0];
|
||||
const option = buildAnalysisVisualOption(item);
|
||||
assert.ok(option.yAxis.min <= 95 && option.yAxis.max >= 99);
|
||||
assert.equal(option.yAxis.axisLabel.formatter(96.5), '96.50%');
|
||||
const bar = parseAnalysisVisuals([visual({ type: 'bar' })]).visuals[0];
|
||||
assert.equal(buildAnalysisVisualOption(bar).xAxis.min, 0);
|
||||
assert.equal(formatVisualValue(.9639601707533932, 'ratio'), '96.40%');
|
||||
assert.equal(formatVisualValue(3, 'kg'), '3.00 kg');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user