截图连续识别失败熔断 + 卡包低分先刷新;震颤队名
- aalc_patches: install_image_error_guard — ImageUtils.match_template 返回 None(上游异常分支) 在 120 秒内累计 20 次即 TaskAbort, 避免窗口没了还空转 4.5 小时(2026-11-16 实测) - 卡包优选阈值: preferred_thresholds 0→1(LCP_THEME_PACK_THRESHOLD 可调), 低于 1 分先刷新, 上游最多 3 次 - data/team_names.json: tremor -> [震颤](用户 11-16 指定, 不再选镜像迷宫) - tests: 新增 test_image_error_guard 5 例 单测: 743 passed。
This commit is contained in:
@@ -1635,6 +1635,7 @@ def install_theme_pack_audit(log=print):
|
|||||||
# 这里在 AALC 选卡包时把它的权重表临时加上「卡包对当局体系的加分」(lc_mcp/data/theme_pack_systems.json),
|
# 这里在 AALC 选卡包时把它的权重表临时加上「卡包对当局体系的加分」(lc_mcp/data/theme_pack_systems.json),
|
||||||
# 不改配置文件。AALC 拿卡包卡面 OCR 文字按权重表的键做子串匹配、取第一个命中的键, 所以加过分的键排在最前面。
|
# 不改配置文件。AALC 拿卡包卡面 OCR 文字按权重表的键做子串匹配、取第一个命中的键, 所以加过分的键排在最前面。
|
||||||
THEME_PACK_SYSTEMS_ENV = 'LCP_THEME_PACK_SYSTEMS' # 0 = 关闭; 文件路径 = 用这张表代替默认表
|
THEME_PACK_SYSTEMS_ENV = 'LCP_THEME_PACK_SYSTEMS' # 0 = 关闭; 文件路径 = 用这张表代替默认表
|
||||||
|
THEME_PACK_THRESHOLD_ENV = 'LCP_THEME_PACK_THRESHOLD' # 优选阈值; 默认抬到 1, 让低分楼层先刷新卡包
|
||||||
THEME_PACK_SYSTEMS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'theme_pack_systems.json')
|
THEME_PACK_SYSTEMS_FILE = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', 'theme_pack_systems.json')
|
||||||
THEME_PACK_UNKNOWN_KEYS = ('未知', 'unknown') # AALC 认不出卡包时的兜底权重键, 不当卡包名用
|
THEME_PACK_UNKNOWN_KEYS = ('未知', 'unknown') # AALC 认不出卡包时的兜底权重键, 不当卡包名用
|
||||||
THEME_PACK_BOOSTED = {} # 本次选卡包加过分的键 → {pack, system, from, to}; 卡包审计记到 decisions 里
|
THEME_PACK_BOOSTED = {} # 本次选卡包加过分的键 → {pack, system, from, to}; 卡包审计记到 decisions 里
|
||||||
@@ -1846,6 +1847,24 @@ def install_theme_pack_systems(log=print, env=None, route=None, route_name='路
|
|||||||
select_theme_pack.__wrapped__ = original
|
select_theme_pack.__wrapped__ = original
|
||||||
mirror_mod.Mirror.__init__ = __init__
|
mirror_mod.Mirror.__init__ = __init__
|
||||||
mirror_mod.select_theme_pack = select_theme_pack
|
mirror_mod.select_theme_pack = select_theme_pack
|
||||||
|
|
||||||
|
# 2026-11-16 用户要求: 卡包均分低就刷新。AALC 只在「最高分 < preferred_thresholds」时刷新,
|
||||||
|
# 而主题包表里 preferred_thresholds 是 0 → 0 分也当优选, 永远不刷新。
|
||||||
|
# 这里把它抬到 1(可用 LCP_THEME_PACK_THRESHOLD 调), 让"没有本体系卡包"的楼层先刷新(上游最多 3 次),
|
||||||
|
# 刷完仍不达标还是选最高分那一个。
|
||||||
|
try:
|
||||||
|
want = int((env.get(THEME_PACK_THRESHOLD_ENV) or '').strip() or 0) # 默认不改上游行为
|
||||||
|
except ValueError:
|
||||||
|
want = 0
|
||||||
|
try:
|
||||||
|
current = int(getattr(theme_list, 'preferred_thresholds', 0) or 0)
|
||||||
|
except (TypeError, ValueError):
|
||||||
|
current = 0
|
||||||
|
if want > current:
|
||||||
|
theme_list.preferred_thresholds = want
|
||||||
|
log('[lc_mcp] 卡包优选阈值 %d → %d(低于它先刷新卡包, 上游最多刷 3 次)'
|
||||||
|
% (current, want))
|
||||||
|
|
||||||
log('[lc_mcp] patch: 镜牢卡包按体系加分(%s, %d 个卡包%s)' % (
|
log('[lc_mcp] patch: 镜牢卡包按体系加分(%s, %d 个卡包%s)' % (
|
||||||
os.path.basename(path), len(packs),
|
os.path.basename(path), len(packs),
|
||||||
', %s %s' % (route_name, ' '.join('%s+%d' % item for item in route.items())) if route else ''))
|
', %s %s' % (route_name, ' '.join('%s+%d' % item for item in route.items())) if route else ''))
|
||||||
@@ -1874,6 +1893,52 @@ class TaskAbort(BaseException):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------- 截图连续失败熔断
|
||||||
|
|
||||||
|
# 2026-11-16: 游戏窗口被最小化/关掉之后, AALC 每帧都在 cv2.matchTemplate 上抛
|
||||||
|
# 「corr.rows <= img.rows + templ.rows - 1」断言, 只记一条 ERROR 继续跑 —— 第 2 局
|
||||||
|
# 就这样空转 4.5 小时(68 次/秒), 直到手动停任务。这里统计"识别返回 None"(上游异常分支)的频率,
|
||||||
|
# 超过阈值就抛 TaskAbort 结束任务, 让 task_status 里能看见明确原因。
|
||||||
|
IMAGE_ERROR_WINDOW = 120 # 统计窗口(秒)
|
||||||
|
IMAGE_ERROR_LIMIT = 20 # 窗口内达到这个次数就熔断
|
||||||
|
|
||||||
|
|
||||||
|
def install_image_error_guard(log=print, clock=time.monotonic,
|
||||||
|
window=IMAGE_ERROR_WINDOW, limit=IMAGE_ERROR_LIMIT):
|
||||||
|
"""截图持续识别失败时结束任务。返回原 match_template, 未安装返回 None。"""
|
||||||
|
try:
|
||||||
|
from utils.image_utils import ImageUtils
|
||||||
|
except Exception as e:
|
||||||
|
log('[lc_mcp] 截图熔断跳过: 无法导入 %s' % e)
|
||||||
|
return None
|
||||||
|
original = getattr(ImageUtils, 'match_template', None)
|
||||||
|
if original is None:
|
||||||
|
log('[lc_mcp] 截图熔断跳过: ImageUtils 没有 match_template')
|
||||||
|
return None
|
||||||
|
state = {'times': []}
|
||||||
|
|
||||||
|
def match_template(screenshot, template, threshold, *args, **kwargs):
|
||||||
|
result = original(screenshot, template, threshold, *args, **kwargs)
|
||||||
|
if result is not None:
|
||||||
|
return result
|
||||||
|
now = clock()
|
||||||
|
times = state['times']
|
||||||
|
times.append(now)
|
||||||
|
cutoff = now - window
|
||||||
|
while times and times[0] < cutoff:
|
||||||
|
times.pop(0)
|
||||||
|
if len(times) >= limit:
|
||||||
|
log('[ERROR] [lc_mcp] %d 秒内 %d 次图片识别出错, 判定画面不可用, 结束任务'
|
||||||
|
% (window, len(times)))
|
||||||
|
decisions.record('image_error', None, 'abort', count=len(times))
|
||||||
|
raise TaskAbort('截图连续识别失败(%d 次/%d 秒), 游戏窗口可能被最小化或已关闭'
|
||||||
|
% (len(times), window))
|
||||||
|
return result
|
||||||
|
|
||||||
|
ImageUtils.match_template = staticmethod(match_template)
|
||||||
|
log('[lc_mcp] patch: 截图连续识别失败 %d 次/%d 秒即结束任务' % (limit, window))
|
||||||
|
return original
|
||||||
|
|
||||||
def install_gift_confirm_guard(log=print, clock=time.monotonic):
|
def install_gift_confirm_guard(log=print, clock=time.monotonic):
|
||||||
"""「获得E.G.O饰品」确认点了不关时换落点, 再不行就结束任务。返回原 click_element, 未安装返回 None。
|
"""「获得E.G.O饰品」确认点了不关时换落点, 再不行就结束任务。返回原 click_element, 未安装返回 None。
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user