mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
✨ 适配 Trending (#539)
* ✨ 适配 v1 tetrio 的 Trending * 🗃️ 添加 compare_delta 配置项 * 🗃️ 添加 TETRIOLeagueUserMap 索引表 * ✨ 添加对比时间配置项 * ✨ 添加 compare_delta 解析函数 * ✨ 添加 Trending 类的 compare 方法 * 🗃️ 移除不正确的复合索引 * ✨ 定时任务拉取tl数据时同步更新索引 * ✨ 适配 trending * 🐛 修复 find_entry 在无 uid 时的索引返回逻辑 * 📝 修正 compare_delta 迁移父迁移注释 * 🗃️ 为非 PostgreSQL 回填迁移补充外键约束 * 🔒 迁移中使用参数绑定设置 PG 内存参数 * ✨ 修正 Trends 的 vs 为 adpm * 🐛 修正获取玩家 ID 的范围
This commit is contained in:
28
nonebot_plugin_tetris_stats/utils/duration.py
Normal file
28
nonebot_plugin_tetris_stats/utils/duration.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from datetime import timedelta
|
||||
|
||||
from .exception import MessageFormatError
|
||||
|
||||
DEFAULT_COMPARE_DELTA = timedelta(days=7)
|
||||
_MIN_DURATION_LEN = 2
|
||||
_DURATION_UNITS = {
|
||||
'w': 'weeks',
|
||||
'd': 'days',
|
||||
'h': 'hours',
|
||||
'm': 'minutes',
|
||||
's': 'seconds',
|
||||
}
|
||||
|
||||
|
||||
def parse_duration(value: str) -> timedelta | MessageFormatError:
|
||||
raw = value.strip().lower()
|
||||
if raw.isdigit():
|
||||
return timedelta(days=int(raw))
|
||||
if len(raw) < _MIN_DURATION_LEN or not raw[:-1].isdigit():
|
||||
return MessageFormatError('时间格式不正确')
|
||||
amount = int(raw[:-1])
|
||||
if amount <= 0:
|
||||
return MessageFormatError('时间格式不正确')
|
||||
unit = _DURATION_UNITS.get(raw[-1])
|
||||
if unit is None:
|
||||
return MessageFormatError('时间格式不正确')
|
||||
return timedelta(**{unit: amount})
|
||||
@@ -41,3 +41,11 @@ class Trending(StrEnum):
|
||||
UP = 'up'
|
||||
KEEP = 'keep'
|
||||
DOWN = 'down'
|
||||
|
||||
@classmethod
|
||||
def compare(cls, old: float, new: float) -> 'Trending':
|
||||
if old > new:
|
||||
return cls.DOWN
|
||||
if old < new:
|
||||
return cls.UP
|
||||
return cls.KEEP
|
||||
|
||||
@@ -2,8 +2,21 @@ from typing import Literal, TypeAlias
|
||||
|
||||
Number: TypeAlias = float | int
|
||||
GameType: TypeAlias = Literal['IO', 'TOP', 'TOS']
|
||||
BaseCommandType: TypeAlias = Literal['bind', 'unbind', 'query']
|
||||
TETRIOCommandType: TypeAlias = BaseCommandType | Literal['rank', 'config', 'list', 'record', 'verify']
|
||||
BaseCommandType: TypeAlias = Literal[
|
||||
'bind',
|
||||
'config',
|
||||
'query',
|
||||
'unbind',
|
||||
]
|
||||
TETRIOCommandType: TypeAlias = (
|
||||
BaseCommandType
|
||||
| Literal[
|
||||
'list',
|
||||
'rank',
|
||||
'record',
|
||||
'verify',
|
||||
]
|
||||
)
|
||||
AllCommandType: TypeAlias = BaseCommandType | TETRIOCommandType
|
||||
Me: TypeAlias = Literal[
|
||||
'我',
|
||||
|
||||
Reference in New Issue
Block a user