diff --git a/scripts/convert_modules.py b/scripts/convert_modules.py index 763505c..d3ebfe6 100644 --- a/scripts/convert_modules.py +++ b/scripts/convert_modules.py @@ -228,6 +228,34 @@ def read_lunacy(reads=5, pause=1.0): return None +# 狂气那个数字的 OCR 读法**不稳定**: 同一个真值(6636)实测被读成过 +# 6636 / 9699 / 6388 / 8859 —— 艺术字加抗锯齿, 同一画面连读几次都可能不一样。 +# +# ⛔ 所以最初那套"前后读数不同 = 真的变了"是错的(2026-10-16 22:03 误报过一次: +# 前 6636 后 9699, 复读仍是 9699, 于是报了"狂气读数发生变化" —— 但那一轮脚本 +# 只点了模组图标和面板内的 » / 确认, 根本没碰 Use Lunacy 页签, 没有任何消费)。 +# +# 能站得住的判断只有两种: +# * 后读数落在"已知读法"集合里 -> 视为没变(可能只是换了个误读法) +# * 后读数不在集合里 -> 出现了从没见过的值, 值得人工看一眼 +# 真正的防线是结构性的(只点 Modules 页签, 且 Use Lunacy 坐标被测试盯着), +# 这里只是补一层"数字有没有变成陌生值"的旁证。 +LUNACY_KNOWN_READINGS = (6636, 9699, 6388, 8859) + + +def lunacy_verdict(before, after): + """返回 (是否可疑, 说明)。宁可说"不确定", 也不要把误读当消费。""" + if before is None or after is None: + return False, '读数不完整(%s -> %s), 本次未做比对' % (before, after) + if before == after: + return False, '前后读数一致 %s' % after + if after in LUNACY_KNOWN_READINGS: + return False, ('前后读法不同(%s -> %s), 但 %s 是已知读法之一, 判为 OCR 抖动, ' + '不算消费' % (before, after, after)) + return True, ('读数 %s -> %s, 而 %s 不在已知读法 %s 里, 需人工核查' + % (before, after, after, list(LUNACY_KNOWN_READINGS))) + + def read_owned(retries=3, pause=2.0): """从合成面板上读 'Owned NN'(当前模组数量)。读不到返回 None。 @@ -606,46 +634,24 @@ def main(argv=None): break log('合成后狂气(OCR): %s' % lunacy_after) - # 狂气只做相对比对: 同一个画面同一套艺术字, OCR 的误读方式大体一致, - # 所以"两次读数不同"是发现变化的主要手段。 - if lunacy_before is not None and lunacy_after is not None and lunacy_before != lunacy_after: - # ⛔ 但"不同"不等于"真的变了": 这个数字的 OCR 会在同一画面上翻转 - # (实测连读 5 次得到 6388 四次、8859 一次)。前后两次恰好各读到一面的话, - # 就会误报"狂气被消费" —— 中止整轮 + 留下一条假的违规记录。 - # 所以报违规前必须复读确认。复读也可能读不到, 那同样不算证据, 再试几次。 - confirm = None - for _ in range(3): - confirm = read_lunacy() - if confirm is not None: - break - time.sleep(2) - log(' [warn] 前后读数不同(%s -> %s), 复读确认得到 %s' - % (lunacy_before, lunacy_after, confirm)) - if confirm == lunacy_before: - log(' → 判定为 OCR 翻转(复读回到原值 %s), 不是真的变化' % confirm) - lunacy_after = confirm - elif confirm is None: - # 读不到不能算"变了", 但也不能当作没事 —— 交给人工看一眼。 - if not args.keep_game: - close_game() - return done(1, '⚠️ 狂气前后读数不同(%s -> %s)且复读不到, 需人工核查' - % (lunacy_before, lunacy_after)) - else: - if not args.keep_game: - close_game() - return done(1, '⚠️ 狂气读数发生变化 %s -> %s (复读仍为 %s), 立即停止并人工核查' - % (lunacy_before, lunacy_after, confirm)) - if lunacy_before is None or lunacy_after is None: - # 读不到就不假装校验过。合成路径本身不碰狂气(只点 Modules 页签), - # 这里只把"没能比对"如实记下来。 - log('[warn] 狂气前后读数不完整(%s -> %s), 本次未做比对' - % (lunacy_before, lunacy_after)) - else: - log('狂气校验: OK (前后读数一致 %s)' % lunacy_after) - # 记进报告: 值守看的是报告, 狂气读数不能只留在日志文本里 + # ⛔ 先记进报告再判 —— 22:03 那次是在判断之后才记, 结果告警分支提前 return, + # 报告里 lunacy_after 留了个 None, 事后想复核这次读数都无从下手。 + # (和第 10 轮修过的"提前收工导致读数丢失"是同一个毛病, 这次犯在告警分支上。) _result['lunacy_before'] = lunacy_before _result['lunacy_after'] = lunacy_after _result['lunacy_checked'] = (lunacy_before is not None and lunacy_after is not None) + + # ⛔ 这里原来是"前后读数不同就报违规", 已证明是错的(2026-10-16 22:03 误报): + # 同一个真值 6636 的 OCR 读法本身就不固定(6636/9699/6388/8859 都出现过), + # 所以"不同"完全可能只是换了个误读法。判据换成 lunacy_verdict(): + # 只有读到**从没见过的值**才算可疑, 已知读法之间的抖动不算。 + suspicious, why = lunacy_verdict(lunacy_before, lunacy_after) + if suspicious: + log(' [warn] %s' % why) + if not args.keep_game: + close_game() + return done(1, '⚠️ %s' % why) + log('狂气校验: %s' % why) if not args.keep_game: close_game() diff --git a/scripts/modules_status.py b/scripts/modules_status.py index 29b8761..0cdd4ff 100644 --- a/scripts/modules_status.py +++ b/scripts/modules_status.py @@ -34,6 +34,28 @@ def load_reports(d): return rows +def recheck_alarm(lb, la, result): + """用**当前**判据重新复核老报告里的狂气告警。 + + ⛔ 为什么需要这个: 2026-10-16 22:03 那份报告按当时的判据写了 + "⚠️ 狂气读数发生变化 6636 -> 9699", 而事后查明那是**误报** —— + 6636 和 9699 都是真值 6636 的已知 OCR 读法。 + + 报告是历史记录, 不该改写; 但汇总工具不能继续拿旧判据吓人。 + 这里重新判一遍, 并把"当时报了、现在看是误报"明说出来。 + """ + if '狂气读数发生变化' not in (result or ''): + return False, False # (是否告警, 是否新版判据认定是误报) + if lb is None or la is None: + return True, False + try: + import convert_modules as cm + suspicious, _ = cm.lunacy_verdict(lb, la) + except Exception: + return True, False + return True, (not suspicious) + + def summarize(rows): out = [] for r in rows: @@ -47,6 +69,7 @@ def summarize(rows): if converted is None: # 老报告没有 converted, 按结果文本推断 converted = '合成完成' in (r.get('result') or '') + alarmed, now_false_alarm = recheck_alarm(lb, la, r.get('result')) out.append({ 'started': r.get('started', '?'), 'ok': bool(r.get('ok')), @@ -57,7 +80,8 @@ def summarize(rows): 'lunacy_before': lb, 'lunacy_after': la, 'lunacy_checked': bool(checked), - 'lunacy_alarm': '狂气读数发生变化' in (r.get('result') or ''), + 'lunacy_alarm': alarmed, + 'lunacy_false_alarm': now_false_alarm, }) return out @@ -65,6 +89,9 @@ def summarize(rows): def lunacy_cell(r): """狂气那格的显示。没比对上时明说, 不装作校过了。""" if r['lunacy_alarm']: + if r.get('lunacy_false_alarm'): + # 报告里那句话是按旧判据写的, 但按现在的证据看是误报 —— 别继续吓人 + return '误报(%s/%s 都是已知读法)' % (r['lunacy_before'], r['lunacy_after']) return '⚠️ %s -> %s' % (r['lunacy_before'], r['lunacy_after']) if not r['converted']: # 这轮压根没合成, 没什么可比 —— 和"合成过但没读到"是两回事 @@ -105,12 +132,17 @@ def main(argv=None): got = sum(1 for r in rows if r['converted']) fails = [r for r in rows if not r['ok']] - alarms = [r for r in rows if r['lunacy_alarm']] + # 告警里要排掉"按现在的判据看是误报"的那些 —— 否则表头会一直喊狼来了 + alarms = [r for r in rows if r['lunacy_alarm'] and not r.get('lunacy_false_alarm')] + false_alarms = [r for r in rows if r.get('lunacy_false_alarm')] # 只统计"真的合成过却没能比对"的 —— 没合成的轮次没什么可比, 混进来会虚高 unchecked = [r for r in rows if r['converted'] and not r['lunacy_checked']] print('共 %d 轮: 换到模块 %d 轮, 失败 %d 轮, 狂气告警 %d 轮, 该比对却没比对 %d 轮' % (len(rows), got, len(fails), len(alarms), len(unchecked))) + if false_alarms: + print(' (另有 %d 轮当时报过狂气告警, 但按现在的判据是误报, 见下表)' + % len(false_alarms)) if alarms: print('⚠️ 有狂气告警, 需要人工核查:') for r in alarms: diff --git a/tests/test_convert_modules.py b/tests/test_convert_modules.py index 44f65ac..191312a 100644 --- a/tests/test_convert_modules.py +++ b/tests/test_convert_modules.py @@ -254,14 +254,61 @@ class WindowSizeTest(QuietLogMixin, unittest.TestCase): self.assertEqual(r, (1278, 719)) -class LunacyFalseAlarmTest(QuietLogMixin, unittest.TestCase): - """⛔ 报"狂气被消费"之前必须复读确认。 +class LunacyVerdictTest(unittest.TestCase): + """⛔ 狂气那个数字的判据 —— 曾被"相对比对"的错假设坑过两次。 - 这个数字的 OCR 会在同一画面上翻转(实测连读 5 次: 6388 四次 / 8859 一次)。 - 前后两次恰好各读到一面, 就会误报违规 —— 中止整轮 + 留下一条假的违规记录, - 而这条记录会让人去查一笔根本没发生的消费。 + 2026-10-16 22:03 实测: 合成前读到 6636、合成后读到 9699, 复读仍是 9699, + 于是报了"狂气读数发生变化"并让整轮 FAIL。但那一轮脚本只点了模组图标和面板内的 + » / 确认, 从没碰 Use Lunacy 页签 —— **是误报**。 + + 根因: 我以为"同一画面的误读方式一致", 实际上真值 6636 被读过 6636 / 9699 / + 6388 / 8859 四种样子, 误读根本不固定。所以"前后不同"区分不了 + "真变了" 和 "换了个误读法"。 + + 现在只有一种情况算可疑: 读到从没见过的值。 """ + KNOWN = cm.LUNACY_KNOWN_READINGS + + def test_same_reading_is_clean(self): + suspicious, why = cm.lunacy_verdict(9699, 9699) + self.assertFalse(suspicious) + self.assertIn('一致', why) + + def test_the_real_false_alarm_is_now_clean(self): + """22:03 那次的真实读数 —— 必须不再被当成消费。""" + suspicious, why = cm.lunacy_verdict(6636, 9699) + self.assertFalse(suspicious, '6636 -> 9699 是已知的两种读法, 不是消费') + self.assertIn('已知读法', why) + + def test_jitter_between_known_readings_is_clean(self): + for a in self.KNOWN: + for b in self.KNOWN: + suspicious, why = cm.lunacy_verdict(a, b) + self.assertFalse(suspicious, '%s -> %s 都属已知读法, 不该报' % (a, b)) + + def test_unreadable_is_not_a_verdict(self): + suspicious, why = cm.lunacy_verdict(9699, None) + self.assertFalse(suspicious, '读不到不等于变了') + self.assertIn('未做比对', why) + + def test_unknown_value_is_suspicious(self): + """真的被消费(或获得)狂气时会读到陌生值, 那种要报出来。""" + suspicious, why = cm.lunacy_verdict(6636, 3000) + self.assertTrue(suspicious) + self.assertIn('不在已知读法', why) + + def test_unknown_value_on_the_before_side_also_alerts(self): + # 合成前就读到陌生值 -> 说明基线本身变了, 同样值得看 + suspicious, why = cm.lunacy_verdict(4000, 4000) + self.assertFalse(suspicious) # 前后一致就不管(可能只是 OCR 一直这么读) + suspicious2, _ = cm.lunacy_verdict(4000, 3000) + self.assertTrue(suspicious2) + + +class LunacyFalseAlarmTest(QuietLogMixin, unittest.TestCase): + """整轮跑下来: 已知读法抖动不该让这一轮 FAIL。""" + def _run(self, lunacy_seq): s = list(lunacy_seq) with mock.patch.object(cm, 'read_enkephalin', lambda: 25), \ @@ -284,18 +331,17 @@ class LunacyFalseAlarmTest(QuietLogMixin, unittest.TestCase): def test_consistent_reading_passes(self): self.assertEqual(self._run([9699, 9699]), 0) - def test_ocr_flip_is_not_a_violation(self): - """前后各读到一面 -> 复读回到原值 -> 判为翻转, 不算消费。""" - self.assertEqual(self._run([9699, 6636, 9699]), 0, - 'OCR 翻转不该被报成"狂气被消费"') + def test_real_false_alarm_case_now_passes(self): + """22:03 那次: 6636 -> 9699 -> 复读 9699。修好后这轮必须算成功。""" + self.assertEqual(self._run([6636, 9699, 9699]), 0, + '已知读法之间的抖动不该让整轮 FAIL') - def test_real_change_still_reported(self): - self.assertEqual(self._run([9699, 6300, 6300]), 1, - '真的变了必须报违规') + def test_unknown_value_still_fails_the_run(self): + self.assertEqual(self._run([6636, 3000, 3000]), 1, + '读到陌生值必须报出来') - def test_unconfirmable_change_goes_to_human(self): - """变了但复读不到 —— 不算证据, 但也不能当作没事, 交给人工看。""" - self.assertEqual(self._run([9699, 6300, None, None, None]), 1) + def test_unreadable_after_is_not_a_failure(self): + self.assertEqual(self._run([9699, None, None, None, None]), 0) class ConvertAttemptVerifiedTest(QuietLogMixin, unittest.TestCase): diff --git a/tests/test_modules_status.py b/tests/test_modules_status.py index 8f1830d..6739b61 100644 --- a/tests/test_modules_status.py +++ b/tests/test_modules_status.py @@ -127,5 +127,48 @@ class LunacyColumnTest(unittest.TestCase): self.assertFalse(r2['lunacy_checked']) +class RecheckAlarmTest(unittest.TestCase): + """老报告里的狂气告警要用**当前**判据重新复核。 + + ⛔ 2026-10-16 22:03 那份报告写的是"⚠️ 狂气读数发生变化 6636 -> 9699", 而事后 + 查明 6636 和 9699 都是真值 6636 的已知 OCR 读法 —— 是误报。报告是历史记录不该 + 改写, 但汇总工具不能继续拿旧判据吓人。 + """ + + ALARM = '⚠️ 狂气读数发生变化 6636 -> 9699 (复读仍为 9699), 立即停止并人工核查' + + def test_false_alarm_is_reclassified(self): + alarmed, false_alarm = ms.recheck_alarm(6636, 9699, self.ALARM) + self.assertTrue(alarmed, '当时确实报过告警') + self.assertTrue(false_alarm, '按现在的判据这是误报') + + def test_real_alarm_stays(self): + # 陌生值 -> 现在的判据也认为可疑 + alarmed, false_alarm = ms.recheck_alarm(6636, 3000, self.ALARM) + self.assertTrue(alarmed) + self.assertFalse(false_alarm) + + def test_non_alarm_report_is_untouched(self): + alarmed, false_alarm = ms.recheck_alarm(9699, 9699, '合成完成: 模组 1 -> 2 (+1)') + self.assertFalse(alarmed) + self.assertFalse(false_alarm) + + def test_missing_readings_cannot_be_rechecked(self): + """读数缺了就没法复核 —— 只能维持原判, 不能凭空洗白。""" + alarmed, false_alarm = ms.recheck_alarm(6636, None, self.ALARM) + self.assertTrue(alarmed) + self.assertFalse(false_alarm) + + def test_summary_excludes_false_alarms_from_the_header_count(self): + """表头那句"狂气告警 N 轮"不该再数误报, 否则一直喊狼来了。""" + rows = ms.summarize([ + {'started': 'a', 'ok': False, 'result': self.ALARM, 'elapsed_s': 10, + 'converted': True, 'lunacy_before': 6636, 'lunacy_after': 9699, + 'lunacy_checked': True}]) + self.assertTrue(rows[0]['lunacy_alarm']) + self.assertTrue(rows[0]['lunacy_false_alarm']) + self.assertIn('误报', ms.lunacy_cell(rows[0])) + + if __name__ == '__main__': unittest.main()