feat: 添加唯一计数去重功能,优化胜利记录逻辑
This commit is contained in:
1 parent
9009b15a2b
commit
90b7daa84e
3 files changed
+58
-58
No files matched your search
@@ -126,6 +126,10 @@ class Runner:
|
||||
self._events_cap: int = 5000
|
||||
self._wins: list[dict] = []
|
||||
self._wins_cap: int = 200
|
||||
# 唯一计数去重集合(用于展示“唯一成功次数”口径)
|
||||
self._unique_keys_seen: set[str] = set()
|
||||
self._unique_keys_open: set[str] = set()
|
||||
self._unique_keys_attend: set[str] = set()
|
||||
|
||||
def is_running(self) -> bool:
|
||||
return self._proc is not None and self._proc.poll() is None
|
||||
@@ -145,6 +149,21 @@ class Runner:
|
||||
if len(self._events) > self._events_cap:
|
||||
self._events = self._events[-self._events_cap :]
|
||||
|
||||
def _make_unique_key(self) -> str:
|
||||
"""根据当前 snapshot 生成一个尽可能稳定的唯一键(用于去重)。
|
||||
|
||||
使用 content/prize_value/countdown 三元组,如果不可用则返回空字符串。
|
||||
"""
|
||||
try:
|
||||
with self._lock:
|
||||
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}"
|
||||
return key
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
def _record_win(self) -> None:
|
||||
item = {
|
||||
"ts": time.time(),
|
||||
|
||||
Reference in new issue
Block a user