feat: Enhance 福袋 template matching functionality

- Introduced a new configuration option to enable or disable 福袋 template matching, improving user control over the feature.
- Updated command-line arguments to support enabling and disabling the 福袋 template matching feature.
- Enhanced the GUI to include options for configuring 福袋 template matching settings.
- Improved error handling and logging in various modules to support the new functionality.
- Updated documentation to reflect changes in 福袋 template matching features and configuration options.
This commit is contained in:
Your Name committed 2025-12-22 04:05:22 +08:00
1 parent 533943620c
commit fe0098c591
18 files changed
+7263 -107

No files matched your search

+1
View File
@@ -110,3 +110,4 @@ python cleanup_unused_files.py
+1
View File
@@ -208,3 +208,4 @@ YYYYMMDD_HHMMSS_操作类型_图片名_步骤_坐标_额外信息.png
+1
View File
@@ -179,3 +179,4 @@ python check_dependencies.py
+1
View File
@@ -158,3 +158,4 @@ douyin_guaji
+1
View File
@@ -99,3 +99,4 @@
+1
View File
@@ -311,3 +311,4 @@ douyin_fudai_finder.py
+1
View File
@@ -69,3 +69,4 @@ python 生成WPS流程图.py
+1
View File
@@ -83,3 +83,4 @@ else:
+8
View File
@@ -113,6 +113,8 @@ class fudai_analyse:
# 直播间检测阈值(模板匹配阈值,0.0~1.0,默认0.8)
self.live_room_match_threshold: float = 0.8
# 福袋模板匹配开关(默认关闭)
self.fudai_template_match_enabled: bool = False
# 福袋模板匹配阈值(0.0~1.0,默认0.7)
self.fudai_template_match_threshold: float = 0.7
@@ -274,6 +276,12 @@ class fudai_analyse:
if self.live_room_match_threshold > 1.0:
self.live_room_match_threshold = 1.0
try:
self.fudai_template_match_enabled = bool(
config.get("fudai_template_match_enabled", self.fudai_template_match_enabled)
)
except Exception:
pass
self.fudai_template_match_threshold = _float(
"fudai_template_match_threshold",
self.fudai_template_match_threshold,
+40 -11
View File
@@ -99,8 +99,8 @@ def main():
left_wrap = ttk.Frame(mid)
right = ttk.Frame(mid)
mid.add(left_wrap, weight=0, minsize=450) # 设置最小宽度
mid.add(right, weight=1)
mid.add(left_wrap, weight=0) # 左侧配置区域
mid.add(right, weight=1) # 右侧日志/预览区域
# 左侧使用Notebook标签页组织配置
left_notebook = ttk.Notebook(left_wrap)
@@ -1320,9 +1320,11 @@ def main():
except Exception:
pass
# 右侧:操作按钮区域(先创建,放在底部)
actions = ttk.Frame(right)
# 右侧:Notebook(日志 / 截图预览 / 统计信息 / 预约队列 / 高价值房间)
notebook = ttk.Notebook(right)
notebook.pack(fill=BOTH, expand=True)
log_tab = ttk.Frame(notebook)
preview_tab = ttk.Frame(notebook)
@@ -1438,17 +1440,29 @@ def main():
img = Image.open(img_path)
img.load() # Force load to catch truncated files early
img = img.convert("RGB")
except (OSError, IOError, SyntaxError):
except (OSError, IOError, SyntaxError) as e:
# Handle truncated image files
preview_status.set(f"图片加载失败:{str(e)[:50]}")
image_label.configure(image="")
_img_ref["photo"] = None
return
except Exception as e:
preview_status.set(f"图片加载错误:{str(e)[:50]}")
image_label.configure(image="")
_img_ref["photo"] = None
return
# 获取预览区域的实际尺寸(如果窗口还未初始化,使用默认值)
try:
preview_body.update_idletasks() # 强制更新布局
w = preview_body.winfo_width()
h = preview_body.winfo_height()
# 如果尺寸无效(窗口未初始化),使用默认值
if w <= 1 or h <= 1:
w, h = 900, 520
except Exception:
image_label.configure(image="")
_img_ref["photo"] = None
return
w = preview_body.winfo_width() or 900
h = preview_body.winfo_height() or 520
w, h = 900, 520
max_w = max(300, w - 20)
max_h = max(200, h - 20)
try:
@@ -1467,6 +1481,17 @@ def main():
command=lambda: update_image_list(refresh_after=True),
).pack(side=LEFT, padx=(0, 5))
ttk.Button(preview_top, text="刷新预览", command=refresh_preview).pack(side=LEFT)
# 绑定选择变化事件,自动刷新预览(在 refresh_preview 函数定义之后)
def on_image_selected(*args):
"""当用户选择图片时自动刷新预览"""
try:
refresh_preview()
except Exception:
pass # 忽略错误,避免影响其他功能
image_var.trace("w", on_image_selected) # 监听变量变化
image_combo.bind("<<ComboboxSelected>>", lambda e: refresh_preview()) # 监听下拉选择
def open_pic_folder():
try:
@@ -1517,6 +1542,7 @@ def main():
reservation_preempt_min_value_var.get() or 0
),
fudai_find_max_attempts=int(fudai_find_max_attempts_var.get() or 0),
fudai_template_match_enabled=bool(fudai_template_match_enabled_var.get()),
fudai_template_match_threshold=float(
fudai_template_match_threshold_var.get() or 0.7
),
@@ -1549,8 +1575,11 @@ def main():
runner.stop()
status_var.set("已停止")
actions = ttk.Frame(right)
actions.pack(fill=X, pady=(10, 0))
# 先打包 actions 到底部(不 expand,固定在底部)
actions.pack(fill=X, pady=(10, 0), padx=12)
# 然后打包 notebook 填充剩余空间(在 actions 之上)
notebook.pack(fill=BOTH, expand=True)
ttk.Button(actions, text="开始运行", command=start_run).pack(side=LEFT, padx=(0, 8))
ttk.Button(actions, text="停止", command=stop_run).pack(side=LEFT, padx=(0, 4))
+7
View File
@@ -90,6 +90,7 @@ class RunParams:
reservation_preempt_min_value: float
fudai_find_max_attempts: int
enable_ocr_mode1: bool
fudai_template_match_enabled: bool
fudai_template_match_threshold: float
@@ -410,6 +411,12 @@ class Runner:
else:
cmd.append("--disable-ocr-mode1")
# 福袋模板匹配开关
if params.fudai_template_match_enabled:
cmd.append("--fudai-template-enabled")
else:
cmd.append("--fudai-template-disabled")
# 添加福袋模板匹配阈值参数
cmd.extend(["--fudai-template-threshold", str(params.fudai_template_match_threshold)])
+1
View File
@@ -40,3 +40,4 @@ paddlepaddle>=2.5.0,<3.0.0
+1
View File
@@ -56,3 +56,4 @@ ttkbootstrap>=1.10.0
+15
View File
@@ -229,6 +229,16 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
default=None,
help="福袋模板匹配阈值(0.0-1.0,默认0.7)",
)
p.add_argument(
"--fudai-template-enabled",
action="store_true",
help="启用福袋模板匹配(默认关闭)",
)
p.add_argument(
"--fudai-template-disabled",
action="store_true",
help="禁用福袋模板匹配(默认已禁用)",
)
return p.parse_args(argv)
@@ -410,6 +420,11 @@ def main(argv: list[str]) -> int:
setattr(analyser, "enable_ocr_mode1", True)
if getattr(args, "disable_ocr_mode1", False):
setattr(analyser, "enable_ocr_mode1", False)
# 福袋模板匹配开关(命令行优先)
if getattr(args, "fudai_template_enabled", False):
setattr(analyser, "fudai_template_match_enabled", True)
if getattr(args, "fudai_template_disabled", False):
setattr(analyser, "fudai_template_match_enabled", False)
# 福袋模板匹配阈值(命令行优先)
if getattr(args, "fudai_template_threshold", None) is not None:
try:
+87 -9
View File
@@ -897,6 +897,28 @@ class ProcRunner:
fudai_find_max_attempts = 0
if fudai_find_max_attempts > 0:
cmd += ["--fudai-find-max-attempts", str(fudai_find_max_attempts)]
# OCR模式1开关(命令行优先)
enable_ocr_mode1 = bool(_pick("enable_ocr_mode1", False))
if enable_ocr_mode1:
cmd.append("--enable-ocr-mode1")
else:
cmd.append("--disable-ocr-mode1")
# 福袋模板匹配开关(命令行优先)
fudai_template_match_enabled = bool(_pick("fudai_template_match_enabled", False))
if fudai_template_match_enabled:
cmd.append("--fudai-template-enabled")
else:
cmd.append("--fudai-template-disabled")
# 福袋模板匹配阈值(命令行优先)
try:
fudai_template_match_threshold = float(_pick("fudai_template_match_threshold", 0.7) or 0.7)
if 0.0 <= fudai_template_match_threshold <= 1.0:
cmd += ["--fudai-template-threshold", str(fudai_template_match_threshold)]
except Exception:
pass
self._start_process(cmd)
@@ -1033,10 +1055,21 @@ class Handler(BaseHTTPRequestHandler):
if not rel_path:
rel_path = "index.html"
safe = os.path.normpath(rel_path).replace("\\", "/")
if safe.startswith("../") or safe.startswith("..\\"):
# 安全检查:防止路径遍历攻击
if safe.startswith("../") or safe.startswith("..\\") or ".." in safe:
self.send_error(HTTPStatus.FORBIDDEN)
return
full = os.path.join(WEBUI_DIR, safe)
# 额外安全检查:确保文件在 WEBUI_DIR 目录内
try:
full_real = os.path.realpath(full)
webui_real = os.path.realpath(WEBUI_DIR)
if not full_real.startswith(webui_real + os.sep) and full_real != webui_real:
self.send_error(HTTPStatus.FORBIDDEN)
return
except Exception:
self.send_error(HTTPStatus.FORBIDDEN)
return
if not os.path.isfile(full):
self.send_error(HTTPStatus.NOT_FOUND)
return
@@ -1052,14 +1085,35 @@ class Handler(BaseHTTPRequestHandler):
".svg": "image/svg+xml; charset=utf-8",
}.get(ext, "application/octet-stream")
with open(full, "rb") as f:
data = f.read()
self.send_response(HTTPStatus.OK)
self.send_header("Content-Type", ctype)
self.send_header("Content-Length", str(len(data)))
self.send_header("Cache-Control", "no-store")
self.end_headers()
self.wfile.write(data)
try:
with open(full, "rb") as f:
data = f.read()
# 对于静态资源,使用适当的缓存策略
cache_control = "no-store" if ext in (".html", ".js") else "public, max-age=3600"
self.send_response(HTTPStatus.OK)
self.send_header("Content-Type", ctype)
self.send_header("Content-Length", str(len(data)))
self.send_header("Cache-Control", cache_control)
# 添加 ETag 支持(简单实现:基于文件大小和修改时间)
try:
stat = os.stat(full)
etag = f'"{stat.st_size}-{int(stat.st_mtime)}"'
self.send_header("ETag", etag)
# 检查 If-None-Match 头,支持 304 Not Modified
if_none_match = self.headers.get("If-None-Match", "")
if if_none_match == etag:
self.send_response(HTTPStatus.NOT_MODIFIED)
self.end_headers()
return
except Exception:
pass
self.end_headers()
self.wfile.write(data)
except FileNotFoundError:
self.send_error(HTTPStatus.NOT_FOUND)
except Exception as e:
print(f"[WEB_GUI] Error serving static file {rel_path}: {e}")
self.send_error(HTTPStatus.INTERNAL_SERVER_ERROR)
def do_GET(self):
u = urlparse(self.path)
@@ -1210,7 +1264,14 @@ class Handler(BaseHTTPRequestHandler):
"min_participants",
"max_participants",
"skip_if_countdown_lt_seconds",
"skip_if_countdown_gt_seconds",
"reset_after_swipes",
"fudai_find_max_attempts",
"fudai_quiet_start_hour",
"fudai_quiet_end_hour",
"high_value_fudai_join_ahead_seconds",
"high_value_fudai_max_swipe_back",
"high_value_fudai_max_reservations",
"yanghao_like_icon_x",
"yanghao_like_icon_y",
"yanghao_fav_icon_x",
@@ -1238,6 +1299,16 @@ class Handler(BaseHTTPRequestHandler):
"yanghao_fav_prob",
"yanghao_comment_prob",
"yanghao_icon_match_threshold",
"fudai_template_match_threshold",
"lucky_draw_red_ratio_threshold",
"live_room_match_threshold",
"stage_diag_max_time",
"stage_diag_max_step_time",
"fudai_icon_retry_delay_seconds",
"fudai_icon_max_wait_seconds",
"reservation_back_swipe_delay",
"reservation_preempt_min_value",
"high_value_fudai_threshold_yuan",
}
bool_keys = {
"auto_join_fansclub",
@@ -1245,6 +1316,13 @@ class Handler(BaseHTTPRequestHandler):
"yanghao_enable_actions",
"yanghao_enabled",
"yanghao_step_screenshot",
"enable_ocr_mode1",
"fudai_template_match_enabled",
"fudai_quiet_hours_enabled",
"high_value_fudai_enabled",
"high_value_room_revisit_enabled",
"high_value_room_revisit_only_current_run",
"reservation_back_verify_enabled",
}
list_str_keys = {
"contains_want",
+1
View File
@@ -84,3 +84,4 @@
+1
View File
@@ -156,3 +156,4 @@ if __name__ == "__main__":