feat: 添加开奖等待时间戳,优化参与逻辑中的状态管理
This commit is contained in:
1 parent
ea1e3dd876
commit
78e53603d3
5 files changed
+29
-28
No files matched your search
+11
-25
@@ -344,6 +344,7 @@ class fudai_analyse:
|
||||
self._fudai_detail_consecutive_failures: int = 0 # 连续失败次数
|
||||
self._detail_closed_by_attend: bool = False # 详情页是否由参与操作关闭
|
||||
self._lottery_result_expected_ts: float = 0.0 # 开奖结果预期时间戳
|
||||
self._lottery_wait_start_ts: float = 0.0 # 开始等待开奖的时间戳
|
||||
|
||||
# 初次加载配置
|
||||
self.load_config()
|
||||
@@ -1173,14 +1174,12 @@ class fudai_analyse:
|
||||
if getattr(self, "_waiting_for_lottery_result", False):
|
||||
wait_lottery_start = time.time()
|
||||
try:
|
||||
# 在等待开奖期间只检测开奖结果,不触发预约抢占逻辑,
|
||||
# 在等待开奖期间持续检测开奖结果,不触发预约抢占逻辑,
|
||||
# 以确保按顺序完成当前参与流程。
|
||||
future_ts = getattr(self, "_lottery_result_expected_ts", 0.0) or 0.0
|
||||
current_ts = time.time()
|
||||
remain_seconds = max(0, future_ts - current_ts + 6.0)
|
||||
|
||||
# 开奖时间 + 1秒缓冲后开始检测开奖结果
|
||||
check_start_ts = future_ts + 1.0
|
||||
# 从设置等待标志后开始持续检测,最多等待开奖时间+10秒
|
||||
timeout_ts = future_ts + 10.0
|
||||
|
||||
if current_ts >= timeout_ts:
|
||||
@@ -1193,15 +1192,17 @@ class fudai_analyse:
|
||||
超时秒数=timeout_seconds,
|
||||
等待开奖总耗时=round(time.time() - wait_lottery_start, 2),
|
||||
)
|
||||
elif current_ts >= check_start_ts:
|
||||
passed_seconds = int(current_ts - future_ts)
|
||||
else:
|
||||
# 持续OCR检测开奖结果
|
||||
wait_start_ts = getattr(self, "_lottery_wait_start_ts", future_ts)
|
||||
passed_seconds = int(current_ts - wait_start_ts)
|
||||
self._log_kv(
|
||||
"参与",
|
||||
f"等待开奖结果中,进入连续检测窗口(最多10s),已过开奖时间{passed_seconds}秒",
|
||||
已过开奖时间秒数=passed_seconds,
|
||||
f"等待开奖结果中,持续OCR检测,已等待{passed_seconds}秒",
|
||||
已等待秒数=passed_seconds,
|
||||
)
|
||||
|
||||
deadline_ts = min(timeout_ts, check_start_ts + 10.0)
|
||||
deadline_ts = timeout_ts
|
||||
|
||||
attempt = 0
|
||||
consecutive_none = 0
|
||||
@@ -1325,22 +1326,6 @@ class fudai_analyse:
|
||||
except Exception:
|
||||
pass
|
||||
return
|
||||
else:
|
||||
wait_s = min(2.0, remain_seconds)
|
||||
remain_seconds_int = int(remain_seconds)
|
||||
self._log_kv(
|
||||
"参与",
|
||||
f"等待开奖中,剩余{remain_seconds_int}秒",
|
||||
剩余秒数=remain_seconds_int,
|
||||
)
|
||||
self.operation.delay(wait_s)
|
||||
elapsed = time.time() - start_time
|
||||
self._log_kv(
|
||||
"流程",
|
||||
f"run_once_basic完成(等待开奖中,剩余{remain_seconds_int}秒)",
|
||||
elapsed_seconds=round(elapsed, 2),
|
||||
)
|
||||
return
|
||||
except Exception as exc:
|
||||
self._log_kv("参与", "等待开奖检测时出错", error=str(exc))
|
||||
self._waiting_for_lottery_result = False
|
||||
@@ -3452,6 +3437,7 @@ class fudai_analyse:
|
||||
# 直接保存开奖时间戳,等待时直接用 future_timestamp - time.time() 计算剩余秒数
|
||||
self._waiting_for_lottery_result = True
|
||||
self._lottery_result_expected_ts = future_timestamp
|
||||
self._lottery_wait_start_ts = time.time()
|
||||
|
||||
self._log_kv(
|
||||
"参与",
|
||||
|
||||
@@ -173,6 +173,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
# 设置等待开奖标志和预期开奖时间
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
analyser._lottery_wait_start_ts = current_time
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"参与成功,设置等待开奖标志",
|
||||
@@ -389,6 +390,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
# 设置等待开奖标志和预期开奖时间
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
analyser._lottery_wait_start_ts = current_time
|
||||
|
||||
# #region agent log - countdown set
|
||||
with open(get_debug_log_path(), "a", encoding="utf-8") as f:
|
||||
|
||||
@@ -2221,6 +2221,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
# 设置等待开奖标志和预期开奖时间
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
analyser._lottery_wait_start_ts = current_time
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"参与成功,设置等待开奖标志",
|
||||
@@ -2368,6 +2369,7 @@ def attend_choujiang(analyser) -> bool:
|
||||
# 设置等待开奖标志和预期开奖时间
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
analyser._lottery_wait_start_ts = current_time
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"点击参与抽奖后,设置等待开奖标志",
|
||||
|
||||
@@ -69,6 +69,17 @@ class SwipeHandler:
|
||||
pass
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
# 在切换直播间前记录当前直播间的标题和位置到运行时映射表
|
||||
try:
|
||||
skip_record = bool(
|
||||
getattr(analyser, "_skip_record_title_during_seek", False)
|
||||
)
|
||||
if not skip_record:
|
||||
analyser._record_room_title_and_pos() # type: ignore[attr-defined]
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
douyin_swipe_ops.swipe_up_switch_live(analyser)
|
||||
# 记录直播间位置:上滑 +1
|
||||
try:
|
||||
@@ -108,14 +119,13 @@ class SwipeHandler:
|
||||
pass
|
||||
|
||||
# 记录当前直播间的标题和位置到运行时映射表(用于回退校验)
|
||||
# 如果是在回退过程中(_seek_reservation_room),跳过记录,因为之前已经记录过了
|
||||
# 切换直播间后跳过记录,因为切换前已记录,避免重复
|
||||
# 切换前已记录,这里跳过避免重复
|
||||
try:
|
||||
skip_record = bool(
|
||||
getattr(analyser, "_skip_record_title_during_seek", False)
|
||||
)
|
||||
if not skip_record:
|
||||
# 由于刚刚切换,跳过记录以避免重复
|
||||
# 切换前已记录,跳过避免重复
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -781,6 +781,7 @@ class ReservationHandler:
|
||||
if remain_seconds > 0:
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
analyser._lottery_wait_start_ts = current_time
|
||||
analyser._current_attending_reservation_fudai = (
|
||||
True # 标记当前正在参与预约福袋
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user