- Deleted obsolete markdown files related to follow tab coordinates testing and results. - Removed outdated batch scripts for launching the Web GUI. - Updated `config.json` to improve reservation handling and adjust prize value settings. - Enhanced logging and error handling in `web_gui.py` and `app.js` for better user experience. - Added automatic screenshot functionality during Web GUI startup for improved monitoring.
369 lines
10 KiB
Python
369 lines
10 KiB
Python
from __future__ import annotations
|
|
|
|
"""
|
|
Reservation core logic shim (WebGUI version)
|
|
===========================================
|
|
|
|
Exports:
|
|
- add_reservation_core_logic
|
|
- validate_back_to_reservation
|
|
- cleanup_expired_reservations
|
|
- process_reservation_attend_window
|
|
- record_high_value_reservation
|
|
"""
|
|
|
|
from typing import Any, Dict, List
|
|
import time
|
|
|
|
|
|
def add_reservation_core_logic(
|
|
reservations: List[Dict[str, Any]],
|
|
item: Dict[str, Any],
|
|
) -> None:
|
|
"""Shim: append item if not already present by basic key."""
|
|
key = (item.get("future_ts"), item.get("content"))
|
|
for r in reservations:
|
|
if (r.get("future_ts"), r.get("content")) == key:
|
|
return
|
|
reservations.append(dict(item))
|
|
|
|
|
|
def validate_back_to_reservation(
|
|
analyser: Any,
|
|
reservations: List[Dict[str, Any]],
|
|
now_ts: float | None = None,
|
|
) -> None:
|
|
"""兼容实现:记录当前预约队列状态,不做严格校验。"""
|
|
if now_ts is None:
|
|
now_ts = time.time()
|
|
try:
|
|
analyser._log_kv(
|
|
"预约",
|
|
"validate_back_to_reservation",
|
|
count=len(reservations),
|
|
now_ts=int(now_ts),
|
|
)
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
def cleanup_expired_reservations(
|
|
analyser: Any,
|
|
reservations: List[Dict[str, Any]],
|
|
write_state_callback,
|
|
) -> None:
|
|
"""兼容实现:清理已过开奖时间的预约,然后写入状态。"""
|
|
try:
|
|
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 and write_state_callback is not None:
|
|
try:
|
|
write_state_callback()
|
|
except Exception:
|
|
pass
|
|
except Exception:
|
|
# Best-effort cleanup only; never crash main loop
|
|
pass
|
|
|
|
|
|
def process_reservation_attend_window(
|
|
analyser: Any,
|
|
reservations: List[Dict[str, Any]],
|
|
room_pos: int,
|
|
reservation_focus_until_ts_ref: list,
|
|
reservation_after_action_pending_ref: list,
|
|
reservation_back_swipe_delay_s: float,
|
|
swipe_down_back_callback,
|
|
seek_reservation_room_callback,
|
|
sort_reservations_callback,
|
|
write_state_callback,
|
|
) -> bool:
|
|
"""兼容实现:匹配原始签名,仅记录预约窗口信息,不主动抢占主流程。"""
|
|
try:
|
|
analyser._log_kv(
|
|
"预约",
|
|
"process_reservation_attend_window",
|
|
count=len(reservations),
|
|
room_pos=room_pos,
|
|
)
|
|
except Exception:
|
|
pass
|
|
return False
|
|
|
|
|
|
def record_high_value_reservation(
|
|
analyser: Any,
|
|
fudai_content_text: str,
|
|
prize_value_yuan: float,
|
|
lastsecond: int,
|
|
future_timestamp: float,
|
|
x: int,
|
|
needswitch: bool,
|
|
wait_minutes: int,
|
|
post_switch_delay_s: float,
|
|
room_pos: int,
|
|
reservations: List[Dict[str, Any]],
|
|
reservation_focus_until_ts_ref: list,
|
|
close_detail_callback,
|
|
swipe_up_switch_callback,
|
|
swipe_down_back_callback,
|
|
add_reservation_callback,
|
|
sort_reservations_callback,
|
|
write_state_callback,
|
|
) -> bool:
|
|
"""兼容实现:按原始签名追加一条简化的高价值预约记录。"""
|
|
try:
|
|
item: Dict[str, Any] = {
|
|
"future_ts": float(future_timestamp or 0.0),
|
|
"prize_value_yuan": float(prize_value_yuan or 0.0),
|
|
"content": str(fudai_content_text or ""),
|
|
"pos_seen": int(room_pos),
|
|
"created_ts": time.time(),
|
|
}
|
|
add_reservation_core_logic(reservations, item)
|
|
analyser._log_kv(
|
|
"预约",
|
|
"record_high_value_reservation:已记录高价值福袋",
|
|
value=item["prize_value_yuan"],
|
|
future_ts=item["future_ts"],
|
|
)
|
|
except Exception:
|
|
pass
|
|
return False
|
|
|
|
|
|
|
|
"""
|
|
Reservation core logic shim (WebGUI version)
|
|
===========================================
|
|
|
|
Exports:
|
|
- add_reservation_core_logic
|
|
- validate_back_to_reservation
|
|
- cleanup_expired_reservations
|
|
- process_reservation_attend_window
|
|
- record_high_value_reservation
|
|
"""
|
|
|
|
from typing import Any, Dict, List
|
|
import time
|
|
|
|
|
|
def add_reservation_core_logic(
|
|
reservations: List[Dict[str, Any]],
|
|
item: Dict[str, Any],
|
|
) -> None:
|
|
"""Shim: append item if not already present by basic key."""
|
|
key = (item.get("future_ts"), item.get("content"))
|
|
for r in reservations:
|
|
if (r.get("future_ts"), r.get("content")) == key:
|
|
return
|
|
reservations.append(dict(item))
|
|
|
|
|
|
def validate_back_to_reservation(
|
|
analyser: Any,
|
|
reservations: List[Dict[str, Any]],
|
|
now_ts: float | None = None,
|
|
) -> None:
|
|
"""兼容实现:记录当前预约队列状态,不做严格校验。"""
|
|
if now_ts is None:
|
|
now_ts = time.time()
|
|
try:
|
|
analyser._log_kv(
|
|
"预约",
|
|
"validate_back_to_reservation",
|
|
count=len(reservations),
|
|
now_ts=int(now_ts),
|
|
)
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
def cleanup_expired_reservations(
|
|
analyser: Any,
|
|
reservations: List[Dict[str, Any]],
|
|
write_state_callback,
|
|
) -> None:
|
|
"""兼容实现:清理已过开奖时间的预约,然后写入状态。"""
|
|
try:
|
|
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 and write_state_callback is not None:
|
|
try:
|
|
write_state_callback()
|
|
except Exception:
|
|
pass
|
|
except Exception:
|
|
# Best-effort cleanup only; never crash main loop
|
|
pass
|
|
|
|
|
|
def process_reservation_attend_window(
|
|
analyser: Any,
|
|
reservations: List[Dict[str, Any]],
|
|
room_pos: int,
|
|
reservation_focus_until_ts_ref: list,
|
|
reservation_after_action_pending_ref: list,
|
|
reservation_back_swipe_delay_s: float,
|
|
swipe_down_back_callback,
|
|
seek_reservation_room_callback,
|
|
sort_reservations_callback,
|
|
write_state_callback,
|
|
) -> bool:
|
|
"""兼容实现:匹配原始签名,仅记录预约窗口信息,不主动抢占主流程。"""
|
|
try:
|
|
analyser._log_kv(
|
|
"预约",
|
|
"process_reservation_attend_window",
|
|
count=len(reservations),
|
|
room_pos=room_pos,
|
|
)
|
|
except Exception:
|
|
pass
|
|
return False
|
|
|
|
|
|
def record_high_value_reservation(
|
|
analyser: Any,
|
|
fudai_content_text: str,
|
|
prize_value_yuan: float,
|
|
lastsecond: int,
|
|
future_timestamp: float,
|
|
x: int,
|
|
needswitch: bool,
|
|
wait_minutes: int,
|
|
post_switch_delay_s: float,
|
|
room_pos: int,
|
|
reservations: List[Dict[str, Any]],
|
|
reservation_focus_until_ts_ref: list,
|
|
close_detail_callback,
|
|
swipe_up_switch_callback,
|
|
swipe_down_back_callback,
|
|
add_reservation_callback,
|
|
sort_reservations_callback,
|
|
write_state_callback,
|
|
) -> bool:
|
|
"""兼容实现:按原始签名追加一条简化的高价值预约记录。"""
|
|
try:
|
|
item: Dict[str, Any] = {
|
|
"future_ts": float(future_timestamp or 0.0),
|
|
"prize_value_yuan": float(prize_value_yuan or 0.0),
|
|
"content": str(fudai_content_text or ""),
|
|
"pos_seen": int(room_pos),
|
|
"created_ts": time.time(),
|
|
}
|
|
add_reservation_core_logic(reservations, item)
|
|
analyser._log_kv(
|
|
"预约",
|
|
"record_high_value_reservation:已记录高价值福袋",
|
|
value=item["prize_value_yuan"],
|
|
future_ts=item["future_ts"],
|
|
)
|
|
except Exception:
|
|
pass
|
|
return False
|
|
|
|
|
|
|
|
def record_high_value_reservation(
|
|
|
|
analyser: Any,
|
|
fudai_content_text: str,
|
|
|
|
prize_value_yuan: float,
|
|
|
|
lastsecond: int,
|
|
|
|
future_timestamp: float,
|
|
|
|
x: int,
|
|
|
|
needswitch: bool,
|
|
|
|
wait_minutes: int,
|
|
|
|
post_switch_delay_s: float,
|
|
|
|
room_pos: int,
|
|
|
|
reservations: List[Dict[str, Any]],
|
|
reservation_focus_until_ts_ref: list,
|
|
close_detail_callback,
|
|
|
|
swipe_up_switch_callback,
|
|
|
|
swipe_down_back_callback,
|
|
|
|
add_reservation_callback,
|
|
|
|
sort_reservations_callback,
|
|
|
|
write_state_callback,
|
|
|
|
) -> bool:
|
|
|
|
"""Shim: match original signature and optionally append a simple reservation.
|
|
|
|
To keep behavior safe and simple, we:
|
|
- create a minimal reservation dict; and
|
|
- append it to `reservations` without triggering any side-effects.
|
|
"""
|
|
try:
|
|
item: Dict[str, Any] = {
|
|
"future_ts": float(future_timestamp or 0.0),
|
|
"prize_value_yuan": float(prize_value_yuan or 0.0),
|
|
"content": str(fudai_content_text or ""),
|
|
"pos_seen": int(room_pos),
|
|
|
|
"created_ts": time.time(),
|
|
|
|
}
|
|
add_reservation_core_logic(reservations, item)
|
|
analyser._log_kv(
|
|
|
|
"预约",
|
|
|
|
"使用精简版 record_high_value_reservation:已记录高价值福袋",
|
|
value=item["prize_value_yuan"],
|
|
future_ts=item["future_ts"],
|
|
)
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|