feat: add is_format_matched method and improve regex for result formatting

This commit is contained in:
2026-07-05 17:51:46 +08:00
parent af3e178c88
commit 84ac3dc9b8
+5 -1
View File
@@ -350,6 +350,10 @@ class DigitCounter(Ocr):
def __init__(self, button: ButtonWrapper, lang='en', name=None): def __init__(self, button: ButtonWrapper, lang='en', name=None):
super().__init__(button, lang=lang, name=name) super().__init__(button, lang=lang, name=name)
@classmethod
def is_format_matched(cls, result) -> bool:
return '/' in result
def format_result(self, result) -> tuple[int, int, int]: def format_result(self, result) -> tuple[int, int, int]:
""" """
Do OCR on a counter, such as `14/15`, and returns 14, 1, 15 Do OCR on a counter, such as `14/15`, and returns 14, 1, 15
@@ -360,7 +364,7 @@ class DigitCounter(Ocr):
result = super().after_process(result) result = super().after_process(result)
logger.attr(name=self.name, text=str(result)) logger.attr(name=self.name, text=str(result))
res = re.search(r'(\d+)/(\d+)', result) res = re.search(r'(\d+)\s*/\s*(\d+)', result)
if res: if res:
groups = [int(s) for s in res.groups()] groups = [int(s) for s in res.groups()]
current, total = int(groups[0]), int(groups[1]) current, total = int(groups[0]), int(groups[1])