Skip to content

fix(ui): normalize ship selection matching and level filtering (copilot addressed v4)#441

Closed
yltx wants to merge 7 commits intomainfrom
fix/ship-selection-level-filter-clean-r5
Closed

fix(ui): normalize ship selection matching and level filtering (copilot addressed v4)#441
yltx wants to merge 7 commits intomainfrom
fix/ship-selection-level-filter-clean-r5

Conversation

@yltx
Copy link
Copy Markdown
Contributor

@yltx yltx commented Apr 14, 2026

Summary

What changed

  1. Treat lowercase i as OCR noise for level digits by adding it to regex capture sets and mapping i -> 1 in coercion.
  2. Update choose-ship docstring to reflect normalized name matching semantics.

Why

  • In captured OCR output, letters after Lv. are recognition artifacts and should be handled as OCR noise, not game data.
  • Keep docs consistent with actual matching behavior.

Files

  • autowsgr/ui/utils/ship_list.py
  • autowsgr/ui/choose_ship_page.py
  • autowsgr/init.py

Notes

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves ship selection robustness in the UI by making level OCR parsing more tolerant to common recognition noise and by aligning ship-name matching behavior with normalized name semantics, plus a patch version bump.

Changes:

  • Expand level parsing to tolerate OCR noise (e.g., i/I/l/o/O) and add a secondary “noisy Lv” regex path with bounded coercion.
  • In choose-ship clicking, compare normalized ship names (strip “·改” and trailing parenthesized aliases) and update docstring accordingly.
  • Bump package version to 2.1.9.post6.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
autowsgr/ui/utils/ship_list.py Adds noisy level regexes, digit coercion, and probing logic to improve level recognition robustness.
autowsgr/ui/choose_ship_page.py Normalizes ship-name matching semantics and adjusts level mapping to be keyed by normalized name.
autowsgr/init.py Version bump for the release containing the UI/OCR fixes.
Comments suppressed due to low confidence (1)

autowsgr/ui/choose_ship_page.py:425

  • _normalize_ship_name() 改变了 _click_ship_in_list() 的匹配语义(去除“·改”与尾部括号别名)。目前缺少单测来锁定该归一化规则(例如 "列克星敦(CV-2)" -> "列克星敦"、带中英文括号/前后空白等)。建议添加一个小的单元测试(可不依赖真实 OCR/设备)来覆盖这些输入输出,避免后续正则或字符串处理变更导致点击匹配回归。
    @staticmethod
    def _normalize_ship_name(name: str) -> str:
        normalized = name.strip()
        normalized = normalized.removesuffix('·改')
        normalized = _SHIP_ALIAS_SUFFIX_RE.sub('', normalized)
        return normalized.strip()


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

{
'I': '1',
'i': '1',
'l': '1',
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_LEVEL_PATTERN/_LEVEL_NOISY_PATTERN 的捕获组允许包含大写 L(常见把数字 1 识别为 L),但 _coerce_level_digits()trans 只映射了 I/i/l -> 1,未处理 L。这会导致像 Lv.L5 这样的输入在 translate 后变成 L5,最终只提取到 5 或直接返回 None,降低等级解析命中率。建议把 'L': '1' 也加入映射表以与正则允许字符保持一致。

Suggested change
'l': '1',
'l': '1',
'L': '1',

Copilot uses AI. Check for mistakes.
Comment on lines 172 to 188
def _parse_level(text: str) -> int | None:
"""从 OCR 文本中提取 ``Lv.XX`` 格式等级数字。"""
m = _LEVEL_PATTERN.search(text)
compact = text.strip().replace(' ', '')

m = _LEVEL_PATTERN.search(compact)
if m:
try:
return int(m.group(1))
except ValueError:
return None
level = _coerce_level_digits(m.group(1))
if level is not None:
return level

m2 = _LEVEL_NOISY_PATTERN.search(compact)
if m2:
level = _coerce_level_digits(m2.group(1))
if level is not None:
return level

return None
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

新增的等级解析/噪声矫正逻辑(_parse_level() + _coerce_level_digits(),包括 i -> 1、前 3 位截断、_LEVEL_NOISY_PATTERN 等)目前没有对应的单元测试覆盖;仓库里已有 testing/vision/test_ocr.py 这类 OCR 相关单测框架。建议补充一些纯字符串输入的单测用例,覆盖典型 OCR 噪声(如 Lv.i5Iv:O3Lv.051Lv.110544)以及超界值被拒绝的情况,避免后续调整 regex/映射时回归。

Copilot uses AI. Check for mistakes.
@yltx
Copy link
Copy Markdown
Contributor Author

yltx commented Apr 14, 2026

Superseded by #442 with bounded OCR fallback policy and retry threshold.

@yltx yltx closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants