Compare commits

..

13 Commits
1.2.0 ... 1.2.6

Author SHA1 Message Date
c9f6817c6a 🔖 1.2.6 2024-05-15 08:56:46 +08:00
4c7cd00a76 🐛 修复 histories 只有一条时推算数据出现除数为0的bug 2024-05-15 08:56:22 +08:00
b8cf10b45d 🔖 1.2.5 2024-05-15 04:43:30 +08:00
4ec5c3bde1 🐛 修复 TETR.IO 大写用户名查询失败 2024-05-15 04:42:27 +08:00
270b953bc9 🔖 1.2.4 2024-05-15 04:22:58 +08:00
13bd0da592 🐛 修复去重添加没有正确工作的bug 2024-05-15 04:22:19 +08:00
9545f0b5d0 🔖 1.2.3 2024-05-14 17:26:07 +08:00
12f320cbb4 🐛 修复 PydanticType 过早加载导致获取不到子类的bug 2024-05-14 17:25:42 +08:00
7ff59cfc01 🔖 1.2.2 2024-05-14 17:09:53 +08:00
498781f376 ✏️ 变量名写错了 2024-05-14 17:09:29 +08:00
a3c00dbd93 🔖 1.2.1 2024-05-14 17:00:33 +08:00
069d5953f9 🐛 修复 TETR.IO User Records 解析失败的bug 2024-05-14 17:00:07 +08:00
3721d92f52 🔇 忘记删 debug 日志了 2024-05-14 16:20:57 +08:00
6 changed files with 26 additions and 16 deletions

View File

@@ -1,3 +1,4 @@
from asyncio import Lock
from collections.abc import AsyncGenerator
from contextlib import asynccontextmanager
from datetime import datetime, timezone
@@ -72,9 +73,11 @@ async def create_or_update_bind(
T = TypeVar('T', 'TETRIOHistoricalData', 'TOPHistoricalData', 'TOSHistoricalData')
lock = Lock()
async def anti_duplicate_add(cls: type[T], model: T) -> None:
async with get_session() as session:
async with lock, get_session() as session:
result = (
await session.scalars(
select(cls)
@@ -88,8 +91,8 @@ async def anti_duplicate_add(cls: type[T], model: T) -> None:
if i.data == model.data:
logger.debug('Anti duplicate successfully')
return
session.add(model)
await session.commit()
session.add(model)
await session.commit()
@asynccontextmanager
@@ -121,12 +124,10 @@ async def trigger(
command_type: CommandType | Literal['rank'],
command_args: list[str],
) -> AsyncGenerator:
logger.debug('running')
trigger_time = datetime.now(UTC)
try:
yield
except FinishedException:
logger.debug('yield')
async with get_session() as session:
session.add(
TriggerHistoricalData(

View File

@@ -23,9 +23,8 @@ class PydanticType(TypeDecorator):
*args: Any,
**kwargs: Any,
):
for i in get_model:
models.update(i())
self.models = models
self.get_model = get_model
self._models = models
super().__init__(*args, **kwargs)
if PYDANTIC_V2:
@@ -33,7 +32,7 @@ class PydanticType(TypeDecorator):
@override
def process_bind_param(self, value: Any | None, dialect: Dialect) -> str:
# 将 Pydantic 模型实例转换为 JSON
if isinstance(value, tuple(self.pydantic_models)):
if isinstance(value, tuple(self.models)):
return value.model_dump_json(by_alias=True) # type: ignore[union-attr]
raise TypeError
else:
@@ -41,7 +40,7 @@ class PydanticType(TypeDecorator):
@override
def process_bind_param(self, value: Any | None, dialect: Dialect) -> str:
# 将 Pydantic 模型实例转换为 JSON
if isinstance(value, tuple(self.pydantic_models)):
if isinstance(value, tuple(self.models)):
return value.json(by_alias=True) # type: ignore[union-attr]
raise TypeError
@@ -49,13 +48,21 @@ class PydanticType(TypeDecorator):
def process_result_value(self, value: Any | None, dialect: Dialect) -> BaseModel:
# 将 JSON 转换回 Pydantic 模型实例
if isinstance(value, str | bytes):
for i in self.pydantic_models:
for i in self.models:
try:
return type_validate_json(i, value)
except ValidationError: # noqa: PERF203
...
raise ValueError
@property
def models(self) -> tuple[type[BaseModel], ...]:
models: set[type[BaseModel]] = set()
for i in self.get_model:
models.update(i())
models.update(self._models)
return tuple(models)
class Bind(MappedAsDataclass, Model):
id: Mapped[int] = mapped_column(init=False, primary_key=True)

View File

@@ -43,7 +43,7 @@ class Player:
if self.user_id is not None:
return self.user_id
if self.user_name is not None:
return self.user_name
return self.user_name.lower()
msg = 'Invalid user'
raise ValueError(msg)

View File

@@ -2,6 +2,7 @@ from datetime import datetime
from pydantic import BaseModel, Field
from .....utils.typing import Number
from .base import FailedModel
from .base import SuccessModel as BaseSuccessModel
@@ -45,7 +46,7 @@ class Finesse(BaseModel):
class EndContext(BaseModel):
seed: int
seed: Number
lines: int
level_lines: int
level_lines_needed: int

View File

@@ -172,9 +172,10 @@ async def query_historical_data(user: User, user_info: UserInfoSuccess) -> list[
# 按照时间排序
histories = sorted(histories, key=lambda x: x.record_at)
print(histories)
for index, value in enumerate(histories):
# 在历史记录里找有没有今天0点后的数据
if value.record_at > today:
# 在历史记录里找有没有今天0点后的数据, 并且至少要有两个数据点
if value.record_at > today and len(histories) >= 2: # noqa: PLR2004
histories = histories[:index] + [
get_specified_point(histories[index - 1], histories[index], today.replace(microsecond=1000))
]

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = 'nonebot-plugin-tetris-stats'
version = '1.2.0'
version = '1.2.6'
description = '一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件'
authors = ['scdhh <wallfjjd@gmail.com>']
readme = 'README.md'