feat: 添加唯一计数去重功能,优化福袋相关统计逻辑
This commit is contained in:
1 parent
90b7daa84e
commit
d81eea63c9
10 files changed
+333
-54
No files matched your search
@@ -2010,7 +2010,7 @@ class underlying_operations:
|
||||
|
||||
return ""
|
||||
|
||||
def extract_ocr_content(self, content=[], return_confidence=False):
|
||||
def extract_ocr_content(self, content=None, return_confidence=False):
|
||||
"""对OCR识别到的内容进行取值和拼接,变成完整的一段内容
|
||||
|
||||
参数:
|
||||
@@ -2021,7 +2021,7 @@ class underlying_operations:
|
||||
如果return_confidence=False: 返回文本字符串
|
||||
如果return_confidence=True: 返回(text, confidence_info)元组,其中confidence_info是置信度信息字典
|
||||
"""
|
||||
ocr_result = content
|
||||
ocr_result = content or []
|
||||
|
||||
# 用于收集置信度信息
|
||||
confidence_scores = []
|
||||
@@ -2431,6 +2431,7 @@ class underlying_operations:
|
||||
stderr=subprocess.PIPE,
|
||||
timeout=5.0,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
# 检查是否有权限错误
|
||||
@@ -2479,6 +2480,7 @@ class underlying_operations:
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
if "event" not in result.stdout.lower():
|
||||
@@ -2493,8 +2495,7 @@ class underlying_operations:
|
||||
|
||||
注意:uiautomator 在某些设备上可能也需要权限,但可以尝试作为备选方案。
|
||||
"""
|
||||
import subprocess
|
||||
|
||||
|
||||
# 使用 uiautomator swipe 命令
|
||||
# 注意:uiautomator 命令格式可能因 Android 版本而异
|
||||
# Android 5.0+: uiautomator swipe <x1> <y1> <x2> <y2> [steps]
|
||||
@@ -2507,6 +2508,7 @@ class underlying_operations:
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
timeout=5.0,
|
||||
check=False,
|
||||
)
|
||||
|
||||
if result.returncode != 0:
|
||||
@@ -2521,8 +2523,7 @@ class underlying_operations:
|
||||
优点:绕过部分权限检查
|
||||
缺点:需要 root 权限,实现复杂,不同设备的事件格式可能不同
|
||||
"""
|
||||
import subprocess
|
||||
import time
|
||||
|
||||
|
||||
# 获取触摸设备路径(通常是 /dev/input/eventX)
|
||||
result = subprocess.run(
|
||||
@@ -2532,6 +2533,7 @@ class underlying_operations:
|
||||
stderr=subprocess.DEVNULL,
|
||||
text=True,
|
||||
timeout=3.0,
|
||||
check=False,
|
||||
)
|
||||
|
||||
# 解析设备路径(简化版,实际需要更复杂的解析)
|
||||
@@ -2579,6 +2581,7 @@ class underlying_operations:
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
timeout=timeout_seconds,
|
||||
check=False,
|
||||
)
|
||||
return r.returncode == 0
|
||||
except Exception:
|
||||
@@ -2598,6 +2601,7 @@ class underlying_operations:
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
errors="ignore",
|
||||
check=False,
|
||||
)
|
||||
return (r.returncode == 0), (r.stdout or "")
|
||||
except Exception:
|
||||
@@ -2949,6 +2953,7 @@ class underlying_operations:
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
timeout=2,
|
||||
check=False,
|
||||
)
|
||||
subprocess.run(
|
||||
f'{self._adb()} -s {device_id} pull {remote} "{local_path}"',
|
||||
@@ -2956,6 +2961,7 @@ class underlying_operations:
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
timeout=2,
|
||||
check=False,
|
||||
)
|
||||
return os.path.exists(local_path)
|
||||
except subprocess.TimeoutExpired:
|
||||
|
||||
+52
-18
@@ -10,15 +10,10 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, List, Tuple, Optional
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
import traceback
|
||||
import logging
|
||||
|
||||
from Underlying_Operations import underlying_operations
|
||||
|
||||
@@ -68,6 +63,8 @@ class fudai_analyse:
|
||||
|
||||
# 日志相关字段:完全独立的日志系统(不依赖原始代码)
|
||||
try:
|
||||
from datetime import datetime
|
||||
|
||||
self._run_id = datetime.now().strftime("%Y%m%d%H%M%S")
|
||||
except Exception:
|
||||
self._run_id = str(int(time.time()))
|
||||
@@ -276,7 +273,6 @@ class fudai_analyse:
|
||||
self._reservations_state_path: str = os.path.join(
|
||||
os.path.dirname(__file__), "state", "reservations.json"
|
||||
)
|
||||
self._reservations_state_last_write_ts: float = 0.0
|
||||
|
||||
# 运行时直播间标题和位置映射表(用于回退校验)
|
||||
# 格式:{room_pos: (room_title, room_title_raw)}
|
||||
@@ -494,6 +490,8 @@ class fudai_analyse:
|
||||
self.resolution_ratio_x, self.resolution_ratio_y = 1080, 2400
|
||||
|
||||
# 记录运行开始
|
||||
from datetime import datetime
|
||||
|
||||
start_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")[:-3]
|
||||
try:
|
||||
actions_log_path = os.path.join(
|
||||
@@ -520,6 +518,8 @@ class fudai_analyse:
|
||||
"ERROR", "fudai_choujiang top-level exception", error=str(top_exc)
|
||||
)
|
||||
except Exception:
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
raise
|
||||
|
||||
@@ -1020,6 +1020,10 @@ class fudai_analyse:
|
||||
|
||||
注意:此方法复杂度较高,已通过模块化重构将部分逻辑拆分到子模块。
|
||||
"""
|
||||
from douyin.reservation import (
|
||||
douyin_reservation_logic,
|
||||
) # pylint: disable=redefined-outer-name
|
||||
|
||||
start_time = time.time()
|
||||
# 直接参与标志已移除,相关旧逻辑已清理,继续按正常流程执行
|
||||
# 0. 如果正在等待开奖,检查高价值预约是否需要抢占,否则只检测开奖结果
|
||||
@@ -1045,11 +1049,16 @@ class fudai_analyse:
|
||||
room_pos_ref[0],
|
||||
reservation_focus_until_ts_ref,
|
||||
reservation_after_action_pending_ref,
|
||||
float(getattr(self, "reservation_back_swipe_delay_s", 0.5) or 0.5),
|
||||
self.swipe_down_back_from_live,
|
||||
self._seek_reservation_room,
|
||||
float(
|
||||
getattr(self, "reservation_back_swipe_delay_s", 0.5)
|
||||
or 0.5
|
||||
),
|
||||
lambda: self.swipe_down_back_from_live(),
|
||||
lambda item: self._seek_reservation_room(item),
|
||||
lambda: (
|
||||
douyin_reservation_logic._sort_reservations_inplace(self.reservations)
|
||||
douyin_reservation_logic._sort_reservations_inplace(
|
||||
self.reservations
|
||||
)
|
||||
if self.reservations
|
||||
else None
|
||||
),
|
||||
@@ -1448,6 +1457,8 @@ class fudai_analyse:
|
||||
for idx, r in enumerate(reservations_list[:3]): # 只显示前3个
|
||||
try:
|
||||
ft = float(r.get("future_ts") or 0)
|
||||
from datetime import datetime
|
||||
|
||||
ft_str = (
|
||||
datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S")
|
||||
if ft > 0
|
||||
@@ -1521,6 +1532,8 @@ class fudai_analyse:
|
||||
return
|
||||
self._reservations_state_last_write_ts = now_ts
|
||||
|
||||
import json
|
||||
|
||||
os.makedirs(
|
||||
os.path.dirname(self._reservations_state_path),
|
||||
exist_ok=True,
|
||||
@@ -1712,7 +1725,10 @@ class fudai_analyse:
|
||||
first_r = self.reservations[0]
|
||||
try:
|
||||
ft = float(first_r.get("future_ts") or 0)
|
||||
now_ts = time.time()
|
||||
from datetime import datetime
|
||||
import time as time_module
|
||||
|
||||
now_ts = time_module.time()
|
||||
ft_str = (
|
||||
datetime.fromtimestamp(ft).strftime("%Y-%m-%d %H:%M:%S")
|
||||
if ft > 0
|
||||
@@ -1834,6 +1850,10 @@ class fudai_analyse:
|
||||
pass
|
||||
|
||||
try:
|
||||
from douyin.reservation import (
|
||||
douyin_reservation_logic,
|
||||
) # pylint: disable=redefined-outer-name
|
||||
|
||||
douyin_reservation_logic.cleanup_expired_reservations(
|
||||
self, self.reservations, _write_state
|
||||
)
|
||||
@@ -2481,8 +2501,8 @@ class fudai_analyse:
|
||||
and isinstance(detail, tuple)
|
||||
and len(detail) >= 6
|
||||
):
|
||||
# 直接获取倒计时字段,避免强制解包
|
||||
countdown_tuple = detail[5]
|
||||
# 使用解包避免索引告警
|
||||
_, _, _, _, _, countdown_tuple = detail
|
||||
if (
|
||||
isinstance(countdown_tuple, (tuple, list))
|
||||
and len(countdown_tuple) >= 2
|
||||
@@ -2774,16 +2794,22 @@ class fudai_analyse:
|
||||
end_y = 700 * ry // 2400
|
||||
# 直接使用 ADB 内部滑动命令
|
||||
try:
|
||||
import subprocess
|
||||
|
||||
if hasattr(self.operation, "_adb"):
|
||||
adb_cmd = self.operation._adb()
|
||||
else:
|
||||
import os
|
||||
|
||||
adb_cmd = (
|
||||
os.environ.get(
|
||||
"ADB_EXECUTABLE", "adb"
|
||||
)
|
||||
or "adb"
|
||||
)
|
||||
if not adb_cmd.startswith('"') and not adb_cmd.endswith('"'):
|
||||
if not adb_cmd.startswith(
|
||||
'"'
|
||||
) and not adb_cmd.endswith('"'):
|
||||
adb_cmd = f'"{adb_cmd}"'
|
||||
cmd = f"{adb_cmd} -s {self.device_id} shell input swipe {start_x} {start_y} {end_x} {end_y} 300"
|
||||
subprocess.run(
|
||||
@@ -2792,7 +2818,6 @@ class fudai_analyse:
|
||||
timeout=5.0,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
check=True,
|
||||
)
|
||||
except Exception:
|
||||
# 回退到 operation.swipe
|
||||
@@ -2950,9 +2975,13 @@ class fudai_analyse:
|
||||
end_y = 700 * ry // 2400
|
||||
# 直接使用 ADB 内部滑动命令
|
||||
try:
|
||||
import subprocess
|
||||
|
||||
if hasattr(self.operation, "_adb"):
|
||||
adb_cmd = self.operation._adb()
|
||||
else:
|
||||
import os
|
||||
|
||||
adb_cmd = (
|
||||
os.environ.get(
|
||||
"ADB_EXECUTABLE", "adb"
|
||||
@@ -2970,7 +2999,6 @@ class fudai_analyse:
|
||||
timeout=5.0,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
check=True,
|
||||
)
|
||||
except Exception:
|
||||
# 回退到 operation.swipe
|
||||
@@ -3171,6 +3199,10 @@ class fudai_analyse:
|
||||
|
||||
# 从预约队列中移除已完成的预约(匹配 future_ts,允许5秒误差)
|
||||
if hasattr(self, "reservations") and self.reservations:
|
||||
from douyin.reservation import (
|
||||
douyin_reservation_logic,
|
||||
) # pylint: disable=redefined-outer-name
|
||||
|
||||
reservations_to_remove = []
|
||||
for idx, r in enumerate(self.reservations):
|
||||
try:
|
||||
@@ -3294,7 +3326,9 @@ class fudai_analyse:
|
||||
|
||||
# 检查是否在锁定期内,且时间窗口未到,避免重复打开福袋详情
|
||||
try:
|
||||
now_ts = time.time()
|
||||
import time as time_module
|
||||
|
||||
now_ts = time_module.time()
|
||||
focus_until = float(getattr(self, "reservation_focus_until_ts", 0.0) or 0.0)
|
||||
queue_full_waiting = bool(
|
||||
getattr(self, "queue_full_waiting_at_earliest", False) or False
|
||||
|
||||
@@ -1,21 +1,119 @@
|
||||
{
|
||||
"updated_ts": 1767489629.8950424,
|
||||
"reason": "remove_reservation_after_attend",
|
||||
"room_pos": 0,
|
||||
"current_room_title": "火烘",
|
||||
"current_room_title_raw": "",
|
||||
"updated_ts": 1767490647.4599805,
|
||||
"reason": "record_reservation",
|
||||
"room_pos": 3,
|
||||
"current_room_title": "带娃的小",
|
||||
"current_room_title_raw": "带娃的小.",
|
||||
"reservations": [
|
||||
{
|
||||
"prize_value_yuan": 3499.0,
|
||||
"content": "",
|
||||
"future_ts": 1767490318.654792,
|
||||
"future_str": "2026-01-04 09:31:58",
|
||||
"future_ts": 1767491224.559842,
|
||||
"future_str": "2026-01-04 09:47:04",
|
||||
"pos_seen": 3,
|
||||
"room_title": "带娃的小",
|
||||
"room_title_raw": "带娃的小.",
|
||||
"created_ts": 1767489560.8793976,
|
||||
"created_ts": 1767490541.6079862,
|
||||
"task_count": 2,
|
||||
"time_text": "12:43",
|
||||
"time_text": "11:28",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767491289.735911,
|
||||
"future_str": "2026-01-04 09:48:09",
|
||||
"pos_seen": 0,
|
||||
"room_title": "作川帮粼",
|
||||
"room_title_raw": "作川帮粼。。",
|
||||
"created_ts": 1767490498.9667225,
|
||||
"task_count": 2,
|
||||
"time_text": "13:16",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767491289.793185,
|
||||
"future_str": "2026-01-04 09:48:09",
|
||||
"pos_seen": 0,
|
||||
"room_title": "作小帮粼",
|
||||
"room_title_raw": "作小帮粼。。",
|
||||
"created_ts": 1767490410.0147398,
|
||||
"task_count": 2,
|
||||
"time_text": "14:45",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767491290.024826,
|
||||
"future_str": "2026-01-04 09:48:10",
|
||||
"pos_seen": 0,
|
||||
"room_title": "作I帮粼",
|
||||
"room_title_raw": "作I帮粼。。",
|
||||
"created_ts": 1767490513.3146324,
|
||||
"task_count": 2,
|
||||
"time_text": "13:02",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767491290.032546,
|
||||
"future_str": "2026-01-04 09:48:10",
|
||||
"pos_seen": 0,
|
||||
"room_title": "作小帮数",
|
||||
"room_title_raw": "作小帮数。。",
|
||||
"created_ts": 1767490484.413875,
|
||||
"task_count": 2,
|
||||
"time_text": "13:31",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767491290.039379,
|
||||
"future_str": "2026-01-04 09:48:10",
|
||||
"pos_seen": 0,
|
||||
"room_title": "作小帮",
|
||||
"room_title_raw": "作小帮\"。。",
|
||||
"created_ts": 1767490439.3004336,
|
||||
"task_count": 2,
|
||||
"time_text": "14:16",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767491290.433496,
|
||||
"future_str": "2026-01-04 09:48:10",
|
||||
"pos_seen": 0,
|
||||
"room_title": "作小羿敉",
|
||||
"room_title_raw": "作小羿敉。。",
|
||||
"created_ts": 1767490424.8472722,
|
||||
"task_count": 2,
|
||||
"time_text": "14:31",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
},
|
||||
{
|
||||
"prize_value_yuan": 1999.0,
|
||||
"content": "",
|
||||
"future_ts": 1767491291.276375,
|
||||
"future_str": "2026-01-04 09:48:11",
|
||||
"pos_seen": 0,
|
||||
"room_title": "作川帮数",
|
||||
"room_title_raw": "作川帮数。。",
|
||||
"created_ts": 1767490469.6016176,
|
||||
"task_count": 2,
|
||||
"time_text": "13:47",
|
||||
"participants": 0,
|
||||
"copies": 0
|
||||
}
|
||||
|
||||
@@ -8,6 +8,15 @@ from __future__ import annotations
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
try:
|
||||
from douyin.utils.ocr_preprocess import preprocess_for_ocr # type: ignore
|
||||
except Exception: # pyright: ignore
|
||||
def preprocess_for_ocr(_analyser, picname: str) -> str: # type: ignore
|
||||
try:
|
||||
return str(picname)
|
||||
except TypeError: # pyright: ignore
|
||||
return picname
|
||||
|
||||
|
||||
def check_lucky_draw_result(analyser) -> int | bool:
|
||||
"""判定福袋抽奖的结果。
|
||||
|
||||
@@ -3,14 +3,13 @@ from __future__ import annotations
|
||||
import re
|
||||
import time
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
from typing import Tuple, Any, Optional, Dict
|
||||
from PIL import Image
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import numpy as np
|
||||
|
||||
from douyin.utils.douyin_utils import normalize_countdown_text, extract_prize_value_yuan
|
||||
from douyin.utils.douyin_utils import extract_prize_value_yuan
|
||||
from douyin.reservation import douyin_reservation_logic
|
||||
import path_config
|
||||
|
||||
@@ -63,6 +62,22 @@ def _get_fudai_ocr_executor(optimal_workers: int) -> ThreadPoolExecutor:
|
||||
return executor
|
||||
|
||||
|
||||
def _build_fudai_key_from_analyser(analyser) -> str:
|
||||
"""构造一个尽可能稳定的福袋唯一键,供统计去重使用。
|
||||
|
||||
使用 content|prize|countdown 三元组组合。
|
||||
"""
|
||||
try:
|
||||
last = getattr(analyser, "_fudai_last", None) or {}
|
||||
content = str(last.get("content") or "").strip()
|
||||
prize = str(last.get("prize_value_yuan") or "").strip()
|
||||
countdown = str(last.get("countdown") or "").strip()
|
||||
key = f"{content}|{prize}|{countdown}"
|
||||
return key
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
|
||||
def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, float]:
|
||||
"""获取福袋的内容和倒计时(从 `fudai_analyse.get_fudai_contain` 抽离)。"""
|
||||
|
||||
@@ -1134,7 +1149,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
"OCR识别任务列表区域",
|
||||
task_list_text=task_list_raw[:200] if task_list_raw else "",
|
||||
)
|
||||
except Exception as e_inner:
|
||||
except Exception as e_pl1:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
@@ -1154,7 +1169,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
"任务列表OCR识别到'观看X分钟'类任务,直接跳过后续处理",
|
||||
task_list_text=task_list_raw[:200] if task_list_raw else "",
|
||||
)
|
||||
except Exception as e_inner:
|
||||
except Exception as e_pl2:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
@@ -1168,7 +1183,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
# 设置标志,让调用方知道这是观看任务
|
||||
try:
|
||||
analyser._is_watch_task_detected = True
|
||||
except Exception as e_inner:
|
||||
except Exception as e_pl3:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
@@ -1226,7 +1241,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
status=button_status,
|
||||
button_text=button_text[:100] if button_text else "",
|
||||
)
|
||||
except Exception as e_inner:
|
||||
except Exception as e_pl4:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
@@ -1247,7 +1262,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
task_count=renwu,
|
||||
button_status=button_status or "未识别",
|
||||
)
|
||||
except Exception as e_inner:
|
||||
except Exception as e_pl5:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
@@ -1328,7 +1343,7 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
|
||||
name_tl2 = preprocess_for_ocr(analyser, "福袋任务列表")
|
||||
return analyser.operation.analyse_pic_word(name_tl2, 0)
|
||||
except Exception as e_inner2:
|
||||
except Exception as e_pl6:
|
||||
try:
|
||||
analyser._log_kv(
|
||||
"错误",
|
||||
@@ -1823,6 +1838,40 @@ def get_fudai_contain(analyser, renwu: int = 2) -> Tuple[str, str, int, int, flo
|
||||
content=content_for_log, # 同时作为字段输出
|
||||
)
|
||||
|
||||
# 结构化统计日志:识别到福袋(attempt),并在首次出现时标记 unique
|
||||
try:
|
||||
fudai_key = _build_fudai_key_from_analyser(analyser)
|
||||
analyser._log_kv(
|
||||
"统计",
|
||||
"fudai_seen",
|
||||
metric="fudai_seen",
|
||||
metric_type="attempt",
|
||||
run_id=getattr(analyser, "_run_id", None),
|
||||
fudai_key=fudai_key,
|
||||
value=1,
|
||||
)
|
||||
# 唯一口径去重(在 analyser 实例上维护一组)
|
||||
try:
|
||||
seen_set = getattr(analyser, "_fudai_seen_keys", None)
|
||||
if seen_set is None:
|
||||
seen_set = set()
|
||||
setattr(analyser, "_fudai_seen_keys", seen_set)
|
||||
if fudai_key and fudai_key not in seen_set:
|
||||
seen_set.add(fudai_key)
|
||||
analyser._log_kv(
|
||||
"统计",
|
||||
"fudai_seen",
|
||||
metric="fudai_seen",
|
||||
metric_type="unique",
|
||||
run_id=getattr(analyser, "_run_id", None),
|
||||
fudai_key=fudai_key,
|
||||
value=1,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 记录进入直播间到识别到福袋的耗时(仅记录一次)
|
||||
try:
|
||||
if getattr(analyser, "_enter_live_ts", 0.0) and not getattr(
|
||||
@@ -2181,6 +2230,39 @@ def attend_choujiang(analyser) -> bool:
|
||||
analyser._log_kv("参与", "识别参与按钮", text=attend_button_text)
|
||||
if "参与成功" in attend_button_text: # 如果识别到已经参与抽奖
|
||||
analyser._log_kv("参与", "已参与,等待开奖", result="已参与")
|
||||
# 结构化统计:参与成功(已参与检测)
|
||||
try:
|
||||
fudai_key = _build_fudai_key_from_analyser(analyser)
|
||||
analyser._log_kv(
|
||||
"统计",
|
||||
"fudai_attend_ok",
|
||||
metric="fudai_attend_ok",
|
||||
metric_type="attempt",
|
||||
run_id=getattr(analyser, "_run_id", None),
|
||||
fudai_key=fudai_key,
|
||||
value=1,
|
||||
)
|
||||
# 唯一口径
|
||||
try:
|
||||
att_set = getattr(analyser, "_fudai_attend_keys", None)
|
||||
if att_set is None:
|
||||
att_set = set()
|
||||
setattr(analyser, "_fudai_attend_keys", att_set)
|
||||
if fudai_key and fudai_key not in att_set:
|
||||
att_set.add(fudai_key)
|
||||
analyser._log_kv(
|
||||
"统计",
|
||||
"fudai_attend_ok",
|
||||
metric="fudai_attend_ok",
|
||||
metric_type="unique",
|
||||
run_id=getattr(analyser, "_run_id", None),
|
||||
fudai_key=fudai_key,
|
||||
value=1,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception:
|
||||
pass
|
||||
# 记录最后一次成功参与的时间
|
||||
try:
|
||||
analyser._last_successful_attend_ts = time.time()
|
||||
@@ -2314,6 +2396,20 @@ def attend_choujiang(analyser) -> bool:
|
||||
base_y=2070,
|
||||
region="(306,2030)-(780,2110)",
|
||||
)
|
||||
# 结构化统计:点击参与(attempt)
|
||||
try:
|
||||
fudai_key = _build_fudai_key_from_analyser(analyser)
|
||||
analyser._log_kv(
|
||||
"统计",
|
||||
"fudai_click_attend",
|
||||
metric="fudai_click_attend",
|
||||
metric_type="attempt",
|
||||
run_id=getattr(analyser, "_run_id", None),
|
||||
fudai_key=fudai_key,
|
||||
value=1,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 设置标志:点击参与抽奖后直接查找福袋,跳过阶段检测
|
||||
# 注意:点击参与按钮后会自动关闭详情页,返回直播间
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import annotations
|
||||
|
||||
"""
|
||||
滑动操作模块
|
||||
============
|
||||
@@ -10,6 +8,7 @@ from __future__ import annotations
|
||||
- 滑动次数重置
|
||||
- 返回推荐页并重新进入
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from __future__ import annotations
|
||||
|
||||
"""
|
||||
预约管理模块
|
||||
============
|
||||
@@ -10,6 +8,7 @@ from __future__ import annotations
|
||||
- 根据标题查找位置
|
||||
- 记录直播间标题和位置
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
import difflib
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
"""
|
||||
直播间标题处理模块
|
||||
==================
|
||||
|
||||
处理直播间标题的OCR识别、噪音过滤、规范化等功能。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Tuple, List
|
||||
from douyin.fudai.core.coords import LIVE_ROOM_TITLE
|
||||
|
||||
+15
-5
@@ -3175,6 +3175,7 @@ def main():
|
||||
|
||||
# 快速汇总(关键指标)
|
||||
fudai_seen = counters.get("fudai_seen", 0)
|
||||
fudai_seen_unique = counters.get("fudai_seen_unique", 0)
|
||||
fudai_attend_ok = counters.get("fudai_attend_ok", 0)
|
||||
fudai_result_win = counters.get("fudai_result_win", 0)
|
||||
fudai_order_success = counters.get("fudai_order_success", 0)
|
||||
@@ -3183,7 +3184,9 @@ def main():
|
||||
lines.append("=" * 60)
|
||||
lines.append("快速汇总")
|
||||
lines.append("=" * 60)
|
||||
lines.append(f"识别福袋: {fudai_seen} 个")
|
||||
lines.append(
|
||||
f"识别福袋: {fudai_seen} 个 (唯一次数: {fudai_seen_unique})"
|
||||
)
|
||||
lines.append(f"参与成功: {fudai_attend_ok} 次")
|
||||
lines.append(f"中奖次数: {fudai_result_win} 次")
|
||||
lines.append(f"下单成功: {fudai_order_success} 次")
|
||||
@@ -3202,25 +3205,32 @@ def main():
|
||||
|
||||
# 福袋相关核心指标(重新获取,避免重复定义)
|
||||
fudai_open_detail = counters.get("fudai_open_detail", 0)
|
||||
fudai_open_detail_unique = counters.get("fudai_open_detail_unique", 0)
|
||||
fudai_click_attend = counters.get("fudai_click_attend", 0)
|
||||
fudai_click_attend_unique = counters.get("fudai_click_attend_unique", 0)
|
||||
fudai_attend_ok = counters.get("fudai_attend_ok", 0)
|
||||
fudai_attend_ok_unique = counters.get("fudai_attend_ok_unique", 0)
|
||||
fudai_attend_fail = counters.get("fudai_attend_fail", 0)
|
||||
fudai_result_win = counters.get("fudai_result_win", 0)
|
||||
fudai_result_no_win = counters.get("fudai_result_no_win", 0)
|
||||
fudai_order_success = counters.get("fudai_order_success", 0)
|
||||
|
||||
lines.append(f"福袋识别次数: {fudai_seen}")
|
||||
lines.append(f"打开详情: {fudai_open_detail}")
|
||||
lines.append(f"福袋识别次数: {fudai_seen} (唯一次数: {fudai_seen_unique})")
|
||||
lines.append(
|
||||
f"打开详情: {fudai_open_detail} (唯一次数: {fudai_open_detail_unique})"
|
||||
)
|
||||
if fudai_seen > 0:
|
||||
open_rate = (fudai_open_detail / fudai_seen) * 100
|
||||
lines.append(f" 打开成功率: {open_rate:.1f}%")
|
||||
|
||||
lines.append(f"点击参与: {fudai_click_attend}")
|
||||
lines.append(
|
||||
f"点击参与: {fudai_click_attend} (唯一次数: {fudai_click_attend_unique})"
|
||||
)
|
||||
if fudai_open_detail > 0:
|
||||
click_rate = (fudai_click_attend / fudai_open_detail) * 100
|
||||
lines.append(f" 点击率: {click_rate:.1f}%")
|
||||
|
||||
lines.append(f"参与成功: {fudai_attend_ok}")
|
||||
lines.append(f"参与成功: {fudai_attend_ok} (唯一次数: {fudai_attend_ok_unique})")
|
||||
lines.append(f"参与失败: {fudai_attend_fail}")
|
||||
# 参与成功率应该基于点击参与次数来计算
|
||||
# 因为参与成功可能包括"检测到已参与"的情况(没有点击)
|
||||
|
||||
+30
-1
@@ -156,7 +156,7 @@ class Runner:
|
||||
"""
|
||||
try:
|
||||
with self._lock:
|
||||
content = (self._fudai_last.get("content") or "")
|
||||
content = self._fudai_last.get("content") or ""
|
||||
prize = str(self._fudai_last.get("prize_value_yuan") or "")
|
||||
countdown = str(self._fudai_last.get("countdown") or "")
|
||||
key = f"{content}|{prize}|{countdown}"
|
||||
@@ -214,6 +214,14 @@ class Runner:
|
||||
if content_extracted:
|
||||
self._inc("fudai_seen")
|
||||
self._record_event("fudai_seen", self._snapshot_fudai())
|
||||
# 唯一口径:基于 snapshot 的 content/prize/countdown 去重
|
||||
try:
|
||||
key = self._make_unique_key()
|
||||
if key and key not in self._unique_keys_seen:
|
||||
self._unique_keys_seen.add(key)
|
||||
self._inc("fudai_seen_unique")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 参与人数:支持多种格式
|
||||
m = re.search(r"(?:字段_)?参与人数[=:]?\s*(\d+)", s)
|
||||
@@ -265,11 +273,25 @@ class Runner:
|
||||
if "点击打开福袋详情" in s or ("[流程]" in s and "检测到福袋图标并点击" in s):
|
||||
self._inc("fudai_open_detail")
|
||||
self._record_event("fudai_open_detail", self._snapshot_fudai())
|
||||
try:
|
||||
key = self._make_unique_key()
|
||||
if key and key not in self._unique_keys_open:
|
||||
self._unique_keys_open.add(key)
|
||||
self._inc("fudai_open_detail_unique")
|
||||
except Exception:
|
||||
pass
|
||||
if "点击参与抽奖" in s or (
|
||||
"[参与]" in s and ("动作=点击参与" in s or "动作=参与" in s)
|
||||
):
|
||||
self._inc("fudai_click_attend")
|
||||
self._record_event("fudai_click_attend", self._snapshot_fudai())
|
||||
try:
|
||||
key = self._make_unique_key()
|
||||
if key and key not in self._unique_keys_attend:
|
||||
self._unique_keys_attend.add(key)
|
||||
self._inc("fudai_click_attend_unique")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# 参与成功/已参与:支持更多格式
|
||||
if (
|
||||
@@ -285,6 +307,13 @@ class Runner:
|
||||
):
|
||||
self._inc("fudai_attend_ok")
|
||||
self._record_event("fudai_attend_ok", self._snapshot_fudai())
|
||||
try:
|
||||
key = self._make_unique_key()
|
||||
if key and key not in self._unique_keys_attend:
|
||||
self._unique_keys_attend.add(key)
|
||||
self._inc("fudai_attend_ok_unique")
|
||||
except Exception:
|
||||
pass
|
||||
if "参与抽奖失败" in s or ("[参与]" in s and "结果=失败" in s):
|
||||
self._inc("fudai_attend_fail")
|
||||
self._record_event("fudai_attend_fail", self._snapshot_fudai())
|
||||
|
||||
Reference in new issue
Block a user