feat: 增强福袋详情记录功能,优化映射表记录逻辑,修复重复标题处理
This commit is contained in:
1 parent
716567dbb0
commit
55a3f3a0af
5 files changed
+64
-101
No files matched your search
@@ -4450,6 +4450,36 @@ def basic_join_decision(
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 在福袋详情识别完成后,设置福袋信息并记录到映射表
|
||||
try:
|
||||
analyser._current_fudai_content = content
|
||||
analyser._last_fudai_detail_tuple = detail
|
||||
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"basic_join_decision:设置福袋信息并记录映射表",
|
||||
content=content[:50] if content else "",
|
||||
prize_value_yuan=prize_value_yuan,
|
||||
log_type="INFO",
|
||||
)
|
||||
|
||||
# 记录到映射表
|
||||
if hasattr(analyser, "_record_room_title_and_pos"):
|
||||
analyser._record_room_title_and_pos()
|
||||
else:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"basic_join_decision:_record_room_title_and_pos 方法不存在",
|
||||
log_type="WARNING",
|
||||
)
|
||||
except Exception as e:
|
||||
analyser._log_kv(
|
||||
"福袋详情",
|
||||
"basic_join_decision:设置福袋信息失败",
|
||||
error=str(e),
|
||||
log_type="WARNING",
|
||||
)
|
||||
|
||||
# 强制参与标志已移除,始终按正常验证流程处理
|
||||
force_attend = False
|
||||
|
||||
@@ -5545,11 +5575,8 @@ def basic_join_decision(
|
||||
pass
|
||||
|
||||
# 记录高价值预约后,立即记录房间标题到映射表,确保一个直播间只记录一次
|
||||
# 注意:福袋信息已在函数开始处设置,这里不再重复设置
|
||||
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:
|
||||
|
||||
@@ -226,7 +226,9 @@ class ReservationHandler:
|
||||
|
||||
# 在记录映射表前清理旧截图文件,避免复用过期的截图
|
||||
# 但在并行处理时不清理,因为主线程还在使用截图文件
|
||||
is_parallel_recording = getattr(analyser, "_screenshot_ready_for_ocr", False)
|
||||
is_parallel_recording = getattr(
|
||||
analyser, "_screenshot_ready_for_ocr", False
|
||||
)
|
||||
if not is_parallel_recording:
|
||||
try:
|
||||
import path_config
|
||||
@@ -342,13 +344,17 @@ class ReservationHandler:
|
||||
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:
|
||||
if (
|
||||
existing_title
|
||||
and existing_title == current_title
|
||||
and pos != room_pos
|
||||
):
|
||||
duplicate_title_positions.append(pos)
|
||||
|
||||
|
||||
if duplicate_title_positions:
|
||||
# 删除重复位置的记录
|
||||
deleted_count = 0
|
||||
@@ -356,7 +362,7 @@ class ReservationHandler:
|
||||
if dup_pos in room_pos_map:
|
||||
del room_pos_map[dup_pos]
|
||||
deleted_count += 1
|
||||
|
||||
|
||||
analyser._log_kv( # type: ignore[attr-defined]
|
||||
"警告",
|
||||
"[警告] 检测到重复直播间标题,已删除重复记录",
|
||||
@@ -367,11 +373,11 @@ class ReservationHandler:
|
||||
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]
|
||||
"预约",
|
||||
"[预约] 重复标题去重完成,继续记录当前位置",
|
||||
|
||||
@@ -544,68 +544,6 @@ 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
|
||||
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
|
||||
def validate_fudai_mapping_recording():
|
||||
"""验证福袋详情识别完成后映射表记录功能"""
|
||||
print("开始验证福袋详情识别完成后映射表记录功能...")
|
||||
@@ -14,17 +16,15 @@ def validate_fudai_mapping_recording():
|
||||
# 检查代码模式
|
||||
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",
|
||||
"启动映射表记录",
|
||||
"映射表记录完成"
|
||||
"analyser._last_fudai_detail_tuple = detail",
|
||||
"basic_join_decision:设置福袋信息并记录映射表",
|
||||
"_record_room_title_and_pos"
|
||||
]
|
||||
|
||||
# 读取文件内容
|
||||
file_path = "fudai_detail_modules/fudai_detail_reader.py"
|
||||
file_path = "douyin/fudai/douyin_fudai_core.py"
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
except Exception as e:
|
||||
print(f"❌ 无法读取文件 {file_path}: {e}")
|
||||
@@ -42,25 +42,14 @@ def validate_fudai_mapping_recording():
|
||||
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(" - 记录时机正确(在识别完成后)")
|
||||
print(" - 记录时机正确(在basic_join_decision开始时)")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = validate_fudai_mapping_recording()
|
||||
sys.exit(0 if success else 1)
|
||||
sys.exit(0 if success else 1)
|
||||
@@ -5,8 +5,10 @@
|
||||
|
||||
import sys
|
||||
import os
|
||||
|
||||
sys.path.insert(0, os.path.dirname(__file__))
|
||||
|
||||
|
||||
def validate_reservation_lock_protection():
|
||||
"""验证预约福袋参与成功后锁定期保护逻辑"""
|
||||
print("开始验证预约福袋参与成功后锁定期保护逻辑...")
|
||||
@@ -17,13 +19,13 @@ def validate_reservation_lock_protection():
|
||||
"has_other_reservations",
|
||||
"设置保护期确保依次参与",
|
||||
"protection_seconds=10",
|
||||
"参与成功,清除锁定期(无其他预约)"
|
||||
"参与成功,清除锁定期(无其他预约)",
|
||||
]
|
||||
|
||||
# 读取文件内容
|
||||
file_path = "douyin/core/douyin_fudai.py"
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
with open(file_path, "r", encoding="utf-8") as f:
|
||||
content = f.read()
|
||||
except Exception as e:
|
||||
print(f"❌ 无法读取文件 {file_path}: {e}")
|
||||
@@ -43,10 +45,10 @@ def validate_reservation_lock_protection():
|
||||
|
||||
# 检查保护期逻辑是否存在
|
||||
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
|
||||
"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:
|
||||
@@ -61,6 +63,7 @@ def validate_reservation_lock_protection():
|
||||
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
success = validate_reservation_lock_protection()
|
||||
sys.exit(0 if success else 1)
|
||||
sys.exit(0 if success else 1)
|
||||
Reference in new issue
Block a user