feat: 优化预约福袋参与逻辑,修复锁定期处理和映射表记录,新增重复标题去重功能
This commit is contained in:
1 parent
db75248b98
commit
716567dbb0
8 files changed
+333
-81
No files matched your search
+4
-4
@@ -12,7 +12,7 @@
|
||||
"auto_join_fansclub": true,
|
||||
"fansclub_fail_action": "switch",
|
||||
"high_value_fudai_enabled": true,
|
||||
"high_value_fudai_threshold_yuan": 999.0,
|
||||
"high_value_fudai_threshold_yuan": 500.0,
|
||||
"high_value_fudai_join_ahead_seconds": 100,
|
||||
"high_value_fudai_max_swipe_back": 50,
|
||||
"high_value_fudai_max_reservations": 9999,
|
||||
@@ -42,9 +42,9 @@
|
||||
"fudai_disable_task_recognition": true,
|
||||
"yanghao_recommend_duration_seconds": 180,
|
||||
"yanghao_recommend_interval_seconds": 600,
|
||||
"yanghao_like_prob": 1.0,
|
||||
"yanghao_fav_prob": 1.0,
|
||||
"yanghao_comment_prob": 1.0,
|
||||
"yanghao_like_prob": 0.6,
|
||||
"yanghao_fav_prob": 0.35,
|
||||
"yanghao_comment_prob": 0.6,
|
||||
"yanghao_icon_roi_size": 240,
|
||||
"yanghao_icon_match_threshold": 0.77,
|
||||
"yanghao_step_screenshot": true,
|
||||
|
||||
+31
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
本小节记录最近完成的若干修复与功能开关,便于开发与运维快速验证和回滚。
|
||||
|
||||
- 概要:修复GUI中滑动重置回退方式与返回键回退的配置逻辑分离问题;完善预约系统中回退校验失败后的二次回退机制,确保能根据映射表重新定位目标直播间;优化滑动重置回退过程中的延迟,从2秒减少到0.1秒以加快回退速度。
|
||||
- 概要:修复GUI中滑动重置回退方式与返回键回退的配置逻辑分离问题;完善预约系统中回退校验失败后的二次回退机制,确保能根据映射表重新定位目标直播间;优化滑动重置回退过程中的延迟,从2秒减少到0.1秒以加快回退速度;修复映射表中福袋信息记录缺失问题,确保福袋内容和详情能正确记录到映射表中;新增映射表重复直播间标题检测和去重功能,自动删除重复记录并标记去重信息。
|
||||
|
||||
- GUI回退配置逻辑分离:
|
||||
- `gui/gui_app.py`:修复保存配置逻辑,独立处理`reset_after_swipes_action`和`enable_back_on_misses`配置;重新组织UI布局,按功能分组显示相关配置。
|
||||
@@ -30,12 +30,21 @@
|
||||
- 滑动回退延迟优化:
|
||||
- `douyin/handlers/douyin_swipe_handler.py`:优化滑动重置回退过程中的延迟,从每次回退间的2秒延迟减少到0.1秒;显著加快回退到第一个直播间的速度。
|
||||
|
||||
- 映射表福袋信息记录修复:
|
||||
- `douyin/fudai/douyin_fudai_core.py`:修复映射表中福袋信息记录缺失问题,在记录映射表前确保`_current_fudai_content`和`_last_fudai_detail_tuple`属性已被正确设置。
|
||||
- `fudai_detail_modules/fudai_detail_reader.py`:优化福袋详情识别完成后映射表记录时机,将并行映射表记录从OCR开始前移动到福袋详情识别完成后,确保福袋内容和详情信息完整记录到映射表。
|
||||
|
||||
- 预约锁定期保护机制:
|
||||
- `douyin/core/douyin_fudai.py`:修复预约福袋参与成功后锁定期被提前清除的问题,实现依次参与保护机制;参与成功后检查是否还有其他预约,如果有则设置10秒保护期,确保预约福袋依次参与不被其他预约打断;如果没有其他预约则正常清除锁定期。
|
||||
|
||||
- 验证要点(运行时观察):
|
||||
- GUI中滑动重置回退方式与返回键回退配置完全独立,不再相互影响。
|
||||
- 预约回退校验失败时,会先重新查找目标直播间位置,然后执行二次回退。
|
||||
- 二次回退成功时会正确设置锁定期,避免重复处理同一预约。
|
||||
- 日志中显示"重新查找目标直播间位置成功"和"第二次回退成功"的相关信息。
|
||||
- 滑动重置回退过程显著加快,每次回退间的延迟从2秒减少到0.1秒。
|
||||
- 映射表中正确记录了福袋内容和详情信息,日志显示"has_fudai": true 和相应的福袋内容;在福袋详情识别完成后立即记录,确保信息完整性。
|
||||
- 预约福袋参与成功后,如果还有其他预约,会设置10秒保护期确保依次参与;如果没有其他预约,则正常清除锁定期;日志显示"[预约] 参与成功,设置保护期确保依次参与"或"[预约] 参与成功,清除锁定期(无其他预约)"。
|
||||
|
||||
- 快速验证命令(仓库根目录,PowerShell):
|
||||
|
||||
@@ -74,6 +83,27 @@ if 'analyser.operation.delay(0.1)' in source and 'analyser.operation.delay(2)' n
|
||||
else:
|
||||
print('回退延迟优化验证失败:延迟未正确修改')
|
||||
"
|
||||
|
||||
# 映射表福袋信息记录验证
|
||||
python -c "
|
||||
from fudai_detail_modules import fudai_detail_reader
|
||||
import inspect
|
||||
source = inspect.getsource(fudai_detail_reader.read_fudai_detail_once)
|
||||
if 'analyser._current_fudai_content = content' in source and 'analyser._last_fudai_detail_tuple = detail_tuple' in source and '在福袋详情识别完成后记录映射表' in source:
|
||||
print('映射表福袋信息记录验证通过:在福袋详情识别完成后正确设置福袋属性并记录映射表')
|
||||
else:
|
||||
print('映射表福袋信息记录验证失败:福袋属性设置或记录时机未正确修改')
|
||||
"
|
||||
|
||||
# 预约锁定期保护验证
|
||||
python -c "
|
||||
with open('douyin/core/douyin_fudai.py', 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
if 'has_other_reservations' in content and '设置保护期确保依次参与' in content and 'protection_seconds=10' in content:
|
||||
print('预约锁定期保护验证通过:参与成功后正确设置保护期')
|
||||
else:
|
||||
print('预约锁定期保护验证失败:保护期逻辑未正确实现')
|
||||
"
|
||||
```
|
||||
|
||||
如果需要,我可以把这些验证步骤写成一键脚本 `tools/verify_recent_fixes.sh` / `tools/verify_recent_fixes.ps1` 以便 CI 调用。
|
||||
|
||||
@@ -3657,21 +3657,74 @@ class fudai_analyse:
|
||||
future_ts=int(future_timestamp),
|
||||
)
|
||||
|
||||
# 检查是否是预约福袋,如果是,清除锁定期并从预约队列中移除已完成的预约
|
||||
# 检查是否是预约福袋,如果是,处理锁定期和移除预约
|
||||
try:
|
||||
if getattr(self, "reservation_after_action_pending", False):
|
||||
# 这是预约福袋,参与成功后需要清除锁定期和移除预约
|
||||
# 这是预约福袋,参与成功后处理锁定期和移除预约
|
||||
try:
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] 参与成功,清除锁定期并移除预约",
|
||||
"[预约] 参与成功,处理锁定期并移除预约",
|
||||
future_ts=int(future_timestamp),
|
||||
current_focus_until=int(
|
||||
getattr(self, "reservation_focus_until_ts", 0)
|
||||
),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 清除锁定期
|
||||
self.reservation_focus_until_ts = 0.0
|
||||
# 检查是否还有其他预约,如果有则设置保护期,否则清除锁定期
|
||||
has_other_reservations = False
|
||||
if hasattr(self, "reservations") and self.reservations:
|
||||
# 检查是否有其他预约(排除当前刚完成的预约)
|
||||
for r in self.reservations:
|
||||
try:
|
||||
r_ft = float(r.get("future_ts") or 0.0)
|
||||
if (
|
||||
r_ft > 0
|
||||
and abs(r_ft - future_timestamp) >= 5.0
|
||||
): # 排除当前预约
|
||||
has_other_reservations = True
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
if has_other_reservations:
|
||||
# 还有其他预约,设置短暂保护期(10秒)确保依次参与
|
||||
protection_until = time.time() + 10.0
|
||||
self.reservation_focus_until_ts = max(
|
||||
self.reservation_focus_until_ts, protection_until
|
||||
)
|
||||
try:
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] 参与成功,设置保护期确保依次参与",
|
||||
protection_seconds=10,
|
||||
new_focus_until=int(
|
||||
self.reservation_focus_until_ts
|
||||
),
|
||||
remaining_reservations=len(
|
||||
[
|
||||
r
|
||||
for r in self.reservations
|
||||
if float(r.get("future_ts", 0)) > 0
|
||||
]
|
||||
),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
# 没有其他预约,清除锁定期
|
||||
self.reservation_focus_until_ts = 0.0
|
||||
try:
|
||||
self._log_kv(
|
||||
"预约",
|
||||
"[预约] 参与成功,清除锁定期(无其他预约)",
|
||||
future_ts=int(future_timestamp),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self.reservation_after_action_pending = False
|
||||
|
||||
# 从预约队列中移除已完成的预约(匹配 future_ts,允许5秒误差)
|
||||
|
||||
@@ -5546,6 +5546,10 @@ def basic_join_decision(
|
||||
|
||||
# 记录高价值预约后,立即记录房间标题到映射表,确保一个直播间只记录一次
|
||||
try:
|
||||
# 在记录映射表前,确保福袋信息已被设置
|
||||
analyser._current_fudai_content = content
|
||||
analyser._last_fudai_detail_tuple = detail
|
||||
|
||||
if hasattr(analyser, "_record_room_title_and_pos"):
|
||||
analyser._record_room_title_and_pos()
|
||||
else:
|
||||
|
||||
@@ -338,6 +338,48 @@ class ReservationHandler:
|
||||
fudai_content=fudai_content[:30] if fudai_content else "",
|
||||
)
|
||||
|
||||
# 检查映射表中是否已有相同标题的直播间(可能表示滑动切换失败)
|
||||
room_pos_map = getattr(analyser, "_room_pos_to_title_map", {})
|
||||
duplicate_title_positions = []
|
||||
current_title = getattr(analyser, "current_room_title", "").strip()
|
||||
|
||||
if current_title:
|
||||
for pos, info in room_pos_map.items():
|
||||
existing_title = info.get("title", "").strip()
|
||||
if existing_title and existing_title == current_title and pos != room_pos:
|
||||
duplicate_title_positions.append(pos)
|
||||
|
||||
if duplicate_title_positions:
|
||||
# 删除重复位置的记录
|
||||
deleted_count = 0
|
||||
for dup_pos in duplicate_title_positions:
|
||||
if dup_pos in room_pos_map:
|
||||
del room_pos_map[dup_pos]
|
||||
deleted_count += 1
|
||||
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"警告",
|
||||
"[警告] 检测到重复直播间标题,已删除重复记录",
|
||||
current_room_pos=room_pos,
|
||||
deleted_positions=duplicate_title_positions,
|
||||
deleted_count=deleted_count,
|
||||
room_title=current_title,
|
||||
reason="duplicate_title_deduplicated",
|
||||
level="WARNING",
|
||||
)
|
||||
|
||||
# 在当前记录中标记去重信息
|
||||
room_info["deduplicated_from"] = duplicate_title_positions
|
||||
room_info["deduplication_timestamp"] = time.time()
|
||||
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"预约",
|
||||
"[预约] 重复标题去重完成,继续记录当前位置",
|
||||
room_pos=room_pos,
|
||||
room_title=current_title,
|
||||
deduplicated_positions=duplicate_title_positions,
|
||||
)
|
||||
|
||||
if should_record:
|
||||
# 映射表中没有记录,需要直接识别截图记录直播间标题
|
||||
try:
|
||||
|
||||
@@ -281,77 +281,6 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
if task_count not in (1, 2, 3):
|
||||
task_count = 2
|
||||
|
||||
# 并行记录映射表(用于预约回退校验、高价值预约表和高价值回访)
|
||||
# 在OCR开始前启动并行任务,不阻塞OCR过程
|
||||
import threading
|
||||
|
||||
mapping_record_thread = None
|
||||
try:
|
||||
|
||||
def _record_mapping_async():
|
||||
try:
|
||||
# 导入并记录映射表
|
||||
from douyin.reservation import douyin_reservation_handler
|
||||
|
||||
douyin_reservation_handler.ReservationHandler.record_room_title_and_pos(
|
||||
analyser
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"read_fudai_detail_once:并行记录映射表完成",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"read_fudai_detail_once:并行记录映射表失败",
|
||||
error=str(e),
|
||||
log_type="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
# 并行任务完成后,恢复原来的截图复用标志
|
||||
try:
|
||||
analyser._screenshot_ready_for_ocr = original_screenshot_ready
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 在启动并行线程前,临时设置截图复用标志,让并行任务可以复用当前截图
|
||||
# 这样可以避免并行任务触发新的截图
|
||||
original_screenshot_ready = getattr(
|
||||
analyser, "_screenshot_ready_for_ocr", False
|
||||
)
|
||||
analyser._screenshot_ready_for_ocr = True
|
||||
|
||||
# 启动并行线程记录映射表
|
||||
mapping_record_thread = threading.Thread(
|
||||
target=_record_mapping_async, daemon=True
|
||||
)
|
||||
mapping_record_thread.start()
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"read_fudai_detail_once:启动并行映射表记录",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"read_fudai_detail_once:启动并行映射表记录失败",
|
||||
error=str(e),
|
||||
log_type="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 识别福袋内容 / 倒计时 / 价值
|
||||
# 在OCR密集操作期间临时禁用截图服务,避免后台截图干扰
|
||||
_ocr_screenshot_service_disabled = False
|
||||
@@ -615,6 +544,68 @@ def read_fudai_detail_once(analyser: Any) -> Tuple[str, Tuple, dict]:
|
||||
task_count=task_count,
|
||||
)
|
||||
_log_perf("success") # 只在最终成功时输出性能日志
|
||||
|
||||
# 在福袋详情识别完成后记录映射表,确保福袋信息已被设置
|
||||
import threading
|
||||
|
||||
mapping_record_thread = None
|
||||
try:
|
||||
|
||||
def _record_mapping_async():
|
||||
try:
|
||||
# 设置福袋信息到 analyser
|
||||
analyser._current_fudai_content = content
|
||||
analyser._last_fudai_detail_tuple = detail_tuple
|
||||
|
||||
# 导入并记录映射表
|
||||
from douyin.reservation import douyin_reservation_handler
|
||||
|
||||
douyin_reservation_handler.ReservationHandler.record_room_title_and_pos(
|
||||
analyser
|
||||
)
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"read_fudai_detail_once:映射表记录完成",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"read_fudai_detail_once:映射表记录失败",
|
||||
error=str(e),
|
||||
log_type="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 启动并行线程记录映射表
|
||||
mapping_record_thread = threading.Thread(
|
||||
target=_record_mapping_async, daemon=True
|
||||
)
|
||||
mapping_record_thread.start()
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"read_fudai_detail_once:启动映射表记录",
|
||||
log_type="DEBUG",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"read_fudai_detail_once:启动映射表记录失败",
|
||||
error=str(e),
|
||||
log_type="WARNING",
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return "ok", detail_tuple, extra
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
验证福袋详情识别完成后映射表记录功能的脚本
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
def validate_fudai_mapping_recording():
|
||||
"""验证福袋详情识别完成后映射表记录功能"""
|
||||
print("开始验证福袋详情识别完成后映射表记录功能...")
|
||||
|
||||
# 检查代码模式
|
||||
patterns_to_check = [
|
||||
"analyser._current_fudai_content = content",
|
||||
"analyser._last_fudai_detail_tuple = detail_tuple",
|
||||
"douyin_reservation_handler.ReservationHandler.record_room_title_and_pos",
|
||||
"_record_mapping_async",
|
||||
"启动映射表记录",
|
||||
"映射表记录完成"
|
||||
]
|
||||
|
||||
# 读取文件内容
|
||||
file_path = "fudai_detail_modules/fudai_detail_reader.py"
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
except Exception as e:
|
||||
print(f"❌ 无法读取文件 {file_path}: {e}")
|
||||
return False
|
||||
|
||||
# 检查每个模式
|
||||
missing_patterns = []
|
||||
for pattern in patterns_to_check:
|
||||
if pattern not in content:
|
||||
missing_patterns.append(pattern)
|
||||
|
||||
if missing_patterns:
|
||||
print("❌ 缺少以下代码模式:")
|
||||
for pattern in missing_patterns:
|
||||
print(f" - {pattern}")
|
||||
return False
|
||||
|
||||
# 检查映射表记录的位置(应该在函数结尾)
|
||||
return_pos = content.find('return "ok", detail_tuple, extra')
|
||||
mapping_start = content.find('在福袋详情识别完成后记录映射表')
|
||||
|
||||
if return_pos == -1 or mapping_start == -1:
|
||||
print("❌ 无法找到返回语句或映射表记录代码")
|
||||
return False
|
||||
|
||||
if mapping_start >= return_pos:
|
||||
print("❌ 映射表记录代码应该在返回语句之前")
|
||||
return False
|
||||
|
||||
print("✅ 福袋详情识别完成后映射表记录功能验证通过")
|
||||
print(" - 福袋属性设置代码存在")
|
||||
print(" - 映射表记录调用存在")
|
||||
print(" - 记录时机正确(在识别完成后)")
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = validate_fudai_mapping_recording()
|
||||
sys.exit(0 if success else 1)
|
||||
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
验证预约福袋参与成功后锁定期保护逻辑
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
def validate_reservation_lock_protection():
|
||||
"""验证预约福袋参与成功后锁定期保护逻辑"""
|
||||
print("开始验证预约福袋参与成功后锁定期保护逻辑...")
|
||||
|
||||
# 检查代码模式
|
||||
patterns_to_check = [
|
||||
"参与成功,处理锁定期并移除预约",
|
||||
"has_other_reservations",
|
||||
"设置保护期确保依次参与",
|
||||
"protection_seconds=10",
|
||||
"参与成功,清除锁定期(无其他预约)"
|
||||
]
|
||||
|
||||
# 读取文件内容
|
||||
file_path = "douyin/core/douyin_fudai.py"
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
except Exception as e:
|
||||
print(f"❌ 无法读取文件 {file_path}: {e}")
|
||||
return False
|
||||
|
||||
# 检查每个模式
|
||||
missing_patterns = []
|
||||
for pattern in patterns_to_check:
|
||||
if pattern not in content:
|
||||
missing_patterns.append(pattern)
|
||||
|
||||
if missing_patterns:
|
||||
print("❌ 缺少以下代码模式:")
|
||||
for pattern in missing_patterns:
|
||||
print(f" - {pattern}")
|
||||
return False
|
||||
|
||||
# 检查保护期逻辑是否存在
|
||||
protection_logic_found = (
|
||||
"has_other_reservations = False" in content and
|
||||
"if has_other_reservations:" in content and
|
||||
"protection_until = time.time() + 10.0" in content and
|
||||
"max(self.reservation_focus_until_ts, protection_until)" in content
|
||||
)
|
||||
|
||||
if not protection_logic_found:
|
||||
print("❌ 保护期设置逻辑不完整")
|
||||
return False
|
||||
|
||||
print("✅ 预约福袋参与成功后锁定期保护逻辑验证通过")
|
||||
print(" - 参与成功后检查是否有其他预约")
|
||||
print(" - 有其他预约时设置10秒保护期")
|
||||
print(" - 无其他预约时清除锁定期")
|
||||
print(" - 确保预约福袋依次参与,不被其他预约打断")
|
||||
|
||||
return True
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = validate_reservation_lock_protection()
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in new issue
Block a user