Skip to content

Commit cfa4425

Browse files
committed
fix: 修复 loot 数量识别错误的 bug
1 parent a8d176a commit cfa4425

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

autowsgr/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""AutoWSGR — 战舰少女R 自动化框架 (v2)"""
22

3-
__version__ = '2.1.5.post1'
3+
__version__ = '2.1.5.post2'

autowsgr/ui/map/panels/sortie.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,26 @@ class LootShipCount:
6666
_FRACTION_RE = re.compile(r'(\d+)\s*[/|]\s*(\d+)')
6767
"""匹配 "X/Y" 格式的正则 (兼容 OCR 把 / 识别为 | 的情况)。"""
6868

69+
_KNOWN_DENOMS = (500, 50)
70+
"""已知分母值, 用于 OCR 将 ``/`` 误识为 ``1`` 时的回退解析 (长的优先匹配)。"""
71+
6972

7073
def _parse_fraction(text: str) -> tuple[int, int] | None:
7174
"""解析 ``"123/500"`` 格式文本, 返回 ``(numerator, denominator)``。"""
7275
m = _FRACTION_RE.search(text)
7376
if m:
7477
return int(m.group(1)), int(m.group(2))
78+
79+
# 回退: OCR 有时将 '/' 误识为 '1', 导致纯数字串如 "17150" (实为 "17/50")。
80+
# 尝试去掉已知分母前的多余 '1' 来还原。
81+
digits = ''.join(c for c in text if c.isdigit())
82+
if digits:
83+
for denom in _KNOWN_DENOMS:
84+
suffix = '1' + str(denom)
85+
if digits.endswith(suffix) and len(digits) > len(suffix):
86+
numerator = int(digits[: -len(suffix)])
87+
if numerator >= 0 and numerator <= denom:
88+
return numerator, denom
7589
return None
7690

7791

0 commit comments

Comments
 (0)