fix: 修正规格摘要误判颜色标题 (#277)
This commit is contained in:
@@ -172,23 +172,29 @@ def _screen_bounds(root: ET.Element) -> Optional[Bounds]:
|
|||||||
return 0, 0, max(item[2] for item in bounds), max(item[3] for item in bounds)
|
return 0, 0, max(item[2] for item in bounds), max(item[3] for item in bounds)
|
||||||
|
|
||||||
|
|
||||||
|
def _spec_heading_name(value: str) -> str:
|
||||||
|
"""返回独立规格标题,排除“请选择”“选择后”等摘要和提示。"""
|
||||||
|
|
||||||
|
compact = re.sub(r"\s+", "", str(value or ""))
|
||||||
|
compact = re.sub(r"[((]\d+[))]$", "", compact)
|
||||||
|
supported = _COLOR_HEADINGS + _PACKAGE_HEADINGS
|
||||||
|
return compact if compact in supported else ""
|
||||||
|
|
||||||
|
|
||||||
def _heading_bounds(root: ET.Element) -> Optional[Bounds]:
|
def _heading_bounds(root: ET.Element) -> Optional[Bounds]:
|
||||||
fuzzy_match: Optional[Bounds] = None
|
fuzzy_match: Optional[Bounds] = None
|
||||||
package_fallback: Optional[Bounds] = None
|
package_fallback: Optional[Bounds] = None
|
||||||
for node in root.iter("node"):
|
for node in root.iter("node"):
|
||||||
text = node.get("text", "").strip()
|
heading = _spec_heading_name(node.get("text", ""))
|
||||||
bounds = _parse_bounds(node.get("bounds", ""))
|
bounds = _parse_bounds(node.get("bounds", ""))
|
||||||
if bounds is None or not _is_available(node):
|
if not heading or bounds is None or not _is_available(node):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# “请选择:颜色分类 尺码”等摘要不能当成颜色列表标题。
|
if heading == "颜色分类":
|
||||||
if text == "颜色分类":
|
|
||||||
return bounds
|
return bounds
|
||||||
if fuzzy_match is None and any(heading in text for heading in _COLOR_HEADINGS):
|
if fuzzy_match is None and heading in _COLOR_HEADINGS:
|
||||||
fuzzy_match = bounds
|
fuzzy_match = bounds
|
||||||
if package_fallback is None and any(
|
if package_fallback is None and heading in _PACKAGE_HEADINGS:
|
||||||
heading in text for heading in _PACKAGE_HEADINGS
|
|
||||||
):
|
|
||||||
package_fallback = bounds
|
package_fallback = bounds
|
||||||
# “款式 + 套餐”优先定位款式;只有套餐一个维度时才用套餐兜底。
|
# “款式 + 套餐”优先定位款式;只有套餐一个维度时才用套餐兜底。
|
||||||
return fuzzy_match or package_fallback
|
return fuzzy_match or package_fallback
|
||||||
|
|||||||
@@ -263,6 +263,50 @@ class StaticColorSelectionTest(unittest.TestCase):
|
|||||||
self.assertTrue(selected)
|
self.assertTrue(selected)
|
||||||
self.assertEqual(device.clicks, [(194, 1389)])
|
self.assertEqual(device.clicks, [(194, 1389)])
|
||||||
|
|
||||||
|
def test_summary_is_ignored_and_counted_color_heading_is_used(self):
|
||||||
|
simplified = "紫色诱惑"
|
||||||
|
traditional = "紫色誘惑"
|
||||||
|
panel_xml = f'''<hierarchy>
|
||||||
|
<node bounds="[0,0][1080,2376]">
|
||||||
|
<node text="请选择:颜色" bounds="[396,827][1053,889]" />
|
||||||
|
<node text="选择款式后查看优惠" bounds="[639,1083][1044,1136]" />
|
||||||
|
<node text="尺码" bounds="[36,1202][126,1255]" />
|
||||||
|
<node text="颜色 (4)" bounds="[36,1416][198,1469]" />
|
||||||
|
<node bounds="[36,1495][1044,1695]">
|
||||||
|
<node text="{simplified}" clickable="true"
|
||||||
|
bounds="[36,1495][249,1580]" />
|
||||||
|
<node text="其他颜色" clickable="true"
|
||||||
|
bounds="[270,1495][483,1580]" />
|
||||||
|
</node>
|
||||||
|
</node>
|
||||||
|
</hierarchy>'''
|
||||||
|
device = StaticColorDevice(panel_xml, selected_text=simplified)
|
||||||
|
|
||||||
|
selected = select_color(
|
||||||
|
device,
|
||||||
|
panel_xml,
|
||||||
|
traditional,
|
||||||
|
action_delay=0.001,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(selected)
|
||||||
|
self.assertEqual(device.clicks, [(142, 1537)])
|
||||||
|
self.assertEqual(device.swipes, [])
|
||||||
|
|
||||||
|
def test_chinese_parentheses_count_is_a_color_heading(self):
|
||||||
|
panel_xml = self.panel_xml.replace("颜色分类", "颜色(4)")
|
||||||
|
device = StaticColorDevice(panel_xml)
|
||||||
|
|
||||||
|
selected = select_color(
|
||||||
|
device,
|
||||||
|
panel_xml,
|
||||||
|
"测试黑色",
|
||||||
|
action_delay=0.001,
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(selected)
|
||||||
|
self.assertEqual(device.clicks, [(194, 1389)])
|
||||||
|
|
||||||
def test_non_scrollable_row_ignores_same_row_style_option_as_heading(self):
|
def test_non_scrollable_row_ignores_same_row_style_option_as_heading(self):
|
||||||
simplified = "纯欲莹白【透.视蕾丝衣.免脱款】"
|
simplified = "纯欲莹白【透.视蕾丝衣.免脱款】"
|
||||||
traditional = "純欲瑩白【透.視蕾絲衣.免脫款】"
|
traditional = "純欲瑩白【透.視蕾絲衣.免脫款】"
|
||||||
|
|||||||
Reference in New Issue
Block a user