chore: remove OCR archive, delete collect_ocr_failures, update docs
This commit is contained in:
1 parent
f2cd77ab0b
commit
9e08ed3bd0
18 files changed
+1516
-512
No files matched your search
+128
-56
@@ -259,24 +259,24 @@ class ProcRunner:
|
||||
|
||||
# --- 统一日志格式解析:提取traceId和MDC信息 ---
|
||||
# 格式:时间戳(毫秒) - [级别] - [线程名] - [模块名:函数名:行号] - [traceId:xxx] - 消息 | MDC: 上下文信息
|
||||
trace_id_match = re.search(r'\[traceId:([^\]]+)\]', s)
|
||||
trace_id_match = re.search(r"\[traceId:([^\]]+)\]", s)
|
||||
if trace_id_match:
|
||||
trace_id = trace_id_match.group(1)
|
||||
# 存储当前traceId(用于统计和显示)
|
||||
if not hasattr(self, '_current_trace_id'):
|
||||
if not hasattr(self, "_current_trace_id"):
|
||||
self._current_trace_id = trace_id
|
||||
elif trace_id != 'N/A':
|
||||
elif trace_id != "N/A":
|
||||
self._current_trace_id = trace_id
|
||||
|
||||
# 提取MDC信息
|
||||
mdc_match = re.search(r'MDC:\s*([^|]+)', s)
|
||||
mdc_match = re.search(r"MDC:\s*([^|]+)", s)
|
||||
if mdc_match:
|
||||
mdc_str = mdc_match.group(1).strip()
|
||||
# 解析MDC键值对
|
||||
mdc_pairs = re.findall(r'(\w+)=([^,\s]+)', mdc_str)
|
||||
mdc_pairs = re.findall(r"(\w+)=([^,\s]+)", mdc_str)
|
||||
for key, value in mdc_pairs:
|
||||
# 存储MDC信息(可用于统计)
|
||||
if not hasattr(self, '_mdc_context'):
|
||||
if not hasattr(self, "_mdc_context"):
|
||||
self._mdc_context = {}
|
||||
self._mdc_context[key] = value
|
||||
|
||||
@@ -284,7 +284,9 @@ class ProcRunner:
|
||||
# 支持多种格式:旧格式"福袋内容:"和新格式"字段_内容="或"内容="
|
||||
content_extracted = False
|
||||
if "福袋内容:" in s:
|
||||
self._fudai_last["content"] = s.split("福袋内容:", 1)[1].strip().split()[0] # 只取第一个词,避免包含后续字段
|
||||
self._fudai_last["content"] = (
|
||||
s.split("福袋内容:", 1)[1].strip().split()[0]
|
||||
) # 只取第一个词,避免包含后续字段
|
||||
self._fudai_last["updated_ts"] = time.time()
|
||||
content_extracted = True
|
||||
else:
|
||||
@@ -317,7 +319,9 @@ class ProcRunner:
|
||||
|
||||
# 倒计时:支持多种格式
|
||||
if "倒计时时间:" in s:
|
||||
self._fudai_last["countdown"] = s.split("倒计时时间:", 1)[1].strip().split()[0]
|
||||
self._fudai_last["countdown"] = (
|
||||
s.split("倒计时时间:", 1)[1].strip().split()[0]
|
||||
)
|
||||
self._fudai_last["updated_ts"] = time.time()
|
||||
else:
|
||||
m = re.search(r"(?:字段_)?倒计时[=:]?\s*([^\s]+)", s)
|
||||
@@ -326,7 +330,9 @@ class ProcRunner:
|
||||
self._fudai_last["updated_ts"] = time.time()
|
||||
|
||||
# 奖品价值:支持多种格式
|
||||
m = re.search(r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s)
|
||||
m = re.search(
|
||||
r"(?:字段_)?(?:价值|价值元|奖品价值)[=:]?\s*([0-9]+(?:\.[0-9]+)?)", s
|
||||
)
|
||||
if not m:
|
||||
m = re.search(r"奖品价值:\s*([0-9]+(?:\.[0-9]+)?)\s*元", s)
|
||||
if m:
|
||||
@@ -341,7 +347,9 @@ class ProcRunner:
|
||||
self._inc("fudai_open_detail")
|
||||
self._record_event("fudai_open_detail", self._snapshot_fudai())
|
||||
# 兼容新结构化中文日志: [参与] 动作=点击参与
|
||||
if "点击参与抽奖" in s or ("[参与]" in s and ("动作=点击参与" in s or "动作=参与" in s)):
|
||||
if "点击参与抽奖" in s or (
|
||||
"[参与]" in s and ("动作=点击参与" in s or "动作=参与" in s)
|
||||
):
|
||||
self._inc("fudai_click_attend")
|
||||
self._record_event("fudai_click_attend", self._snapshot_fudai())
|
||||
|
||||
@@ -350,7 +358,10 @@ class ProcRunner:
|
||||
"已经参与,等待开奖" in s
|
||||
or "已经参与,等待看播时间凑齐开奖" in s
|
||||
or "已参与成功(或看播中)" in s
|
||||
or ("[参与]" in s and ("结果=已参与" in s or "结果=看播中" in s or "结果=参与成功" in s))
|
||||
or (
|
||||
"[参与]" in s
|
||||
and ("结果=已参与" in s or "结果=看播中" in s or "结果=参与成功" in s)
|
||||
)
|
||||
or ("[参与]" in s and "已参与" in s and "等待开奖" in s)
|
||||
or ("预约回退后直接参与" in s and "参与成功" in s)
|
||||
):
|
||||
@@ -377,9 +388,7 @@ class ProcRunner:
|
||||
meta["threshold"] = int(m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
self._record_event(
|
||||
"fudai_skip", {"reason": "participants_low", **meta}
|
||||
)
|
||||
self._record_event("fudai_skip", {"reason": "participants_low", **meta})
|
||||
if "参与人数" in s and "> 阈值" in s and "不参与" in s:
|
||||
self._inc("fudai_skip_participants_high")
|
||||
# 提取实际参与人数和阈值
|
||||
@@ -396,9 +405,7 @@ class ProcRunner:
|
||||
meta["threshold"] = int(m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
self._record_event(
|
||||
"fudai_skip", {"reason": "participants_high", **meta}
|
||||
)
|
||||
self._record_event("fudai_skip", {"reason": "participants_high", **meta})
|
||||
if "奖品价值" in s and "< 阈值" in s and "不参与" in s:
|
||||
self._inc("fudai_skip_value_low")
|
||||
# 提取实际价值和阈值
|
||||
@@ -415,9 +422,7 @@ class ProcRunner:
|
||||
meta["threshold"] = float(m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
self._record_event(
|
||||
"fudai_skip", {"reason": "value_low", **meta}
|
||||
)
|
||||
self._record_event("fudai_skip", {"reason": "value_low", **meta})
|
||||
if "福袋内容不理想" in s or ("[筛选]" in s and "内容" in s and "黑名单" in s):
|
||||
self._inc("fudai_skip_content")
|
||||
self._record_event(
|
||||
@@ -433,9 +438,7 @@ class ProcRunner:
|
||||
meta["countdown_seconds"] = int(m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
self._record_event(
|
||||
"fudai_skip", {"reason": "countdown_short", **meta}
|
||||
)
|
||||
self._record_event("fudai_skip", {"reason": "countdown_short", **meta})
|
||||
if "抽奖倒计时时间大于" in s and "暂不参与" in s:
|
||||
self._inc("fudai_skip_countdown_long")
|
||||
# 提取倒计时秒数
|
||||
@@ -446,9 +449,7 @@ class ProcRunner:
|
||||
meta["countdown_seconds"] = int(m.group(1))
|
||||
except Exception:
|
||||
pass
|
||||
self._record_event(
|
||||
"fudai_skip", {"reason": "countdown_long", **meta}
|
||||
)
|
||||
self._record_event("fudai_skip", {"reason": "countdown_long", **meta})
|
||||
# 看播门槛:默认不参与(新结构化日志)
|
||||
if (
|
||||
"需要看播时长:默认不参与" in s
|
||||
@@ -466,7 +467,9 @@ class ProcRunner:
|
||||
self._inc("fudai_open_error_too_many")
|
||||
self._record_event("fudai_open_error_too_many", self._snapshot_fudai())
|
||||
# 倒计时大于阈值但价值达到高价值阈值,记录预约
|
||||
if ("[流程]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s) or ("[参与]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s):
|
||||
if (
|
||||
"[流程]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s
|
||||
) or ("[参与]" in s and "倒计时大于阈值,但价值达到高价值阈值,记录预约" in s):
|
||||
self._inc("fudai_reserved_high_value")
|
||||
# 提取价值和倒计时信息
|
||||
meta = self._snapshot_fudai()
|
||||
@@ -529,7 +532,9 @@ class ProcRunner:
|
||||
if "load_config" in s and ("失败" in s or "错误" in s or "异常" in s):
|
||||
self._inc("error_config_load")
|
||||
self._record_event("error_config_load", {})
|
||||
if ("预约队列状态文件" in s or "reservations.json" in s) and ("失败" in s or "错误" in s):
|
||||
if ("预约队列状态文件" in s or "reservations.json" in s) and (
|
||||
"失败" in s or "错误" in s
|
||||
):
|
||||
self._inc("error_state_file")
|
||||
self._record_event("error_state_file", {})
|
||||
if "直播间检测" in s and ("失败" in s or "错误" in s):
|
||||
@@ -569,7 +574,9 @@ class ProcRunner:
|
||||
self._record_event("reservation_clear", {})
|
||||
|
||||
# --- 预约记录相关(与 gui_core.py 保持一致) ---
|
||||
if ("[预约]" in s and "已记录高价值福袋" in s) or "record_high_value_reservation:已记录高价值福袋" in s:
|
||||
if (
|
||||
"[预约]" in s and "已记录高价值福袋" in s
|
||||
) or "record_high_value_reservation:已记录高价值福袋" in s:
|
||||
self._inc("reservation_recorded")
|
||||
# 提取预约价值:支持多种格式
|
||||
value = None
|
||||
@@ -591,7 +598,9 @@ class ProcRunner:
|
||||
pass
|
||||
# 提取直播间名称
|
||||
room_title = None
|
||||
m = re.search(r"(?:字段_)?(?:直播间|直播间名|room_title)[=:]?\s*([^\s]+)", s)
|
||||
m = re.search(
|
||||
r"(?:字段_)?(?:直播间|直播间名|room_title)[=:]?\s*([^\s]+)", s
|
||||
)
|
||||
if m:
|
||||
room_title = m.group(1).strip()
|
||||
meta = self._snapshot_fudai()
|
||||
@@ -602,10 +611,16 @@ class ProcRunner:
|
||||
if room_title:
|
||||
meta["room_title"] = room_title
|
||||
self._record_event("reservation_recorded", meta)
|
||||
if ("[预约]" in s and "进入预约参与窗口" in s) or "进入预约参与窗口,准备回退到目标直播间" in s:
|
||||
if (
|
||||
"[预约]" in s and "进入预约参与窗口" in s
|
||||
) or "进入预约参与窗口,准备回退到目标直播间" in s:
|
||||
self._inc("reservation_window_entered")
|
||||
self._record_event("reservation_window_entered", {})
|
||||
if ("[预约]" in s and "已回退到目标直播间" in s) or "已回退到目标直播间" in s or ("[预约]" in s and "已回退到最早开奖的预约直播间" in s):
|
||||
if (
|
||||
("[预约]" in s and "已回退到目标直播间" in s)
|
||||
or "已回退到目标直播间" in s
|
||||
or ("[预约]" in s and "已回退到最早开奖的预约直播间" in s)
|
||||
):
|
||||
self._inc("reservation_back_success")
|
||||
# 提取回退信息
|
||||
meta = {}
|
||||
@@ -619,20 +634,28 @@ class ProcRunner:
|
||||
if ("[预约]" in s and "时间窗口未到" in s) or "时间窗口未到,跳过回退" in s:
|
||||
self._inc("reservation_window_not_reached")
|
||||
self._record_event("reservation_window_not_reached", {})
|
||||
if ("[预约]" in s and "已明显错过开奖时间" in s) or "已明显错过开奖时间,清理过期预约" in s:
|
||||
if (
|
||||
"[预约]" in s and "已明显错过开奖时间" in s
|
||||
) or "已明显错过开奖时间,清理过期预约" in s:
|
||||
self._inc("reservation_expired")
|
||||
self._record_event("reservation_expired", {})
|
||||
if ("[预约]" in s and "预约队列为空" in s) or "process_reservation_attend_window:预约队列为空" in s:
|
||||
if (
|
||||
"[预约]" in s and "预约队列为空" in s
|
||||
) or "process_reservation_attend_window:预约队列为空" in s:
|
||||
self._inc("reservation_queue_empty")
|
||||
if ("[预约]" in s and "锁定期未结束" in s) or "锁定期未结束" in s:
|
||||
self._inc("reservation_locked")
|
||||
self._record_event("reservation_locked", {})
|
||||
if ("[预约]" in s and "已回退到第一个直播间" in s):
|
||||
if "[预约]" in s and "已回退到第一个直播间" in s:
|
||||
self._inc("reservation_back_to_first")
|
||||
self._record_event("reservation_back_to_first", {})
|
||||
if ("[预约]" in s and "run_once_basic:检查预约回退触发条件" in s):
|
||||
if "[预约]" in s and "run_once_basic:检查预约回退触发条件" in s:
|
||||
self._inc("reservation_check_triggered")
|
||||
if ("[预约]" in s and "队列已满" in s) or "handle_queue_full_wait_at_earliest" in s or ("[预约]" in s and "队列已满,回退到最早开奖的预约直播间" in s):
|
||||
if (
|
||||
("[预约]" in s and "队列已满" in s)
|
||||
or "handle_queue_full_wait_at_earliest" in s
|
||||
or ("[预约]" in s and "队列已满,回退到最早开奖的预约直播间" in s)
|
||||
):
|
||||
self._inc("reservation_queue_full_wait")
|
||||
self._record_event("reservation_queue_full_wait", {})
|
||||
# 回退后直接参与
|
||||
@@ -640,11 +663,11 @@ class ProcRunner:
|
||||
self._inc("reservation_back_direct_attend")
|
||||
self._record_event("reservation_back_direct_attend", {})
|
||||
# 队列满回退后设置参与标志
|
||||
if ("[预约]" in s and "队列满回退后,直接设置参与标志" in s):
|
||||
if "[预约]" in s and "队列满回退后,直接设置参与标志" in s:
|
||||
self._inc("reservation_queue_full_back_attend")
|
||||
self._record_event("reservation_queue_full_back_attend", {})
|
||||
# 通过相似度匹配识别重复预约
|
||||
if ("[预约]" in s and "通过相似度匹配识别为重复预约" in s):
|
||||
if "[预约]" in s and "通过相似度匹配识别为重复预约" in s:
|
||||
self._inc("reservation_duplicate_detected")
|
||||
self._record_event("reservation_duplicate_detected", {})
|
||||
|
||||
@@ -652,7 +675,11 @@ class ProcRunner:
|
||||
if "没有抽中" in s and "关闭弹窗" in s:
|
||||
self._inc("fudai_result_no_win")
|
||||
self._record_event("fudai_result_no_win", self._snapshot_fudai())
|
||||
if "恭喜中奖了" in s or "检测到中奖结果" in s or ("[开奖结果]" in s and "中奖" in s):
|
||||
if (
|
||||
"恭喜中奖了" in s
|
||||
or "检测到中奖结果" in s
|
||||
or ("[开奖结果]" in s and "中奖" in s)
|
||||
):
|
||||
self._inc("fudai_result_win")
|
||||
# 提取中奖信息
|
||||
meta = self._snapshot_fudai()
|
||||
@@ -666,7 +693,9 @@ class ProcRunner:
|
||||
self._record_event("fudai_order_success", self._snapshot_fudai())
|
||||
# 等待开奖(只在设置等待开奖标志时计数,避免重复计数)
|
||||
# 注意:不要匹配"已经参与,等待开奖",因为那已经在参与成功时计数了
|
||||
if ("[参与]" in s and "参与成功,设置等待开奖标志" in s) or ("[参与]" in s and "设置等待开奖标志" in s):
|
||||
if ("[参与]" in s and "参与成功,设置等待开奖标志" in s) or (
|
||||
"[参与]" in s and "设置等待开奖标志" in s
|
||||
):
|
||||
self._inc("fudai_waiting_lottery")
|
||||
# 提取剩余秒数
|
||||
meta = self._snapshot_fudai()
|
||||
@@ -752,14 +781,21 @@ class ProcRunner:
|
||||
# 记录耗时较长的操作
|
||||
if elapsed > 5.0:
|
||||
self._inc("slow_operation")
|
||||
self._record_event("slow_operation", {"elapsed_seconds": elapsed, "operation": s[:100]})
|
||||
self._record_event(
|
||||
"slow_operation",
|
||||
{"elapsed_seconds": elapsed, "operation": s[:100]},
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# --- 详情识别统计 ---
|
||||
if ("[福袋详情]" in s and "识别" in s) or "识别福袋详情" in s:
|
||||
self._inc("fudai_detail_read_attempt")
|
||||
if "识别成功" in s or "识别完成" in s or "read_fudai_detail_once完成(成功)" in s:
|
||||
if (
|
||||
"识别成功" in s
|
||||
or "识别完成" in s
|
||||
or "read_fudai_detail_once完成(成功)" in s
|
||||
):
|
||||
self._inc("fudai_detail_read_success")
|
||||
# 提取任务数量
|
||||
meta = {}
|
||||
@@ -829,7 +865,16 @@ class ProcRunner:
|
||||
try:
|
||||
path = path_config.get_reservations_path()
|
||||
except Exception:
|
||||
path = os.path.join(path_config.PROJECT_ROOT if hasattr(path_config, "PROJECT_ROOT") else os.getcwd(), "douyin", "state", "reservations.json")
|
||||
path = os.path.join(
|
||||
(
|
||||
path_config.PROJECT_ROOT
|
||||
if hasattr(path_config, "PROJECT_ROOT")
|
||||
else os.getcwd()
|
||||
),
|
||||
"douyin",
|
||||
"state",
|
||||
"reservations.json",
|
||||
)
|
||||
else:
|
||||
path = os.path.join(os.getcwd(), "douyin", "state", "reservations.json")
|
||||
try:
|
||||
@@ -1012,7 +1057,9 @@ class ProcRunner:
|
||||
if isinstance(cd, str) and cd.strip():
|
||||
sec = self._parse_countdown_seconds(cd)
|
||||
if isinstance(sec, int):
|
||||
b = self._bucket(float(sec), [float(e) for e in countdown_edges])
|
||||
b = self._bucket(
|
||||
float(sec), [float(e) for e in countdown_edges]
|
||||
)
|
||||
self._inc_map(countdown_buckets, b, 1)
|
||||
|
||||
def _top_k(m: dict, k: int = 10) -> list[dict]:
|
||||
@@ -1280,7 +1327,9 @@ class ProcRunner:
|
||||
cmd.append("--disable-ocr-mode1")
|
||||
|
||||
# 福袋模板匹配开关(命令行优先)
|
||||
fudai_template_match_enabled = bool(_pick("fudai_template_match_enabled", False))
|
||||
fudai_template_match_enabled = bool(
|
||||
_pick("fudai_template_match_enabled", False)
|
||||
)
|
||||
if fudai_template_match_enabled:
|
||||
cmd.append("--fudai-template-enabled")
|
||||
else:
|
||||
@@ -1288,9 +1337,14 @@ class ProcRunner:
|
||||
|
||||
# 福袋模板匹配阈值(命令行优先)
|
||||
try:
|
||||
fudai_template_match_threshold = float(_pick("fudai_template_match_threshold", 0.7) or 0.7)
|
||||
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)]
|
||||
cmd += [
|
||||
"--fudai-template-threshold",
|
||||
str(fudai_template_match_threshold),
|
||||
]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -1438,7 +1492,10 @@ class Handler(BaseHTTPRequestHandler):
|
||||
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:
|
||||
if (
|
||||
not full_real.startswith(webui_real + os.sep)
|
||||
and full_real != webui_real
|
||||
):
|
||||
self.send_error(HTTPStatus.FORBIDDEN)
|
||||
return
|
||||
except Exception:
|
||||
@@ -1463,7 +1520,9 @@ class Handler(BaseHTTPRequestHandler):
|
||||
with open(full, "rb") as f:
|
||||
data = f.read()
|
||||
# 对于静态资源,使用适当的缓存策略
|
||||
cache_control = "no-store" if ext in (".html", ".js") else "public, max-age=3600"
|
||||
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)))
|
||||
@@ -1583,7 +1642,15 @@ class Handler(BaseHTTPRequestHandler):
|
||||
try:
|
||||
path = path_config.get_actions_log_path()
|
||||
except Exception:
|
||||
path = os.path.join(path_config.PROJECT_ROOT if hasattr(path_config, "PROJECT_ROOT") else os.getcwd(), "logs", "actions.log")
|
||||
path = os.path.join(
|
||||
(
|
||||
path_config.PROJECT_ROOT
|
||||
if hasattr(path_config, "PROJECT_ROOT")
|
||||
else os.getcwd()
|
||||
),
|
||||
"logs",
|
||||
"actions.log",
|
||||
)
|
||||
else:
|
||||
path = os.path.join(os.getcwd(), "logs", "actions.log")
|
||||
out_lines: list[str] = []
|
||||
@@ -1701,6 +1768,7 @@ class Handler(BaseHTTPRequestHandler):
|
||||
"fudai_template_match_enabled",
|
||||
"fudai_quiet_hours_enabled",
|
||||
"high_value_fudai_enabled",
|
||||
"fudai_disable_content_recognition",
|
||||
"high_value_room_revisit_enabled",
|
||||
"high_value_room_revisit_only_current_run",
|
||||
"reservation_back_verify_enabled",
|
||||
@@ -1760,11 +1828,15 @@ class Handler(BaseHTTPRequestHandler):
|
||||
if isinstance(v, list):
|
||||
set_nested_value(cfg, k, [str(x) for x in v if str(x).strip()])
|
||||
else:
|
||||
set_nested_value(cfg, k, [
|
||||
str(x).strip()
|
||||
for x in str(v).splitlines()
|
||||
if str(x).strip()
|
||||
])
|
||||
set_nested_value(
|
||||
cfg,
|
||||
k,
|
||||
[
|
||||
str(x).strip()
|
||||
for x in str(v).splitlines()
|
||||
if str(x).strip()
|
||||
],
|
||||
)
|
||||
else:
|
||||
set_nested_value(cfg, k, v)
|
||||
|
||||
|
||||
Reference in new issue
Block a user