feat: 优化代码格式,提升可读性和一致性
This commit is contained in:
1 parent
b940c91e2e
commit
54a99d4bbd
4 files changed
+502
-240
No files matched your search
+5
-5
@@ -5,10 +5,10 @@
|
||||
"min_prize_value_yuan": 300.0,
|
||||
"min_participants": 0,
|
||||
"max_participants": 0,
|
||||
"skip_if_countdown_gt_seconds": 120,
|
||||
"skip_if_countdown_gt_seconds": 118,
|
||||
"reset_after_swipes_enabled": true,
|
||||
"reset_after_swipes": 25,
|
||||
"reset_after_swipes_action": "swipe",
|
||||
"reset_after_swipes_action": "back",
|
||||
"auto_join_fansclub": true,
|
||||
"fansclub_fail_action": "switch",
|
||||
"high_value_fudai_enabled": true,
|
||||
@@ -42,9 +42,9 @@
|
||||
"fudai_disable_task_recognition": true,
|
||||
"yanghao_recommend_duration_seconds": 180,
|
||||
"yanghao_recommend_interval_seconds": 600,
|
||||
"yanghao_like_prob": 0.6,
|
||||
"yanghao_fav_prob": 0.35,
|
||||
"yanghao_comment_prob": 0.6,
|
||||
"yanghao_like_prob": 0.1,
|
||||
"yanghao_fav_prob": 0.05,
|
||||
"yanghao_comment_prob": 0.25,
|
||||
"yanghao_icon_roi_size": 240,
|
||||
"yanghao_icon_match_threshold": 0.77,
|
||||
"yanghao_step_screenshot": true,
|
||||
|
||||
@@ -3038,11 +3038,76 @@ class fudai_analyse:
|
||||
except Exception:
|
||||
pass
|
||||
# 调用 basic_join_decision 来记录预约
|
||||
# 注意:basic_join_decision 内部已经关闭详情并切换直播间,不需要再次关闭
|
||||
# 注意:basic_join_decision 内部已经关闭详情,返回False表示需要切换直播间
|
||||
try:
|
||||
douyin_fudai_core.basic_join_decision(
|
||||
result = douyin_fudai_core.basic_join_decision(
|
||||
self, detail, (skip, skip_reason)
|
||||
)
|
||||
if not result:
|
||||
# 记录预约成功,需要切换直播间
|
||||
try:
|
||||
needswitch = bool(
|
||||
getattr(self, "needswitch", True)
|
||||
)
|
||||
except Exception:
|
||||
needswitch = True
|
||||
if needswitch:
|
||||
try:
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail:记录预约后切换直播间",
|
||||
reason="high_value_reservation",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
# 优先使用封装好的上滑切房方法
|
||||
if hasattr(
|
||||
self, "swipe_up_to_next_live"
|
||||
):
|
||||
self.swipe_up_to_next_live()
|
||||
else:
|
||||
# 兜底:直接调用底层 swipe(基于 1080x2400 基准坐标)
|
||||
try:
|
||||
rx = int(
|
||||
getattr(
|
||||
self,
|
||||
"resolution_ratio_x",
|
||||
1080,
|
||||
)
|
||||
or 1080
|
||||
)
|
||||
ry = int(
|
||||
getattr(
|
||||
self,
|
||||
"resolution_ratio_y",
|
||||
2400,
|
||||
)
|
||||
or 2400
|
||||
)
|
||||
except Exception:
|
||||
rx, ry = 1080, 2400
|
||||
start_x = 540 * rx // 1080
|
||||
start_y = 1200 * ry // 2400
|
||||
end_x = 540 * rx // 1080
|
||||
end_y = 600 * ry // 2400
|
||||
self.operation.swipe(
|
||||
self.device_id,
|
||||
start_x,
|
||||
start_y,
|
||||
end_x,
|
||||
end_y,
|
||||
300,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
"_handle_in_fudai_detail完成(记录预约)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
)
|
||||
return
|
||||
except Exception as e:
|
||||
try:
|
||||
self._log_kv(
|
||||
|
||||
@@ -21,62 +21,139 @@ def attend_choujiang(analyser) -> bool:
|
||||
attend_button_text = ""
|
||||
button_status = getattr(analyser, "_fudai_button_status", None)
|
||||
button_text = getattr(analyser, "_fudai_button_text", "")
|
||||
try:
|
||||
current_room_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
except Exception:
|
||||
current_room_pos = 0
|
||||
try:
|
||||
cached_room_pos = int(getattr(analyser, "_fudai_button_room_pos", 0) or 0)
|
||||
except Exception:
|
||||
cached_room_pos = 0
|
||||
|
||||
# 如果并行OCR已经识别了按钮,且识别时间较近(5秒内),直接使用
|
||||
if button_text and button_status:
|
||||
# 如果并行OCR属性缺失或不完整,尝试从其它缓存字段复用识别结果(例如 button_text_raw 或映射表)
|
||||
if not button_text or not button_status:
|
||||
try:
|
||||
button_ocr_time = getattr(analyser, "_fudai_button_ocr_time", 0)
|
||||
current_time = time.time()
|
||||
# 如果并行OCR结果在5秒内,且状态有效,直接使用
|
||||
if current_time - button_ocr_time < 5.0:
|
||||
candidate = getattr(analyser, "button_text_raw", None)
|
||||
if not candidate:
|
||||
try:
|
||||
room_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
room_map = getattr(analyser, "_room_pos_to_title_map", {}) or {}
|
||||
if room_map and room_pos in room_map:
|
||||
info = room_map.get(room_pos) or {}
|
||||
if isinstance(info, dict):
|
||||
fudai_detail = info.get("fudai_detail") or {}
|
||||
candidate = (
|
||||
fudai_detail.get("button_text")
|
||||
or fudai_detail.get("button_text_raw")
|
||||
or None
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if candidate:
|
||||
bt = str(candidate or "").strip()
|
||||
if bt:
|
||||
# 推断按钮状态(与并行OCR的判断逻辑保持一致)
|
||||
if "参与成功" in bt or "等待开奖" in bt:
|
||||
bs = "已参与"
|
||||
elif "加入粉丝团" in bt or "粉丝团" in bt:
|
||||
bs = "需要加入粉丝团"
|
||||
elif "评论" in bt or "发表评论" in bt or "一键发表评论" in bt:
|
||||
bs = "需要评论"
|
||||
elif "还需看播" in bt or "开始观看" in bt:
|
||||
bs = "需要观看"
|
||||
elif "未达成" in bt:
|
||||
bs = "未达成要求"
|
||||
elif "参与抽奖" in bt or "参与" in bt:
|
||||
bs = "可以参与"
|
||||
else:
|
||||
bs = "未知状态"
|
||||
|
||||
try:
|
||||
analyser._fudai_button_status = bs
|
||||
analyser._fudai_button_text = bt
|
||||
analyser._fudai_button_ocr_time = time.time()
|
||||
try:
|
||||
analyser._fudai_button_room_pos = int(
|
||||
getattr(analyser, "room_pos", 0) or 0
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"复用缓存的并行OCR文本作为按钮状态",
|
||||
button_text=(bt[:100] if bt else ""),
|
||||
button_status=bs,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
button_text = bt
|
||||
button_status = bs
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 使用并行OCR识别的按钮状态(如果可用且在有效期内)
|
||||
try:
|
||||
button_ocr_time = getattr(analyser, "_fudai_button_ocr_time", 0)
|
||||
current_time = time.time()
|
||||
if button_text and button_status and current_time - button_ocr_time < 5.0:
|
||||
attend_button_text = button_text
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"使用并行OCR识别的按钮状态",
|
||||
button_text=(
|
||||
attend_button_text[:100] if attend_button_text else ""
|
||||
),
|
||||
button_status=button_status,
|
||||
)
|
||||
elif button_text and button_status:
|
||||
same_room = (
|
||||
not current_room_pos
|
||||
or not cached_room_pos
|
||||
or current_room_pos == cached_room_pos
|
||||
)
|
||||
if same_room:
|
||||
attend_button_text = button_text
|
||||
try:
|
||||
age_ms = int(
|
||||
max(0.0, current_time - float(button_ocr_time)) * 1000
|
||||
)
|
||||
except Exception:
|
||||
age_ms = None
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"使用并行OCR识别的按钮状态",
|
||||
"使用并行OCR缓存的按钮状态(超时复用)",
|
||||
button_text=(
|
||||
attend_button_text[:100] if attend_button_text else ""
|
||||
),
|
||||
button_status=button_status,
|
||||
age_ms=age_ms,
|
||||
room_pos=current_room_pos,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 如果并行OCR结果不可用,直接放弃参与(决策已由福袋详情中的并行OCR进行)
|
||||
if not attend_button_text:
|
||||
analyser.last_attend_fail_reason = "no_parallel_ocr_result"
|
||||
analyser._log_kv("参与", "并行OCR结果不可用,放弃参与", result="不参与")
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"统计",
|
||||
"metric",
|
||||
metric="fudai_attend",
|
||||
metric_type="fail",
|
||||
reason="no_parallel_ocr_result",
|
||||
run_id=getattr(analyser, "_run_id", ""),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser.click(500, 470)
|
||||
analyser._log_kv("参与", "关闭福袋详情", action="关闭详情")
|
||||
return False
|
||||
|
||||
# 如果并行OCR结果不可用,则重新识别
|
||||
if not attend_button_text:
|
||||
from douyin.fudai.core.coords import PARTICIPATE_BUTTON
|
||||
|
||||
analyser.cut_pic(*PARTICIPATE_BUTTON, "", "参与按钮") # 参与福袋抽奖的文字
|
||||
|
||||
# 统一使用预处理工具生成可供 OCR 使用的图片名(若失败则回退到原名)
|
||||
try:
|
||||
from douyin.utils.ocr_preprocess import preprocess_for_ocr
|
||||
|
||||
use_name = preprocess_for_ocr(analyser, "参与按钮")
|
||||
except Exception:
|
||||
use_name = "参与按钮"
|
||||
|
||||
# 优化:尝试多种OCR模式提高精准度(优先保证精准)
|
||||
attend_button_text = str(
|
||||
analyser.operation.analyse_pic_word(use_name, 0) or ""
|
||||
)
|
||||
if not attend_button_text or not any(
|
||||
k in attend_button_text
|
||||
for k in (
|
||||
"参与成功",
|
||||
"还需看播",
|
||||
"评论",
|
||||
"参与抽奖",
|
||||
"开始观看",
|
||||
"参与",
|
||||
"加入粉丝团",
|
||||
"粉丝团",
|
||||
)
|
||||
):
|
||||
# 切换到模式1识别,优先使用预处理图(若存在)
|
||||
attend_button_text = str(
|
||||
analyser.operation.analyse_pic_word(use_name, 1) or ""
|
||||
)
|
||||
analyser._log_kv("参与", "识别参与按钮", text=attend_button_text)
|
||||
# 基于并行OCR结果进行决策
|
||||
if attend_button_text and "不满足参与条件" in attend_button_text:
|
||||
analyser.last_attend_fail_reason = "condition_not_met"
|
||||
analyser._log_kv("参与", "不满足参与条件,直接放弃", result="不满足条件")
|
||||
@@ -1532,13 +1609,10 @@ def attend_choujiang(analyser) -> bool:
|
||||
)
|
||||
return True
|
||||
|
||||
click_times += 1
|
||||
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"参与抽奖失败:多次尝试均未识别到有效按钮",
|
||||
click_times=click_times,
|
||||
last_text=attend_button_text or "", # type: ignore[possibly-unbound]
|
||||
"参与抽奖失败:并行OCR结果无效",
|
||||
last_text=attend_button_text or "",
|
||||
result="参与失败",
|
||||
)
|
||||
try:
|
||||
@@ -1547,7 +1621,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
"metric",
|
||||
metric="fudai_attend",
|
||||
metric_type="fail",
|
||||
reason="button_not_recognized",
|
||||
reason="parallel_ocr_invalid",
|
||||
run_id=getattr(analyser, "_run_id", ""),
|
||||
)
|
||||
except Exception:
|
||||
|
||||
+307
-184
@@ -1093,7 +1093,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
futures[name] = executor.submit(func)
|
||||
|
||||
task_list_raw = fudai_content_raw = countdown_mm_raw = None
|
||||
countdown_ss_raw = value_raw = button_text_raw = None
|
||||
countdown_ss_raw = value_raw = None
|
||||
live_room_title_raw = live_room_title_text_raw = None
|
||||
|
||||
# 收集结果并记录耗时
|
||||
@@ -1243,7 +1243,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"并行OCR识别参与按钮",
|
||||
"主并行OCR识别参与按钮",
|
||||
button_text=button_text if button_text else "",
|
||||
)
|
||||
except Exception:
|
||||
@@ -1269,14 +1269,14 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
else:
|
||||
button_status = "未知状态"
|
||||
|
||||
# 将按钮状态存储到 analyser 对象中,供后续决策使用
|
||||
# 将按钮状态存储到 analyser 对象中
|
||||
try:
|
||||
analyser._fudai_button_status = button_status
|
||||
analyser._fudai_button_text = button_text
|
||||
analyser.button_text_raw = (
|
||||
button_text_raw # 设置按钮文本原始值供过滤使用
|
||||
)
|
||||
# 存储所有并行OCR识别的原始字段供验证使用
|
||||
# 存储所有主并行OCR识别的原始字段供验证使用
|
||||
analyser.fudai_content_raw = fudai_content_raw
|
||||
analyser.task_list_raw = task_list_raw
|
||||
analyser.countdown_mm_raw = countdown_mm_raw
|
||||
@@ -1284,23 +1284,20 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
analyser.value_raw = value_raw
|
||||
analyser.live_room_title_raw = live_room_title_raw
|
||||
analyser._fudai_button_ocr_time = time.time() # 记录识别时间
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"按钮状态判断",
|
||||
status=button_status,
|
||||
button_text=button_text if button_text else "",
|
||||
)
|
||||
except Exception as e_inner:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"保存按钮状态失败",
|
||||
error=str(e_inner),
|
||||
error_type=type(e_inner).__name__,
|
||||
level="WARNING",
|
||||
analyser._fudai_button_room_pos = int(
|
||||
getattr(analyser, "room_pos", 0) or 0
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"主按钮状态判断",
|
||||
status=button_status,
|
||||
button_text=button_text if button_text else "",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
ocr_elapsed = time.time() - ocr_start_time
|
||||
try:
|
||||
@@ -2051,19 +2048,18 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
# log_type="INFO",
|
||||
# )
|
||||
|
||||
# 更新映射表中的标题信息和福袋详情(如果存在该位置的记录)
|
||||
# 更新映射表中的标题信息和福袋详情(总是记录完整信息)
|
||||
try:
|
||||
room_pos = int(getattr(analyser, "room_pos", 0) or 0)
|
||||
room_pos_map = getattr(analyser, "_room_pos_to_title_map", {})
|
||||
if room_pos in room_pos_map:
|
||||
# 更新标题信息
|
||||
room_pos_map[room_pos]["title"] = live_room_title_raw
|
||||
room_pos_map[room_pos]["title_raw"] = live_room_title_text_raw
|
||||
|
||||
# 更新福袋详细信息
|
||||
room_pos_map[room_pos]["has_fudai"] = True
|
||||
room_pos_map[room_pos]["fudai_content"] = fudai_content_text
|
||||
room_pos_map[room_pos]["fudai_detail"] = {
|
||||
|
||||
# 创建或更新完整的房间信息
|
||||
room_info = {
|
||||
"title": live_room_title_raw or "",
|
||||
"title_raw": live_room_title_text_raw or "",
|
||||
"has_fudai": True,
|
||||
"fudai_content": fudai_content_text,
|
||||
"fudai_detail": {
|
||||
"content": fudai_content_text,
|
||||
"time_text": time_text,
|
||||
"participants": participants,
|
||||
@@ -2071,23 +2067,39 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
"prize_value_yuan": prize_value_yuan,
|
||||
"button_text": getattr(analyser, "button_text_raw", ""),
|
||||
"timestamp": time.time(),
|
||||
}
|
||||
room_pos_map[room_pos]["timestamp"] = time.time()
|
||||
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 更新映射表标题和福袋详情信息",
|
||||
room_pos=room_pos,
|
||||
title=live_room_title_raw[:30] if live_room_title_raw else "",
|
||||
fudai_content=fudai_content_text[:30] if fudai_content_text else "",
|
||||
prize_value_yuan=prize_value_yuan,
|
||||
log_type="DEBUG",
|
||||
},
|
||||
"timestamp": time.time(),
|
||||
}
|
||||
|
||||
room_pos_map[room_pos] = room_info
|
||||
analyser._room_pos_to_title_map = room_pos_map
|
||||
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"[预约] 并行OCR完成后记录完整映射表信息",
|
||||
room_pos=room_pos,
|
||||
title=live_room_title_raw[:30] if live_room_title_raw else "",
|
||||
fudai_content=fudai_content_text[:30] if fudai_content_text else "",
|
||||
prize_value_yuan=prize_value_yuan,
|
||||
log_type="DEBUG",
|
||||
)
|
||||
|
||||
# 序列化运行时映射表到文件,供 GUI 刷新使用
|
||||
try:
|
||||
from douyin.reservation import (
|
||||
douyin_reservation_handler as _rh,
|
||||
)
|
||||
|
||||
if hasattr(_rh, "_dump_room_pos_map_to_state"):
|
||||
_rh._dump_room_pos_map_to_state(analyser)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
except Exception as e_update:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
"更新映射表标题和福袋详情信息失败",
|
||||
"并行OCR完成后记录映射表信息失败",
|
||||
error=str(e_update),
|
||||
level="WARNING",
|
||||
)
|
||||
@@ -4475,21 +4487,11 @@ def basic_join_decision(
|
||||
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"basic_join_decision:设置福袋信息并记录映射表",
|
||||
"basic_join_decision:设置福袋信息",
|
||||
content=content[:50] if content else "",
|
||||
prize_value_yuan=prize_value_yuan,
|
||||
log_type="INFO",
|
||||
)
|
||||
|
||||
# 记录到映射表
|
||||
if hasattr(analyser, "_record_room_title_and_pos"):
|
||||
analyser._record_room_title_and_pos()
|
||||
else:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"basic_join_decision:_record_room_title_and_pos 方法不存在",
|
||||
log_type="WARNING",
|
||||
)
|
||||
except Exception as e:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
@@ -4771,6 +4773,10 @@ def basic_join_decision(
|
||||
else:
|
||||
skip, reason = should_skip_fudai_by_config(analyser, detail)
|
||||
|
||||
# 记录原始筛选结果,避免后续分支覆盖后丢失上下文
|
||||
orig_skip = bool(skip)
|
||||
orig_skip_reason = str(reason or "")
|
||||
|
||||
# 特殊处理:如果被倒计时过滤筛掉(倒计时大于阈值),但价值达到高价值阈值
|
||||
# 需要检查剩余秒数是否在"预约参与阈值"内,如果在阈值内则立即参与,否则记录预约
|
||||
# 注意:如果是观看任务,不应该进入这个特殊处理逻辑(should_skip_fudai_by_config 已经返回 watch_task_detected)
|
||||
@@ -4887,40 +4893,59 @@ def basic_join_decision(
|
||||
|
||||
# 如果剩余秒数在"预约参与阈值"内,则立即参与而不是预约
|
||||
if remain_seconds is not None and remain_seconds <= join_ahead_seconds:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:倒计时在预约参与阈值内,立即参与",
|
||||
reason=reason,
|
||||
value_yuan=prize_value_yuan,
|
||||
threshold=high_value_threshold,
|
||||
remain_seconds=(
|
||||
int(remain_seconds) if remain_seconds is not None else None
|
||||
),
|
||||
join_ahead_threshold=join_ahead_seconds,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 不关闭详情,继续走立即参与逻辑
|
||||
skip = False
|
||||
reason = (
|
||||
"high_value_immediate_join"
|
||||
if not force_attend
|
||||
else "reservation_back_force_attend"
|
||||
)
|
||||
# 如果是强制参与,设置 is_high_value = False,跳过后续的高价值处理逻辑(避免再次记录预约)
|
||||
# 注意:强制参与标志会在参与成功后清除(在 attend_choujiang 返回后),避免影响后续福袋
|
||||
if force_attend:
|
||||
if orig_skip:
|
||||
try:
|
||||
# 设置 is_high_value = False,跳过后续的高价值处理逻辑
|
||||
is_high_value = False
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:强制参与模式,跳过后续高价值处理逻辑,直接参与",
|
||||
force_attend=force_attend,
|
||||
"basic_join_decision:原始筛选未通过,即使倒计时在阈值内也不参与",
|
||||
reason=orig_skip_reason,
|
||||
value_yuan=prize_value_yuan,
|
||||
threshold=high_value_threshold,
|
||||
remain_seconds=(
|
||||
int(remain_seconds) if remain_seconds is not None else None
|
||||
),
|
||||
join_ahead_threshold=join_ahead_seconds,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 保持高价值预约逻辑,不走立即参与
|
||||
skip = False
|
||||
reason = "high_value_reservation"
|
||||
else:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:倒计时在预约参与阈值内,立即参与",
|
||||
reason=reason,
|
||||
value_yuan=prize_value_yuan,
|
||||
threshold=high_value_threshold,
|
||||
remain_seconds=(
|
||||
int(remain_seconds) if remain_seconds is not None else None
|
||||
),
|
||||
join_ahead_threshold=join_ahead_seconds,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 不关闭详情,继续走立即参与逻辑
|
||||
skip = False
|
||||
reason = (
|
||||
"high_value_immediate_join"
|
||||
if not force_attend
|
||||
else "reservation_back_force_attend"
|
||||
)
|
||||
# 如果是强制参与,设置 is_high_value = False,跳过后续的高价值处理逻辑(避免再次记录预约)
|
||||
# 注意:强制参与标志会在参与成功后清除(在 attend_choujiang 返回后),避免影响后续福袋
|
||||
if force_attend:
|
||||
try:
|
||||
# 设置 is_high_value = False,跳过后续的高价值处理逻辑
|
||||
is_high_value = False
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:强制参与模式,跳过后续高价值处理逻辑,直接参与",
|
||||
force_attend=force_attend,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
# 剩余秒数大于"预约参与阈值",但在记录预约之前再次检查是否是观看任务
|
||||
is_watch_task_check = False
|
||||
@@ -5143,21 +5168,37 @@ def basic_join_decision(
|
||||
|
||||
# 如果剩余秒数在"预约参与阈值"内(<= 阈值),立即参与而不是记录预约
|
||||
if remain_seconds is not None and remain_seconds <= join_ahead_seconds:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:价值达到高价值阈值,剩余秒数在预约参与阈值内,立即参与",
|
||||
value_yuan=prize_value_yuan,
|
||||
threshold=high_value_threshold,
|
||||
remain_seconds=(
|
||||
int(remain_seconds) if remain_seconds is not None else None
|
||||
),
|
||||
join_ahead_threshold=join_ahead_seconds,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 不记录预约,继续执行后续的立即参与逻辑
|
||||
is_high_value = False
|
||||
if orig_skip:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:原始筛选未通过,高价值不走立即参与",
|
||||
reason=orig_skip_reason,
|
||||
value_yuan=prize_value_yuan,
|
||||
threshold=high_value_threshold,
|
||||
remain_seconds=(
|
||||
int(remain_seconds) if remain_seconds is not None else None
|
||||
),
|
||||
join_ahead_threshold=join_ahead_seconds,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:价值达到高价值阈值,剩余秒数在预约参与阈值内,立即参与",
|
||||
value_yuan=prize_value_yuan,
|
||||
threshold=high_value_threshold,
|
||||
remain_seconds=(
|
||||
int(remain_seconds) if remain_seconds is not None else None
|
||||
),
|
||||
join_ahead_threshold=join_ahead_seconds,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 不记录预约,继续执行后续的立即参与逻辑
|
||||
is_high_value = False
|
||||
else:
|
||||
# 剩余秒数大于"预约参与阈值",记录预约
|
||||
try:
|
||||
@@ -5173,6 +5214,7 @@ def basic_join_decision(
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:价值达到高价值阈值,但剩余秒数大于预约参与阈值,记录预约",
|
||||
@@ -5610,6 +5652,31 @@ def basic_join_decision(
|
||||
# 记录预约,并检查队列是否已满
|
||||
queue_full_flag = [False]
|
||||
|
||||
def _add_reservation_with_flag(res_list, item) -> None:
|
||||
max_reservations = None
|
||||
try:
|
||||
max_reservations = int(
|
||||
getattr(
|
||||
analyser, "high_value_fudai_max_reservations", 3
|
||||
)
|
||||
or 3
|
||||
)
|
||||
except Exception:
|
||||
max_reservations = 3
|
||||
queue_full = (
|
||||
douyin_reservation_logic.add_reservation_core_logic(
|
||||
res_list,
|
||||
item,
|
||||
max_reservations=max_reservations,
|
||||
analyser=analyser,
|
||||
write_state_callback=_write_reservation_state,
|
||||
)
|
||||
)
|
||||
try:
|
||||
queue_full_flag[0] = bool(queue_full)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 检查预约队列中是否已经存在相同的福袋
|
||||
existing_reservation = None
|
||||
try:
|
||||
@@ -5647,7 +5714,9 @@ def basic_join_decision(
|
||||
pass
|
||||
|
||||
# 如果已经预约过,更新现有预约;否则新增预约
|
||||
need_record = True
|
||||
if existing_reservation is not None:
|
||||
need_record = False
|
||||
# 更新现有预约的信息
|
||||
try:
|
||||
existing_reservation.update(
|
||||
@@ -5692,114 +5761,118 @@ def basic_join_decision(
|
||||
except Exception:
|
||||
pass
|
||||
existing_reservation = None # 强制新增
|
||||
copies = 0
|
||||
try:
|
||||
# 优先从缓存的福袋详情中获取信息
|
||||
cached_detail = getattr(
|
||||
analyser, "_last_fudai_detail_tuple", None
|
||||
)
|
||||
if (
|
||||
cached_detail
|
||||
and isinstance(cached_detail, tuple)
|
||||
and len(cached_detail) >= 6
|
||||
):
|
||||
time_text = str(cached_detail[1] or "")
|
||||
participants = int(cached_detail[2] or 0)
|
||||
copies = int(cached_detail[3] or 0)
|
||||
need_record = True
|
||||
|
||||
# 从阶段检测结果获取任务数量(如果还没有被清除)
|
||||
task_count_from_stage = getattr(
|
||||
analyser, "_fudai_detail_task_count_from_stage", None
|
||||
)
|
||||
if task_count_from_stage is not None:
|
||||
task_count = int(task_count_from_stage or 0)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:从阶段检测获取任务数量",
|
||||
log_type="OP",
|
||||
任务数量=task_count,
|
||||
原始值=task_count_from_stage,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 清除标志,避免影响后续调用
|
||||
analyser._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
# 如果阶段检测结果已被清除,尝试从缓存的详情中获取任务数量
|
||||
try:
|
||||
cached_extra = getattr(
|
||||
analyser, "_last_fudai_detail_extra", None
|
||||
)
|
||||
if cached_extra and isinstance(cached_extra, dict):
|
||||
cached_task_count = cached_extra.get(
|
||||
"task_count"
|
||||
)
|
||||
if cached_task_count is not None:
|
||||
task_count = int(cached_task_count or 0)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:从缓存详情获取任务数量",
|
||||
log_type="OP",
|
||||
任务数量=task_count,
|
||||
来源="缓存详情",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
# 警告:未获取到任务数量,使用默认值0
|
||||
task_count = 0
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:警告:未从缓存获取任务数量,使用默认值0",
|
||||
log_type="WARNING",
|
||||
可能原因="缓存详情不完整或任务数量缺失",
|
||||
建议="检查福袋详情识别是否正常",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
time_text = ""
|
||||
participants = 0
|
||||
copies = 0
|
||||
task_count = 2
|
||||
try:
|
||||
# 优先从缓存的福袋详情中获取信息
|
||||
cached_detail = getattr(
|
||||
analyser, "_last_fudai_detail_tuple", None
|
||||
)
|
||||
if (
|
||||
cached_detail
|
||||
and isinstance(cached_detail, tuple)
|
||||
and len(cached_detail) >= 6
|
||||
):
|
||||
time_text = str(cached_detail[1] or "")
|
||||
participants = int(cached_detail[2] or 0)
|
||||
copies = int(cached_detail[3] or 0)
|
||||
|
||||
# 从阶段检测结果获取任务数量(如果还没有被清除)
|
||||
task_count_from_stage = getattr(
|
||||
analyser, "_fudai_detail_task_count_from_stage", None
|
||||
)
|
||||
if task_count_from_stage is not None:
|
||||
task_count = int(task_count_from_stage or 0)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:从阶段检测获取任务数量",
|
||||
log_type="OP",
|
||||
任务数量=task_count,
|
||||
原始值=task_count_from_stage,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 清除标志,避免影响后续调用
|
||||
analyser._fudai_detail_task_count_from_stage = None
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:清除任务数量标志",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
# 如果阶段检测结果已被清除,尝试从缓存的详情中获取任务数量
|
||||
try:
|
||||
cached_extra = getattr(
|
||||
analyser, "_last_fudai_detail_extra", None
|
||||
)
|
||||
if cached_extra and isinstance(cached_extra, dict):
|
||||
cached_task_count = cached_extra.get("task_count")
|
||||
if cached_task_count is not None:
|
||||
task_count = int(cached_task_count or 0)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:从缓存详情获取任务数量",
|
||||
log_type="OP",
|
||||
任务数量=task_count,
|
||||
来源="缓存详情",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
# 警告:未获取到任务数量,使用默认值0
|
||||
task_count = 0
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:警告:未从阶段检测获取任务数量,使用默认值0",
|
||||
"douyin_fudai_core:警告:未从缓存获取任务数量,使用默认值0",
|
||||
log_type="WARNING",
|
||||
可能原因="阶段检测未触发或像素检测失败",
|
||||
建议="检查点击验证阶段检测是否正常执行",
|
||||
可能原因="缓存详情不完整或任务数量缺失",
|
||||
建议="检查福袋详情识别是否正常",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
# 获取缓存失败,使用默认值
|
||||
else:
|
||||
# 警告:未获取到任务数量,使用默认值0
|
||||
task_count = 0
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:从缓存获取任务数量失败,使用默认值",
|
||||
error=str(e),
|
||||
使用默认值=True,
|
||||
"douyin_fudai_core:警告:未从阶段检测获取任务数量,使用默认值0",
|
||||
log_type="WARNING",
|
||||
可能原因="阶段检测未触发或像素检测失败",
|
||||
建议="检查点击验证阶段检测是否正常执行",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
# 获取缓存失败,使用默认值
|
||||
task_count = 0
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"douyin_fudai_core:从缓存获取任务数量失败,使用默认值",
|
||||
error=str(e),
|
||||
使用默认值=True,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 限制任务数量在合理范围内
|
||||
if task_count not in (1, 2, 3):
|
||||
task_count = 2
|
||||
except Exception:
|
||||
# 限制任务数量在合理范围内
|
||||
if task_count not in (1, 2, 3):
|
||||
task_count = 2
|
||||
except Exception:
|
||||
task_count = 2
|
||||
|
||||
if need_record:
|
||||
douyin_reservation_logic.record_high_value_reservation( # type: ignore[attr-defined]
|
||||
analyser=analyser,
|
||||
fudai_content_text=content,
|
||||
@@ -5984,18 +6057,68 @@ def basic_join_decision(
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return True
|
||||
except Exception:
|
||||
# 若预约逻辑异常,退化为直接参与抽奖
|
||||
# 记录预约后返回False,触发切换直播间继续找别的福袋
|
||||
return False
|
||||
except Exception as e:
|
||||
# 若预约逻辑异常:对“倒计时>阈值”的原始筛选场景,避免退化为直接参与
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"basic_join_decision:记录预约时异常,退化为直接参与",
|
||||
"basic_join_decision:记录预约时异常",
|
||||
error=str(e),
|
||||
error_type=type(e).__name__,
|
||||
orig_skip=orig_skip,
|
||||
orig_reason=orig_skip_reason,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
if orig_skip and orig_skip_reason.startswith("countdown_gt_"):
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:原始筛选为倒计时>阈值,预约异常时不参与",
|
||||
reason=orig_skip_reason,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 尽量关闭详情页,避免停留
|
||||
try:
|
||||
analyser.click(500, 470)
|
||||
except Exception:
|
||||
try:
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
# 其它场景保持原行为:退化为直接参与抽奖
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"预约",
|
||||
"basic_join_decision:记录预约异常,继续尝试直接参与",
|
||||
level="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 默认分支:未进入预约路径或预约失败,直接参与抽奖
|
||||
if orig_skip:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"basic_join_decision:原始筛选未通过,放弃参与",
|
||||
reason=orig_skip_reason,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
# 尽量关闭详情页,避免停留
|
||||
try:
|
||||
analyser.click(500, 470)
|
||||
except Exception:
|
||||
try:
|
||||
analyser.operation.click_back(analyser.device_id)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
try:
|
||||
analyser._log_kv("参与", "basic_join_decision:尝试参与抽奖")
|
||||
except Exception:
|
||||
|
||||
Reference in new issue
Block a user