refactor: 优化倒计时逻辑,移除多余的时间修正,调整相关日志记录
This commit is contained in:
1 parent
d100ac0a66
commit
bffca95af0
7 files changed
+115
-47
No files matched your search
+1
-1
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"needswitch": true,
|
||||
"needswitch": false,
|
||||
"infinite_loop_enabled": true,
|
||||
"wait_minutes": 5,
|
||||
"min_prize_value_yuan": 200.0,
|
||||
|
||||
@@ -733,7 +733,11 @@ class fudai_analyse:
|
||||
# 检测到结果,清等待并处理
|
||||
self._waiting_for_lottery_result = False
|
||||
try:
|
||||
self._log_kv("参与", "等待期间检测到开奖结果,开始处理", attempt=attempt)
|
||||
self._log_kv(
|
||||
"参与",
|
||||
"等待期间检测到开奖结果,开始处理",
|
||||
attempt=attempt,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
self._handle_lottery_result_by_ocr(result)
|
||||
@@ -2079,10 +2083,17 @@ class fudai_analyse:
|
||||
try:
|
||||
# 从保存的 tuple 中安全读取倒计时信息,使用 cast 明确类型以帮助静态分析
|
||||
detail = getattr(self, "_last_fudai_detail_tuple", None)
|
||||
if detail is not None and isinstance(detail, tuple) and len(detail) >= 6:
|
||||
if (
|
||||
detail is not None
|
||||
and isinstance(detail, tuple)
|
||||
and len(detail) >= 6
|
||||
):
|
||||
# 使用解包避免索引告警
|
||||
_, _, _, _, _, countdown_tuple = detail
|
||||
if isinstance(countdown_tuple, (tuple, list)) and len(countdown_tuple) >= 2:
|
||||
if (
|
||||
isinstance(countdown_tuple, (tuple, list))
|
||||
and len(countdown_tuple) >= 2
|
||||
):
|
||||
future_ts = float(countdown_tuple[1] or 0.0)
|
||||
if future_ts > 0:
|
||||
# 设置当前福袋的 future_ts,供 attend_choujiang 使用
|
||||
@@ -2746,11 +2757,8 @@ class fudai_analyse:
|
||||
if remain_seconds > 0:
|
||||
# 设置等待开奖标志和预期开奖时间
|
||||
# 直接保存开奖时间戳,等待时直接用 future_timestamp - time.time() 计算剩余秒数
|
||||
# 提前13秒,修正倒计时误差
|
||||
self._waiting_for_lottery_result = True
|
||||
self._lottery_result_expected_ts = (
|
||||
future_timestamp - 13.0
|
||||
) # 提前13秒,修正倒计时误差
|
||||
self._lottery_result_expected_ts = future_timestamp
|
||||
|
||||
self._log_kv(
|
||||
"参与",
|
||||
|
||||
@@ -1,23 +1,8 @@
|
||||
{
|
||||
"updated_ts": 1767438731.9581015,
|
||||
"reason": "record_reservation",
|
||||
"room_pos": 6,
|
||||
"current_room_title": "作业帮数",
|
||||
"current_room_title_raw": "作业帮数",
|
||||
"reservations": [
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767439294.678569,
|
||||
"future_str": "2026-01-03 19:21:34",
|
||||
"pos_seen": 6,
|
||||
"room_title": "作业帮数",
|
||||
"room_title_raw": "作业帮数",
|
||||
"created_ts": 1767438731.950231,
|
||||
"task_count": 2,
|
||||
"time_text": "09:28",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
}
|
||||
]
|
||||
}
|
||||
"updated_ts": 1767440958.0048747,
|
||||
"reason": "startup_clear",
|
||||
"room_pos": 0,
|
||||
"current_room_title": "",
|
||||
"current_room_title_raw": "",
|
||||
"reservations": []
|
||||
}
|
||||
@@ -133,9 +133,9 @@ def attend_choujiang(analyser) -> bool:
|
||||
current_time = time.time()
|
||||
remain_seconds = max(0, future_ts - current_time)
|
||||
if remain_seconds > 0:
|
||||
# 设置等待开奖标志和预期开奖时间(提前13秒,修正倒计时误差)
|
||||
# 设置等待开奖标志和预期开奖时间
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts - 13.0
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"参与成功,设置等待开奖标志",
|
||||
@@ -278,9 +278,8 @@ def attend_choujiang(analyser) -> bool:
|
||||
remain_seconds = int(future_ts - current_time)
|
||||
if remain_seconds > 0:
|
||||
# 设置等待开奖标志和预期开奖时间
|
||||
# 提前13秒,修正倒计时误差
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts - 13.0
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
|
||||
# #region agent log - countdown set
|
||||
with open(get_debug_log_path(), "a", encoding="utf-8") as f:
|
||||
|
||||
@@ -2215,9 +2215,9 @@ def attend_choujiang(analyser) -> bool:
|
||||
current_time = time.time()
|
||||
remain_seconds = max(0, future_ts - current_time)
|
||||
if remain_seconds > 0:
|
||||
# 设置等待开奖标志和预期开奖时间(提前13秒,修正倒计时误差)
|
||||
# 设置等待开奖标志和预期开奖时间
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts - 13.0
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"参与成功,设置等待开奖标志",
|
||||
@@ -2331,9 +2331,8 @@ def attend_choujiang(analyser) -> bool:
|
||||
remain_seconds = int(future_ts - current_time)
|
||||
if remain_seconds > 0:
|
||||
# 设置等待开奖标志和预期开奖时间
|
||||
# 提前13秒,修正倒计时误差
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts - 13.0
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
analyser._log_kv(
|
||||
"参与",
|
||||
"点击参与抽奖后,设置等待开奖标志",
|
||||
|
||||
@@ -725,7 +725,7 @@ class ReservationHandler:
|
||||
remain_seconds = max(0, future_ts - current_time)
|
||||
if remain_seconds > 0:
|
||||
analyser._waiting_for_lottery_result = True
|
||||
analyser._lottery_result_expected_ts = future_ts - 13.0
|
||||
analyser._lottery_result_expected_ts = future_ts
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 预约回退后参与成功,设置开奖等待状态",
|
||||
|
||||
+85
-8
@@ -2206,6 +2206,23 @@ def main():
|
||||
# 右侧:Notebook(日志 / 截图预览 / 统计信息 / 预约队列 / 高价值房间)
|
||||
notebook = ttk.Notebook(right)
|
||||
|
||||
# 实时状态工具栏(固定在 Notebook 上方,始终可见)
|
||||
show_actions_var = tk.BooleanVar(value=True)
|
||||
show_screenshot_var = tk.BooleanVar(value=False)
|
||||
auto_scroll_var = tk.BooleanVar(value=True)
|
||||
|
||||
realtime_tools = ttk.Frame(right)
|
||||
realtime_tools.pack(fill=X, padx=8, pady=(4, 0))
|
||||
ttk.Checkbutton(
|
||||
realtime_tools, text="显示动作流", variable=show_actions_var
|
||||
).pack(side=LEFT, padx=(0, 8))
|
||||
ttk.Checkbutton(
|
||||
realtime_tools, text="显示截图", variable=show_screenshot_var
|
||||
).pack(side=LEFT, padx=(0, 8))
|
||||
ttk.Checkbutton(
|
||||
realtime_tools, text="自动滚动", variable=auto_scroll_var
|
||||
).pack(side=LEFT, padx=(0, 8))
|
||||
|
||||
log_tab = ttk.Frame(notebook)
|
||||
preview_tab = ttk.Frame(notebook)
|
||||
stats_tab = ttk.Frame(notebook)
|
||||
@@ -2234,7 +2251,13 @@ def main():
|
||||
realtime_frame = ttk.Frame(realtime_tab)
|
||||
realtime_frame.pack(fill=BOTH, expand=True, padx=8, pady=8)
|
||||
|
||||
realtime_text = ScrolledText(realtime_frame, height=20)
|
||||
|
||||
|
||||
# 截图预览区域(根据选项显示/隐藏)
|
||||
image_label = ttk.Label(realtime_frame)
|
||||
image_label.pack(fill=X)
|
||||
|
||||
realtime_text = ScrolledText(realtime_frame, height=14)
|
||||
realtime_text.pack(fill=BOTH, expand=True)
|
||||
realtime_text.configure(state="disabled")
|
||||
|
||||
@@ -2309,14 +2332,68 @@ def main():
|
||||
|
||||
parsed = list(reversed(parsed))
|
||||
|
||||
realtime_text.configure(state="normal")
|
||||
realtime_text.delete("1.0", "end")
|
||||
if not parsed:
|
||||
realtime_text.insert("1.0", "暂无动作日志(仅显示包含“耗时”的行)")
|
||||
# 更新截图(若选中)
|
||||
if show_screenshot_var.get():
|
||||
try:
|
||||
try:
|
||||
from path_config import get_screenshot_path
|
||||
|
||||
screenshot_path = get_screenshot_path()
|
||||
except Exception:
|
||||
import path_config
|
||||
|
||||
screenshot_path = path_config.get_screenshot_path()
|
||||
|
||||
if os.path.exists(screenshot_path):
|
||||
img = Image.open(screenshot_path)
|
||||
# 缩放以适应宽度(保持纵横比),最大宽度 420
|
||||
max_w = 420
|
||||
w, h = img.size
|
||||
if w > max_w:
|
||||
nw = max_w
|
||||
nh = int(h * (nw / w))
|
||||
img = img.resize((nw, nh), Image.LANCZOS)
|
||||
tk_img = ImageTk.PhotoImage(img)
|
||||
image_label.configure(image=tk_img)
|
||||
image_label.image = tk_img
|
||||
image_label.pack(fill=X)
|
||||
else:
|
||||
image_label.configure(image="")
|
||||
image_label.image = None
|
||||
image_label.pack_forget()
|
||||
except Exception:
|
||||
image_label.configure(image="")
|
||||
image_label.image = None
|
||||
image_label.pack_forget()
|
||||
else:
|
||||
for action, dur in parsed:
|
||||
realtime_text.insert("end", f"{action} {dur}\n")
|
||||
realtime_text.configure(state="disabled")
|
||||
image_label.configure(image="")
|
||||
image_label.image = None
|
||||
image_label.pack_forget()
|
||||
|
||||
# 更新动作流文本(若选中)
|
||||
if show_actions_var.get():
|
||||
realtime_text.configure(state="normal")
|
||||
realtime_text.delete("1.0", "end")
|
||||
if not parsed:
|
||||
realtime_text.insert("1.0", "暂无动作日志(仅显示包含“耗时”的行)")
|
||||
else:
|
||||
for action, dur in parsed:
|
||||
realtime_text.insert("end", f"{action} {dur}\n")
|
||||
# 自动滚动
|
||||
if auto_scroll_var.get():
|
||||
try:
|
||||
realtime_text.see("end")
|
||||
except Exception:
|
||||
try:
|
||||
realtime_text.yview_moveto(1.0)
|
||||
except Exception:
|
||||
pass
|
||||
realtime_text.configure(state="disabled")
|
||||
else:
|
||||
# 隐藏文本内容但保留控件
|
||||
realtime_text.configure(state="normal")
|
||||
realtime_text.delete("1.0", "end")
|
||||
realtime_text.configure(state="disabled")
|
||||
|
||||
# 安排下一次刷新
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user