re-style: 格式化代码
This commit is contained in:
committed by
Windpicker-owo
parent
00ba07e0e1
commit
a79253c714
@@ -16,8 +16,7 @@ Chat Frequency Analyzer
|
||||
"""
|
||||
|
||||
import time as time_module
|
||||
from datetime import datetime, timedelta, time
|
||||
from typing import List, Tuple, Optional
|
||||
from datetime import datetime, time, timedelta
|
||||
|
||||
from .tracker import chat_frequency_tracker
|
||||
|
||||
@@ -42,7 +41,7 @@ class ChatFrequencyAnalyzer:
|
||||
self._cache_ttl_seconds = 60 * 30 # 缓存30分钟
|
||||
|
||||
@staticmethod
|
||||
def _find_peak_windows(timestamps: List[float]) -> List[Tuple[datetime, datetime]]:
|
||||
def _find_peak_windows(timestamps: list[float]) -> list[tuple[datetime, datetime]]:
|
||||
"""
|
||||
使用滑动窗口算法来识别时间戳列表中的高峰时段。
|
||||
|
||||
@@ -59,7 +58,7 @@ class ChatFrequencyAnalyzer:
|
||||
datetimes = [datetime.fromtimestamp(ts) for ts in timestamps]
|
||||
datetimes.sort()
|
||||
|
||||
peak_windows: List[Tuple[datetime, datetime]] = []
|
||||
peak_windows: list[tuple[datetime, datetime]] = []
|
||||
window_start_idx = 0
|
||||
|
||||
for i in range(len(datetimes)):
|
||||
@@ -83,7 +82,7 @@ class ChatFrequencyAnalyzer:
|
||||
|
||||
return peak_windows
|
||||
|
||||
def get_peak_chat_times(self, chat_id: str) -> List[Tuple[time, time]]:
|
||||
def get_peak_chat_times(self, chat_id: str) -> list[tuple[time, time]]:
|
||||
"""
|
||||
获取指定用户的高峰聊天时间段。
|
||||
|
||||
@@ -116,7 +115,7 @@ class ChatFrequencyAnalyzer:
|
||||
|
||||
return peak_time_windows
|
||||
|
||||
def is_in_peak_time(self, chat_id: str, now: Optional[datetime] = None) -> bool:
|
||||
def is_in_peak_time(self, chat_id: str, now: datetime | None = None) -> bool:
|
||||
"""
|
||||
检查当前时间是否处于用户的高峰聊天时段内。
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import orjson
|
||||
import time
|
||||
from typing import Dict, List, Optional
|
||||
from pathlib import Path
|
||||
|
||||
import orjson
|
||||
|
||||
from src.common.logger import get_logger
|
||||
|
||||
# 数据存储路径
|
||||
@@ -19,10 +19,10 @@ class ChatFrequencyTracker:
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
self._timestamps: Dict[str, List[float]] = self._load_timestamps()
|
||||
self._timestamps: dict[str, list[float]] = self._load_timestamps()
|
||||
|
||||
@staticmethod
|
||||
def _load_timestamps() -> Dict[str, List[float]]:
|
||||
def _load_timestamps() -> dict[str, list[float]]:
|
||||
"""从本地文件加载时间戳数据。"""
|
||||
if not TRACKER_FILE.exists():
|
||||
return {}
|
||||
@@ -61,7 +61,7 @@ class ChatFrequencyTracker:
|
||||
logger.debug(f"为 chat_id '{chat_id}' 记录了新的聊天时间: {now}")
|
||||
self._save_timestamps()
|
||||
|
||||
def get_timestamps_for_chat(self, chat_id: str) -> Optional[List[float]]:
|
||||
def get_timestamps_for_chat(self, chat_id: str) -> list[float] | None:
|
||||
"""
|
||||
获取指定聊天的所有时间戳记录。
|
||||
|
||||
|
||||
@@ -18,11 +18,10 @@ Frequency-Based Proactive Trigger
|
||||
import asyncio
|
||||
import time
|
||||
from datetime import datetime
|
||||
from typing import Dict, Optional
|
||||
|
||||
from src.common.logger import get_logger
|
||||
# AFC manager has been moved to chatter plugin
|
||||
|
||||
# AFC manager has been moved to chatter plugin
|
||||
# TODO: 需要重新实现主动思考和睡眠管理功能
|
||||
from .analyzer import chat_frequency_analyzer
|
||||
|
||||
@@ -42,10 +41,10 @@ class FrequencyBasedTrigger:
|
||||
|
||||
def __init__(self):
|
||||
# TODO: 需要重新实现睡眠管理器
|
||||
self._task: Optional[asyncio.Task] = None
|
||||
self._task: asyncio.Task | None = None
|
||||
# 记录上次为用户触发的时间,用于冷却控制
|
||||
# 格式: { "chat_id": timestamp }
|
||||
self._last_triggered: Dict[str, float] = {}
|
||||
self._last_triggered: dict[str, float] = {}
|
||||
|
||||
async def _run_trigger_cycle(self):
|
||||
"""触发器的主要循环逻辑。"""
|
||||
|
||||
Reference in New Issue
Block a user