同步:完善质量分析工作台并更新主题字体

同步已上线的智能分析执行协议、来源查询、图表报告与管理页面配套代码。
补齐数据库迁移、运行依赖和回归测试,保留原有指标计算口径。
统一午夜黑及其他主题的控件细节、中文和业务数字字体。
排除本地业务数据、凭据、预览、发布与验收产物。

验证:生产构建通过,320项前端回归通过;本轮仅同步Git,不再次部署。
This commit is contained in:
2026-10-30 22:40:58 +08:00
parent edef747e3b
commit ff7bbe3e46
393 changed files with 62999 additions and 1783 deletions
+146 -4
View File
@@ -7,6 +7,7 @@ from __future__ import annotations
import json
import os
import copy
from pathlib import Path
import re
import stat
@@ -61,14 +62,19 @@ def load_visual_evidence(directory: Path, release_id: str, *, exclude_files=froz
or not isinstance(result, dict) or result.get('releaseId') != release_id
or not re.fullmatch(r'Q[A-F0-9]{8}', str(document.get('evidenceRef', '')))):
raise ValueError('evidence binding mismatch')
if document.get('mode') in ('query', 'compare', 'top', 'changes', 'defects'):
if document.get('mode') in ('query', 'rank', 'compare', 'top', 'changes', 'defects'):
documents.append(document)
return documents
def visual_result(directory: Path, release_id: str, question: str, turn_id: str,
*, exclude_files=frozenset(), cancel_event=None) -> dict:
"""A chart failure is presentation-only and must never change turn status."""
*, exclude_files=frozenset(), cancel_event=None, context=None) -> dict:
"""Build a presentation-only result without changing turn status.
The complete server-normalized context, including an exact-question
``_agentTask`` when present, is forwarded to the deterministic builder.
This adapter does not reinterpret the task or question.
"""
if os.environ.get('QUALITY_ANALYSIS_VISUALS_ENABLED', 'true').lower() not in ('true', '1', 'yes'):
return {'visualSchemaVersion': 1, 'visualState': 'not_requested', 'visuals': []}
if cancel_event is not None and cancel_event.is_set():
@@ -79,8 +85,144 @@ def visual_result(directory: Path, release_id: str, question: str, turn_id: str,
cancel_event=cancel_event)
if cancel_event is not None and cancel_event.is_set():
return {'visualSchemaVersion': 1, 'visualState': 'unavailable', 'visuals': []}
return build_visuals(evidence, question, turn_id)
return build_visuals(evidence, question, turn_id, context=context)
except Exception:
# Presentation must not turn an otherwise successful business answer into
# a failed task, including unexpected adapter bugs. Do not expose paths.
return {'visualSchemaVersion': 1, 'visualState': 'failed', 'visuals': []}
def protocol_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': []}
if not isinstance(evidence, list) or not isinstance(scopes, list):
return {'visualSchemaVersion': 1, 'visualState': 'failed', 'visuals': [],
'missingEvidence': ['queryPlan图表输入范围无效。']}
try:
from analysis_visuals import build_visuals
from nao_query_plan import scope_context, scope_documents
all_visuals, missing, requested_visuals = [], [], False
for scope in scopes:
if not isinstance(scope, dict) or not isinstance(scope.get('task'), dict):
missing.append('服务器签发的图表范围不完整。')
continue
task = scope['task']
node_id, scope_id = scope.get('nodeId'), scope.get('scopeId')
child_question = task.get('question') if isinstance(task.get('question'), str) else question
selected = scope_documents(evidence, scope, release_id=release_id)
context = scope_context(scope, release_id=release_id, question=question)
if isinstance(base_context, dict):
for key in ('_protocol', '_protocolScopes'):
if key in base_context:
context[key] = copy.deepcopy(base_context[key])
preference = task.get('visualPreference', 'auto')
# Batch Top1 results may intentionally omit auto charts. A model's
# style hint alone must not mark that omission as unavailable.
if scope.get('purpose') == 'changes':
requested_visuals |= preference == 'required'
else:
requested_visuals |= preference != 'none' and (
task.get('trendRequired') is True or preference == 'required'
or task.get('visualType') is not None or task.get('kind') == 'analysis'
and bool(task.get('dimensions')) and set(task.get('fields', [])) <= {'totalWeight', 'scrapWeight'})
child = build_visuals(selected, child_question, turn_id, context=context)
child_visuals = child.get('visuals') if isinstance(child.get('visuals'), list) else []
metric_visual_requirements = []
if task.get('kind') == 'metrics' and task.get('comparisonRequired'):
stages = task.get('stages') or []
for field in task.get('fields', []):
if field == 'rate':
metric_visual_requirements.extend(
[(stage + '_rate', stage) for stage in stages] if stages
else [('composite_rate', None)])
elif field == 'scrapRate':
metric_visual_requirements.extend(
[(stage + '_scrap_rate', stage) for stage in (stages or ['black', 'bright'])])
elif field == 'totalWeight':
metric_visual_requirements.extend([(stage + '_total_weight', stage) for stage in stages])
elif field == 'scrapWeight':
metric_visual_requirements.extend([(stage + '_scrap_weight', stage) for stage in stages])
expected_pairs = set(metric_visual_requirements)
# The visual builder may offer both stage rates for a composite
# 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]
if scope.get('purpose') == 'defects' and preference != 'none':
query = task.get('defectQuery') if isinstance(task.get('defectQuery'), dict) else {}
expected_dimension = query.get('dimension')
expected_sort = task.get('sort', 'scrap_delta' if task.get('comparisonRequired') else 'current_scrap')
expected_metric = ('source_defect_delta_weight'
if task.get('comparisonRequired') and expected_sort == 'scrap_delta'
else 'source_defect_weight')
chart_types = ({task.get('visualType')} if task.get('visualType') else {'bar', 'column'})
for stage in task.get('stages', []):
matched = any(
chart.get('metric') == expected_metric
and chart.get('stage') == stage
and chart.get('dimension') == expected_dimension
and chart.get('type') in chart_types
and isinstance(chart.get('scope'), dict)
and chart['scope'].get('defect') == query.get('defect')
and chart['scope'].get('category') == query.get('category')
for chart in child_visuals if isinstance(chart, dict))
if not matched:
missing.append('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)
+'缺少'+str(stage)+'来源具体缺陷重量图,或所选图表类型无法诚实表达该范围。')
for visual in child_visuals:
if isinstance(visual, dict):
# Keep the established chart wire schema. Node/scope
# identity is validated from the server-issued tasks and
# evidence before building charts; it is not chart data.
all_visuals.append(copy.deepcopy(visual))
if child.get('visualState') == 'failed':
missing.append('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)+'图表整理失败。')
if (scope.get('purpose') != 'defects' and task.get('kind') == 'analysis'
and task.get('dimensions') and set(task.get('fields', [])) <= {'totalWeight', 'scrapWeight'}):
from nao_weight_ranking import missing_ranking_visuals
missing.extend('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)+':'+gap
for gap in missing_ranking_visuals(task, child_visuals, selected))
elif task.get('trendRequired') and preference != 'none':
expected = []
stages = task.get('stages') or []
for field in task.get('fields', []):
if field == 'rate':
expected.extend([('composite_rate', None)] if not stages else
[(stage+'_rate', stage) for stage in stages])
elif field == 'scrapRate':
expected.extend([(stage+'_scrap_rate', stage) for stage in (stages or ['black', 'bright'])])
elif field == 'totalWeight':
expected.extend([(stage+'_total_weight', stage) for stage in (stages or ['black', 'bright'])])
elif field == 'scrapWeight':
expected.extend([('current_scrap_weight', stage) for stage in (stages or ['black', 'bright'])])
for metric, stage in expected:
chart_types = ({task.get('visualType')} if task.get('visualType') else {'line', 'area', 'heatmap'})
if not any(chart.get('metric') == metric and chart.get('stage') == stage
and chart.get('type') in chart_types for chart in child_visuals):
missing.append('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)
+'缺少'+str(stage or '综合')+' '+metric+'趋势图。')
elif task.get('kind') == 'metrics' and preference != 'none' and (
preference == 'required' or task.get('visualType') is not None):
required = metric_visual_requirements
chart_types = ({task.get('visualType')} if task.get('visualType') else
{'bar', 'column'} if task.get('comparisonRequired') else set())
if not required:
missing.append('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)
+'缺少当前指标范围可表达的图表。')
else:
for metric, stage in required:
if not any(chart.get('metric') == metric and chart.get('stage') == stage
and chart.get('type') in chart_types for chart in child_visuals):
missing.append('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)
+'缺少'+str(stage or '综合')+' '+metric+'比较图。')
elif preference == 'required' and not child_visuals:
missing.append('节点'+str(node_id)+'范围'+str(scope.get('label') or scope_id)+'缺少所需图表。')
if len(all_visuals) > 12:
missing.append(f'queryPlan共有{len(all_visuals)}张图表,超过12张呈现上限,已截取前12张;结果为部分完成。')
all_visuals = all_visuals[:12]
state = 'ready' if all_visuals else ('unavailable' if requested_visuals else 'not_requested')
return {'visualSchemaVersion': 1, 'visualState': state, 'visuals': all_visuals,
'missingEvidence': list(dict.fromkeys(missing))}
except Exception:
return {'visualSchemaVersion': 1, 'visualState': 'failed', 'visuals': [],
'missingEvidence': ['queryPlan图表整理失败;已保留文字证据。']}