From e21e5a5fcaf2e7325071d25f85720dbe3dfcb067 Mon Sep 17 00:00:00 2001 From: Codex Date: Fri, 22 May 2026 11:37:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor(fudai):=20=E6=8A=BD=20run=5Fonce=5Fbas?= =?UTF-8?q?ic=20=E4=B8=AD"=E7=AC=AC=E4=B8=80=E4=B8=AA=E9=A2=84=E7=BA=A6?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=97=A5=E5=BF=97"=E5=9D=97=E5=88=B0=20log?= =?UTF-8?q?=5Ffirst=5Freservation=5Fcheck?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将 40 行的纯日志块抽到 fudai_detail_helpers.log_first_reservation_check。 输出 needswitch 配置 + 队列长度 + 第一个预约的详细信息(future_ts、 剩余秒数、目标位置等)。 douyin_fudai.py: 2503 → 2468 行 (-35) fudai_detail_helpers.py: 1266 → 1311 行 验证: - pytest 1013 passed - compile OK Co-Authored-By: Claude Opus 4.7 (1M context) --- douyin/core/douyin_fudai.py | 43 ++---------------- .../fudai_modules/fudai_detail_helpers.py | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+), 39 deletions(-) diff --git a/douyin/core/douyin_fudai.py b/douyin/core/douyin_fudai.py index 1937435..441e253 100644 --- a/douyin/core/douyin_fudai.py +++ b/douyin/core/douyin_fudai.py @@ -888,46 +888,11 @@ class fudai_analyse: needswitch_cfg = True # 添加详细的调试日志,确认 needswitch 的值和预约信息 - try: - # 输出第一个预约的详细信息 - first_reservation_info = {} - if self.reservations and len(self.reservations) > 0: - first_r = self.reservations[0] - try: - ft = float(first_r.get("future_ts") or 0) - from datetime import datetime + from douyin.core.fudai_modules.fudai_detail_helpers import ( + log_first_reservation_check, + ) - now_ts = time.time() - ft_str = ( - datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") - if ft > 0 - else "无效" - ) - remain_seconds = int(ft - now_ts) if ft > 0 else 0 - first_reservation_info = { - "future_ts": int(ft) if ft > 0 else 0, - "future_str": ft_str, - "value": float(first_r.get("prize_value_yuan", 0)), - "pos_seen": int(first_r.get("pos_seen", 0)), - "remain_seconds": remain_seconds, - "current_room_pos": int( - getattr(self, "room_pos", 0) or 0 - ), - } - except Exception: - pass - - self._log_kv( - "预约", - "[预约] run_once_basic:检查预约回退条件", - needswitch_cfg=needswitch_cfg, - reservations_count=( - len(self.reservations) if self.reservations else 0 - ), - first_reservation=first_reservation_info, - ) - except Exception: - pass + log_first_reservation_check(self, needswitch_cfg) if needswitch_cfg: # 多间模式:需要回退到预约直播间 diff --git a/douyin/core/fudai_modules/fudai_detail_helpers.py b/douyin/core/fudai_modules/fudai_detail_helpers.py index d659bc6..483019b 100644 --- a/douyin/core/fudai_modules/fudai_detail_helpers.py +++ b/douyin/core/fudai_modules/fudai_detail_helpers.py @@ -42,6 +42,51 @@ def log_screenshot_failed( pass +def log_first_reservation_check(analyser, needswitch_cfg: bool) -> None: + """run_once_basic 步骤 0.1.3:记录第一个预约的检查日志(纯日志,无副作用)。 + + 输出当前 needswitch 配置 + 队列长度 + 第一个预约的详细信息(future_ts、 + 剩余秒数、目标位置等)。 + """ + try: + from datetime import datetime + + first_reservation_info = {} + if analyser.reservations and len(analyser.reservations) > 0: + first_r = analyser.reservations[0] + try: + ft = float(first_r.get("future_ts") or 0) + now_ts = time.time() + ft_str = ( + datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S") + if ft > 0 + else "无效" + ) + remain_seconds = int(ft - now_ts) if ft > 0 else 0 + first_reservation_info = { + "future_ts": int(ft) if ft > 0 else 0, + "future_str": ft_str, + "value": float(first_r.get("prize_value_yuan", 0)), + "pos_seen": int(first_r.get("pos_seen", 0)), + "remain_seconds": remain_seconds, + "current_room_pos": int(getattr(analyser, "room_pos", 0) or 0), + } + except Exception: + pass + + analyser._log_kv( + "预约", + "[预约] run_once_basic:检查预约回退条件", + needswitch_cfg=needswitch_cfg, + reservations_count=( + len(analyser.reservations) if analyser.reservations else 0 + ), + first_reservation=first_reservation_info, + ) + except Exception: + pass + + def log_reservation_check_status(analyser, high_value_enabled: bool) -> None: """run_once_basic 步骤 0.1.2:记录预约回退的触发条件日志(纯日志,无副作用)。