优化:未分类连续维护与柏拉图预汇总,同步已发布修复

This commit is contained in:
2026-11-01 12:40:50 +08:00
parent 572873c6b8
commit 38290f5fec
135 changed files with 17613 additions and 663 deletions
@@ -0,0 +1,60 @@
import sys
import unittest
from pathlib import Path
sys.path[:0] = [str(Path(__file__).resolve().parents[1] / 'scripts'), str(Path(__file__).parent)]
from nao_quality_tools import QualityTools, _valid_composite_rate_reference, symmetric_stage_decomposition
from nao_evidence_report import _display_rate
from nao_weight_ranking import rank_response, ranking_report
from analysis_visuals import build_visuals
from test_agent_visuals import evidence, context_for
def formal_row():
return {'key': 'synthetic', 'label': '修正分母规格', 'compositeRate': 1.08,
'black': {'totalWeight': 100, 'qualifiedWeight': 120, 'scrapWeight': 2, 'rate': 1.2},
'bright': {'totalWeight': 100, 'qualifiedWeight': 90, 'scrapWeight': 10, 'rate': .9},
'coverage': {'blackRows': 1, 'brightRows': 1}}
class FormalRateReferenceTests(unittest.TestCase):
def test_official_adjusted_denominator_rate_remains_citable_above_one(self):
row = formal_row()
period = {'year': 2026, 'month': 9}
snapshot = {**row, 'period': period, 'coverage': {'sourceMonths': [
{**period, 'blackRows': 1, 'brightRows': 1}]}}
self.assertTrue(_valid_composite_rate_reference(snapshot, period)[0])
self.assertEqual(float(QualityTools._row_rate(row, None)), 1.08)
self.assertEqual(_display_rate(snapshot, 'black'), 1.2)
def test_combined_ranking_retains_published_rate_and_formats_108_percent(self):
row = formal_row()
raw = {'rows': [row], 'summary': row, 'coverage': {'sourceMonths': [
{'year': 2026, 'month': 9, 'blackRows': 1, 'brightRows': 1}]}}
result = rank_response(raw, {'id': 'release'}, {'year': 2026, 'month': 9},
{}, 'product', None, 'scrapWeight', 5)
task = {'period': result['period'], 'filters': {}, 'dimensions': ['product'],
'stages': [], 'dimensionStages': {'product': []}, 'fields': ['rate', 'scrapWeight']}
self.assertEqual(result['rows'][0]['compositeRate'], 1.08)
report = ranking_report([{'result': result, 'evidenceRef': 'Q11111111'}], task, {'releaseId': 'release'})
self.assertIn('108.00%', report['facts'][0]['text'])
def test_comparison_chart_preserves_the_same_official_values(self):
doc = evidence()
doc['result']['current'].update(formal_row())
doc['result']['comparison'].update({'compositeRate': .9,
'black': {'rate': 1.0, 'totalWeight': 100, 'qualifiedWeight': 100},
'bright': {'rate': .9, 'totalWeight': 100, 'qualifiedWeight': 90}})
doc['result']['delta'] = {'available': True, 'percentagePoints': 18}
doc['result']['stageRateChangesPP'] = {'black': 20, 'bright': 0}
question = '核对正式综合合格率变化'
result = build_visuals([doc], question, 'turn', context=context_for(question, fields=['rate']))
chart = next(v for v in result['visuals'] if v['metric'] == 'composite_rate')
self.assertEqual(chart['series'][0]['values'], [.9, 1.08])
def test_decomposition_still_reconciles_with_the_official_delta(self):
result = symmetric_stage_decomposition(1.2, .9, 1.0, .9, .18,
black_current_total_weight=100, bright_current_total_weight=100,
black_comparison_total_weight=100, bright_comparison_total_weight=100)
self.assertEqual(result['status'], 'available')
self.assertAlmostEqual(float(result['blackPP']), 18)