feat: Add runtime overrides for reservation settings and update high value rooms

- Introduced new command-line arguments for runtime configuration:
  - `--reservation-back-swipe-delay`: Adjusts swipe delay after rollback (only effective when rollback verification is disabled).
  - `--reservation-preempt-min-value`: Sets the minimum value for preempting reservations.
  - `--fudai-find-max-attempts`: Limits the maximum attempts to find the 福袋 icon.

- Updated `high_value_rooms.json` to reflect new room entries and updated timestamps.
- Modified `reservations.json` to change the current reservation details and added a new reservation entry.
- Enhanced `web_gui.py` to support new runtime parameters from the GUI.
- Updated `app.js` and `index.html` in the web UI to include new settings for 福袋 attempts, reservation preemption value, and swipe delay.
This commit is contained in:
Your Name committed 2025-12-15 20:31:41 +08:00
1 parent 02b2930639
commit ea8d221543
8 files changed
+531 -335

No files matched your search

+6 -2
View File
@@ -16,7 +16,7 @@
"high_value_fudai_threshold_yuan": 500,
"high_value_fudai_join_ahead_seconds": 90,
"high_value_fudai_max_swipe_back": 0,
"high_value_fudai_max_reservations": 5,
"high_value_fudai_max_reservations": 4,
"high_value_fudai_after_action": "continue",
"fudai_abnormal_reopen_delay_seconds": 1.2,
"fudai_quiet_hours_enabled": true,
@@ -146,5 +146,9 @@
"reset_after_swipes_enabled": false,
"high_value_room_revisit_enabled": false,
"high_value_room_revisit_only_current_run": false,
"reservation_back_verify_enabled": false
"reservation_back_verify_enabled": false,
"fudai_icon_max_wait_seconds": 10,
"fudai_icon_adaptive_enabled": false,
"fudai_find_max_attempts": 5,
"reservation_preempt_min_value": 0
}
+225 -247
View File
@@ -5,7 +5,6 @@ from PIL import Image
from datetime import datetime
from Underlying_Operations import underlying_operations
import json
import math
import re
import shutil
import random
@@ -277,6 +276,11 @@ class fudai_analyse:
self.high_value_room_revisit_only_current_run = False # 若为 True,则仅回访本次运行记录的直播间
# 预约回退校验开关:用于在运行时决定是否做回退后详细校验(可通过 Run 面板控制)
self.reservation_back_verify_enabled = True
# 轮询策略:在预计开奖前多少秒开始积极轮询结果(默认 10 秒)
self.poll_before_open_seconds = 10
# 预约抢占最小价值:低于该价值的预约不抢占当前任务(元,默认0表示任何预约可抢占)
self.reservation_preempt_min_value_yuan = 0.0
# 详情页识别兜底(参与按钮 OCR)节流
self.detail_ocr_check_min_interval_seconds = 8.0
@@ -489,8 +493,8 @@ class fudai_analyse:
# 福袋图标检测提速参数(默认更快;可在 config.json 覆盖)
self.fudai_icon_retry_delay_seconds = 0.6
self.fudai_icon_max_wait_seconds = 4.0
# 自适应开关:是否根据历史日志尝试缩短等待时间
self.fudai_icon_adaptive_enabled = True
# 最多尝试寻找福袋图标次数(默认 5,可由 UI 修改)
self.fudai_find_max_attempts = 5
# 截图阶段诊断(OCR)节流:避免高频截图时反复 OCR 拖慢
self.screenshot_diagnose_min_interval_seconds = 8.0
self._last_diag_ts = 0.0
@@ -538,8 +542,8 @@ class fudai_analyse:
pass
if self.fudai_icon_retry_delay_seconds < 0.2:
self.fudai_icon_retry_delay_seconds = 0.2
self.fudai_icon_max_wait_seconds = 3.0
self.fudai_icon_adaptive_enabled = False
if self.fudai_icon_retry_delay_seconds > 5:
self.fudai_icon_retry_delay_seconds = 5.0
try:
self.fudai_icon_max_wait_seconds = float(config.get("fudai_icon_max_wait_seconds", self.fudai_icon_max_wait_seconds) or self.fudai_icon_max_wait_seconds)
except (TypeError, ValueError):
@@ -548,58 +552,14 @@ class fudai_analyse:
self.fudai_icon_max_wait_seconds = 0.0
if self.fudai_icon_max_wait_seconds > 30:
self.fudai_icon_max_wait_seconds = 30.0
# 自适应开关(是否启用基于历史日志的缩短建议)
try:
self.fudai_icon_adaptive_enabled = bool(config.get("fudai_icon_adaptive_enabled", self.fudai_icon_adaptive_enabled))
except Exception:
self.fudai_icon_adaptive_enabled = bool(self.fudai_icon_adaptive_enabled)
# 尝试从历史统一日志中自适配此超时(仅在自适应开关开启时尝试)
try:
if not getattr(self, 'fudai_icon_adaptive_enabled', True):
# 自适应被禁用,跳过历史分析
pass
else:
hist_path = os.path.join(os.path.dirname(__file__), "logs", "unified.log")
if os.path.exists(hist_path):
with open(hist_path, "r", encoding="utf-8", errors="ignore") as hf:
data = hf.read()
# 只匹配同时包含秒数字段和福袋 x 坐标字段(表示识别成功)的记录
pair_matches = re.findall(r"进入直播间后找到福袋耗时[\s\S]{0,200}?字段_seconds=([0-9]+(?:\.[0-9]+)?)[\s\S]{0,200}?字段_fudai_x=(\d+)", data)
vals = []
for sec_str, fudai_x in pair_matches:
try:
# 只接受 fudai_x > 0 的记录(更严格的成功判定)
if int(fudai_x) > 0:
vals.append(float(sec_str))
except Exception:
pass
if vals:
# 仅使用最近 50 次记录(按日志出现顺序,默认为时间顺序)来计算统计量
recent = vals[-50:]
recent_sorted = sorted(recent)
n = len(recent_sorted)
# 中位数
if n % 2 == 1:
median = recent_sorted[n // 2]
else:
median = (recent_sorted[n // 2 - 1] + recent_sorted[n // 2]) / 2.0
# 90% 分位(保守取靠近上界的值)
idx90 = int(math.ceil(0.9 * (n - 1)))
p90 = recent_sorted[min(idx90, n - 1)]
# 以 p90 为主,保守加 1 秒缓冲,限制在 [2,30]
adaptive = min(30.0, max(2.0, float(p90) + 1.0))
# 打印建议:无论是否缩短都输出建议值;仅在建议更短时实际缩短当前值
old = self.fudai_icon_max_wait_seconds
action = "keep"
if adaptive < old:
self.fudai_icon_max_wait_seconds = adaptive
action = "shorten"
print(f"[自适应] 建议 fudai_icon_max_wait_seconds={adaptive:.2f}s 当前={old:.2f}s 操作={action} n={n} median={median:.2f}s p90={p90:.2f}s")
except Exception:
# 不要抛出异常影响主流程
self.fudai_find_max_attempts = int(config.get("fudai_find_max_attempts", self.fudai_find_max_attempts) or self.fudai_find_max_attempts)
except (TypeError, ValueError):
pass
if self.fudai_find_max_attempts < 1:
self.fudai_find_max_attempts = 1
if self.fudai_find_max_attempts > 50:
self.fudai_find_max_attempts = 50
# 截图阶段诊断(OCR)节流
try:
@@ -680,6 +640,18 @@ class fudai_analyse:
self.reservation_back_verify_enabled = bool(config.get("reservation_back_verify_enabled", True))
except Exception:
self.reservation_back_verify_enabled = True
try:
self.reservation_preempt_min_value_yuan = float(config.get("reservation_preempt_min_value_yuan", self.reservation_preempt_min_value_yuan) or self.reservation_preempt_min_value_yuan)
except (TypeError, ValueError):
pass
if self.reservation_preempt_min_value_yuan < 0:
self.reservation_preempt_min_value_yuan = 0.0
try:
self.poll_before_open_seconds = int(config.get("poll_before_open_seconds", self.poll_before_open_seconds) or self.poll_before_open_seconds)
except (TypeError, ValueError):
pass
if self.poll_before_open_seconds < 0:
self.poll_before_open_seconds = 0
try:
self.high_value_room_revisit_interval_seconds = float(
config.get("high_value_room_revisit_interval_seconds", self.high_value_room_revisit_interval_seconds)
@@ -913,63 +885,6 @@ class fudai_analyse:
except Exception:
self._enter_live_reason = ""
self._enter_live_fudai_logged = False
# 每次进入直播间时重置检测起始时间,确保统计仅基于当前直播间的检测
try:
self._fudai_detect_start_ts = float(time.time())
except Exception:
try:
self._fudai_detect_start_ts = time.time()
except Exception:
pass
# 当自适应开关开启时,尝试基于历史日志(仅当前直播间的检测成功记录)计算建议值
try:
if getattr(self, 'fudai_icon_adaptive_enabled', False):
cur_reason = str(getattr(self, '_enter_live_reason', '') or '')
hist_path = os.path.join(os.path.dirname(__file__), "logs", "unified.log")
if os.path.exists(hist_path):
try:
with open(hist_path, 'r', encoding='utf-8', errors='ignore') as hf:
data = hf.read()
except Exception:
data = ''
if data:
# 只匹配检测到福袋的记录(检测阶段),并提取 seconds、fudai_x、enter_reason
pair_matches = re.findall(r"进入直播间检测到福袋耗时[\s\S]{0,300}?字段_seconds=([0-9]+(?:\.[0-9]+)?)[\s\S]{0,300}?字段_fudai_x=(\d+)[\s\S]{0,300}?字段_enter_reason=([^\n\r]+)", data)
vals = []
for sec_str, fudai_x, er in pair_matches:
try:
er = str(er).strip()
# 仅使用与当前直播间 enter_reason 完全相同的记录
if cur_reason and (er != cur_reason):
continue
if int(fudai_x) > 0:
vals.append(float(sec_str))
except Exception:
pass
if vals:
recent = vals[-50:]
recent_sorted = sorted(recent)
n = len(recent_sorted)
if n % 2 == 1:
median = recent_sorted[n // 2]
else:
median = (recent_sorted[n // 2 - 1] + recent_sorted[n // 2]) / 2.0
idx90 = int(math.ceil(0.9 * (n - 1)))
p90 = recent_sorted[min(idx90, n - 1)]
adaptive = min(30.0, max(2.0, float(p90) + 1.0))
old = float(getattr(self, 'fudai_icon_max_wait_seconds', 4.0) or 4.0)
action = 'keep'
if adaptive < old:
try:
self.fudai_icon_max_wait_seconds = adaptive
action = 'shorten'
except Exception:
pass
print(f"[自适应][当前房间] 建议 fudai_icon_max_wait_seconds={adaptive:.2f}s 当前={old:.2f}s 操作={action} n={n} median={median:.2f}s p90={p90:.2f}s enter_reason='{cur_reason}'")
else:
print(f"[自适应][当前房间] 未找到匹配记录,enter_reason='{cur_reason}' 无历史检测成功数据用于自适应")
except Exception:
pass
def _in_quiet_hours(self, hour: int) -> bool:
"""判断当前小时是否处于禁抢时段(支持跨天区间)。"""
@@ -1695,18 +1610,14 @@ class fudai_analyse:
if max_wait_s < 0:
max_wait_s = 0.0
max_loops = int(max(2, min(12, (max_wait_s / retry_delay_s) + 1)))
# 记录本次寻找福袋的起始时间(用于衡量“从首次开始判断到打开详情页”的耗时)
try:
if not getattr(self, '_fudai_detect_start_ts', 0.0):
self._fudai_detect_start_ts = time.time()
user_max = int(getattr(self, 'fudai_find_max_attempts', 5) or 5)
except Exception:
try:
self._fudai_detect_start_ts = time.time()
except Exception:
pass
user_max = 5
# 限制实际循环次数为两者的最小值,便于通过 UI 控制最大尝试次数
max_loops = int(min(max_loops, max(1, user_max)))
start_time = time.time()
while (time.time() - start_time) < max_wait_s and loop < max_loops:
while loop < max_loops:
# 首轮可复用外层已截图;未命中才继续短等+重试
if not (screenshot_ready and loop == 0):
# 找福袋是高频路径:默认关闭 OCR 阶段诊断(使用缓存阶段信息),减少耗时
@@ -1769,35 +1680,6 @@ class fudai_analyse:
if detected:
# 额外兜底:防止‘开奖结果’弹窗被错当作福袋图标(例如弹窗区域颜色/像素相近)
try:
# 记录从首次开始判定到本次成功识别(检测到福袋图标)的耗时,便于核验自适应使用的数据
try:
start_ts = float(getattr(self, '_fudai_detect_start_ts', 0.0) or 0.0)
except Exception:
start_ts = 0.0
if start_ts > 0:
try:
detect_dt = float(time.time() - start_ts)
except Exception:
detect_dt = -1.0
if detect_dt >= 0:
try:
print("[性能] 识别到福袋耗时(检测):{:.2f} 秒 fudai_x={}".format(round(detect_dt, 2), int(detected_x or 0)))
except Exception:
pass
try:
enter_reason = str(getattr(self, "_enter_live_reason", "") or "")
except Exception:
enter_reason = ""
try:
self._log_kv(
"性能",
"进入直播间检测到福袋耗时",
seconds=round(detect_dt, 2),
fudai_x=int(detected_x or 0),
enter_reason=enter_reason,
)
except Exception:
pass
# 轻量 OCR 诊断:仅识别结果弹窗区域的文字
self.cut_pic(350, 655, 740, 755, '', 'diag_result')
diag_txt = str(self.operation.analyse_pic_word('diag_result') or "")
@@ -1807,8 +1689,40 @@ class fudai_analyse:
except Exception:
# 若诊断失败则继续按原逻辑处理
pass
# 不在此处打印耗时统计;耗时定义为从首次开始判断到成功打开详情页,
# 将在成功打开详情页后统一记录(以避免重复或不准)。
# 统计:每次“进入直播间”后首次找到福袋图标耗时
try:
enter_ts = float(getattr(self, "_enter_live_ts", 0.0) or 0.0)
except Exception:
enter_ts = 0.0
try:
already = bool(getattr(self, "_enter_live_fudai_logged", False))
except Exception:
already = False
if (enter_ts > 0) and (not already):
try:
dt = float(time.time() - enter_ts)
except Exception:
dt = -1.0
if dt >= 0:
try:
reason = str(getattr(self, "_enter_live_reason", "") or "")
except Exception:
reason = ""
self._enter_live_fudai_logged = True
try:
print("[性能] 进入直播间到识别福袋耗时:{:.2f} 秒 进入原因={}".format(round(dt, 2), reason))
except Exception:
pass
try:
self._log_kv(
"性能",
"进入直播间后找到福袋耗时",
seconds=round(dt, 2),
enter_reason=reason,
fudai_x=int(detected_x or 0),
)
except Exception:
pass
return int(detected_x or 0)
loop += 1
if loop >= 4:
@@ -2755,10 +2669,25 @@ class fudai_analyse:
revisit_forced_x = None # 回访过程中如果已确认该直播间存在福袋,则把 x 提前算好供后续流程复用
# 回退速度参数:每次回退滑动后的等待(秒)。值越小越快,但过小可能导致 UI 未稳定。
# 行为:当启用回退校验时使用较慢的默认值(保持兼容);否则使用可配置的“快速回退”值以加快速度。
try:
reservation_back_swipe_delay_s = float(getattr(self, "reservation_back_swipe_delay_seconds", 1.2) or 1.2)
verify_delay = float(getattr(self, "reservation_back_swipe_delay_seconds", 1.2) or 1.2)
except Exception:
reservation_back_swipe_delay_s = 1.2
verify_delay = 1.2
try:
fast_delay = getattr(self, "reservation_back_swipe_delay_fast_seconds", None)
if fast_delay is not None:
fast_delay = float(fast_delay)
except Exception:
fast_delay = None
# 选择:若启用了回退校验,保持原来的(较慢)延迟;否则使用用户配置的快速延迟(若未配置则回退到原始值)。
use_fast = not bool(getattr(self, "reservation_back_verify_enabled", False))
if use_fast and (fast_delay is not None):
reservation_back_swipe_delay_s = fast_delay
else:
reservation_back_swipe_delay_s = verify_delay
if reservation_back_swipe_delay_s < 0.4:
reservation_back_swipe_delay_s = 0.4
@@ -3571,37 +3500,6 @@ class fudai_analyse:
if not _ensure_fudai_detail_open(int(x2), quick=bool(quick)):
self._log_kv("预约", "回退校验失败:未能打开福袋详情", result="详情未打开")
return False
# 记录:从首次开始判断福袋到成功打开详情页的耗时(按用户定义)
try:
start_ts = float(getattr(self, '_fudai_detect_start_ts', 0.0) or 0.0)
except Exception:
start_ts = 0.0
try:
if start_ts > 0:
dt = float(time.time() - start_ts)
try:
reason = str(getattr(self, "_enter_live_reason", "") or "")
except Exception:
reason = ""
try:
print("[性能] 从首次判定到打开福袋详情耗时:{:.2f} 秒 进入原因={}".format(round(dt, 2), reason))
except Exception:
pass
try:
self._log_kv(
"性能",
"进入直播间后找到福袋耗时",
seconds=round(dt, 2),
enter_reason=reason,
fudai_x=int(x2 or 0),
)
except Exception:
pass
finally:
try:
self._fudai_detect_start_ts = 0.0
except Exception:
pass
# 详情页刚出现时可能仍在动画/加载,稍等再识别更稳定
self.operation.delay(0.6 if quick else 1.1)
detail2 = _read_fudai_detail_with_retries(int(x2))
@@ -4024,18 +3922,6 @@ class fudai_analyse:
nonlocal swipe_times, room_pos
self.swipe(760, 1600, 760, 800, 200)
print(msg)
# 切换直播间完成后,重置检测起点:从此处开始计时到点击福袋详情
try:
self._fudai_detect_start_ts = float(time.time())
except Exception:
try:
self._fudai_detect_start_ts = time.time()
except Exception:
pass
try:
self._log_kv("性能", "切换直播间-重置检测起点", ts=round(float(getattr(self, '_fudai_detect_start_ts', 0.0) or 0.0), 3), reason=str(msg or ""))
except Exception:
pass
swipe_times += 1
room_pos += 1
# 有预约队列时,不做“达到阈值后自动回到第一个直播间”的重置,避免破坏位置计数
@@ -4335,6 +4221,17 @@ class fudai_analyse:
est_back_times = min(est_back_times, max_back)
dynamic_ahead = float(max(ahead0, est_back_times * reservation_back_swipe_delay_s + 18))
# 若预约价值低于最低抢占阈值,则不抢占当前正在执行的任务
try:
pv = float(target.get("prize_value_yuan") or 0.0)
except Exception:
pv = 0.0
try:
minv = float(getattr(self, "reservation_preempt_min_value_yuan", 0.0) or 0.0)
except Exception:
minv = 0.0
if pv < minv:
return False
return time.time() >= (future_ts - dynamic_ahead)
def swipe_down_back(times: int, reason: str) -> None:
@@ -4524,6 +4421,31 @@ class fudai_analyse:
# 卡死自救(不改变主流程;仅在疑似冻结时按一次返回)
_stuck_guard_tick()
# 清理已到期的预约:若预约的开奖时间已到或已过去,立即删除该预约并写状态(不再等待)
try:
if reservations:
now_ts_drop = time.time()
dropped = 0
for r in list(reservations):
try:
ft = float(r.get("future_ts") or 0.0)
except Exception:
ft = 0.0
if ft > 0 and now_ts_drop >= ft:
try:
reservations.remove(r)
except Exception:
try:
reservations.pop()
except Exception:
pass
dropped += 1
if dropped:
self._log_kv("预约", "到期删除过期预约", dropped=dropped, qsize=len(reservations))
_write_reservations_state("drop_expired_by_time")
except Exception:
pass
# 入口门禁:先截图判断是否处于直播间;若不在直播间则先进入直播间,再开始判断福袋。
try:
# 只截图一次,用这张截图做阶段判断
@@ -5260,60 +5182,94 @@ class fudai_analyse:
# 等待开奖结果:可中断(预约窗口到达时立刻抢占)
total_wait_s = max(0.0, float(lastsecond) + 5.0)
waited_s = 0.0
step_s = 1.5
preempted_by_reservation = False
# 记录参与点击时间,用于诊断参与->开奖识别耗时
t_participate = time.time()
draw_ts = t_participate + total_wait_s
detect_attempts = 0
first_detect_ts = None
# 倒计时打印控制(最后3秒的可视倒计时)
last_countdown_print = None
while True:
# 在正式开始轮询结果前,先静默等待直到预计开奖前 poll_before_open_seconds 秒
try:
poll_advance = int(getattr(self, 'poll_before_open_seconds', 10) or 10)
except Exception:
poll_advance = 10
try:
start_poll_ts = float(future_timestamp) - float(poll_advance)
except Exception:
start_poll_ts = 0.0
# 标志:若在正式轮询前已即时检测到结果,则可跳过低频等待
skip_wait_due_to_initial_result = False
# 若开奖时间已到且已参与,则先做一次立即检测,避免继续等待丢失弹窗
initial_check_result = None
try:
if time.time() >= float(future_timestamp):
try:
self._shot_and_diagnose("等待开奖-立即检测", "参与后立即检测开奖", self.device_id, diagnose=False)
except Exception:
pass
try:
r0 = self.check_lucky_draw_result()
if r0 is not False:
detect_attempts += 1
first_detect_ts = time.time()
try:
self._log_kv("开奖识别耗时", elapsed_s=round(first_detect_ts - t_participate, 3), attempts=detect_attempts)
except Exception:
pass
initial_check_result = r0
# 标记:已即时检测到结果,跳过后续低频等待,直接进入结果处理
skip_wait_due_to_initial_result = True
except Exception:
pass
except Exception:
initial_check_result = None
# 若当前时间早于开始轮询时间,则先进入低频等待(可被预约抢占)
skip_wait_due_to_initial_result = False
if start_poll_ts > time.time():
try:
dt_to_start = int(max(0, start_poll_ts - time.time()))
except Exception:
dt_to_start = 0
try:
dt_strf = datetime.fromtimestamp(float(future_timestamp)).strftime('%Y-%m-%d %H:%M:%S')
except Exception:
dt_strf = str(future_timestamp)
self._log_kv("等待开奖", "预轮询等待", target_future=dt_strf, remain_to_join_window_s=dt_to_start)
# 以小片段睡眠,期间允许预约抢占
try:
while time.time() < start_poll_ts:
if (not reservation_after_action_pending) and _reservation_should_preempt():
preempted_by_reservation = True
self._log_kv("等待开奖被预约抢占", remain_wait_s=round(total_wait_s - waited_s, 1))
break
# 若之前已在 start_poll 前立即检测到结果,则跳过后续等待,进入处理
if skip_wait_due_to_initial_result:
break
to_sleep = min(1.0, start_poll_ts - time.time())
if to_sleep <= 0:
break
self.operation.delay(to_sleep)
except Exception:
pass
if not skip_wait_due_to_initial_result:
while waited_s < total_wait_s:
# 当当前正在处理预约(reservation_after_action_pending=True)时,
# 不允许其它预约抢占等待(避免在参与后判定延迟时被打断造成重复回退)。
if (not reservation_after_action_pending) and _reservation_should_preempt():
remain_wait_s = round(max(0.0, draw_ts - time.time()), 1)
remain_wait_s = round(total_wait_s - waited_s, 1)
self._log_kv("等待开奖被预约抢占", remain_wait_s=remain_wait_s)
preempted_by_reservation = True
break
remaining_before = max(0.0, draw_ts - time.time())
# 如果已经过了等待时间,退出循环
if remaining_before <= 0:
chunk = min(step_s, total_wait_s - waited_s)
if chunk <= 0:
break
# 仅在开奖前 5 秒开始进行诊断/结果识别(避免参与后立即开始大量 OCR)
if remaining_before > 5.0:
# 睡到接近 5s 点,避免因 chunk 导致超时或延迟
sleep_target = max(0.0, remaining_before - 5.0)
chunk = min(step_s, sleep_target)
if chunk <= 0:
# 若计算后为0则继续下一轮以尽快进入诊断阶段
self.operation.delay(0.05)
continue
self.operation.delay(chunk)
continue
# 若距离开奖小于等于3秒,则缩短轮询间隔并显示倒计时
if remaining_before <= 3.0 and remaining_before > 0:
chunk = min(0.15, remaining_before)
# 每秒打印一次倒计时(整数秒)
try:
sec_left = int(math.ceil(remaining_before))
if last_countdown_print is None or sec_left != last_countdown_print:
print(f"倒计时:{sec_left} 秒")
last_countdown_print = sec_left
except Exception:
pass
else:
chunk = min(step_s, remaining_before)
# 等待一小段时间后立刻检查是否出现结果弹窗,减少遗漏
self.operation.delay(chunk)
waited_s += chunk
try:
# 在距离开奖 <=5s 时开启阶段诊断(diagnose=True),否则保持轻量轮询以减少耗时
do_diagnose = (remaining_before <= 5.0)
self._shot_and_diagnose("等待开奖-轮询", "轮询是否已弹出结果", self.device_id, diagnose=do_diagnose)
# 快速截图诊断(不开启重 OCR),避免频繁 OCR 导致延迟
self._shot_and_diagnose("等待开奖-轮询", "轮询是否已弹出结果", self.device_id, diagnose=False)
except Exception:
pass
try:
@@ -5331,16 +5287,26 @@ class fudai_analyse:
break
except Exception:
pass
else:
# 跳过等待:已在开始轮询前通过即时检测拿到结果,后续使用 initial_check_result 处理
pass
if preempted_by_reservation:
# 预约优先:不等待弹窗/结果,回主循环立刻执行回退参与
continue
# 如果之前做过立即检测且有结果,或常规轮询检测到结果,统一在下面的循环里处理。
have_clicked_no_award = False
first_iter = True
while True:
detect_attempts += 1
t_iter = time.time()
check_result = self.check_lucky_draw_result()
try:
if first_iter and (initial_check_result is not None):
check_result = initial_check_result
else:
check_result = self.check_lucky_draw_result()
except Exception:
check_result = False
first_iter = False
if check_result is not False and first_detect_ts is None:
first_detect_ts = time.time()
elapsed = first_detect_ts - t_participate
@@ -5348,21 +5314,33 @@ class fudai_analyse:
self._log_kv("开奖识别耗时", elapsed_s=round(elapsed, 3), attempts=detect_attempts)
except Exception:
pass
print(f"[开奖诊断] 参与后首次检测到结果: elapsed={elapsed:.3f}s attempts={detect_attempts}")
try:
print(f"[开奖诊断] 参与后首次检测到结果: elapsed={elapsed:.3f}s attempts={detect_attempts}")
except Exception:
pass
if check_result is False: # 没有弹窗需要处理
break
elif check_result in (1, 2, 3): # 未中奖流程
self.click(540, 1270)
print("没有抽中,点击:我知道了,关闭弹窗")
self.operation.delay(3)
try:
self.click(540, 1270)
print("没有抽中,点击:我知道了,关闭弹窗")
self.operation.delay(3)
except Exception:
pass
have_clicked_no_award = True
if check_result == 2: # 处理特殊状态(领取并使用)
print("未中奖点击了优惠券‘领取并使用’按钮,点击外部关闭商品浏览弹窗")
self.click(x, 380) # 点击刚才打开福袋的上方位置
self.operation.delay(2)
try:
print("未中奖点击了优惠券‘领取并使用’按钮,点击外部关闭商品浏览弹窗")
self.click(x, 380) # 点击刚才打开福袋的上方位置
self.operation.delay(2)
except Exception:
pass
else: # 中奖流程(返回y坐标)
print("检测到中奖结果,执行领奖流程")
self.get_reward(check_result)
try:
print("检测到中奖结果,执行领奖流程")
self.get_reward(check_result)
except Exception:
pass
continue
if have_clicked_no_award: # 如果点击了没有中奖
# 若处于“回退到预约直播间后的停留窗口”,不进入养号;短暂停留即可
+20
View File
@@ -64,6 +64,9 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
p.add_argument("--high-value-room-revisit-only-current-run", action="store_true", help="仅回访本次运行记录的高价值直播间")
p.add_argument("--reservation-back-verify-enabled", action="store_true", help="启用回退后预约校验(默认启用)")
p.add_argument("--reservation-back-verify-disabled", action="store_true", help="禁用回退后预约校验")
p.add_argument("--reservation-back-swipe-delay", type=float, default=None, help="运行时覆盖:回退后滑动等待(秒),仅在未启用回退校验时生效,可加快回退速度")
p.add_argument("--reservation-preempt-min-value", type=float, default=None, help="运行时覆盖:预约抢占最小价值(元),低于该值的预约不会抢占当前任务")
p.add_argument("--fudai-find-max-attempts", type=int, default=None, help="运行时覆盖:找福袋图标最多尝试次数(整数)")
# 按需求:删除“自动养号/随机等待/轻微扰动”等参数,仅保留“推荐页养号流程”。
# 推荐页养号的动作/概率/阈值等由 config.json 控制(GUI 会保存)。
@@ -194,6 +197,23 @@ def main(argv: list[str]) -> int:
analyser.reservation_back_verify_enabled = True
if getattr(args, "reservation_back_verify_disabled", False):
analyser.reservation_back_verify_enabled = False
# 运行时覆盖:回退后滑动等待(快速值,仅在未启用回退校验时使用)
if getattr(args, "reservation_back_swipe_delay", None) is not None:
try:
analyser.reservation_back_swipe_delay_fast_seconds = float(args.reservation_back_swipe_delay)
except Exception:
pass
if getattr(args, "reservation_preempt_min_value", None) is not None:
try:
analyser.reservation_preempt_min_value_yuan = max(0.0, float(args.reservation_preempt_min_value))
except Exception:
pass
# 运行时覆盖:找福袋最大尝试次数
if getattr(args, "fudai_find_max_attempts", None) is not None:
try:
analyser.fudai_find_max_attempts = max(1, int(args.fudai_find_max_attempts))
except Exception:
pass
device_id = args.device_id.strip() if args.device_id else ""
if not device_id:
+218 -56
View File
@@ -1,8 +1,224 @@
{
"updated_ts": 1765793514.5361085,
"updated_ts": 1765801533.9487214,
"reason": "reservation",
"total": 22,
"total": 32,
"rooms": [
{
"first_seen_ts": 1765801533.9487214,
"last_seen_ts": 1765801533.9487214,
"seen_count": 1,
"pos_seen": 3,
"pos_updated_ts": 1765801533.9487214,
"room_title_raw_last": "帝克5中年快乐",
"alias_raw": [
"帝克5中年快乐"
],
"key_kind": "norm",
"last_content": "小米红米/redmi14C智能手机",
"last_prize_value_yuan": 899.0,
"max_prize_value_yuan": 899.0,
"room_title": "帝克5中年快乐"
},
{
"first_seen_ts": 1765797819.8754272,
"last_seen_ts": 1765801497.4218397,
"seen_count": 5,
"pos_seen": 2,
"pos_updated_ts": 1765801497.4218397,
"room_title_raw_last": "李亚鹏今...",
"alias_raw": [
"李亚鹏今..."
],
"key_kind": "norm",
"last_content": "【粉丝专属】福联想平板电脑10.1英寸大屏护眼学习娱.",
"last_prize_value_yuan": 1999.0,
"max_prize_value_yuan": 1999.0,
"room_title": "李亚鹏今"
},
{
"first_seen_ts": 1765768936.3513777,
"last_seen_ts": 1765801460.0205128,
"seen_count": 6,
"pos_seen": 1,
"pos_updated_ts": 1765801460.0205128,
"room_title_raw_last": "彩虹夫妇..道天团",
"alias_raw": [
"彩虹夫妇..道天团",
"彩虹夫妇?道天团",
"彩虹夫妇道天团",
"彩虹夫妇",
"彩虹夫妇.",
"彩虹夫妇直天团"
],
"key_kind": "norm",
"last_content": "【彩虹夫妇专属】适用于苹/果17256颜色随机",
"last_prize_value_yuan": 6999.0,
"max_prize_value_yuan": 6999.0,
"alias_norm": [
"彩虹夫妇道天团",
"彩虹夫妇"
],
"merged_from_last": "彩虹夫妇道天团",
"merged_ratio_last": 0.8571428571428571,
"room_title": "彩虹夫妇直天团"
},
{
"first_seen_ts": 1765801075.5843241,
"last_seen_ts": 1765801420.922197,
"seen_count": 2,
"pos_seen": 0,
"pos_updated_ts": 1765801420.922197,
"room_title_raw_last": "值天团",
"alias_raw": [
"值天团"
],
"key_kind": "norm",
"last_content": "【云上珠宝专属】iPhone17256GB颜色随机发",
"last_prize_value_yuan": 5999.0,
"max_prize_value_yuan": 5999.0,
"room_title": "值天团"
},
{
"first_seen_ts": 1765772560.378592,
"last_seen_ts": 1765801363.3825512,
"seen_count": 11,
"pos_seen": 0,
"pos_updated_ts": 1765801363.3825512,
"room_title_raw_last": "彩虹夫妇...",
"alias_raw": [
"彩虹夫妇...",
"彩虹夫妇.2道天团1291.",
"彩虹夫妇..2道天团",
"彩虹夫妇..?",
"彩虹夫妇.2馄直天团987.万",
"彩虹夫妇..",
"彩虹夫妇"
],
"key_kind": "norm",
"last_content": "【彩虹夫妇专属】适用于苹/果17256颜色随机",
"last_prize_value_yuan": 6999.0,
"max_prize_value_yuan": 6999.0,
"room_title": "彩虹夫妇",
"alias_norm": [
"彩虹夫妇2道天团1291",
"彩虹夫妇2道天团",
"彩虹夫妇2馄直天团987万"
],
"merged_from_last": "彩虹夫妇2道天团1291",
"merged_ratio_last": 0.86
},
{
"first_seen_ts": 1765801208.2099712,
"last_seen_ts": 1765801208.2099712,
"seen_count": 1,
"pos_seen": 3,
"pos_updated_ts": 1765801208.2099712,
"room_title_raw_last": "帝克5惠任年快乐24",
"alias_raw": [
"帝克5惠任年快乐24"
],
"key_kind": "norm",
"last_content": "小米红米/redmi14C智能手机",
"last_prize_value_yuan": 899.0,
"max_prize_value_yuan": 899.0,
"room_title": "帝克5惠任年快乐24"
},
{
"first_seen_ts": 1765800850.9807138,
"last_seen_ts": 1765800850.9807138,
"seen_count": 1,
"pos_seen": 2,
"pos_updated_ts": 1765800850.9807138,
"room_title_raw_last": "米叨叻",
"alias_raw": [
"米叨叻"
],
"key_kind": "norm",
"last_content": "【空气炸锅】多功能家用烤箱大容量全自动电烤箱空",
"last_prize_value_yuan": 599.0,
"max_prize_value_yuan": 599.0,
"room_title": "米叨叻"
},
{
"first_seen_ts": 1765800214.4004803,
"last_seen_ts": 1765800214.4004803,
"seen_count": 1,
"pos_seen": 10,
"pos_updated_ts": 1765800214.4004803,
"room_title_raw_last": "左家皮具",
"alias_raw": [
"左家皮具"
],
"key_kind": "norm",
"last_content": "【粉丝专属小黄钞一夜暴富创意礼品",
"last_prize_value_yuan": 1299.0,
"max_prize_value_yuan": 1299.0,
"room_title": "左家皮具"
},
{
"first_seen_ts": 1765797952.1912286,
"last_seen_ts": 1765799968.679657,
"seen_count": 3,
"pos_seen": 1,
"pos_updated_ts": 1765799968.679657,
"room_title_raw_last": "米叻叻",
"alias_raw": [
"米叻叻"
],
"key_kind": "norm",
"last_content": "【空气炸锅】多功能家用烤箱大容量全自动电烤箱空",
"last_prize_value_yuan": 599.0,
"max_prize_value_yuan": 599.0,
"room_title": "米叻叻"
},
{
"first_seen_ts": 1765799932.458368,
"last_seen_ts": 1765799932.458368,
"seen_count": 1,
"pos_seen": 0,
"pos_updated_ts": 1765799932.458368,
"room_title_raw_last": "小明正能..",
"alias_raw": [
"小明正能.."
],
"key_kind": "norm",
"last_content": "半只羊肉礼盒10斤装2",
"last_prize_value_yuan": 599.0,
"max_prize_value_yuan": 599.0,
"room_title": "小明正能"
},
{
"first_seen_ts": 1765799022.2357109,
"last_seen_ts": 1765799022.2357109,
"seen_count": 1,
"pos_seen": 0,
"pos_updated_ts": 1765799022.2357109,
"room_title_raw_last": "作业帮数商城毛欧季",
"alias_raw": [
"作业帮数商城毛欧季"
],
"key_kind": "norm",
"last_content": "【粉丝专属】联想平板电脑福10.1英寸大屏护眼学习娱.",
"last_prize_value_yuan": 1999.0,
"max_prize_value_yuan": 1999.0,
"room_title": "作业帮数商城毛欧季"
},
{
"first_seen_ts": 1765796883.4779012,
"last_seen_ts": 1765796883.4779012,
"seen_count": 1,
"pos_seen": 0,
"pos_updated_ts": 1765796883.4779012,
"room_title_raw_last": "糖果家居",
"alias_raw": [
"糖果家居"
],
"key_kind": "norm",
"last_content": "口红口红口红口红口红口红口红V",
"last_prize_value_yuan": 799.0,
"max_prize_value_yuan": 799.0,
"room_title": "糖果家居"
},
{
"first_seen_ts": 1765787027.4476137,
"last_seen_ts": 1765793514.5361085,
@@ -183,34 +399,6 @@
"max_prize_value_yuan": 5999.0,
"room_title": "云上珠宝"
},
{
"first_seen_ts": 1765772560.378592,
"last_seen_ts": 1765786243.9525945,
"seen_count": 10,
"pos_seen": 1,
"pos_updated_ts": 1765786243.9525945,
"room_title_raw_last": "彩虹夫妇.2道天团1291.",
"alias_raw": [
"彩虹夫妇.2道天团1291.",
"彩虹夫妇..2道天团",
"彩虹夫妇..?",
"彩虹夫妇.2馄直天团987.万",
"彩虹夫妇..",
"彩虹夫妇"
],
"key_kind": "norm",
"last_content": "【彩虹夫妇专属】适用于苹/果17256颜色随机",
"last_prize_value_yuan": 6999.0,
"max_prize_value_yuan": 6999.0,
"room_title": "彩虹夫妇",
"alias_norm": [
"彩虹夫妇2道天团1291",
"彩虹夫妇2道天团",
"彩虹夫妇2馄直天团987万"
],
"merged_from_last": "彩虹夫妇2道天团1291",
"merged_ratio_last": 0.86
},
{
"first_seen_ts": 1765777832.5013368,
"last_seen_ts": 1765782102.7063458,
@@ -255,32 +443,6 @@
"max_prize_value_yuan": 5999.0,
"room_title": "多余和毛优质主播"
},
{
"first_seen_ts": 1765768936.3513777,
"last_seen_ts": 1765778794.3641992,
"seen_count": 5,
"pos_seen": 1,
"pos_updated_ts": 1765778794.3641992,
"room_title_raw_last": "彩虹夫妇直天团",
"alias_raw": [
"彩虹夫妇?道天团",
"彩虹夫妇道天团",
"彩虹夫妇",
"彩虹夫妇.",
"彩虹夫妇直天团"
],
"key_kind": "norm",
"last_content": "【彩虹夫妇专属】适用于苹/果17256颜色随机",
"last_prize_value_yuan": 0.0,
"max_prize_value_yuan": 6999.0,
"alias_norm": [
"彩虹夫妇道天团",
"彩虹夫妇"
],
"merged_from_last": "彩虹夫妇",
"merged_ratio_last": 0.86,
"room_title": "彩虹夫妇直天团"
},
{
"first_seen_ts": 1765772163.6234417,
"last_seen_ts": 1765776050.9045503,
+21 -12
View File
@@ -1,18 +1,27 @@
{
"updated_ts": 1765793514.5326908,
"reason": "add",
"room_pos": 0,
"current_room_title": "三火孙",
"current_room_title_raw": "三火孙...",
"updated_ts": 1765801656.3584177,
"reason": "pop_for_attend",
"room_pos": 3,
"current_room_title": "帝克5中年快乐",
"current_room_title_raw": "帝克5中年快乐",
"reservations": [
{
"prize_value_yuan": 1699.0,
"content": "【三火专属】新国标成人代步男女自行电车通用休闲.",
"future_ts": 1765794311.943616,
"future_str": "2025-12-15 18:25:11",
"pos_seen": 0,
"room_title": "三火孙",
"room_title_raw": "三火孙..."
"prize_value_yuan": 6999.0,
"content": "【彩虹夫妇专属】适用于苹/果17256颜色随机",
"future_ts": 1765802011.100544,
"future_str": "2025-12-15 20:33:31",
"pos_seen": 1,
"room_title": "彩虹夫妇道天团",
"room_title_raw": "彩虹夫妇..道天团"
},
{
"prize_value_yuan": 899.0,
"content": "小米红米/redmi14C智能手机",
"future_ts": 1765802295.628174,
"future_str": "2025-12-15 20:38:15",
"pos_seen": 3,
"room_title": "帝克5中年快乐",
"room_title_raw": "帝克5中年快乐"
}
]
}
+21
View File
@@ -717,6 +717,27 @@ class ProcRunner:
cmd.append("--reservation-back-verify-enabled")
else:
cmd.append("--reservation-back-verify-disabled")
# 回退回滑快速延迟(可由 Run 面板设置):仅在未启用回退校验时生效
try:
rbd = float(_pick("reservation_back_swipe_delay", 0) or 0)
except Exception:
rbd = 0.0
if rbd > 0:
cmd += ["--reservation-back-swipe-delay", str(rbd)]
# 预约抢占最小价值(GUI 启动时可覆盖)
try:
rpmin = float(_pick("reservation_preempt_min_value", 0) or 0)
except Exception:
rpmin = 0.0
if rpmin > 0:
cmd += ["--reservation-preempt-min-value", str(rpmin)]
# 找福袋最大尝试次数(GUI 启动时可覆盖)
try:
fudai_find_max_attempts = int(_pick("fudai_find_max_attempts", 0) or 0)
except Exception:
fudai_find_max_attempts = 0
if fudai_find_max_attempts > 0:
cmd += ["--fudai-find-max-attempts", str(fudai_find_max_attempts)]
self._start_process(cmd)
+6 -5
View File
@@ -40,14 +40,14 @@ const DEFAULTS = {
high_value_room_revisit_enabled: true,
high_value_room_revisit_only_current_run: false,
reservation_back_verify_enabled: true,
fudai_find_max_attempts: 5,
reservation_preempt_min_value: 0,
reservation_back_swipe_delay: 0.6,
// 定时禁抢福袋(默认 2-7 点)
fudai_quiet_hours_enabled: true,
fudai_quiet_start_hour: 2,
fudai_quiet_end_hour: 7,
// 福袋图标检测等待参数(可调)
fudai_icon_max_wait_seconds: 3.0,
fudai_icon_adaptive_enabled: false,
};
function $(id) { return document.getElementById(id); }
@@ -525,8 +525,9 @@ async function startRun() {
high_value_room_revisit_enabled: cfgPart.high_value_room_revisit_enabled,
high_value_room_revisit_only_current_run: cfgPart.high_value_room_revisit_only_current_run,
reservation_back_verify_enabled: cfgPart.reservation_back_verify_enabled,
fudai_icon_max_wait_seconds: cfgPart.fudai_icon_max_wait_seconds,
fudai_icon_adaptive_enabled: cfgPart.fudai_icon_adaptive_enabled,
reservation_back_swipe_delay: cfgPart.reservation_back_swipe_delay,
fudai_find_max_attempts: cfgPart.fudai_find_max_attempts,
reservation_preempt_min_value: cfgPart.reservation_preempt_min_value,
});
appendLog([`[WEB] 已开始运行:device=${deviceId || '(auto)'}`]);
}
+14 -13
View File
@@ -131,19 +131,15 @@
<input id="reset_after_swipes" class="input" data-key="reset_after_swipes" data-type="int" type="number" min="1" step="1" />
<div class="hint">用于需要循环切换时的回退阈值;配合上方开关启用</div>
</div>
<div class="row grid2">
<div>
<label class="label">福袋图标等待最大秒数</label>
<input id="fudai_icon_max_wait_seconds" class="input" data-key="fudai_icon_max_wait_seconds" data-type="float" type="number" min="0" step="0.1" />
<div class="hint">默认 4.0 秒;自适应可缩短该等待时间</div>
</div>
<div>
<label class="label">启用自适应等待时间</label>
<label class="check">
<input id="fudai_icon_adaptive_enabled" type="checkbox" data-key="fudai_icon_adaptive_enabled" data-type="bool" />
<span>启用</span>
</label>
</div>
<div class="row">
<label class="label">找福袋最大尝试次数</label>
<input id="fudai_find_max_attempts" class="input" data-key="fudai_find_max_attempts" data-type="int" type="number" min="1" max="50" step="1" />
<div class="hint">找小福袋图标时的最大重试次数,默认 5</div>
</div>
<div class="row">
<label class="label">预约抢占最小价值(元)</label>
<input id="reservation_preempt_min_value" class="input" data-key="reservation_preempt_min_value" data-type="float" type="number" min="0" step="1" />
<div class="hint">低于该价值的预约不会抢占当前任务;0 表示任何预约可抢占</div>
</div>
</div>
@@ -247,6 +243,11 @@
<span>启用回退校验</span>
</label>
</div>
<div class="row">
<label class="label">回退回滑快速延迟(秒,未启用回退校验时生效)</label>
<input id="reservation_back_swipe_delay" class="input" data-key="reservation_back_swipe_delay" data-type="float" type="number" min="0.2" step="0.1" />
<div class="hint">较小值能加快回退速度;当启用回退校验时仍使用兼容的较慢延迟。</div>
</div>
<div class="sectionTitle">定时禁抢(仅养号)</div>
<div class="row">