统一:DSH 智能分析、Top100 与图表静默恢复
接入 DSH 专用运行时和对话界面,保留模型原始回答,支持会话分页、连续追问与显式报告。 补齐组合筛选、各维度 Top100、分组查询到排名图的转换,图表故障静默省略并基于保存数据自动恢复。 优化报告风格、图表顺序和表格换行,更新接入说明及构建输入。 验证:独立目录前后端构建通过;118 项 Java、102 项前端、102 项图表、14 项 DSH 应用和 13 项组合筛选检查通过。 仅提交相关源码、锁定依赖与测试;不包含凭据、会话、业务数据或本地产物。
This commit is contained in:
@@ -93,6 +93,34 @@ def visual_result(directory: Path, release_id: str, question: str, turn_id: str,
|
||||
|
||||
|
||||
def protocol_visual_result(evidence, scopes, question, turn_id, *, release_id, base_context=None):
|
||||
"""One shared chart exit for live queries and frozen-response recovery.
|
||||
|
||||
Isolate each scope so a malformed optional chart never removes healthy
|
||||
charts produced from other query results in the same answer.
|
||||
"""
|
||||
if not isinstance(evidence, list) or not isinstance(scopes, list):
|
||||
return _protocol_scope_visual_result(evidence, scopes, question, turn_id,
|
||||
release_id=release_id, base_context=base_context)
|
||||
visuals, missing, states, seen = [], [], [], set()
|
||||
for scope in scopes:
|
||||
part = _protocol_scope_visual_result(evidence, [scope], question, turn_id,
|
||||
release_id=release_id, base_context=base_context)
|
||||
states.append(part.get('visualState'))
|
||||
missing.extend(part.get('missingEvidence', []))
|
||||
for chart in part.get('visuals', []):
|
||||
if chart.get('id') not in seen:
|
||||
seen.add(chart.get('id'))
|
||||
visuals.append(chart)
|
||||
if len(visuals) > 12:
|
||||
missing.append('图表数量超过12张呈现上限,已保留前12张。')
|
||||
visuals = visuals[:12]
|
||||
state = ('ready' if visuals else 'failed' if 'failed' in states else
|
||||
'unavailable' if 'unavailable' in states else 'not_requested')
|
||||
return {'visualSchemaVersion': 1, 'visualState': state, 'visuals': visuals,
|
||||
'missingEvidence': list(dict.fromkeys(missing))}
|
||||
|
||||
|
||||
def _protocol_scope_visual_result(evidence, scopes, question, turn_id, *, release_id, base_context=None):
|
||||
"""Build charts independently within each server-issued node/scope frame."""
|
||||
if os.environ.get('QUALITY_ANALYSIS_VISUALS_ENABLED', 'true').lower() not in ('true', '1', 'yes'):
|
||||
return {'visualSchemaVersion': 1, 'visualState': 'not_requested', 'visuals': [], 'missingEvidence': []}
|
||||
@@ -132,6 +160,20 @@ def protocol_visual_result(evidence, scopes, question, turn_id, *, release_id, b
|
||||
if key in base_context:
|
||||
context[key] = copy.deepcopy(base_context[key])
|
||||
preference = task.get('visualPreference', 'auto')
|
||||
selection = root.get('aggregateSelection')
|
||||
if (selection and scope.get('purpose') == 'metrics'
|
||||
and task.get('dimensions') == [selection.get('dimension')]):
|
||||
if preference != 'none':
|
||||
from dsh_row_selection import ranking_chart
|
||||
# A genuinely empty filtered population has no chart to
|
||||
# retry. Missing signed documents remain a recoverable gap.
|
||||
requested_visuals |= not selected
|
||||
for document in selected:
|
||||
charts = ranking_chart(document, root, turn_id)
|
||||
if charts:
|
||||
requested_visuals = True
|
||||
all_visuals.extend(charts)
|
||||
continue
|
||||
fields, stages = task.get('fields'), task.get('stages') or []
|
||||
optional_auto_scalar = (metric_scope and task.get('visualPreference') == 'auto'
|
||||
and task.get('comparisonRequired') is not True and task.get('trendRequired') is not True
|
||||
@@ -172,6 +214,44 @@ def protocol_visual_result(evidence, scopes, question, turn_id, *, release_id, b
|
||||
# request. Keep only the exact node fields and stage frame.
|
||||
child_visuals = [chart for chart in child_visuals
|
||||
if (chart.get('metric'), chart.get('stage')) in expected_pairs]
|
||||
# Composition is already present in the same signed overall result.
|
||||
# A scalar scrapWeight node must not erase those category values
|
||||
# when the user explicitly asks for a structure report.
|
||||
if (root.get('executionMode') == 'native_agent' and preference != 'none'
|
||||
and scope.get('purpose') in ('metrics', 'trend')
|
||||
and not task.get('dimensions')
|
||||
and re.search(r'报废.*(?:结构|构成|占比)|正式报废大类', root.get('question', ''))):
|
||||
from analysis_visuals import _metrics_category_charts
|
||||
for document in selected:
|
||||
for chart in _metrics_category_charts(document, document.get('result', {}), turn_id, '',
|
||||
semantic_chart_type='donut', semantic_stages=root.get('stages') or None):
|
||||
if not any(existing.get('id') == chart.get('id') for existing in child_visuals):
|
||||
child_visuals.append(chart)
|
||||
# Native overall queries carry all three formal rates in the same
|
||||
# signed monthly response. The scalar stage selector cannot encode
|
||||
# "composite plus both stages". Honour that explicit report request
|
||||
# using only this already scope-checked evidence, never a new query.
|
||||
requested_text = root.get('question', '')
|
||||
wants_stages = (all(label in requested_text for label in ('黑片合格率', '亮片合格率'))
|
||||
or bool(re.search(r'(?:两阶段|阶段)(?:月度)?对照', requested_text)))
|
||||
if (root.get('executionMode') == 'native_agent' and root.get('kind') in ('analysis', 'report')
|
||||
and root.get('trendRequired') is True and preference != 'none' and wants_stages
|
||||
and root.get('stages') in ([], ['black', 'bright'], ['bright', 'black'])
|
||||
and scope.get('purpose') == 'trend' and 'rate' in task.get('fields', []) and selected):
|
||||
present = {chart.get('metric') for chart in child_visuals}
|
||||
for stages, metrics in (([], {'composite_rate'}), (['black', 'bright'], {'black_rate', 'bright_rate'})):
|
||||
if metrics <= present:
|
||||
continue
|
||||
rate_context = copy.deepcopy(context)
|
||||
rate_context['_agentTask'].update(kind='metrics', fields=['rate'], stages=stages)
|
||||
supplement = build_visuals(selected, child_question, turn_id, context=rate_context)
|
||||
for chart in supplement.get('visuals', []):
|
||||
if (chart.get('metric') in metrics - present and chart.get('sectionKey') == 'trend'
|
||||
and chart.get('type') in ('line', 'area') and chart.get('unit') == 'ratio'):
|
||||
child_visuals.append(chart)
|
||||
present.add(chart['metric'])
|
||||
if not {'composite_rate', 'black_rate', 'bright_rate'} <= present:
|
||||
missing.append('当前正式月度证据未完整生成综合、黑片和亮片合格率趋势对照。')
|
||||
if scope.get('purpose') == 'defects' and preference != 'none':
|
||||
query = task.get('defectQuery') if isinstance(task.get('defectQuery'), dict) else {}
|
||||
expected_dimension = query.get('dimension')
|
||||
|
||||
Reference in New Issue
Block a user