Files
douyi_guaji_main/douyin/other/douyin_lottery.py
T
Your Name 93d47a16d6 Refactor reservation preemption handling and logging
- Removed the reservation preempt minimum value from the Runner and GUI components.
- Updated logging mechanism to streamline log message handling and improve readability.
- Introduced a new method for appending log lines in the Runner class.
- Cleaned up related GUI elements and configuration options in web interface.
- Deleted obsolete simulation scripts related to reservation preemption checks.
2026-01-07 21:24:10 +08:00

79 lines
2.3 KiB
Python

from __future__ import annotations
"""
Lottery helpers shim (WebGUI version)
=====================================
Exports:
- wait_for_lottery_result
- process_lottery_result
"""
from typing import Any, Dict, Tuple
import time
def wait_for_lottery_result(
analyser: Any,
lastsecond: int,
future_timestamp: float,
reservation_after_action_pending: bool,
reservation_should_preempt_callback=None,
) -> Tuple[bool, int, float | None, int | None]:
"""兼容实现:按原始签名等待开奖,当前版本只做时间等待与简单抢占判断。"""
start = time.time()
# 简单轮询等待一小段时间,保留结构但不做重型逻辑
detect_attempts = 0
first_detect_ts: float | None = None
initial_check_result: int | None = None
# 最多等待 min(倒计时+5, 15) 秒,避免阻塞过久
total_wait_s = max(0.0, float(lastsecond or 0) + 5.0)
total_wait_s = min(total_wait_s, 15.0)
step_s = 1.5
while (time.time() - start) < total_wait_s:
detect_attempts += 1
if first_detect_ts is None:
first_detect_ts = time.time()
# 抢占逻辑已删除,直接继续等待
try:
analyser.operation.delay(step_s)
except Exception:
time.sleep(step_s)
# 占位返回:未被预约抢占,未检测到明确结果
return False, detect_attempts, first_detect_ts, initial_check_result
def process_lottery_result(
analyser: Any,
x: int,
t_participate: float,
detect_attempts: int,
first_detect_ts: float | None,
initial_check_result: int | None,
reservation_focus_until_ts: float,
reservation_focus_until_ts_ref: list,
reservation_after_action_pending_ref: list,
needswitch: bool,
post_switch_delay_s: float,
swipe_up_switch_callback,
clear_reservations_callback,
get_recommend_seconds_callback,
yanghao_wait_callback,
) -> bool:
"""兼容实现:记录开奖阶段的调试信息,当前版本不修改预约/房间状态。"""
try:
analyser._log_kv(
"开奖",
"process_lottery_result",
x=x,
detect_attempts=detect_attempts,
first_detect_ts=first_detect_ts,
initial_check_result=initial_check_result,
)
except Exception:
pass
return False